-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Statically compile libstdc++ everywhere if asked #94719
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
I think on balance I've fixed more issues than I've caused 😅 Found this one due to a case where I tried to do a |
For reference, the code that used to live in And, actually, looking at it it used to apply to sanitizers as well, so I think the only actual semantics change here is that |
PR rust-lang#93918 made it so that `-static-libstdc++` was only set in one place, and was only set during linking, but accidentally also made it so that it is no longer passed when building LLD or sanitizers, only when building LLVM itself. This moves the logic for setting `-static-libstdc++` in the linker flags back to `configure_cmake` so that it takes effect for all CMake invocations in `native.rs`. As a side-effect, this also causes libstdc++ to be statically compiled into sanitizers and LLD if `llvm-tools-enabled` is set but `llvm-static-stdcpp` is not, even though previously it was only linked statically if `llvm-static-stdcpp` was set explicitly. But that seems more like the expected behavior anyway.
4542075
to
b328688
Compare
I force-pushed a change that just changes the commit message to be accurate with respect to sanitizers. |
@@ -576,6 +564,18 @@ fn configure_cmake( | |||
ldflags.push_all(&flags); | |||
} | |||
|
|||
// For distribution we want the LLVM tools to be *statically* linked to libstdc++. | |||
// We also do this if the user explicitly requested static libstdc++. | |||
if builder.config.llvm_tools_enabled || builder.config.llvm_static_stdcpp { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We blanket enable llvm-static-stdcpp in our CI (see
Line 72 in 03918ba
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp" |
It looks like that was originally added in #50336, but it seems like an odd thing to force opt-in users of the build system to with an orthogonal flag. Maybe you have a better sense here though!
I think this somewhat makes this PR a clearer "yes" to me, since if we're migrating to a simpler story of only enabling static stdcpp if asked explicitly, then doing that for everything makes sense. But if that's gated on llvm tools being enabled, it feels weird for that to apply to "not tools".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a tough call. When you need llvm-tools
, you'll very often want them with static libstdc++, because otherwise they may just not run on whatever host you try running them on, and you won't be able to tell until a user with an old host is bitten by it. But at the same time, as you point out, there's no fundamental reason they need to be coupled (at least as far as I can tell), which suggests the two flags should be decoupled. I think of this as an anti-footgun of having llvm-tools
imply static-libstdc++
because builders may not have thought through the implications of not linking it statically (they may not even be aware of the static-stdcpp
flag).
Which is all to say — I think decoupling them gives more flexibility to builders, but at the cost of making it harder to get to a functioning build for someone who's trying to replicate the upstream build process. Which of those is more important, I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Yes, that makes sense. I think we should probably be changing the default for static stdcpp, then, rather than specifically checking tools here, but that seems like a change that needs it's own PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah, I like that idea! Can submit a PR for that tomorrow. And then you'd want this PR to just switch on llvm_static_stdcpp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think we should do a separate PR that changes the if
condition to just be llvm_static_stdcpp
and flips its default. Otherwise, in the interrim (however short) we'll be changing the behavior of the code.
Sanitizers don't use or link to the C++ standard library. It would be better to avoid adding |
Prior to #93918, we were passing |
I actually wonder if this needs a backport (along with #94466), since otherwise users of 1.60 will just get #93918, which in turn means their lld won't be statically linked with libstdc++. It should only affect stable users who are linking with rust-lld and running on fairly old platforms, but that number probably isn't zero. |
Yeah, I'm going to go ahead and unilaterally approve for beta backport, I think it makes sense to roll these two into one change from user's perspective. The alternative I think would be to back out #93918, but that seems worse to me. In any case, these changes should be fairly well-tested since they affect our shipped artifacts, and if they cause problems for distros they can locally revert fairly easily (since it just touches rustbuild). @bors r+ rollup |
📌 Commit b328688 has been approved by |
…mulacrum Statically compile libstdc++ everywhere if asked PR rust-lang#93918 made it so that `-static-libstdc++` was only set in one place, and was only set during linking, but accidentally also made it so that it is no longer passed when building LLD, only when building LLVM itself. This moves the logic for setting `-static-libstdc++` in the linker flags to `configure_cmake` so that it takes effect for all CMake invocations in `native.rs`. As a side-effect, this also causes libstdc++ to be statically compiled into sanitizers, whereas previously the `llvm-static-stdcpp` flag had no effect on sanitizers. It also makes it so that LLD will be compiled statically if `llvm-tools-enabled` is set, even though previously it was only linked statically if `llvm-static-stdcpp` was set explicitly. Both of these seem like they match expected behavior than what was there prior to rust-lang#93918.
…mulacrum Statically compile libstdc++ everywhere if asked PR rust-lang#93918 made it so that `-static-libstdc++` was only set in one place, and was only set during linking, but accidentally also made it so that it is no longer passed when building LLD, only when building LLVM itself. This moves the logic for setting `-static-libstdc++` in the linker flags to `configure_cmake` so that it takes effect for all CMake invocations in `native.rs`. As a side-effect, this also causes libstdc++ to be statically compiled into sanitizers, whereas previously the `llvm-static-stdcpp` flag had no effect on sanitizers. It also makes it so that LLD will be compiled statically if `llvm-tools-enabled` is set, even though previously it was only linked statically if `llvm-static-stdcpp` was set explicitly. Both of these seem like they match expected behavior than what was there prior to rust-lang#93918.
…mulacrum Statically compile libstdc++ everywhere if asked PR rust-lang#93918 made it so that `-static-libstdc++` was only set in one place, and was only set during linking, but accidentally also made it so that it is no longer passed when building LLD, only when building LLVM itself. This moves the logic for setting `-static-libstdc++` in the linker flags to `configure_cmake` so that it takes effect for all CMake invocations in `native.rs`. As a side-effect, this also causes libstdc++ to be statically compiled into sanitizers, whereas previously the `llvm-static-stdcpp` flag had no effect on sanitizers. It also makes it so that LLD will be compiled statically if `llvm-tools-enabled` is set, even though previously it was only linked statically if `llvm-static-stdcpp` was set explicitly. Both of these seem like they match expected behavior than what was there prior to rust-lang#93918.
…mulacrum Statically compile libstdc++ everywhere if asked PR rust-lang#93918 made it so that `-static-libstdc++` was only set in one place, and was only set during linking, but accidentally also made it so that it is no longer passed when building LLD, only when building LLVM itself. This moves the logic for setting `-static-libstdc++` in the linker flags to `configure_cmake` so that it takes effect for all CMake invocations in `native.rs`. As a side-effect, this also causes libstdc++ to be statically compiled into sanitizers, whereas previously the `llvm-static-stdcpp` flag had no effect on sanitizers. It also makes it so that LLD will be compiled statically if `llvm-tools-enabled` is set, even though previously it was only linked statically if `llvm-static-stdcpp` was set explicitly. Both of these seem like they match expected behavior than what was there prior to rust-lang#93918.
…mulacrum Statically compile libstdc++ everywhere if asked PR rust-lang#93918 made it so that `-static-libstdc++` was only set in one place, and was only set during linking, but accidentally also made it so that it is no longer passed when building LLD, only when building LLVM itself. This moves the logic for setting `-static-libstdc++` in the linker flags to `configure_cmake` so that it takes effect for all CMake invocations in `native.rs`. As a side-effect, this also causes libstdc++ to be statically compiled into sanitizers, whereas previously the `llvm-static-stdcpp` flag had no effect on sanitizers. It also makes it so that LLD will be compiled statically if `llvm-tools-enabled` is set, even though previously it was only linked statically if `llvm-static-stdcpp` was set explicitly. Both of these seem like they match expected behavior than what was there prior to rust-lang#93918.
Rollup of 7 pull requests Successful merges: - rust-lang#93950 (Use modern formatting for format! macros) - rust-lang#94274 (Treat unstable lints as unknown) - rust-lang#94368 ([1/2] Implement macro meta-variable expressions) - rust-lang#94719 (Statically compile libstdc++ everywhere if asked) - rust-lang#94728 (Only emit pointer-like metadata for `Box<T, A>` when `A` is ZST) - rust-lang#94790 (enable portable-simd doctests in Miri) - rust-lang#94811 (Update browser-ui-test version) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Wooo! Let me get you a PR that changes the default 👍 |
Previously, the static-libstdcpp setting was tied to llvm-tools such that enabling the latter always enabled the latter. This seems unfortunate, since it is entirely reasonable for someone to want to _not_ statically link stdc++, but _also_ want to build the llvm-tools. This patch therefore separates the two settings such that neither implies the other. On its own, that would change the default behavior in a way that's likely to surprise users. Specifically, users who build llvm-tools _likely_ want those tools to be statically compiled against libstdc++, since otherwise users with older GLIBCXX will be unable to run the vended tools. So, we also flip the default for the `static-libstdcpp` setting such that builds always link statically against libstdc++ by default, but it's _possible_ to opt out. See also rust-lang#94719.
Opened #94832 |
bootstrap: untangle static-libstdcpp & llvm-tools Previously, the static-libstdcpp setting was tied to llvm-tools such that enabling the latter always enabled the latter. This seems unfortunate, since it is entirely reasonable for someone to want to _not_ statically link stdc++, but _also_ want to build the llvm-tools. This patch therefore separates the two settings such that neither implies the other. On its own, that would change the default behavior in a way that's likely to surprise users. Specifically, users who build llvm-tools _likely_ want those tools to be statically compiled against libstdc++, since otherwise users with older GLIBCXX will be unable to run the vended tools. So, we also flip the default for the `static-libstdcpp` setting such that builds always link statically against libstdc++ by default, but it's _possible_ to opt out. See also rust-lang#94719.
…ulacrum [beta] backports * Update LLVM submodule rust-lang#94764 * Statically compile libstdc++ everywhere if asked rust-lang#94719 * Downgrade #[test] on macro call to warning rust-lang#94624 * Delay bug in expr adjustment when check_expr is called multiple times rust-lang#94596 * bootstrap: correct reading of flags for llvm rust-lang#94466 * Check method input expressions once rust-lang#94438 * remove feature gate in control_flow examples rust-lang#94283 r? `@Mark-Simulacrum`
PR #93918 made it so that
-static-libstdc++
was only set in one place,and was only set during linking, but accidentally also made it so that
it is no longer passed when building LLD, only when building LLVM
itself. This moves the logic for setting
-static-libstdc++
in thelinker flags to
configure_cmake
so that it takes effect for all CMakeinvocations in
native.rs
.As a side-effect, this also causes libstdc++ to be statically compiled
into sanitizers, whereas previously the
llvm-static-stdcpp
flag had noeffect on sanitizers. It also makes it so that LLD will be compiled
statically if
llvm-tools-enabled
is set, even though previously it wasonly linked statically if
llvm-static-stdcpp
was set explicitly. Bothof these seem like they match expected behavior than what was there
prior to #93918.