Skip to content

Commit 8b9c539

Browse files
committed
Fix missing libLLVM.so in stage0 sysroot.
When we dynamically link against libLLVM.so (as opposed to statically linking LLVM), we need libLLVM.so to be present in the stage0 sysroot, so that stage1 tools (which are built against the stage0 compiler+sysroot) can see it at build time (when the linker is run) See the comment in the commit for more details
1 parent 1aa34d4 commit 8b9c539

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/bootstrap/compile.rs

+38
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,44 @@ impl Step for Rustc {
456456
vec![],
457457
false);
458458

459+
// We used to build librustc_codegen_llvm as a separate step,
460+
// which produced a dylib that the compiler would dlopen() at runtime.
461+
// This meant that we only needed to make sure that libLLVM.so was
462+
// installed by the time we went to run a tool using it - since
463+
// librustc_codegen_llvm was effectively a standalone artifact,
464+
// other crates were completely oblivious to its dependency
465+
// on `libLLVM.so` during build time.
466+
//
467+
// However, librustc_codegen_llvm is now built as an ordinary
468+
// crate during the same step as the rest of the compiler crates.
469+
// This means that any crates depending on it will see the fact
470+
// that it uses `libLLVM.so` as a native library, and will
471+
// cause us to pass `-llibLLVM.so` to the linker when we link
472+
// a binary.
473+
//
474+
// For `rustc` itself, this works out fine.
475+
// During the `Assemble` step, we call `dist::maybe_install_llvm_dylib`
476+
// to copy libLLVM.so into the `stage` directory. We then link
477+
// the compiler binary, which will find `libLLVM.so` in the correct place.
478+
//
479+
// However, this is insufficient for tools that are build against stage0
480+
// (e.g. stage1 rustdoc). Since `Assemble` for stage0 doesn't actually do anything,
481+
// we won't have `libLLVM.so` in the stage0 sysroot. In the past, this wasn't
482+
// a problem - we would copy the tool binary into its correct stage directory
483+
// (e.g. stage1 for a stage1 rustdoc built against a stage0 compiler).
484+
// Since libLLVM.so wasn't resolved until runtime, it was fine for it to
485+
// not exist while we were building it.
486+
//
487+
// To ensure that we can still build stage1 tools against a stage0 compiler,
488+
// we explicitly copy libLLVM.so into the stage0 sysroot when building
489+
// the stage0 compiler. This ensures that tools built against stage0
490+
// will see libLLVM.so at build time, making the linker happy.
491+
if compiler.stage == 0 {
492+
builder.info(&format!("Installing libLLVM.so to stage 0 ({})", compiler.host));
493+
let sysroot = builder.sysroot(compiler);
494+
dist::maybe_install_llvm_dylib(builder, compiler.host, &sysroot);
495+
}
496+
459497
builder.ensure(RustcLink {
460498
compiler: builder.compiler(compiler.stage, builder.config.build),
461499
target_compiler: compiler,

0 commit comments

Comments
 (0)