Commit ceda47d0 authored by Cherry Zhang's avatar Cherry Zhang

cmd/link: fix plugin on linux/arm64

The init function and runtime.addmoduledata were not added when
building plugin, which caused the runtime could not find the
module.

Testplugin is still not enabled on linux/arm64
(https://go.googlesource.com/go/+/master/src/cmd/dist/test.go#948)
because the gold linker on the builder is too old, which fails
with an internal error (see issue #17138). I tested locally and
it passes.

Fixes #24940.
Updates #17138.

Change-Id: I26aebca6c38a3443af0949471fa12b6d550e8c6c
Reviewed-on: https://go-review.googlesource.com/109917
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 2959128d
...@@ -46,7 +46,7 @@ func gentext(ctxt *ld.Link) { ...@@ -46,7 +46,7 @@ func gentext(ctxt *ld.Link) {
return return
} }
addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0) addmoduledata := ctxt.Syms.Lookup("runtime.addmoduledata", 0)
if addmoduledata.Type == sym.STEXT { if addmoduledata.Type == sym.STEXT && ctxt.BuildMode != ld.BuildModePlugin {
// we're linking a module containing the runtime -> no need for // we're linking a module containing the runtime -> no need for
// an init function // an init function
return return
...@@ -72,7 +72,7 @@ func gentext(ctxt *ld.Link) { ...@@ -72,7 +72,7 @@ func gentext(ctxt *ld.Link) {
rel.Sym = ctxt.Moduledata rel.Sym = ctxt.Moduledata
rel.Type = objabi.R_ADDRARM64 rel.Type = objabi.R_ADDRARM64
// 8: 14000000 bl 0 <runtime.addmoduledata> // 8: 14000000 b 0 <runtime.addmoduledata>
// 8: R_AARCH64_CALL26 runtime.addmoduledata // 8: R_AARCH64_CALL26 runtime.addmoduledata
o(0x14000000) o(0x14000000)
rel = initfunc.AddRel() rel = initfunc.AddRel()
...@@ -81,6 +81,9 @@ func gentext(ctxt *ld.Link) { ...@@ -81,6 +81,9 @@ func gentext(ctxt *ld.Link) {
rel.Sym = ctxt.Syms.Lookup("runtime.addmoduledata", 0) rel.Sym = ctxt.Syms.Lookup("runtime.addmoduledata", 0)
rel.Type = objabi.R_CALLARM64 // Really should be R_AARCH64_JUMP26 but doesn't seem to make any difference rel.Type = objabi.R_CALLARM64 // Really should be R_AARCH64_JUMP26 but doesn't seem to make any difference
if ctxt.BuildMode == ld.BuildModePlugin {
ctxt.Textp = append(ctxt.Textp, addmoduledata)
}
ctxt.Textp = append(ctxt.Textp, initfunc) ctxt.Textp = append(ctxt.Textp, initfunc)
initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0) initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0)
initarray_entry.Attr |= sym.AttrReachable initarray_entry.Attr |= sym.AttrReachable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment