Skip to content
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

[SR-3573] SwiftPM should be able to weak link modules/libraries (-undefined dynamic_lookup) #5135

Open
swift-ci opened this issue Jan 8, 2017 · 6 comments

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Jan 8, 2017

Previous ID SR-3573
Radar None
Original Reporter lupinglade (JIRA User)
Type New Feature
Additional Detail from JIRA
Votes 2
Component/s Package Manager
Labels New Feature
Assignee None
Priority Medium

md5: 6ce36079553406d7894ae71ab38075bf

Issue Description:

We would like to see the ability to weak link against a swift module or a dylib when building using the Swift PM. Right now we are encountering issues when loading dylibs generated via Swift PM - there are duplicate definitions because the dylib always links in any packages it depends on. This does not seem like correct behavior in many cases. There needs to be a way to specify -undefined dynamic_lookup or similar.

This is not doable via the -Xlinker arguments to swift build, as it then applies to the dependencies as well and does not build. The only way we have been able to work around it is to not specify the dependencies in Package.swift and then pass -I /path/to/other/module and -undefined dynamic_lookup - but this pretty much defeats the benefits of the packaging.

Our use case is plug-ins.

The issue we are running into is:

objc[32082]: Class _TtC14ExampleLibrary10ExampleClass is implemented in both /path/to/hostingBinary (0x10f60e168) and /path/to/plugin.dylib (0x11377a2e8). One of the two will be used. Which one is undefined.

This error appears for all dependency classes when loading the produced dylib.

@ankitspd
Copy link
Member

ankitspd commented Jan 9, 2017

Hi,

The product proposal will allow you to specify that you want to vend your products as a dylib and they should be linked dynamically:
https://github.com/apple/swift-evolution/blob/master/proposals/0146-package-manager-product-definitions.md

Can you give it a read and see if it fits your usecase?

@swift-ci
Copy link
Contributor Author

swift-ci commented Jan 9, 2017

Comment by Maksim Rogov (JIRA)

We are a already using what is described in this proposal and getting the issue mentioned above. The problem is that the linking should be resolved dynamically at load/run time and not at build time. In essence SwiftPM needs to be able to skip linking in certain modules/dylibs and pass -undefined dynamic_lookup to the linker.

@belkadan
Copy link

This doesn't seem like the right approach. For you to get this behavior, you have to be building a library and an executable with the same module name and crossing your fingers that everything lines up, which isn't supported. The expected way to do this is to have both the executable and the loadable bundle link against a common library.

@swift-ci
Copy link
Contributor Author

Comment by Maksim Rogov (JIRA)

@jordan Rose Is there a way to have SPM link this way though? Or do we have to link against the shared library using the -Xlinker flag? It seems no matter what I do we get the duplicate symbol definition issue at load time.

@belkadan
Copy link

Why is the symbol in your hosting binary at all?

@belkadan
Copy link

…static linking. Right. Never mind.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants