-
Notifications
You must be signed in to change notification settings - Fork 18k
gccgo: export data linked into binary #26204
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
cc @aclements |
We use the system linker. We want the export data to be present in a shared library, but not in an executable. I don't know of a way to tell the linker to do that. Perhaps we could have the go tool run |
Executable produced by gollvm doesn't have the export data. The .o and .a files have the .go_export sections, but they don't get linked into the final executable. Gollvm invokes the linker as
gccgo linking uses collect2, as
The flags looks pretty similar. I don't know what makes the difference. |
Does a shared library produced by gollvm have the export data? |
I'm not sure what is the "right" way to produce a shared library with gccgo (or gollvm). I tried
(where p.go is not main package) This works, and libp.so contains the export data. I can then import it, like
(where main.go import package p) With gollvm, libp.so doesn't have the export data, and I cannot do the above.
I looked into this. The reason is that when generating the object file, the .go_export section has the "e" (exclude) flag set. Gccgo doesn't set this flag. If I don't set this flag, shared libraries will have the export data, so will executables. Is there a way to instruct the linker to drop a section when we are linking executable? In "normal" builds (i.e. using the go tool, instead of invoking gccgo or llvm-goc manually), does it need to look up the export data from shared libraries? When? cc @thanm |
I'm wondering how important it is to support this use case -- do people actually rely on this behavior? |
I also don't know how important it is to put export information in a shared library. Historically it worked naturally with But I don't know if anybody actually does that. Now that gccgo includes the Go tool, it should in principle work to use |
My preference would be to keep the current behavior (not incorporate the export data when linking) -- perhaps as a fallback we could add a command line flag to enable it (in case someone really needs this)? |
I guess a command line option would be consistent with the general GCC approach to these matters. |
With gccgo,
Dumping out the .go_export section, it looks like indeed export data. I think it is not needed at run time. It probably should not be linked into the binary.
-static-libgo
is just for demonstration. The export data also present in the default dynamically linked binary, or completely-static
binary, though the size varies.With some big binaries, like kubernetes, the export data can be quite big (over 40% of the binary size).
cc @ianlancetaylor
The text was updated successfully, but these errors were encountered: