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

Miri (possibly everything that depends on rustc private crates) no longer builds: cannot find -lLLVM-18-rust-1.78.0-nightly #121889

Closed
RalfJung opened this issue Mar 2, 2024 · 28 comments · Fixed by #121967
Assignees
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Mar 2, 2024

Trying to build Miri against latest rustc artifacts fails:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/r/.opam/coq-8.17/bin:/home/r/bin:/home/r/.cargo/bin:/home/r/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games" VSLANG="1033" "cc" "-m64" "/tmp/rustcKdET34/symbols.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.11xmci8slcb5avxi.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.12qdf7a036c4vr02.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.15b6acljysgkq0tu.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.16aneeg9x35abgfk.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.19n04kvindlihsq4.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1anbmrreqp5yl3t7.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1cvirxj3fkpsytp3.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1f2f3tzhb4qd756u.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1fx8rr91ki8r0rlb.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1gcfbjf0sqqsikft.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1hsv5pb43rvh4f79.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1jv2r4bh2poygsjx.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1jylhxsdskbbm99x.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1k5lzruxwatzbj2s.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1mgar9vu7xj3r5mb.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1mv2ygq8yvvq0jq6.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1pkdaqyh21r0839z.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1rioyg5mmyf8ssnd.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1t27p4z7bidzdjqd.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1tkxukot08dgpwbt.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1tz9gmedjn9p737z.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1v72fc0np44swbku.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1w1ju2tfjtpulam9.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1wd50i4kd74vdv4c.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.1xwt5aalooldi3ex.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.20dyrydgf428k5q5.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.211hbbml25qq68ez.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.23gucqwjf7j5l69x.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.24ib78nyvdpsehn2.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.29cxicvofkw0jq4z.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.29x9mfivg0jv356x.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2a3ksyit21txexs0.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2jjqzvqhtzu921ja.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2mmwcx28xlg7n3y.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2nhvryvgosli4t2b.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2rzxpo4wjlg688le.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2u52aaxbbnmzirqq.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2w2dng6cmtx51n0t.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2y1135tvki6xx0us.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.2zbm1kexdud4ock.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.31lql8y4cwqq1rsc.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.33ucu751hxg4cyp1.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.34zsrisfrvqit1qq.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.35311tvn2k2eznof.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.35glmbccb6dlrm6t.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.37242ih5zl9hnflb.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.3frlgq4ppsqjfetr.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.3kjz6fj8y8a3b2lq.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.3m5ddhkq79a4w9zn.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.3neuj8d1sh5n5y70.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.3srbft7cf0q3knwl.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.3y1du7vm261s6dqc.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.3za3p4ouch3zlwft.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.40aepun10jbxed3l.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.40s7n70at8yvyzky.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.41vkwl7szymn0ydb.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.42cxnfc26ifudjg4.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.430qo95zjwl988gu.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.45ghfp84t7v6v1zn.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.46n99y900bjdc2c9.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.46vcmvebey20dmo2.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.47unlhthlw5w3ur4.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.47zeayp8oss7h8nj.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4bnhetudb5on11hn.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4fjwgz4uzeevtuym.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4g2yyfwyz2o8orwf.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4gac27tdcsxhmsg8.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4gnz9hfs1leuyg3v.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4h8f28uyw22iopxn.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4iisxetqadowrrjc.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4jn1wt1wyf6k5uqv.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4opzxpspbu41ps9j.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4qb2rbmcieiz0lkv.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4qw6owwety6j8tti.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.4ws90etbifrlzvyp.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.54j4girgkeq887ai.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.54ozlt8pgqdcir2n.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.55snzhhyjc1y3xuw.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.56fyqr7ezx9hnynk.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.5gm2kf7lr0z2mz4z.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.63wn2sw0lsflw4q.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.6bvsrczg4mob2iq.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.bvzhfeqrd1miunh.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.gfgkbg63bdgtrhu.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.hcsfaat1yr86gdb.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.hwhafoy2x1yrwu9.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.iece6mxl3ynkwfm.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.m1ycnnzho3hu308.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.nazzxdvx4tni2st.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.qq8qh95ksor3yte.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.vtnwx071pemu57t.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.ypwq9ji9yo78kzz.rcgu.o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e.ysmoy9rm9wap8g2.rcgu.o" "-Wl,--as-needed" "-L" "/home/r/src/rust/miri.2/target/debug/deps" "-L" "/home/r/src/rust/miri.2/target/debug/build/jemalloc-sys-e486b8af66a531e2/out/build/lib" "-L" "/home/r/src/rust/miri.2/target/debug/build/libffi-sys-e1e746640b368ab4/out/libffi-root/lib" "-L" "/home/r/src/rust/miri.2/target/debug/build/libffi-sys-e1e746640b368ab4/out/libffi-root/lib64" "-L" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/r/src/rust/miri.2/target/debug/deps/libaes-d27d768da7a7b0b1.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libcpufeatures-761c6e9bf04d6606.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libcipher-c90706229fcff33e.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libinout-de362980c6a24efa.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libcrypto_common-d0f50804162871cb.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libgeneric_array-3f2ffc280ce1dbbf.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libtypenum-f28a8382956c41d8.rlib" "/home/r/src/rust/miri.2/target/debug/deps/liblibloading-306f9ee4a9858b9d.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libmeasureme-2d58b4bc5bbf7ebe.rlib" "/home/r/src/rust/miri.2/target/debug/deps/librustc_hash-bbbf74eb674bc8eb.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libparking_lot-2a8e11285ae5880f.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libparking_lot_core-82788d9c72c2ac23.rlib" "/home/r/src/rust/miri.2/target/debug/deps/liblock_api-3f7a67bc67bad859.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libscopeguard-0e29fa3dc136589b.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libperf_event_open_sys-796a3bcc04573a4f.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libmemmap2-42ecdbe0a18eebc7.rlib" "/home/r/src/rust/miri.2/target/debug/deps/liblog-bffec5f23a73e889.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libctrlc-2c97869c38cdbe01.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libnix-5222d02097068a7d.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libbitflags-307cc57d485557b2.rlib" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-0cd255ee414ee1b7.rlib" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-d94d981cfad2e302.rlib" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-bc5c85135ebc2d28.rlib" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-a783581261810918.rlib" "/home/r/src/rust/miri.2/target/debug/deps/liblibffi-1d4f6b13e9fd3e81.rlib" "/home/r/src/rust/miri.2/target/debug/deps/liblibffi_sys-99c31e51ef500979.rlib" "/home/r/src/rust/miri.2/target/debug/deps/librand-88ef0f10864fca5a.rlib" "/home/r/src/rust/miri.2/target/debug/deps/librand_chacha-6b0a1e7cb7bcc201.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libppv_lite86-fe09708be6de18e2.rlib" "/home/r/src/rust/miri.2/target/debug/deps/librand_core-d7a6061eaf088212.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libgetrandom-d5c3da24fb92135e.rlib" "/home/r/src/rust/miri.2/target/debug/deps/liblibc-433eaf9623d4a3c8.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libcfg_if-33350d16ae301f5d.rlib" "/home/r/src/rust/miri.2/target/debug/deps/libsmallvec-d31fd5d95e65d547.rlib" "-L" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bdynamic" "-lrustc_driver-c39020f115acfe15" "-L" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lstd-41777efa78699460" "-Wl,-Bstatic" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-b7903030bc1640bf.rlib" "-Wl,-Bdynamic" "-ldl" "-lLLVM-18-rust-1.78.0-nightly" "-ldl" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/r/src/rust/miri.2/target/debug/deps/miri-c318c1261dd2c19e" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "-Wl,-rpath,/home/r/.rustup/toolchains/miri/lib/rustlib/x86_64-unknown-linux-gnu/lib"
  = note: /usr/bin/ld: cannot find -lLLVM-18-rust-1.78.0-nightly: No such file or directory
          collect2: error: ld returned 1 exit status

Regression range: 6f435eb...eaee1e9

Likely cause: #121395
Cc @nikic

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 2, 2024
@nikic
Copy link
Contributor

nikic commented Mar 2, 2024

How does miri link against rust?

@RalfJung
Copy link
Member Author

RalfJung commented Mar 2, 2024

Just a bunch of extern crate:

extern crate rustc_apfloat;
extern crate rustc_ast;
extern crate rustc_const_eval;
extern crate rustc_data_structures;
extern crate rustc_errors;
extern crate rustc_hir;
extern crate rustc_index;
#[macro_use]
extern crate rustc_middle;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;

// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
// files.
#[allow(unused_extern_crates)]
extern crate rustc_driver;

@RalfJung
Copy link
Member Author

RalfJung commented Mar 2, 2024

Given that rustc CI still works and only builds against the distributed rustc toolchain are affected, it seems likely that the issue is related to the rustc-dev component -- maybe that doesn't contain all the required files any more?

@Noratrieb Noratrieb added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. requires-nightly This issue requires a nightly compiler in some way. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 2, 2024
@RalfJung
Copy link
Member Author

RalfJung commented Mar 2, 2024

Reproducing instructions:

  • checkout out this Miri branch
  • ./miri toolchain to install the right toolchain (that branch uses eaee1e9)
  • ./miri build

