Got error `undefined reference to `getauxval’` during Rust cross-compile to aarch64 with musl on x86_64

Hello everyone. I am trying to build Rust application for two OpenWRT routers. One is on ramips (mipsel) platform and another is on rockchip (aarch64) platform.

I completed the cross-compilation for mipsel very well, but blocked for aarch64 with error message undefined reference to getauxval'`. Please see below for details.

-linux-musl/lib/self-contained" "-o" "/tmp/hello-reqwest/target/aarch64-unknown-linux-musl/debug/deps/hello_reqwest-4e5be7f0a2aebac1" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs" "/home/janvier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtend.o" "/home/janvier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtn.o"
  = note: /home/janvier/toolchain/toolchain-aarch64_generic_gcc-11.2.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/11.2.0/../../../../aarch64-openwrt-linux-musl/bin/ld: /home/janvier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-0a28d23d76fcec1d.rlib(cpu_model.o): in function `init_have_lse_atomics':
          /cargo/registry/src/ undefined reference to `getauxval'
          collect2: error: ld returned 1 exit status
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see

error: could not compile `hello-reqwest` due to previous error

use std::error::Error;
use reqwest::Client;

async fn main() -> Result<(), Box<dyn Error>> {
    let client = Client::new();
    let response = client.get("").send().await?;
    let body = response.text().await?;
    println!("Body:\n{}", body);


name = "hello-reqwest"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at

reqwest = "0.11.16"
tokio = { version = "1.27.0", features = ["full"] }
openssl = { version = "0.10.50", features = ["vendored"] }

and ~/.cargo/config.toml

linker = "/home/janvier/openwrt-sdk-22.03.2/rockchip/staging_dir/toolchain-aarch64_generic_gcc-11.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc"

linker = "/home/janvier/openwrt-sdk-22.03.2/ramips/staging_dir/toolchain-mipsel_24kc_gcc-11.2.0_musl/bin/mipsel-openwrt-linux-musl-gcc"

After inspecting the error message, I noticed the problem may on libcompiler_builtins-0a28d23d76fcec1d.rlib which comes with rustup target add. Perhaps this is a bug of Rust cross-compiling.

Is anyone knows how to resolve this problem?

Musl should have getauxval afaik. The respective object file that references it comes from LLVM's compiler-rt by the way.

So, do you have any idea to fix this?

Unfortunately not. Try opening an issue.

No problem. Thanks for your kindly reply.

ps. I have posted an issue at Got error `undefined reference to 'getauxval'` during Rust cross-compile to aarch64 with musl on x86_64 · Issue #3324 · rust-lang/rustup · GitHub

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.