mirror of
https://github.com/golang/go
synced 2024-11-18 12:04:57 -07:00
[dev.link] cmd/link: fix R_GOTOFF handling
When applying relocations, we need to resolve ABI aliases. relocsym does that. Architecture-specific archreloc also needs to do that. The old code doesn't do that since ABI aliases are resolved in loadlibfull, or, in the old linker, in a much earlier stage. We don't do this in the new linker, as we want to avoid mutating relocations. While here, move R_CONST and R_GOTOFF handling to generic code. They appear on several architectures and the handling are same. Should fix 386-clang and *bsd-386 builds. Change-Id: I6681c94f0327555d6cf329d0a518c88848773671 Reviewed-on: https://go-review.googlesource.com/c/go/+/230857 Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
parent
095d2a4532
commit
df2a46f85a
@ -528,6 +528,12 @@ func relocsym(target *Target, ldr *loader.Loader, err *ErrorReporter, syms *Arch
|
||||
case objabi.R_DWARFFILEREF:
|
||||
// We don't renumber files in dwarf.go:writelines anymore.
|
||||
continue
|
||||
|
||||
case objabi.R_CONST:
|
||||
o = r.Add()
|
||||
|
||||
case objabi.R_GOTOFF:
|
||||
o = ldr.SymValue(rs) + r.Add() - ldr.SymValue(syms.GOT2)
|
||||
}
|
||||
|
||||
//if target.IsPPC64() || target.IsS390X() {
|
||||
|
@ -436,29 +436,6 @@ func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, secto
|
||||
}
|
||||
|
||||
func archreloc2(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r *loader.Reloc2, sym loader.Sym, val int64) (int64, bool) {
|
||||
if target.IsExternal() {
|
||||
return val, false
|
||||
}
|
||||
switch r.Type() {
|
||||
case objabi.R_CONST:
|
||||
return r.Add(), true
|
||||
case objabi.R_GOTOFF:
|
||||
return ldr.SymValue(r.Sym()) + r.Add() - ldr.SymValue(syms.GOT2), true
|
||||
}
|
||||
return val, false
|
||||
}
|
||||
|
||||
func archreloc(target *ld.Target, syms *ld.ArchSyms, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) {
|
||||
if target.IsExternal() {
|
||||
return val, false
|
||||
}
|
||||
switch r.Type {
|
||||
case objabi.R_CONST:
|
||||
return r.Add, true
|
||||
case objabi.R_GOTOFF:
|
||||
return ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(syms.GOT), true
|
||||
}
|
||||
|
||||
return val, false
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,6 @@ func Init() (*sys.Arch, ld.Arch) {
|
||||
|
||||
Adddynrel2: adddynrel2,
|
||||
Archinit: archinit,
|
||||
Archreloc: archreloc,
|
||||
Archreloc2: archreloc2,
|
||||
Archrelocvariant: archrelocvariant,
|
||||
Asmb: asmb,
|
||||
|
Loading…
Reference in New Issue
Block a user