@nikic
Copy link
Contributor

nikic commented Mar 2, 2024

Given that rustc CI still works and only builds against the distributed rustc toolchain are affected, it seems likely that the issue is related to the rustc-dev component -- maybe that doesn't contain all the required files any more?

The necessary symlink is indeed not part of rustc-dev (only rust-dev). We could add it, but it's not obvious to me why it is needed. I'm not familiar with how rustc generates that linker invocation, but the fact that it explicitly includes -lLLVM in it seems wrong to me (-lLLVM is a dependency of -lrustc_driver and just linking against -lrustc_driver should be sufficient).

@RalfJung
Copy link
Member Author

RalfJung commented Mar 2, 2024

The necessary symlink is indeed not part of rustc-dev (only rust-dev).

There is no rust-dev component? At least this doesn't list one and rustup +nightly component list | grep rust-dev comes back empty.

We could add it, but it's not obvious to me why it is needed. I'm not familiar with how rustc generates that linker invocation, but the fact that it explicitly includes -lLLVM in it seems wrong to me (-lLLVM is a dependency of -lrustc_driver and just linking against -lrustc_driver should be sufficient).

I don't know anything about this linking magic either.^^ Cc @bjorn3

@RalfJung
Copy link
Member Author

RalfJung commented Mar 2, 2024

But evidently the symlink is needed... so in the mean time it'd be good to unstuck this by adding the symlink I think. I expect this will break out-of-tree builds of Clippy as well, and rustfmt -- basically every tool that links against rustc.

@nikic
Copy link
Contributor

nikic commented Mar 2, 2024

The necessary symlink is indeed not part of rustc-dev (only rust-dev).

There is no rust-dev component? At least this doesn't list one and rustup +nightly component list | grep rust-dev comes back empty.

Ah, it's not a real component, just the tarball that download-ci-llvm uses.

But evidently the symlink is needed... so in the mean time it'd be good to unstuck this by adding the symlink I think. I expect this will break out-of-tree builds of Clippy as well, and rustfmt -- basically every tool that links against rustc.

Main problem is that we have checks against shipping symlinks, and I expect they exist for good reason...

@RalfJung
Copy link
Member Author

RalfJung commented Mar 2, 2024

Ah, yeah probably Windows doesn't like them.

Why can't rustc_driver link against the correct .so file, i.e., why is a symlink needed in the first place?

@nikic
Copy link
Contributor

nikic commented Mar 2, 2024

I think this is the reason why it gets added to the linker line:

// 2. If the upstream crate is a dylib or a rlib linked through dylib, then we have to link
// the native library too because inline/const/generic functions from the dylib can refer
// to symbols from the native library, so the native library providing those symbols should
// be available when linking our final binary.

Why can't rustc_driver link against the correct .so file, i.e., why is a symlink needed in the first place?

This is because llvm-config returns something like -lLLVM-18 and the symlink is needed to resolve that to -l:libLLVM.so.18.1. And it seems like rustc just embeds the original name in the dylib, rather than the symlink-resolved variant, so the symlink is still needed.

Possibly that's a bug? Similar to how shared objects embed the resolved name, maybe rustc should do the same for its own metadata.

Though independent of general rustc behavior, I guess we could explicitly resolve the symlink in the build.rs for rustc_llvm. That might be the most straightforward fix.

@RalfJung
Copy link
Member Author

RalfJung commented Mar 2, 2024

This is because llvm-config returns something like -lLLVM-18 and the symlink is needed to resolve that to -l:libLLVM.so.18.1

If llvm-config inherently relies on a symlink, how do they support Windows?

@bjorn3
Copy link
Member

bjorn3 commented Mar 2, 2024

Possibly that's a bug? Similar to how shared objects embed the resolved name, maybe rustc should do the same for its own metadata.

That would break compiling an rlib which states that it links against a certain dylib when said dylib is not available on the host, right? Currently you only need dylibs to be available when actually linking (that is using a crate type other than rlib or staticlib).

I'm not familiar with how rustc generates that linker invocation, but the fact that it explicitly includes -lLLVM in it seems wrong to me (-lLLVM is a dependency of -lrustc_driver and just linking against -lrustc_driver should be sufficient).

