Skip to content

Commit 8a5a6f4

Browse files
vikmikianlancetaylor
authored andcommitted
debug/elf: don't apply DWARF relocations for ET_EXEC binaries
Some ET_EXEC binaries might have relocations for non-loadable sections like .debug_info. These relocations must not be applied, because: * They may be incorrect * The correct relocations were already applied at link time Binaries in Linux Kernel debug packages like Fedora/Centos kernel-debuginfo are such examples. Relocations for .debug_* sections are included in the final binaries because they are compiled with --emit-relocs, but the resulting relocations are incorrect and shouldn't be used when reading DWARF sections. Fixes #46673 Change-Id: I2b4214f1584bfc243446d0eaee41512657325b95 GitHub-Last-Rev: 8350fad GitHub-Pull-Request: #46698 Reviewed-on: https://go-review.googlesource.com/c/go/+/327009 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 9d13f8d commit 8a5a6f4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/debug/elf/file.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,13 @@ func (f *File) DWARF() (*dwarf.Data, error) {
11641164
b = dbuf
11651165
}
11661166

1167+
if f.Type == ET_EXEC {
1168+
// Do not apply relocations to DWARF sections for ET_EXEC binaries.
1169+
// Relocations should already be applied, and .rela sections may
1170+
// contain incorrect data.
1171+
return b, nil
1172+
}
1173+
11671174
for _, r := range f.Sections {
11681175
if r.Type != SHT_RELA && r.Type != SHT_REL {
11691176
continue

0 commit comments

Comments
 (0)