-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go,cmd/cgo: link-time symbol resolution for buildmode=c-shared #12216
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
It sounds like Ian fixed your problem. Are you proposing a change for the toolchain? |
@rsc I do think that passing '--unresolved-symbols=ignore-all' would be a better defaut, but I can't say I feel strongly about it. |
@ianlancetaylor, should we make -Wl,--unresolved-symbols=ignore-all the default for buildmode=c-shared uses of cgo? If so, let's wait until Go 1.7 since the c-shared stuff is still experimental and there's an easy workaround. Otherwise, let's close the bug. |
The issue here isn't really with -buildmode=c-shared. It's with using cgo to call a function that is not defined as far as cgo knows, because it is actually defined in a Go package. This comes up pretty naturally with -buildmode=c-shared, but it's easy to construct a similar case in other build modes as well. The real fix might be to have cgo do its links with -r, and not fuss about undefined symbols. Or have cgo use --unresolved-symbols=ignore-all; I'm not sure which would work better. Either way, we would let the final link give any errors about undefined symbols. |
@ianlancetaylor, sorry for the delayed response, but can you explain the difference between -r and --unresolved-symbols=ignore-all? Which should we use? |
The two options are completely different. Using For either one I'm not quite sure what will happen with an undefined symbol. We may be left without any using DWARF info, which could be a problem in some cases. |
I just stumbled on this thread while searching for the same thing (I'm attempting to build python modules written in go). This solution was perfect, +1 for it becoming the default. |
Yeah it's not suitable for what I want to do. You can see what I've done here though : https://github.com/asottile/setuptools-golang |
As discussed [here](golang/go#12216).
version:
I'm working with a software that loads plugins structured as follows. Plugins implement an interface, and the main program provides an API, so a typical call stack might look like:
Up to now, the main program and the plugins are written in C. I was eager to see if I could start building plugins in Go instead of C, now that 1.5 is out, so I gave it a try with something that looks like:
Unfortunately, this fails with:
Ian Lance Taylor suggested I pass '--unresolved-symbols' to the linker as a work around. I verified that that works as expected, both when passed via the command line:
or via the code
// #cgo LDFLAGS: -Wl,--unresolved-symbols=ignore-all
The text was updated successfully, but these errors were encountered: