-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/go: executable created using linkshared option is not linking .so created by buildmode=shared with go modules enabled #38499
Comments
I took a look at this, testing with tip of master. First off, please be aware that "-linkshared" and "-buildmode=shared" are very obscure, not a lot of people use them, so they are not as well tested and/or supported. There are know issues with building things this way (for example, linker DWARF generation is weak). I believe the problem here is not with the linker, though, it looks as though it is with the Go command. If I use the Go command in GOPATH mode (avoid use of modules), I can get your example to work properly. This is because when you do go install -buildmode=shared -linkshared github.com/ramanvis/buildsharedwithmod/lib/advmath the generated shared library is installed into ${GOPATH}/pkg/linux_amd64_dynlink, which the final link can then pick up. Without GOPATH (e.g. in modules mode) the Go command seems to be just dropping the shared library into the current directory. When the final link of the command takes place, the Go command is not picking up the shared library created in the previous step, it's just getting a regular archive from the cache. From the "-x" output: packagefile github.com/ramanvis/buildsharedwithmod/lib/advmath=/usr/local/google/home/thanm/.cache/go-build/7b/7b01d210cc8dc2591258e60ee56bdf7b9b3d0283bc2ddb8d6f58cf01d11f327f-d Somebody who knows the internals of the Go command (and module mode in particular) might be able to say more about how this is supposed to be handled, or even if it is supported at all. Maybe @bcmills might be the right person to ask? |
This might be a duplicate of #37675. This TODO (from CL 208233, for #35759) is almost certainly relevant: go/src/cmd/go/internal/load/pkg.go Lines 1663 to 1665 in d5e1b7c
|
Thanks for the really quick turnaround. I too see that it works as expected when modules are turned off. Not using modules is not an option. I guess "buildmode=shared" and "linkshared" would not work because of this issue My intentions are to build a "shared" library and using the same in another go project, so that I could share without revealing the source. I could probably explore buildmode c-shared and use cgo. Could you let me know if there are any popular ways of doing the same? |
The fact that I couldn't find an issue to mark this as a duplicate of suggests that there is no “popular” way to do what you are trying to do. (You can't really “share without revealing the source” either way, since someone could always disassemble the library and reconstruct the original program logic — at that point, a At any rate: the |
Obsoleted by #47788 |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Refer to: https://github.com/ramanvis/buildsharedwithmod
I did the following:
buildmode=shared
for library "github.com/ramanvis/buildsharedwithmod/lib/advmath".How to reproduce:
docker pull ramanvis/buildsharedwithmod:latest
docker run --rm -it ramanvis/buildsharedwithmod:latest /bin/bash
What did you expect to see?
I was expecting to see the binary being dynamically linked to libgithub.com-ramanvis-buildsharedwithmod-lib-advmath.so
What did you see instead?
The text was updated successfully, but these errors were encountered: