mirror of
https://github.com/golang/go
synced 2024-11-26 23:11:24 -07:00
cmd/link: fix up more zero-sized local symbols on darwin dynamic linking
When dynamic linking on darwin, the darwin linker doesn't link relocations pointing to zero-sized local symbols, like our start/end marker symbols, e.g. runtime.text and runtime.etext. It will choose to resolve to another symbol on the same address that may not be local, therefore that reference may point to a different DSO, which is not what we want. We already fix up some marker symbols, like text/etext, data/edata, bss/ebss. But we currently don't fix up noptrdata and noptrbss. With the new darwin linker ld-prime, this causes problems when building a plugin. Fix up those symbols. For #61229. Change-Id: I2181bb9184b85af9a3c3f5dc6d78e4d5a1d56d53 Reviewed-on: https://go-review.googlesource.com/c/go/+/503538 Reviewed-by: Than McIntosh <thanm@google.com> Run-TryBot: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
463887d5cc
commit
e417698e84
@ -1075,7 +1075,7 @@ func writeBlock(ctxt *Link, out *OutBuf, ldr *loader.Loader, syms []loader.Sym,
|
||||
break
|
||||
}
|
||||
if val < addr {
|
||||
ldr.Errorf(s, "phase error: addr=%#x but sym=%#x type=%v sect=%v", addr, val, ldr.SymType(s), ldr.SymSect(s).Name)
|
||||
ldr.Errorf(s, "phase error: addr=%#x but val=%#x sym=%s type=%v sect=%v sect.addr=%#x", addr, val, ldr.SymName(s), ldr.SymType(s), ldr.SymSect(s).Name, ldr.SymSect(s).Vaddr)
|
||||
errorexit()
|
||||
}
|
||||
if addr < val {
|
||||
@ -1426,6 +1426,20 @@ func fixZeroSizedSymbols(ctxt *Link) {
|
||||
edata.SetType(sym.SXCOFFTOC)
|
||||
}
|
||||
|
||||
noptrbss := ldr.CreateSymForUpdate("runtime.noptrbss", 0)
|
||||
noptrbss.SetSize(8)
|
||||
ldr.SetAttrSpecial(noptrbss.Sym(), false)
|
||||
|
||||
enoptrbss := ldr.CreateSymForUpdate("runtime.enoptrbss", 0)
|
||||
ldr.SetAttrSpecial(enoptrbss.Sym(), false)
|
||||
|
||||
noptrdata := ldr.CreateSymForUpdate("runtime.noptrdata", 0)
|
||||
noptrdata.SetSize(8)
|
||||
ldr.SetAttrSpecial(noptrdata.Sym(), false)
|
||||
|
||||
enoptrdata := ldr.CreateSymForUpdate("runtime.enoptrdata", 0)
|
||||
ldr.SetAttrSpecial(enoptrdata.Sym(), false)
|
||||
|
||||
types := ldr.CreateSymForUpdate("runtime.types", 0)
|
||||
types.SetType(sym.STYPE)
|
||||
types.SetSize(8)
|
||||
@ -2234,10 +2248,12 @@ func (state *dodataState) dodataSect(ctxt *Link, symn sym.SymKind, syms []loader
|
||||
// end of their section.
|
||||
if (ctxt.DynlinkingGo() && ctxt.HeadType == objabi.Hdarwin) || (ctxt.HeadType == objabi.Haix && ctxt.LinkMode == LinkExternal) {
|
||||
switch ldr.SymName(s) {
|
||||
case "runtime.text", "runtime.bss", "runtime.data", "runtime.types", "runtime.rodata":
|
||||
case "runtime.text", "runtime.bss", "runtime.data", "runtime.types", "runtime.rodata",
|
||||
"runtime.noptrdata", "runtime.noptrbss":
|
||||
head = s
|
||||
continue
|
||||
case "runtime.etext", "runtime.ebss", "runtime.edata", "runtime.etypes", "runtime.erodata":
|
||||
case "runtime.etext", "runtime.ebss", "runtime.edata", "runtime.etypes", "runtime.erodata",
|
||||
"runtime.enoptrdata", "runtime.enoptrbss":
|
||||
tail = s
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user