diff options
Diffstat (limited to 'src/debug/elf/file.go')
-rw-r--r-- | src/debug/elf/file.go | 77 |
1 files changed, 30 insertions, 47 deletions
diff --git a/src/debug/elf/file.go b/src/debug/elf/file.go index 1e863ef78e..cd5bf8fab0 100644 --- a/src/debug/elf/file.go +++ b/src/debug/elf/file.go @@ -628,23 +628,14 @@ func (f *File) applyRelocations(dst []byte, rels []byte) error { } } -// relocSymbolTargetOK decides whether we should try to apply a +// canApplyRelocation reports whether we should try to apply a // relocation to a DWARF data section, given a pointer to the symbol -// targeted by the relocation. Most relocations in DWARF data tend to -// be section-relative, but some target non-section symbols (for -// example, low_PC attrs on subprogram or compilation unit DIEs that -// target function symbols), and we need to include these as well. -// Return value is a pair (X,Y) where X is a boolean indicating -// whether the relocation is needed, and Y is the symbol value in the -// case of a non-section relocation that needs to be applied. -func relocSymbolTargetOK(sym *Symbol) (bool, uint64) { - if ST_TYPE(sym.Info) == STT_SECTION { - return true, 0 - } - if sym.Section != SHN_UNDEF && sym.Section < SHN_LORESERVE { - return true, sym.Value - } - return false, 0 +// targeted by the relocation. +// Most relocations in DWARF data tend to be section-relative, but +// some target non-section symbols (for example, low_PC attrs on +// subprogram or compilation unit DIEs that target function symbols). +func canApplyRelocation(sym *Symbol) bool { + return sym.Section != SHN_UNDEF && sym.Section < SHN_LORESERVE } func (f *File) applyRelocationsAMD64(dst []byte, rels []byte) error { @@ -670,8 +661,7 @@ func (f *File) applyRelocationsAMD64(dst []byte, rels []byte) error { continue } sym := &symbols[symNo-1] - needed, val := relocSymbolTargetOK(sym) - if !needed { + if !canApplyRelocation(sym) { continue } @@ -684,13 +674,13 @@ func (f *File) applyRelocationsAMD64(dst []byte, rels []byte) error { if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val64 := val + uint64(rela.Addend) + val64 := sym.Value + uint64(rela.Addend) f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], val64) case R_X86_64_32: if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val32 := uint32(val) + uint32(rela.Addend) + val32 := uint32(sym.Value) + uint32(rela.Addend) f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32) } } @@ -796,8 +786,7 @@ func (f *File) applyRelocationsARM64(dst []byte, rels []byte) error { continue } sym := &symbols[symNo-1] - needed, val := relocSymbolTargetOK(sym) - if !needed { + if !canApplyRelocation(sym) { continue } @@ -810,13 +799,13 @@ func (f *File) applyRelocationsARM64(dst []byte, rels []byte) error { if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val64 := uint64(val) + uint64(rela.Addend) + val64 := sym.Value + uint64(rela.Addend) f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], val64) case R_AARCH64_ABS32: if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val32 := uint32(val) + uint32(rela.Addend) + val32 := uint32(sym.Value) + uint32(rela.Addend) f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32) } } @@ -847,8 +836,7 @@ func (f *File) applyRelocationsPPC(dst []byte, rels []byte) error { continue } sym := &symbols[symNo-1] - needed, val := relocSymbolTargetOK(sym) - if !needed { + if !canApplyRelocation(sym) { continue } @@ -857,7 +845,7 @@ func (f *File) applyRelocationsPPC(dst []byte, rels []byte) error { if rela.Off+4 >= uint32(len(dst)) || rela.Addend < 0 { continue } - val32 := uint32(val) + uint32(rela.Addend) + val32 := uint32(sym.Value) + uint32(rela.Addend) f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32) } } @@ -888,8 +876,7 @@ func (f *File) applyRelocationsPPC64(dst []byte, rels []byte) error { continue } sym := &symbols[symNo-1] - needed, val := relocSymbolTargetOK(sym) - if !needed { + if !canApplyRelocation(sym) { continue } @@ -898,13 +885,13 @@ func (f *File) applyRelocationsPPC64(dst []byte, rels []byte) error { if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val64 := val + uint64(rela.Addend) + val64 := sym.Value + uint64(rela.Addend) f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], val64) case R_PPC64_ADDR32: if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val32 := uint32(val) + uint32(rela.Addend) + val32 := uint32(sym.Value) + uint32(rela.Addend) f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32) } } @@ -980,8 +967,7 @@ func (f *File) applyRelocationsMIPS64(dst []byte, rels []byte) error { continue } sym := &symbols[symNo-1] - needed, val := relocSymbolTargetOK(sym) - if !needed { + if !canApplyRelocation(sym) { continue } @@ -990,13 +976,13 @@ func (f *File) applyRelocationsMIPS64(dst []byte, rels []byte) error { if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val64 := val + uint64(rela.Addend) + val64 := sym.Value + uint64(rela.Addend) f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], val64) case R_MIPS_32: if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val32 := uint32(val) + uint32(rela.Addend) + val32 := uint32(sym.Value) + uint32(rela.Addend) f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32) } } @@ -1027,8 +1013,7 @@ func (f *File) applyRelocationsRISCV64(dst []byte, rels []byte) error { continue } sym := &symbols[symNo-1] - needed, val := relocSymbolTargetOK(sym) - if !needed { + if !canApplyRelocation(sym) { continue } @@ -1037,13 +1022,13 @@ func (f *File) applyRelocationsRISCV64(dst []byte, rels []byte) error { if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val64 := val + uint64(rela.Addend) + val64 := sym.Value + uint64(rela.Addend) f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], val64) case R_RISCV_32: if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val32 := uint32(val) + uint32(rela.Addend) + val32 := uint32(sym.Value) + uint32(rela.Addend) f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32) } } @@ -1074,8 +1059,7 @@ func (f *File) applyRelocationss390x(dst []byte, rels []byte) error { continue } sym := &symbols[symNo-1] - needed, val := relocSymbolTargetOK(sym) - if !needed { + if !canApplyRelocation(sym) { continue } @@ -1084,13 +1068,13 @@ func (f *File) applyRelocationss390x(dst []byte, rels []byte) error { if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val64 := val + uint64(rela.Addend) + val64 := sym.Value + uint64(rela.Addend) f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], val64) case R_390_32: if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val32 := uint32(val) + uint32(rela.Addend) + val32 := uint32(sym.Value) + uint32(rela.Addend) f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32) } } @@ -1121,8 +1105,7 @@ func (f *File) applyRelocationsSPARC64(dst []byte, rels []byte) error { continue } sym := &symbols[symNo-1] - needed, val := relocSymbolTargetOK(sym) - if !needed { + if !canApplyRelocation(sym) { continue } @@ -1131,13 +1114,13 @@ func (f *File) applyRelocationsSPARC64(dst []byte, rels []byte) error { if rela.Off+8 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val64 := val + uint64(rela.Addend) + val64 := sym.Value + uint64(rela.Addend) f.ByteOrder.PutUint64(dst[rela.Off:rela.Off+8], val64) case R_SPARC_32, R_SPARC_UA32: if rela.Off+4 >= uint64(len(dst)) || rela.Addend < 0 { continue } - val32 := uint32(val) + uint32(rela.Addend) + val32 := uint32(sym.Value) + uint32(rela.Addend) f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], val32) } } |