Skip to content

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

Open
@djkoloski

Description

@djkoloski

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++.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-contributor-roadblockArea: Makes things more difficult for new or seasoned contributors to RustA-linkageArea: linking into static, shared libraries and binariesP-mediumMedium priorityT-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions