diff options
| author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2011-07-20 12:47:02 -0300 |
|---|---|---|
| committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2011-07-20 12:47:02 -0300 |
| commit | ba2e3af1778da52340a9f3f7dd7262e5ebf64055 (patch) | |
| tree | 042764904ef3de91ac6038ae8622ffdffedeb748 /src/pkg/debug | |
| parent | 971459e826e705fc7c0ce4cd65609a19876627b1 (diff) | |
| download | go-ba2e3af1778da52340a9f3f7dd7262e5ebf64055.tar.xz | |
ld: remove overlap of ELF sections on dynamic binaries
The dynamic ELF sections were pointing to the proper data,
but that data was already owned by the rodata and text sections.
Some ELF references explicitly prohibit multiple sections from
owning the same data, and strip behaves accordingly.
The data for these sections was moved out and their ranges are
now owned by their respective sections. This change makes strip
happy both with and without -s being provided at link time.
A test was added in debug/elf to ensure there are no regressions
on this area in the future.
Fixes #1242.
Fixes #2022.
NOTE: Tested on Linux amd64/386/arm only.
R=rsc
CC=golang-dev
https://golang.org/cl/4808043
Diffstat (limited to 'src/pkg/debug')
| -rw-r--r-- | src/pkg/debug/elf/file_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/pkg/debug/elf/file_test.go b/src/pkg/debug/elf/file_test.go index 62e2f3b2df..451d3d5147 100644 --- a/src/pkg/debug/elf/file_test.go +++ b/src/pkg/debug/elf/file_test.go @@ -7,7 +7,10 @@ package elf import ( "debug/dwarf" "encoding/binary" + "net" + "os" "reflect" + "runtime" "testing" ) @@ -210,3 +213,29 @@ func TestDWARFRelocations(t *testing.T) { } } } + +func TestNoSectionOverlaps(t *testing.T) { + // Ensure 6l outputs sections without overlaps. + if runtime.GOOS != "linux" && runtime.GOOS != "freebsd" { + return // not ELF + } + _ = net.ResolveIPAddr // force dynamic linkage + f, err := Open(os.Args[0]) + if err != nil { + t.Error(err) + return + } + for i, si := range f.Sections { + sih := si.SectionHeader + for j, sj := range f.Sections { + sjh := sj.SectionHeader + if i == j || sjh.Type == SHT_NOBITS || sih.Offset == sjh.Offset && sih.Size == 0 { + continue + } + if sih.Offset >= sjh.Offset && sih.Offset < sjh.Offset+sjh.Size { + t.Errorf("ld produced ELF with section %s within %s: 0x%x <= 0x%x..0x%x < 0x%x", + sih.Name, sjh.Name, sjh.Offset, sih.Offset, sih.Offset+sih.Size, sjh.Offset+sjh.Size) + } + } + } +} |
