]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: don't write text address directly if using plugins
authorCherry Zhang <cherryyz@google.com>
Mon, 20 Apr 2020 17:40:22 +0000 (13:40 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 20 Apr 2020 18:26:46 +0000 (18:26 +0000)
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 <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/pcln.go

index 7d5a756a62e62f31c37d48211269c4a72a892684..75fb828bef565451235c37b615b229cb94d8055c 100644 (file)
@@ -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))