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

Explicit support for whole-archive linker option #7586

Closed
leeopop opened this issue Nov 13, 2019 · 5 comments
Closed

Explicit support for whole-archive linker option #7586

leeopop opened this issue Nov 13, 2019 · 5 comments
Labels
A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@leeopop
Copy link

leeopop commented Nov 13, 2019

  1. The problem

Some libraries using __attribute__((constructor)) suffers when their libraries are not linked via whole-archive linker option.
However, current cargo build script does not support this functionality.

  1. Alternatives

We may use RUSTFLAGS option to give custom linker option, however I expect that this is not a desired use case of cargo.

whole-archive is not needed when dynamically loading a shared library.
(the loader explicitly invoke the constructor function)
(in static linking case, linker finds no explicit linkage so that the library is omitted)

  1. Solution

Add another link type to cargo's link-lib list.
Currently, we have static, dylib, and framework.
As whole-archive works on static linking case, we may name it as static-whole.

e.g. cargo:rustc-link-lib=static-whole=foo at the build script.

I'm aware of the risk when the linker flag is fully open.
I expect that this is the reason why linker flags are not open to build scripts.
Thus, I suggest to explicit support a single type of linking: static-whole along with other specialized link types.

  1. Implementation strategy

Cargo internally manages the static-whole database.
At the final linking state, cargo opens a whole-archive, listing all static-whole libraries from the depending crates, and closes whole-archive.

@leeopop leeopop added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Nov 13, 2019
@ehuss ehuss added the A-linkage Area: linker issues, dylib, cdylib, shared libraries, so label Dec 3, 2019
@leeopop
Copy link
Author

leeopop commented Feb 14, 2020

ping @alexcrichton @ehuss

My previous writing is not that clear.
To be more specific, I would like to propose a concrete abstraction for the --whole-archive compiler option.

@leeopop
Copy link
Author

leeopop commented Feb 14, 2020

Here is an example of possible workaround of this topic.
https://github.com/ANLAB-KAIST/rust-dpdk/blob/9773c2b61676bdf16b94c9d4c00660b998481779/Dockerfile#L44

However, I think it is better to have this feature as standard cargo options.

@dcsommer
Copy link

dcsommer commented Aug 1, 2022

@ehuss I think this issue can be closed now that 53ec56c is in?

@ehuss
Copy link
Contributor

ehuss commented Aug 1, 2022

Seems like it, thanks!

@ehuss ehuss closed this as completed Aug 1, 2022
@dcsommer
Copy link

dcsommer commented Aug 2, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linker issues, dylib, cdylib, shared libraries, so C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

3 participants