]> Cypherpunks repositories - gostls13.git/commit
cmd/link: use a .def file to mark exported symbols on Windows
authorqmuntal <quimmuntal@gmail.com>
Mon, 22 Sep 2025 13:48:36 +0000 (15:48 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Mon, 29 Sep 2025 19:24:13 +0000 (12:24 -0700)
commiteaf2345256613dfbda7e8e69e5f845c4209246c6
tree0fb9914a190feb83c14cdb40e5c9d3a24abe0608
parent4b7773356515c178f0af859b952b4b3a78f0813d
cmd/link: use a .def file to mark exported symbols on Windows

Binutils defaults to exporting all symbols when building a Windows DLL.
To avoid that we were marking symbols with __declspec(dllexport) in
the cgo-generated headers, which instructs ld to export only those
symbols. However, that approach makes the headers hard to reuse when
importing the resulting DLL into other projects, as imported symbols
should be marked with __declspec(dllimport).

A better approach is to generate a .def file listing the symbols to
export, which gets the same effect without having to modify the headers.

Updates #30674
Fixes #56994

Change-Id: I22bd0aa079e2be4ae43b13d893f6b804eaeddabf
Reviewed-on: https://go-review.googlesource.com/c/go/+/705776
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
Reviewed-by: Than McIntosh <thanm@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/cmd/cgo/internal/testcshared/cshared_test.go
src/cmd/cgo/out.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/pe.go
src/cmd/link/internal/ld/xcoff.go
src/cmd/link/internal/loader/loader.go
src/runtime/cgo/gcc_libinit_windows.c
src/runtime/cgo/windows.go [new file with mode: 0644]