From 56b783ad94f9a55163d494d5b34c783a9603d478 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 10 Dec 2020 08:44:44 -0500 Subject: [PATCH] cmd/go, cmd/asm: pass -linkshared to assembler for shared linkage builds When the -linkshared build mode is in effect, the Go command passes the "-linkshared" command line option to the compiler so as to insure special handling for things like builtin functions (which may appear in a shared library and not the main executable). This patch extends this behavior to the assembler, since the assembler may also wind up referencing builtins when emitting a stack-split prolog. Fixes #43107. Change-Id: I56eaded79789b083f3c3d800fb140353dee33ba9 Reviewed-on: https://go-review.googlesource.com/c/go/+/276932 Trust: Than McIntosh Run-TryBot: Than McIntosh TryBot-Result: Go Bot Reviewed-by: Jay Conrod Reviewed-by: Cherry Zhang --- src/cmd/asm/internal/flags/flags.go | 1 + src/cmd/asm/main.go | 1 + src/cmd/go/internal/work/init.go | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/asm/internal/flags/flags.go b/src/cmd/asm/internal/flags/flags.go index 426e0156aa..1335860315 100644 --- a/src/cmd/asm/internal/flags/flags.go +++ b/src/cmd/asm/internal/flags/flags.go @@ -20,6 +20,7 @@ var ( TrimPath = flag.String("trimpath", "", "remove prefix from recorded source file paths") Shared = flag.Bool("shared", false, "generate code that can be linked into a shared library") Dynlink = flag.Bool("dynlink", false, "support references to Go symbols defined in other shared libraries") + Linkshared = flag.Bool("linkshared", false, "generate code that will be linked against Go shared libraries") AllErrors = flag.Bool("e", false, "no limit on number of errors reported") SymABIs = flag.Bool("gensymabis", false, "write symbol ABI information to output file, don't assemble") Importpath = flag.String("p", "", "set expected package import to path") diff --git a/src/cmd/asm/main.go b/src/cmd/asm/main.go index 149925d23f..31636e3045 100644 --- a/src/cmd/asm/main.go +++ b/src/cmd/asm/main.go @@ -37,6 +37,7 @@ func main() { ctxt := obj.Linknew(architecture.LinkArch) ctxt.Debugasm = flags.PrintOut ctxt.Flag_dynlink = *flags.Dynlink + ctxt.Flag_linkshared = *flags.Linkshared ctxt.Flag_shared = *flags.Shared || *flags.Dynlink ctxt.IsAsm = true ctxt.Pkgpath = *flags.Importpath diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index 102def4838..ba7c7c2fbb 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -241,7 +241,8 @@ func buildModeInit() { if gccgo { codegenArg = "-fPIC" } else { - forcedAsmflags = append(forcedAsmflags, "-D=GOBUILDMODE_shared=1") + forcedAsmflags = append(forcedAsmflags, "-D=GOBUILDMODE_shared=1", + "-linkshared") codegenArg = "-dynlink" forcedGcflags = append(forcedGcflags, "-linkshared") // TODO(mwhudson): remove -w when that gets fixed in linker. -- 2.48.1