Skip to content

Commit

Permalink
debug/elf: don't apply DWARF relocations for ET_EXEC binaries
Browse files Browse the repository at this point in the history
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 <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
  • Loading branch information
vikmik authored and ianlancetaylor committed Jun 14, 2021
1 parent 9d13f8d commit 8a5a6f4
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/debug/elf/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,13 @@ func (f *File) DWARF() (*dwarf.Data, error) {
b = dbuf
}

if f.Type == ET_EXEC {
// Do not apply relocations to DWARF sections for ET_EXEC binaries.
// Relocations should already be applied, and .rela sections may
// contain incorrect data.
return b, nil
}

for _, r := range f.Sections {
if r.Type != SHT_RELA && r.Type != SHT_REL {
continue
Expand Down

0 comments on commit 8a5a6f4

Please sign in to comment.