]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: support .def file with MSVC clang toolchain
authorCherry Mui <cherryyz@google.com>
Thu, 2 Oct 2025 22:24:12 +0000 (18:24 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 3 Oct 2025 13:30:28 +0000 (06:30 -0700)
lld-link supports .def file, but requires a "-def:" (or "/def:")
flag. (MinGW linker, on the other hand, requires no flag.) Pass
the flag when using MSVC-based toolchain.

CL originally authored by Chressie Himpel.

Change-Id: I8c327ab48d36b0bcbb1d127cff544ffdb06be38e
Reviewed-on: https://go-review.googlesource.com/c/go/+/708716
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Chressie Himpel <chressie@google.com>
src/cmd/link/internal/ld/lib.go

index 79d3d37835e9ad302c6d82023eee66e2ae187ad2..2c861129b52f9abb00b7b7feef3600acd9ae4484 100644 (file)
@@ -1787,9 +1787,13 @@ func (ctxt *Link) hostlink() {
        case ctxt.IsAIX():
                fileName := xcoffCreateExportFile(ctxt)
                argv = append(argv, "-Wl,-bE:"+fileName)
-       case ctxt.IsWindows() && !slices.Contains(flagExtldflags, "-Wl,--export-all-symbols"):
+       case ctxt.IsWindows() && !slices.Contains(flagExtldflags, wlPrefix+"export-all-symbols"):
                fileName := peCreateExportFile(ctxt, filepath.Base(outopt))
-               argv = append(argv, fileName)
+               prefix := ""
+               if isMSVC {
+                       prefix = "-Wl,-def:"
+               }
+               argv = append(argv, prefix+fileName)
        }
 
        const unusedArguments = "-Qunused-arguments"