It includes -lLLVM-18-rust-1.78.0-nightly, not -lLLVM. Even if just -lrustc_driver was passed, librustc_driver.so has a DT_NEEDED for LLVM-18-rust-1.78.0-nightly and thus libLLVM-18-rust-1.78.0-nightly.so needs to be present in $(rustc --print target-libdir). It seems libLLVM-18-rust-1.78.0-nightly.so is now entirely missing from rustc-dev. Edit: Forgot it is supposed to be in llvm-tools-preview, not in rustc-dev.

By the way libLLVM-18-rust-1.78.0-nightly.so has never been a symlink afaik. Instead a separate copy was shipped in both the rustc and llvm-tools-preview components. The first for rustc itself to link against and the second for user code to link against. Just like we ship librustc_driver.so in both the rustc and rustc-dev components. Both copies just happened to be identical.

@bjorn3
Copy link
Member

bjorn3 commented Mar 2, 2024

I just looked at the latest nightly and libLLVM-18-rust-1.78.0-nightly.so is present in both $(rustc --print sysroot)/lib and $(rustc --print target-libdir) as it should and librustc_driver.so has the correct DT_NEEDED filename for it. libLLVM-18-rust-1.78.0-nightly.so also has libLLVM-18-rust-1.78.0-nightly.so as DT_SONAME.

@bjorn3
Copy link
Member

bjorn3 commented Mar 2, 2024

I got confused about when #121395 got merged. I though it was already included in the latest nightly. I just looked at the llvm-preview component for that PR and it includes libLLVM.so.18.1-rust-1.78.0-nightly rather than the libLLVM-18-rust-1.78.0-nightly.so that is expected. Is it possible to rename it back and patch up the DT_SONAME? There is no way to link against libLLVM.so.18.1-rust-1.78.0-nightly with all linkers without a symlink, while for libLLVM-18-rust-1.78.0-nightly.so that is not a problem.

@RalfJung
Copy link
Member Author

RalfJung commented Mar 3, 2024

Why can't rustc_driver include -lLLVM-18.1-rust-1.78.0-nightly?

@bjorn3
Copy link
Member

bjorn3 commented Mar 3, 2024

Because the linker will prefix the name with lib and postfix it with .so, so -lLLVM-18.1-rust-1.78.0-nightly would cause the linker to look for libLLVM-18.1-rust-1.78.0-nightly.so rather than libLLVM.so.18.1-rust-1.78.0-nightly. (notice the different location of .so) The only portable way to link against libfoo.so.x.y.z is to create a symlink from libfoo.so to libfoo.so.x.y.z, set the SONAME to libfoo.x.y.z and then tell the linker to link against libfoo.so. But on Windows we can't use symlinks. While on linux -l:/path/to/libfoo.x.y.z is possible, this is not the case on most other targets.

@nikic
Copy link
Contributor

nikic commented Mar 3, 2024

This is because llvm-config returns something like -lLLVM-18 and the symlink is needed to resolve that to -l:libLLVM.so.18.1

If llvm-config inherently relies on a symlink, how do they support Windows?

Windows doesn't have a concept of sonames, so I don't think a symlink would be used there. I don't know what the dylib is called there. We use static linking there anyway. So I think we wouldn't actually ship a symlink on anything but Linux.

More problematic is the other part of this comment:

// Ensure there are no symbolic links in the tarball. In particular,
// rustup-toolchain-install-master and most versions of Windows can't handle symbolic links.

If rustup-toolchain-install-master can't deal with symlinks, that's also a problem for Linux.

@bjorn3
Copy link
Member

bjorn3 commented Mar 3, 2024

So I think we wouldn't actually ship a symlink on anything but Linux.

Any platform except Windows you mean?

@nikic
Copy link
Contributor

nikic commented Mar 3, 2024

So I think we wouldn't actually ship a symlink on anything but Linux.

Any platform except Windows you mean?

