]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: add LIBRARY statement only with -buildmode=cshared
authorqmuntal <quimmuntal@gmail.com>
Fri, 3 Oct 2025 09:18:47 +0000 (11:18 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Fri, 3 Oct 2025 20:50:05 +0000 (13:50 -0700)
When creating a .def file for Windows linking, add a LIBRARY statement
only when building a DLL with -buildmode=cshared. That statement is
documented to instruct the linker to create a DLL, overriding any
other flag that might indicate building an executable.

Fixes #75734

Change-Id: I0231435df70b71a493a39deb639f6328a8e354f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/708815
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Dominic Della Valle <ddvpublic@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/link/internal/ld/pe.go

index 0f0650e5e149e37dbba1805eb3af51745f71cd97..e0186f46b035d933004045145983b2267d0c5707 100644 (file)
@@ -1758,7 +1758,9 @@ func peCreateExportFile(ctxt *Link, libName string) (fname string) {
        fname = filepath.Join(*flagTmpdir, "export_file.def")
        var buf bytes.Buffer
 
-       fmt.Fprintf(&buf, "LIBRARY %s\n", libName)
+       if ctxt.BuildMode == BuildModeCShared {
+               fmt.Fprintf(&buf, "LIBRARY %s\n", libName)
+       }
        buf.WriteString("EXPORTS\n")
 
        ldr := ctxt.loader