diff --git a/src/cmd/link/internal/arm64/asm.go b/src/cmd/link/internal/arm64/asm.go index 858363e45a9ba..0151fa7e0d64e 100644 --- a/src/cmd/link/internal/arm64/asm.go +++ b/src/cmd/link/internal/arm64/asm.go @@ -46,7 +46,7 @@ func gentext(ctxt *ld.Link) { return } 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 // an init function return @@ -72,7 +72,7 @@ func gentext(ctxt *ld.Link) { rel.Sym = ctxt.Moduledata rel.Type = objabi.R_ADDRARM64 - // 8: 14000000 bl 0 + // 8: 14000000 b 0 // 8: R_AARCH64_CALL26 runtime.addmoduledata o(0x14000000) rel = initfunc.AddRel() @@ -81,6 +81,9 @@ func gentext(ctxt *ld.Link) { 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 + if ctxt.BuildMode == ld.BuildModePlugin { + ctxt.Textp = append(ctxt.Textp, addmoduledata) + } ctxt.Textp = append(ctxt.Textp, initfunc) initarray_entry := ctxt.Syms.Lookup("go.link.addmoduledatainit", 0) initarray_entry.Attr |= sym.AttrReachable