Skip to content

Distributed libLLVM conflicts with system libraries #55737

Description

@rinon

Now that libLLVM.so is distributed with rust, we are unable to dynamically link a rust binary against a different libLLVM.so library. The rustlib directory containing libLLVM is prepended to the linker search path, and I don't see a good way to ask cargo to add a search path earlier than the rustlib is added. It looks to me like the rustlib directory is added here:

cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));

I noticed that support for appending a suffix to the LLVM libs was added in #53987. Can we turn that on for CI so the prebuilt distributions have a suffix on the library?

Unfortunately, the suffix won't actually fix this issue on MacOS, since the LLVM build does not append the suffix (or any version info) to the name of the dynamic library when building on MacOS: (see https://github.com/rust-lang/llvm/blob/7051ead40a5f825878b59bf08d4e768be9e99a4a/cmake/modules/AddLLVM.cmake#L520)

Activity

  1. added
    A-linkageArea: linking into static, shared libraries and binaries
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 27, 2019
  2. emilio commented on Mar 18, 2019

    @emilio
    Contributor

    This should be fixed by #59173.

  3. rinon commented on Mar 18, 2019

    @rinon
    ContributorAuthor

    #59173 fixed this on Linux, thanks! The issue still persists on OS X because the filename is always libLLVM.dylib as mentioned above.

  4. Ionic commented on Apr 20, 2019

    @Ionic

    This is not just a redistribution problem, but also leads to a general FTBFS while bootstrapping with clang compilers since rust 1.34.0.

    1.34.0 now seems to put libLLVM.dylib into the stage0-$arch/lib artifacts dir and use that via DYLD_LIBRARY_PATH, so subsequent usages of clang will fail to execute.

    1.33.0 and prior didn't do this. They only created a librustc_codegen_llvm-llvm.dylib file as a later stage artifact (1? 2?), which didn't clash with system libraries.

  5. Ionic commented on Apr 24, 2019

    @Ionic

    I'm stupid - rust isn't compiling its own version of llvm - at least not when passing --llvm-root.

    The problem is that the precompiled 1.33 binaries that are used to bootstrap rust contain a libLLVM.dylib file which makes compiling with clang impossible since the rust-root lib directory is added to the dynamic linker library path, overriding the correct LLVM library.

  6. Lord-Kamina commented on Aug 16, 2019

    @Lord-Kamina

    I'm stupid - rust isn't compiling its own version of llvm - at least not when passing --llvm-root. ...

    @Ionic The problem is most likely the same in as in cargo, people assume DYLD_LIBRARY_PATH is equivalent to LD_LIBRARY_PATH and set it to whatever but it's actually not thes same. DYLD_LIBRARY_PATH is a hack and should not be used at all if possible because it overrides default system search paths. Instead, DYLD_FALLBACK_LIBRARY_PATH should be used; as those paths are only searched if a suitable library cannot be found in the default locations.

    Sent with GitHawk

  7. Enselic commented on Oct 2, 2025

    @Enselic
    Member

    Triage: Is this still a problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-linkageArea: linking into static, shared libraries and binariesO-macosOperating system: macOST-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions