Bump bootstrap compiler to 1.33 beta by Mark-Simulacrum · Pull Request #57765 · rust-lang/rust (original) (raw)

I have confirmed that the problem is that Cargo adds the stage0/lib directory to the dynamic library search path (i.e., LD_LIBRARY_PATH), presumably because that's the directory that contains std (and I suppose we'd need that to be in the path if we're dynamically, or maybe even statically, linking against std).

Unfortunately, Cargo prepends this to the search path so we can't really do anything in rustbuild to override that -- at least as far as I can tell. This behavior was added forever ago in rust-lang/cargo#2891.

At this point, I'm honestly somewhat not sure if there's a good solution to this. The llvm-config binary specifies the RUNPATH (presumably, equivalent to DT_RUNPATH) header, which is what we want to use to resolve the libLLVM dependency, but according to https://blog.qt.io/blog/2011/10/28/rpath-and-runpath/, LD_LIBRARY_PATH will take precedence over the RUNPATH header.

One solution is to simply run llvm-config without any LD_LIBRARY_PATH set. On a standard configuration with our built-in LLVM, this'll work -- but I assume that some distros and other configurations that want to use their own LLVM won't work with this option, though I have no concrete evidence of such.

We could also stop including the libLLVM-8svn.so just raw, I suppose, adding some form of hash to it's symbols or moving it to a sub-directory somehow.

I'm going to implement what I see as a "presumably good" variant: never execute llvm_config in build scripts. We don't do this much anyway and so feeding that information through environment variables doesn't seem terrible; it should also solve the problems here. As such this post is primarily a documentation of thought process.