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

Statically linking libc++ requires disabling static-libstdcpp #94983

Open
djkoloski opened this issue Mar 16, 2022 · 9 comments
Open

Statically linking libc++ requires disabling static-libstdcpp #94983

djkoloski opened this issue Mar 16, 2022 · 9 comments
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself A-linkage Area: linking into static, shared libraries and binaries P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@djkoloski
Copy link
Contributor

djkoloski commented Mar 16, 2022

In 737ef08, the default value of static-libstdcpp was changed from false to true. When statically linking libc++ on linux, this has a rather unfortunate cascade of effects:

  1. If static-libstdcpp is set to true, then bootstrap/compile.rs will ask clang++ where libstdc++.a is located.
  2. For pure-LLVM toolchains, only libc++.a is provided and clang++ will unhelpfully return "libstdc++.a". compile.rs stores this in LLVM_STATIC_STDCPP.
  3. rustc_llvm's build script checks whether LLVM_STATIC_STDCPP is set. Seeing that it is, it adds cargo:rustc-link-search=native=<PARENT_DIR> to the command line where <PARENT_DIR> is the directory containing LLVM_STATIC_STDCPP.
  4. Because there is no parent directory, this winds up adding -L native=, which triggers the error "empty search path given via -L" in rustc_session/src/search_paths.rs.

To get the behavior that we actually want, we need to fall into the case where LLVM_STATIC_STDCPP is not defined, and instead add -stdlib=libc++ to cxxflags. To do so, we have to set static-libstdcpp = false in config.toml. This is unintuitive behavior as it appears that we're disabling static linking entirely, but in reality we're just statically linking against libc++ instead of libstdc++.

@compiler-errors
Copy link
Member

+1, was affected by the "empty search path" bug when trying to build stage1 from a clean centos8. Was overwhelmingly unclear that I needed to install libstdc++-static to fix.

@jonhoo
Copy link
Contributor

jonhoo commented Mar 21, 2022

Huh, yeah, that definitely does seem weird. I wonder where the right place to fix this is though. It does feel like static-libstdcpp is slightly too low-level a setting at the moment in that it only considers libstdc++ at the moment. My thinking here is that we should fix static-libstdcpp to be "libc++ aware", where if libc++ is being used, it should pass the "appropriate" options instead of continuing to assume libstdc++ everywhere. Which is to say I think the bug is actually in step 1, which should realize it ought to be asking for libc++.a instead. And then also in the #94832 logic to pass a different flag (-static?) instead of -static-libstdc++ as part of the linker flags.

@hvdijk
Copy link
Contributor

hvdijk commented May 22, 2022

This has become more visible now that 1.61.0 has been released. 1.61.0 no longer builds on pure LLVM systems with libc++, even if use-libcxx = true is set, unless static-libstdcpp = false is also set.

It does feel like static-libstdcpp is slightly too low-level a setting at the moment in that it only considers libstdc++ at the moment. My thinking here is that we should fix static-libstdcpp to be "libc++ aware", where if libc++ is being used, it should pass the "appropriate" options instead of continuing to assume libstdc++ everywhere.

My initial thought is the opposite. The name static-libstdcpp and its description are both highly specific to libstdc++, and the option already has no effect on targets that normally do not use libstdc++, so my thinking is that this should be extended to all cases where libstdc++ is not used.

@psumbera
Copy link
Contributor

I'm not able to build 1.61.0 on Solaris now. There is no libstdc++.a bundled with Solaris GCC. And there is also no libc++. Any suggestion?

@psumbera
Copy link
Contributor

I'm not able to build 1.61.0 on Solaris now. There is no libstdc++.a bundled with Solaris GCC. And there is also no libc++. Any suggestion?

My issue was already reported here: #97260 (including working patch file).

@jyn514 jyn514 added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) A-linkage Area: linking into static, shared libraries and binaries A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself labels Apr 9, 2023
@jyn514
Copy link
Member

jyn514 commented Apr 9, 2023

My thinking here is that we should fix static-libstdcpp to be "libc++ aware", where if libc++ is being used, it should pass the "appropriate" options instead of continuing to assume libstdc++ everywhere. Which is to say I think the bug is actually in step 1, which should realize it ought to be asking for libc++.a instead. And then also in the #94832 logic to pass a different flag (-static?) instead of -static-libstdc++ as part of the linker flags.

@jonhoo do you have time to follow-up on this? It seems like a reasonable fix but I'm not familiar with the difference between libc++ and libstdc++.

@jyn514 jyn514 added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Apr 9, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 9, 2023
@jonhoo
Copy link
Contributor

jonhoo commented Apr 9, 2023

I probably won't have a chance to get to this for a week or two unfortunately. I think I agree with the more recent discussion now though in that we should just fix step 3 from OP's post so that if the parent directory is empty we don't add it to -L.

@apiraino
Copy link
Contributor

apiraino commented May 2, 2023

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 2, 2023
@jonhoo
Copy link
Contributor

jonhoo commented Jul 30, 2023

Given my recent change of jobs, I probably won't have a chance to pick this up again. Sorry about that! I still think the proposed fix is the way to go though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself A-linkage Area: linking into static, shared libraries and binaries P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

No branches or pull requests

8 participants