Skip to content

Commit

Permalink
cmd/link: remove ABI aliases
Browse files Browse the repository at this point in the history
It is now gone.

Change-Id: I59f68b324af706476695de2f291dd3aa5734e192
Reviewed-on: https://go-review.googlesource.com/c/go/+/351332
Trust: Cherry Mui <[email protected]>
Run-TryBot: Cherry Mui <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Than McIntosh <[email protected]>
  • Loading branch information
cherrymui committed Sep 22, 2021
1 parent a630783 commit 55d22f7
Show file tree
Hide file tree
Showing 16 changed files with 23 additions and 66 deletions.
7 changes: 0 additions & 7 deletions src/cmd/internal/objabi/symkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ const (
SDWARFRANGE
SDWARFLOC
SDWARFLINES
// ABI alias. An ABI alias symbol is an empty symbol with a
// single relocation with 0 size that references the native
// function implementation symbol.
//
// TODO(austin): Remove this and all uses once the compiler
// generates real ABI wrappers rather than symbol aliases.
SABIALIAS
// Coverage instrumentation counter for libfuzzer.
SLIBFUZZER_EXTRA_COUNTER
// Update cmd/link/internal/sym/AbiSymKindToSymKind for new SymKind values.
Expand Down
7 changes: 3 additions & 4 deletions src/cmd/internal/objabi/symkind_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/cmd/link/internal/arm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,6 @@ func gentrampdyn(arch *sys.Arch, tramp *loader.SymbolBuilder, target loader.Sym,

func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loader.Reloc, s loader.Sym, val int64) (o int64, nExtReloc int, ok bool) {
rs := r.Sym()
rs = ldr.ResolveABIAlias(rs)
if target.IsExternal() {
switch r.Type() {
case objabi.R_CALLARM:
Expand Down Expand Up @@ -592,7 +591,7 @@ func archrelocvariant(*ld.Target, *loader.Loader, loader.Reloc, sym.RelocVariant
}

func extreloc(target *ld.Target, ldr *loader.Loader, r loader.Reloc, s loader.Sym) (loader.ExtReloc, bool) {
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
var rr loader.ExtReloc
switch r.Type() {
case objabi.R_CALLARM:
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/arm64/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
const noExtReloc = 0
const isOk = true

rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()

if target.IsExternal() {
nExtReloc := 0
Expand Down
16 changes: 6 additions & 10 deletions src/cmd/link/internal/ld/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func trampoline(ctxt *Link, s loader.Sym) {
if !ldr.AttrReachable(rs) || ldr.SymType(rs) == sym.Sxxx {
continue // something is wrong. skip it here and we'll emit a better error later
}
rs = ldr.ResolveABIAlias(rs)
if ldr.SymValue(rs) == 0 && (ldr.SymType(rs) != sym.SDYNIMPORT && ldr.SymType(rs) != sym.SUNDEFEXT) {
if ldr.SymPkg(s) != "" && ldr.SymPkg(rs) == ldr.SymPkg(s) {
// Symbols in the same package are laid out together.
Expand Down Expand Up @@ -194,7 +193,6 @@ func (st *relocSymState) relocsym(s loader.Sym, P []byte) {
off := r.Off()
siz := int32(r.Siz())
rs := r.Sym()
rs = ldr.ResolveABIAlias(rs)
rt := r.Type()
weak := r.Weak()
if off < 0 || off+siz > int32(len(P)) {
Expand Down Expand Up @@ -340,7 +338,6 @@ func (st *relocSymState) relocsym(s loader.Sym, P []byte) {
if weak && !ldr.AttrReachable(rs) {
// Redirect it to runtime.unreachableMethod, which will throw if called.
rs = syms.unreachableMethod
rs = ldr.ResolveABIAlias(rs)
}
if target.IsExternal() {
nExtReloc++
Expand Down Expand Up @@ -614,7 +611,7 @@ func extreloc(ctxt *Link, ldr *loader.Loader, s loader.Sym, r loader.Reloc) (loa

case objabi.R_TLS_LE, objabi.R_TLS_IE:
if target.IsElf() {
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
rr.Xsym = rs
if rr.Xsym == 0 {
rr.Xsym = ctxt.Tlsg
Expand All @@ -626,10 +623,9 @@ func extreloc(ctxt *Link, ldr *loader.Loader, s loader.Sym, r loader.Reloc) (loa

case objabi.R_ADDR:
// set up addend for eventual relocation via outer symbol.
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
if r.Weak() && !ldr.AttrReachable(rs) {
rs = ctxt.ArchSyms.unreachableMethod
rs = ldr.ResolveABIAlias(rs)
}
rs, off := FoldSubSymbolOffset(ldr, rs)
rr.Xadd = r.Add() + off
Expand All @@ -644,13 +640,13 @@ func extreloc(ctxt *Link, ldr *loader.Loader, s loader.Sym, r loader.Reloc) (loa
if target.IsDarwin() {
return rr, false
}
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
rr.Xsym = loader.Sym(ldr.SymSect(rs).Sym)
rr.Xadd = r.Add() + ldr.SymValue(rs) - int64(ldr.SymSect(rs).Vaddr)

// r.Sym() can be 0 when CALL $(constant) is transformed from absolute PC to relative PC call.
case objabi.R_GOTPCREL, objabi.R_CALL, objabi.R_PCREL:
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
if rt == objabi.R_GOTPCREL && target.IsDynlinkingGo() && target.IsDarwin() && rs != 0 {
rr.Xadd = r.Add()
rr.Xadd -= int64(siz) // relative to address after the relocated chunk
Expand Down Expand Up @@ -692,7 +688,7 @@ func extreloc(ctxt *Link, ldr *loader.Loader, s loader.Sym, r loader.Reloc) (loa
// symbol and addend.
func ExtrelocSimple(ldr *loader.Loader, r loader.Reloc) loader.ExtReloc {
var rr loader.ExtReloc
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
rr.Xsym = rs
rr.Xadd = r.Add()
rr.Type = r.Type()
Expand All @@ -705,7 +701,7 @@ func ExtrelocSimple(ldr *loader.Loader, r loader.Reloc) loader.ExtReloc {
func ExtrelocViaOuterSym(ldr *loader.Loader, r loader.Reloc, s loader.Sym) loader.ExtReloc {
// set up addend for eventual relocation via outer symbol.
var rr loader.ExtReloc
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
rs, off := FoldSubSymbolOffset(ldr, rs)
rr.Xadd = r.Add() + off
rst := ldr.SymType(rs)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/ld/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,7 @@ func (ctxt *Link) callgraph() {
if rs == 0 {
continue
}
if r.Type().IsDirectCall() && (ldr.SymType(rs) == sym.STEXT || ldr.SymType(rs) == sym.SABIALIAS) {
if r.Type().IsDirectCall() && ldr.SymType(rs) == sym.STEXT {
ctxt.Logf("%s calls %s\n", ldr.SymName(s), ldr.SymName(rs))
}
}
Expand Down
1 change: 0 additions & 1 deletion src/cmd/link/internal/ld/pe.go
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,6 @@ func addPEBaseRelocSym(ldr *loader.Loader, s loader.Sym, rt *peBaseRelocTable) {
continue
}
rs := r.Sym()
rs = ldr.ResolveABIAlias(rs)
if rs == 0 {
continue
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/link/internal/ld/xcoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ func Xcoffadddynrel(target *Target, ldr *loader.Loader, syms *ArchSyms, s loader
sym: s,
roff: r.Off(),
}
targ := ldr.ResolveABIAlias(r.Sym())
targ := r.Sym()
var targType sym.SymKind
if targ != 0 {
targType = ldr.SymType(targ)
Expand Down Expand Up @@ -1333,7 +1333,7 @@ func (ctxt *Link) doxcoff() {
panic("cgo_export on static symbol")
}

if ldr.SymType(s) == sym.STEXT || ldr.SymType(s) == sym.SABIALIAS {
if ldr.SymType(s) == sym.STEXT {
// On AIX, a exported function must have two symbols:
// - a .text symbol which must start with a ".".
// - a .data symbol which is a function descriptor.
Expand Down
22 changes: 0 additions & 22 deletions src/cmd/link/internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ type extSymPayload struct {
const (
// Loader.flags
FlagStrictDups = 1 << iota
FlagUseABIAlias
)

func NewLoader(flags uint32, elfsetstring elfsetstringFunc, reporter *ErrorReporter) *Loader {
Expand Down Expand Up @@ -2297,27 +2296,6 @@ func abiToVer(abi uint16, localSymVersion int) int {
return v
}

// ResolveABIAlias given a symbol returns the ABI alias target of that
// symbol. If the sym in question is not an alias, the sym itself is
// returned.
func (l *Loader) ResolveABIAlias(s Sym) Sym {
if l.flags&FlagUseABIAlias == 0 {
return s
}
if s == 0 {
return 0
}
if l.SymType(s) != sym.SABIALIAS {
return s
}
relocs := l.Relocs(s)
target := relocs.At(0).Sym()
if l.SymType(target) == sym.SABIALIAS {
panic(fmt.Sprintf("ABI alias %s references another ABI alias %s", l.SymName(s), l.SymName(target)))
}
return target
}

// TopLevelSym tests a symbol (by name and kind) to determine whether
// the symbol first class sym (participating in the link) or is an
// anonymous aux or sub-symbol containing some sub-part or payload of
Expand Down
1 change: 0 additions & 1 deletion src/cmd/link/internal/mips/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func applyrel(arch *sys.Arch, ldr *loader.Loader, rt objabi.RelocType, off int32

func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loader.Reloc, s loader.Sym, val int64) (o int64, nExtReloc int, ok bool) {
rs := r.Sym()
rs = ldr.ResolveABIAlias(rs)
if target.IsExternal() {
switch r.Type() {
default:
Expand Down
1 change: 0 additions & 1 deletion src/cmd/link/internal/mips64/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
const isOk = true
const noExtReloc = 0
rs := r.Sym()
rs = ldr.ResolveABIAlias(rs)
switch r.Type() {
case objabi.R_ADDRMIPS,
objabi.R_ADDRMIPSU:
Expand Down
10 changes: 5 additions & 5 deletions src/cmd/link/internal/ppc64/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func symtoc(ldr *loader.Loader, syms *ld.ArchSyms, s loader.Sym) int64 {
// symbol address can be used directly.
// This code is for AIX only.
func archreloctoc(ldr *loader.Loader, target *ld.Target, syms *ld.ArchSyms, r loader.Reloc, s loader.Sym, val int64) int64 {
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
if target.IsLinux() {
ldr.Errorf(s, "archrelocaddr called for %s relocation\n", ldr.SymName(rs))
}
Expand All @@ -562,7 +562,7 @@ func archreloctoc(ldr *loader.Loader, target *ld.Target, syms *ld.ArchSyms, r lo
var t int64
useAddi := false
relocs := ldr.Relocs(rs)
tarSym := ldr.ResolveABIAlias(relocs.At(0).Sym())
tarSym := relocs.At(0).Sym()

if target.IsInternal() && tarSym != 0 && ldr.AttrReachable(tarSym) && ldr.SymSect(tarSym).Seg == &ld.Segdata {
t = ldr.SymValue(tarSym) + r.Add() - ldr.SymValue(syms.TOC)
Expand Down Expand Up @@ -603,7 +603,7 @@ func archreloctoc(ldr *loader.Loader, target *ld.Target, syms *ld.ArchSyms, r lo
// archrelocaddr relocates a symbol address.
// This code is for AIX only.
func archrelocaddr(ldr *loader.Loader, target *ld.Target, syms *ld.ArchSyms, r loader.Reloc, s loader.Sym, val int64) int64 {
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
if target.IsAIX() {
ldr.Errorf(s, "archrelocaddr called for %s relocation\n", ldr.SymName(rs))
}
Expand Down Expand Up @@ -802,7 +802,7 @@ func gentramp(ctxt *ld.Link, ldr *loader.Loader, tramp *loader.SymbolBuilder, ta
}

func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loader.Reloc, s loader.Sym, val int64) (relocatedOffset int64, nExtReloc int, ok bool) {
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
if target.IsExternal() {
// On AIX, relocations (except TLS ones) must be also done to the
// value with the current addresses.
Expand Down Expand Up @@ -909,7 +909,7 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
}

func archrelocvariant(target *ld.Target, ldr *loader.Loader, r loader.Reloc, rv sym.RelocVariant, s loader.Sym, t int64, p []byte) (relocatedOffset int64) {
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
switch rv & sym.RV_TYPE_MASK {
default:
ldr.Errorf(s, "unexpected relocation variant %d", rv)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/riscv64/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func archreloc(target *ld.Target, ldr *loader.Loader, syms *ld.ArchSyms, r loade
return val, 0, false
}

rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()

switch r.Type() {
case objabi.R_CALLRISCV:
Expand Down
4 changes: 0 additions & 4 deletions src/cmd/link/internal/sym/symkind.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ const (
SDWARFRANGE
SDWARFLOC
SDWARFLINES

// ABI aliases (these never appear in the output)
SABIALIAS
)

// AbiSymKindToSymKind maps values read from object files (which are
Expand All @@ -143,7 +140,6 @@ var AbiSymKindToSymKind = [...]SymKind{
SDWARFRANGE,
SDWARFLOC,
SDWARFLINES,
SABIALIAS,
SLIBFUZZER_EXTRA_COUNTER,
}

Expand Down
5 changes: 2 additions & 3 deletions src/cmd/link/internal/sym/symkind_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/cmd/link/internal/wasm/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func asmb2(ctxt *ld.Link, ldr *loader.Loader) {
}
wfn.Write(P[off:r.Off()])
off = r.Off()
rs := ldr.ResolveABIAlias(r.Sym())
rs := r.Sym()
switch r.Type() {
case objabi.R_ADDR:
writeSleb128(wfn, ldr.SymValue(rs)+r.Add())
Expand Down

0 comments on commit 55d22f7

Please sign in to comment.