diff options
author | Quim Muntal <quimmuntal@gmail.com> | 2020-10-15 23:12:49 +0200 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-10-22 22:40:17 +0000 |
commit | 6f7b553c82b69b47becbe36d9115971d30fdab48 (patch) | |
tree | 61e0919083d23ea9ef8c1d617aab8f0168dc8935 /src/cmd/cgo | |
parent | 4ce9ea52c9ac48f85fba1233b6e7d563f89dff8b (diff) | |
download | go-6f7b553c82b69b47becbe36d9115971d30fdab48.tar.gz go-6f7b553c82b69b47becbe36d9115971d30fdab48.zip |
cmd/cgo: avoid exporting all symbols on windows buildmode=c-shared
Disable default symbol auto-export behaviour by marking exported
function with the __declspec(dllexport) attribute. Old behaviour can
still be used by setting -extldflags=-Wl,--export-all-symbols.
See https://sourceware.org/binutils/docs/ld/WIN32.html for more info.
This change cuts 50kb of a "hello world" dll.
Updates #6853
Fixes #30674
Change-Id: I9c7fb09c677cc760f24d0f7d199740ae73981413
Reviewed-on: https://go-review.googlesource.com/c/go/+/262797
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Diffstat (limited to 'src/cmd/cgo')
-rw-r--r-- | src/cmd/cgo/out.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index b447b07645..82316a300b 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -939,7 +939,11 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) { } // Build the wrapper function compiled by gcc. - s := fmt.Sprintf("%s %s(", gccResult, exp.ExpName) + gccExport := "" + if goos == "windows" { + gccExport = "__declspec(dllexport)" + } + s := fmt.Sprintf("%s %s %s(", gccExport, gccResult, exp.ExpName) if fn.Recv != nil { s += p.cgoType(fn.Recv.List[0].Type).C.String() s += " recv" |