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

Consider making cfg(feature = "crt-static") available *only* for link-time configuration #72510

Open
petrochenkov opened this issue May 23, 2020 · 4 comments
Assignees
Labels
A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@petrochenkov
Copy link
Contributor

cfg predicates used for link-time configuration (#[link(cfg(predicate))] #37406 #72059) may want to use data that is available only long after the regular cfg expansion happens.

For example,

We can come up with some predicate value during regular cfg expansion, but it may be different from the predicate value that we really want at link time.

Is cfg(feature = "crt-static") ever used for regular cfg expansion?
It was created mostly with link-time configuration in mind.
We probably need to check it with crater.

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels May 23, 2020
@retep998
Copy link
Member

retep998 commented May 23, 2020

Do people even use cfg(feature = "crt-static")? The only time I can think of is either in libc or in build scripts to decide how to build C/C++ code (in which case they pull it from environment variables and not cfg directly).

@petrochenkov
Copy link
Contributor Author

@retep998
I wouldn't expect such use, but who knows, we need to check at least.

@petrochenkov
Copy link
Contributor Author

petrochenkov commented May 24, 2020

So, right now the value of crt-static predicate is evaluated during regular cfg expansion, even if it's used during link-time configuration.
After #69519 (which introduced separate crt-static defaults for executables and libraries basically) this scheme is incorrect, and means that proc macro crates can get linked with static libc anyway in some cases.

So in addition to deprecating expansion time use of this predicate we also need to move its actual evaluation to link time where the crate type is known.
(To clarify, both "expansion time" and "link time" are about building the final binary, #[link(cfg)] is still lazy.)

@petrochenkov petrochenkov self-assigned this Jun 8, 2020
@petrochenkov
Copy link
Contributor Author

Unfortunately, cfgs in #[link] attributes also need to be evaluated before linking during codegen to determine library kinds.

One query using them is is_dllimport_foreign_item used to set dllimport attributes.
Another one is is_statically_included_foreign_item used to determine reachable non-generic items for symbol exports (reachable_non_generics_provider).

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants