BLAKE3
BLAKE3 copied to clipboard
Add linkage attributes to extern "C" blocks
This crate is now used in the compiler since https://github.com/rust-lang/rust/pull/126930. The problem I'm fixing is just like https://github.com/rust-lang/rust/issues/118084; if you try to run
RUSTFLAGS=-Zcross-crate-inline-threshold=always ./x.py build library
After around 30 minutes (-Zcross-crate-inline-threshold=always
makes compilation much slower) you get
= note: rust-lld: error: undefined symbol: blake3_hash_many_avx512
>>> referenced by ffi_avx512.rs:49 (/home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blake3-1.5.2/src/ffi_avx512.rs:49)
>>> /home/ben/rust-master/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_main-1766fdd0f895a9f6.rustc_main.5f5b835cb13221b6-cgu.0.rcgu.o:(blake3::compress_subtree_wide::<blake3::join::SerialJoin>)
>>> referenced by ffi_avx512.rs:49 (/home/ben/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blake3-1.5.2/src/ffi_avx512.rs:49)
>>> /home/ben/rust-master/build/x86_64-unknown-linux-gnu/stage1-rustc/x86_64-unknown-linux-gnu/release/deps/rustc_main-1766fdd0f895a9f6.rustc_main.5f5b835cb13221b6-cgu.0.rcgu.o:(blake3::compress_parents_parallel)
... any many more!
I think this is exactly the same problem as the above-linked issue: the blake3 crate does not have any link(name =
attributes, so it only links correctly if all calls to the extern "C"
functions are monomorphized by blake3
crate. But with -Zcross-crate-inline-threshold=always
, nearly all monomorphization is done by the last crate to be compiled, and without these attributes we lose track of these symbols by the time we need them.
I'm not filing an issue because I'm pretty sure nobody else cares about my silly flag continuing to work when bootstrapping the compiler, but I occasionally find legitimate codegen bugs with it, so I'm sending you the patch to keep it working.
I've confirmed in my local dev setup that this PR makes it again possible to build the compiler with -Zcross-crate-inline-threshold=always
.