From: Cherry Zhang Date: Mon, 20 Apr 2020 17:40:22 +0000 (-0400) Subject: [dev.link] cmd/link: don't write text address directly if using plugins X-Git-Tag: go1.15beta1~401^2^2~18 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=6290a5436578751bb04dacc9d8910a6e968683a2;p=gostls13.git [dev.link] cmd/link: don't write text address directly if using plugins When using plugins, on darwin we do weird things with runtime.etext symbol, assigning a value for it, then clear it, reassign a different value. This breaks the logic of writing text address directly. I think we should remove the weird thing with runtime.etext, if possible. But for now, disable the optimization (this is not a common case anyway). Fix darwin-nocgo build. Change-Id: Iab6a9f8519115226a5bbaaafe4a93f17042a928a Reviewed-on: https://go-review.googlesource.com/c/go/+/229057 Run-TryBot: Cherry Zhang Reviewed-by: Than McIntosh --- diff --git a/src/cmd/link/internal/ld/pcln.go b/src/cmd/link/internal/ld/pcln.go index 7d5a756a62..75fb828bef 100644 --- a/src/cmd/link/internal/ld/pcln.go +++ b/src/cmd/link/internal/ld/pcln.go @@ -326,12 +326,16 @@ func (ctxt *Link) pclntab() loader.Bitmap { } setAddr := (*loader.SymbolBuilder).SetAddrPlus - if ctxt.IsExe() && ctxt.IsInternal() { + if ctxt.IsExe() && ctxt.IsInternal() && !ctxt.DynlinkingGo() { // Internal linking static executable. At this point the function // addresses are known, so we can just use them instead of emitting // relocations. // For other cases we are generating a relocatable binary so we // still need to emit relocations. + // + // Also not do this optimization when using plugins (DynlinkingGo), + // as on darwin it does weird things with runtime.etext symbol. + // TODO: remove the weird thing and remove this condition. setAddr = func(s *loader.SymbolBuilder, arch *sys.Arch, off int64, tgt loader.Sym, add int64) int64 { if v := ldr.SymValue(tgt); v != 0 { return s.SetUint(arch, off, uint64(v+add))