diff options
author | Than McIntosh <thanm@google.com> | 2020-10-16 09:22:31 -0400 |
---|---|---|
committer | Than McIntosh <thanm@google.com> | 2020-10-30 18:01:54 +0000 |
commit | fb184a383e756cb57267590ac290be0d3bb64874 (patch) | |
tree | 5724424b3d307f99ea52ba75a100e92c5dab0f6a /src/debug | |
parent | e02ab89eb8994fa6f2dfa2924cdadb097633fcc1 (diff) | |
download | go-fb184a383e756cb57267590ac290be0d3bb64874.tar.gz go-fb184a383e756cb57267590ac290be0d3bb64874.zip |
cmd/link: emit include directories in DWARF line table prologue
This patch changes the way the linker emits the DWARF line table
prologue, specifically the file table. Previously files were left
unmodified, and the directory table was empty. For each compilation
unit we now scan the unit file table and build up a common set of
directories, emit them into the directory table, and then emit file
entries that refer to the dirs. This provides a modest binary size
savings.
For kubernetes kubelet:
$ objdump -h /tmp/kubelet.old | fgrep debug_line
36 .zdebug_line 019a55f5 0000000000000000 0000000000000000 084a5123 2**0
$ objdump -h /tmp/kubelet.new | fgrep debug_line
36 .zdebug_line 01146fd2 0000000000000000 0000000000000000 084a510a 2**0
[where the value following the section name above is the section size
in hex, so roughly a 30% decrease in this case.]
The actual savings will depend on the length of the pathnames
involved, so it's hard to really pin down how much savings we'll see
here. In addition, emitting the files this way reduces the
"compressibility" of the line table, so there could even be cases
where we don't win at all.
Updates #6853, #19784, #36495.
Change-Id: I298d8561da5ed3ebc9d38aa772874851baa2f4f4
Reviewed-on: https://go-review.googlesource.com/c/go/+/263017
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Trust: Than McIntosh <thanm@google.com>
Diffstat (limited to 'src/debug')
-rw-r--r-- | src/debug/dwarf/line.go | 6 | ||||
-rw-r--r-- | src/debug/dwarf/line_test.go | 8 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/debug/dwarf/line.go b/src/debug/dwarf/line.go index 7692f05552..c4937ca7dd 100644 --- a/src/debug/dwarf/line.go +++ b/src/debug/dwarf/line.go @@ -814,7 +814,11 @@ func pathJoin(dirname, filename string) string { // Drives are the same. Ignore drive on filename. } if !(strings.HasSuffix(dirname, "/") || strings.HasSuffix(dirname, `\`)) && dirname != "" { - dirname += `\` + sep := `\` + if strings.HasPrefix(dirname, "/") { + sep = `/` + } + dirname += sep } return drive + dirname + filename } diff --git a/src/debug/dwarf/line_test.go b/src/debug/dwarf/line_test.go index 1fd9b19b03..b13818e8b5 100644 --- a/src/debug/dwarf/line_test.go +++ b/src/debug/dwarf/line_test.go @@ -341,6 +341,14 @@ var joinTests = []joinTest{ {`\\host\share\`, `foo\bar`, `\\host\share\foo\bar`}, {`//host/share/`, `foo/bar`, `//host/share/foo/bar`}, + // Note: the Go compiler currently emits DWARF line table paths + // with '/' instead of '\' (see issues #19784, #36495). These + // tests are to cover cases that might come up for Windows Go + // binaries. + {`c:/workdir/go/src/x`, `y.go`, `c:/workdir/go/src/x/y.go`}, + {`d:/some/thing/`, `b.go`, `d:/some/thing/b.go`}, + {`e:\blah\`, `foo.c`, `e:\blah\foo.c`}, + // The following are "best effort". We shouldn't see relative // base directories in DWARF, but these test that pathJoin // doesn't fail miserably if it sees one. |