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

Need to be able to explicitly set --whole-archive linker flag when building a binary #56306

Closed
jkryl opened this issue Nov 28, 2018 · 2 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jkryl
Copy link

jkryl commented Nov 28, 2018

I'm using 1.32.0-nightly (6bfb46e4a 2018-11-26) but it likely applies to all rust versions. The default behaviour when building a binary is to include only static/shared libraries which are actually referenced from the code. There is a legitimate use case when you want to include everything from a native library regardless if it appears to be used or not. Native library can contain functions marked as __attribute__((constructor, used)) which are executed at the time when the library is loaded and can influence behaviour of other libraries which are explicitly referenced. One such example is DPDK library. Currently there does not seem to be a way to instruct explicitly rustc to include the lib even if not used.

Using .cargo/config to override rustc flags looks more like a workaround than a proper solution. Or maybe I missed some other way how to accomplish the same without hacking the code? I will be thankful for any advice. Thanks!

For more in-depth discussion about the particular case of DPDK/SPDK see:
jkozlowski/starfish#6 or spdk/spdk#518 or a PR jkozlowski/starfish#8 .

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 27, 2019
@petrochenkov
Copy link
Contributor

I have submitted an RFC about supporting whole archive - rust-lang/rfcs#2951.

@petrochenkov
Copy link
Contributor

Closing this issue, the whole-archive modifier was implemented about 9 months ago, and #93901 now intends to make it available on stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants