Repository navigation
riscv: link libgcc for jemalloc's __ffsdi2 - #180
Conversation
Base rv64gc has no count-trailing-zeros instruction, so gcc lowers the ffs in bit_util.h to a __ffsdi2 libgcc call. rust's compiler_builtins ships the rest of the *di2 family but not that one, so linking a static riscv64 binary fails with undefined reference to `__ffsdi2'. Name libgcc for riscv as is already done for android, guarded on a gnu-like compiler so a clang/compiler-rt toolchain is left alone. Signed-off-by: Mathieu Poumeyrol <kali@zoy.org>
|
Welcome @kali! It looks like this is your first PR to tikv/jemallocator 🎉 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe RISC-V build script now links ChangesRISC-V linker configuration
Estimated code review effort: 1 (Trivial) | ~5 minutes Merge Risk: ⚪ Minimal · up to GNU RISC-V builds now link libgcc to resolve the missing __ffsdi2 symbol for base rv64gc targets, without changing Clang/compiler-rt linkage. No current merge-blocking risk is identified. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Do you have a minimal reproduction? It seems rustc will link gcc automatically (tested on Rust 1.71 和 Rust 1.95). |
|
Yes. Sorry, there was a missing bit. The discriminator is a static link: with Minimal repro, TC comes from https://toolchains.bootlin.com/downloads/releases/toolchains/riscv64-lp64d/tarballs/riscv64-lp64d--musl--stable-2025.08-1.tar.xz . # Cargo.toml
[dependencies]
tikv-jemallocator = "0.7"// src/main.rs
#[global_allocator]
static A: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
fn main() { println!("{}", vec![1u8; 32].len()); }TC=<bootlin-toolchain>
export CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_LINKER=$TC/bin/riscv64-buildroot-linux-musl-gcc
export CC_riscv64gc_unknown_linux_musl=$TC/bin/riscv64-buildroot-linux-musl-gcc
export AR_riscv64gc_unknown_linux_musl=$TC/bin/riscv64-buildroot-linux-musl-ar
export CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-C target-feature=+crt-static"
cargo build --release --target riscv64gc-unknown-linux-musl(5 such references, all from Same command with Symbol side of it: So With this PR's |
Base rv64gc has no count-trailing-zeros instruction, so gcc lowers the ffs in bit_util.h to a __ffsdi2 libgcc call. rust's compiler_builtins ships the rest of the *di2 family but not that one, so linking a static riscv64 binary fails with undefined reference to `__ffsdi2'.
Name libgcc for riscv as is already done for android, guarded on a gnu-like compiler so a clang/compiler-rt toolchain is left alone.
Summary by CodeRabbit