As far as I can tell, dist-x86_64-linux is the only configuration where we link LLVM dynamically. (Well and the llvm-16/llvm-17 images, but that's non-dist and a different situation anyway.)

@nbdd0121
Copy link
Contributor

nbdd0121 commented Mar 3, 2024

klint CI also starts failing with this exact same issue.

@nikic
Copy link
Contributor

nikic commented Mar 3, 2024

So to summarize, I see a few options here:

  1. Undo the library name change by carrying a patch in our LLVM fork. Implies carrying a long-term patch to LLVM, though a fairly small one.
  2. Undo the library name change after the fact. As @bjorn3 pointed out, this isn't just a matter of moving the files, we also have to fix up the DT_SONAME, which doesn't appear straightforward. Would require adding a dependency on patchelf?
  3. Ship the symlink in rustup components like rustc-dev, on Linux only. May require updates to tooling like rustup-toolchain-install-master.
  4. Change the way rustc links against upstream dylib dependencies, by resolving library names. Requires replicating linker search path logic and may break other other things. Not sure if this is possible.
  5. Same as 4, but only do this in rust_llvms build.rs. Again, not sure about the consequences, but at least this is more limited.

I think 3 is probably ideal long term, but depends on just how broken symlink support is right now. Is this a matter of "we'll copy the file instead of symlinking" or "rustup-toolchain-install-master is going to abort"? Maybe @Mark-Simulacrum knows.

The easiest fix would be 1.

@nbdd0121
Copy link
Contributor

nbdd0121 commented Mar 3, 2024

There's another fix, which is to ship a libLLVM-18-rust-1.78.0-nightly.so with content

INPUT(libLLVM.so.18.1-rust-1.78.0-nightly)

@nikic
Copy link
Contributor

nikic commented Mar 3, 2024

Oooh, that's a great idea!

@nbdd0121
Copy link
Contributor

nbdd0121 commented Mar 3, 2024

I got klint CI working with the fix: Rust-for-Linux/klint@277cb26

@RalfJung
Copy link
Member Author

RalfJung commented Mar 3, 2024

Option 6, convince LLVM that this way of naming libraries is a bad idea and causes problems?

I can't tell to what extent this is caused by Rust idiosyncrasies vs LLVM doing something strange.

There's another fix, which is to ship a libLLVM-18-rust-1.78.0-nightly.so with content

Wait, a .so file can be just a text file...?!?

@nikic
Copy link
Contributor

nikic commented Mar 3, 2024

Option 6, convince LLVM that this way of naming libraries is a bad idea and causes problems?

I can't tell to what extent this is caused by Rust idiosyncrasies vs LLVM doing something strange.

Basically, LLVM used to do it's own thing here, and now follows the standard convention for shared object naming on Linux. This turns out to be quite inconvenient for us, but I don't think it would be reasonable to ask LLVM to undo the change. (Though, imho, this change really should not have been done in an rc3 release...)

There's another fix, which is to ship a libLLVM-18-rust-1.78.0-nightly.so with content

Wait, a .so file can be just a text file...?!?

It can be a linker script. Somewhat unusual, but things like libc.so or libcxx.so are often linker scripts.

@RalfJung
Copy link
Member Author

RalfJung commented Mar 4, 2024

Well, if that linker script solution works that would be great. :)

@nikic nikic self-assigned this Mar 4, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 4, 2024
Replace libLLVM symlink with linker script

It turns out that the libLLVM-N.so -> libLLVM.so.N.1 symlink is also needed when projects like miri link against librustc_driver.so. As such, we have to distribute it in real rustup components like rustc-dev, rather than only for download-ci-llvm.

To avoid actually distributing symlinks (which are not supported or not fully supported by the rustup infrastructure) replace it with a linker script that does the same thing instead.

Fixes rust-lang#121889.

r? `@cuviper`
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 4, 2024
Replace libLLVM symlink with linker script

It turns out that the libLLVM-N.so -> libLLVM.so.N.1 symlink is also needed when projects like miri link against librustc_driver.so. As such, we have to distribute it in real rustup components like rustc-dev, rather than only for download-ci-llvm.

To avoid actually distributing symlinks (which are not supported or not fully supported by the rustup infrastructure) replace it with a linker script that does the same thing instead.

Fixes rust-lang#121889.

r? `@cuviper`
@RalfJung
Copy link
Member Author

RalfJung commented Mar 6, 2024

This is now beginning to block Miri development. If someone reading along knows enough about linkers to approve #121967 that would be great. :)

@bors bors closed this as completed in bfe762e Mar 6, 2024
bors added a commit to rust-lang/miri that referenced this issue Mar 6, 2024
Replace libLLVM symlink with linker script

It turns out that the libLLVM-N.so -> libLLVM.so.N.1 symlink is also needed when projects like miri link against librustc_driver.so. As such, we have to distribute it in real rustup components like rustc-dev, rather than only for download-ci-llvm.

To avoid actually distributing symlinks (which are not supported or not fully supported by the rustup infrastructure) replace it with a linker script that does the same thing instead.

Fixes rust-lang/rust#121889.

r? `@cuviper`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants