cmd/link: add LIBRARY statement only with -buildmode=cshared

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>
This commit is contained in:
qmuntal
2025-10-03 11:18:47 +02:00
committed by Quim Muntal
parent 1bca4c1673
commit ee5369b003

View 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