-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: -buildmode=c-shared exports many functions, not just //export functions #30674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This problem also occurs in Linux. |
This seems like a significant issue and quite easy to hit on Windows. Using go 1.15.2 (but this also reproduces on 1.14 and 1.13) I can hit the error "Error: export ordinal too large" during compilation after importing a few 3rd party packages. My code only intends to export one function, but as this issue describes...dumpbin shows thousands of symbols being exported for each of the 3rd party packages that I imported. This quickly causes me to hit the 'export ordinal too large error'. Is there any workaround that you are aware of for this? (switching to another buildmode such as -buildmode=exe is not an option for projects which require a shared library to be produced). |
Also reported in #40795 cc @aclements @thanm @jeremyfaller @cherrymui @alexbrainman @mattn @zx2c4 |
Change https://golang.org/cl/262797 mentions this issue: |
I´ve submitted a commit which adds I guess it can also fix #40795 by adding a dummy |
That is fantastic news - thanks for taking a look at this @qmuntal ! Is there a workaround that we use today with golang 1.13 or 1.14 to avoid the unnecessary symbols being exported? I was trying to see if there is a way to call go build with params that would achieve something like -Wl,--exclude-all-symbols but still export the symbols for the functions we marked in the go code with //export ? Edit: The following approach worked for me, but i'm still curious if there is a simpler/better way:
Where the content of myproject.version file is:
Resultant DLL only exports the functions I requested in the global section of the myproject.version file (and the syntax of that file also supports wildcard * to make it easy to export a bunch of functions without having to explicitly name each one). |
@gopherbot please backport to 1.15 buildmode=pie became the default in 1.15, so folks have to manually set buildmode=exe to work around this bug. |
Backport issue(s) opened: #43591 (for 1.15). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
Change https://golang.org/cl/300693 mentions this issue: |
…ws 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. Updates #30674. Fixes #43591. 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> Reviewed-on: https://go-review.googlesource.com/c/go/+/300693 Trust: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: David Chase <drchase@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
Third-party library functions have also been exported.
Since most of the code for the project is not stored in the main package, it is actually equivalent to all function names being leaked.
It is hoped that only functions that explicitly mark //export will be exported, not all functions will be exported.
The text was updated successfully, but these errors were encountered: