rust-lang / wg-cargo-std-aware

Repo for working on "std aware cargo"
133 stars 8 forks source link

undefined reference errors on aarch64 #74

Closed SparrowLii closed 11 months ago

SparrowLii commented 2 years ago

My main.rs:

fn main() {
    println!("Hello, world!");
}

My Cargo.toml:

[package]
name = "untitled1"
version = "0.1.0"
edition = "2021"

[dependencies]

[profile.dev]
panic = "abort"

[profile.release]
lto = true
codegen-units = 1
panic = "abort"

My rust version:

rustc 1.58.0-nightly (18bc4bee9 2021-11-02)
binary: rustc
commit-hash: 18bc4bee9710b181b440a472635150f0d6257713
commit-date: 2021-11-02
host: aarch64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

My cargo version:

cargo 1.58.0-nightly (94ca096af 2021-10-29)

And when I run cargo +nightly build -Z build-std=std,panic_abort --target aarch64-unknown-linux-gnu --release, it failed as following:

Compiling untitled1 v0.1.0 (/home/liyuan/untitled1)
error: linking with `cc` failed: exit status: 1
|
= note: "cc" "/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps" "-L" "/home/liyuan/untitled1/target/release/deps" "-L" "/root/.rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,--end-group" "-Wl,-Bstatic" "/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/libcompiler_builtins-b1c09b11534f431a.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/root/.rustup/toolchains/nightly-aarch64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-gnu/lib" "-o" "/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-Wl,-O1" "-nodefaultlibs"
= note: /home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `main':
untitled1.a81abd85-cgu.0:(.text.main+0x584): undefined reference to `__aarch64_ldadd8_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `std::thread::current':
untitled1.a81abd85-cgu.0:(.text._ZN3std6thread7current17hcadb8da67f75b371E+0x94): undefined reference to `__aarch64_ldadd8_relax'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `std::sys_common::thread_info::THREAD_INFO::__getit::destroy':
untitled1.a81abd85-cgu.0:(.text._ZN3std10sys_common11thread_info11THREAD_INFO7__getit7destroy17hc88165896c9c7150E+0x30): undefined reference to `__aarch64_ldadd8_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `std::panicking::rust_panic_with_hook':
untitled1.a81abd85-cgu.0:(.text._ZN3std9panicking20rust_panic_with_hook17h33f06dd76800d30eE+0x38): undefined reference to `__aarch64_ldadd8_relax'
untitled1.a81abd85-cgu.0:(.text._ZN3std9panicking20rust_panic_with_hook17h33f06dd76800d30eE+0x21c): undefined reference to `__aarch64_ldadd8_relax'
untitled1.a81abd85-cgu.0:(.text._ZN3std9panicking20rust_panic_with_hook17h33f06dd76800d30eE+0x470): undefined reference to `__aarch64_ldadd8_relax'
untitled1.a81abd85-cgu.0:(.text._ZN3std9panicking20rust_panic_with_hook17h33f06dd76800d30eE+0x5e4): undefined reference to `__aarch64_swp1_acq_rel'
untitled1.a81abd85-cgu.0:(.text._ZN3std9panicking20rust_panic_with_hook17h33f06dd76800d30eE+0x808): undefined reference to `__aarch64_ldadd8_rel'
untitled1.a81abd85-cgu.0:(.text._ZN3std9panicking20rust_panic_with_hook17h33f06dd76800d30eE+0x828): undefined reference to `__aarch64_ldadd8_relax'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `std::sys::unix::os::getenv':
untitled1.a81abd85-cgu.0:(.text._ZN3std3sys4unix2os6getenv17h637ec447b7777c5dE+0xf4): undefined reference to `__aarch64_ldadd8_relax'
untitled1.a81abd85-cgu.0:(.text._ZN3std3sys4unix2os6getenv17h637ec447b7777c5dE+0x164): undefined reference to `__aarch64_ldadd8_relax'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `alloc::sync::Arc<T>::drop_slow':
untitled1.a81abd85-cgu.0:(.text._ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17h0b382be5746a13ddE+0x34): undefined reference to `__aarch64_ldadd8_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `core::ptr::drop_in_place<std::backtrace_rs::symbolize::gimli::Mapping>':
untitled1.a81abd85-cgu.0:(.text._ZN4core3ptr65drop_in_place$LT$std..backtrace_rs..symbolize..gimli..Mapping$GT$17he792609af40a5799E+0x3c): undefined reference to `__aarch64_ldadd8_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `std::backtrace_rs::symbolize::gimli::Context::new':
untitled1.a81abd85-cgu.0:(.text._ZN3std12backtrace_rs9symbolize5gimli7Context3new17h1cd0c0cb82efaeddE+0x6ec): undefined reference to `__aarch64_ldadd8_relax'
untitled1.a81abd85-cgu.0:(.text._ZN3std12backtrace_rs9symbolize5gimli7Context3new17h1cd0c0cb82efaeddE+0x73c): undefined reference to `__aarch64_ldadd8_rel'
untitled1.a81abd85-cgu.0:(.text._ZN3std12backtrace_rs9symbolize5gimli7Context3new17h1cd0c0cb82efaeddE+0x844): undefined reference to `__aarch64_ldadd8_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `addr2line::ResDwarf<R>::parse':
untitled1.a81abd85-cgu.0:(.text._ZN9addr2line17ResDwarf$LT$R$GT$5parse17h34982b0f66c65899E+0x43a4): undefined reference to `__aarch64_ldadd8_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `alloc::sync::Arc<T>::drop_slow':
untitled1.a81abd85-cgu.0:(.text._ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17hcf08a91070e3189aE+0x1c): undefined reference to `__aarch64_ldadd8_rel'
untitled1.a81abd85-cgu.0:(.text._ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17hcf08a91070e3189aE+0x48): undefined reference to `__aarch64_ldadd8_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o:untitled1.a81abd85-cgu.0:(.text._ZN4core3ptr149drop_in_place$LT$alloc..boxed..Box$LT$addr2line..ResDwarf$LT$gimli..read..endian_slice..EndianSlice$LT$gimli..endianity..LittleEndian$GT$$GT$$GT$$GT$17h0e1366d15b11f48fE+0x40): more undefined references to `__aarch64_ldadd8_rel' follow
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `std::sys_common::thread_local_key::StaticKey::lazy_init':
untitled1.a81abd85-cgu.0:(.text._ZN3std10sys_common16thread_local_key9StaticKey9lazy_init17h00558e98e3620b2eE+0x68): undefined reference to `__aarch64_cas8_acq_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `std::sync::once::Once::call_inner':
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x80): undefined reference to `__aarch64_cas8_acq'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x1f8): undefined reference to `__aarch64_ldadd8_relax'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x230): undefined reference to `__aarch64_cas8_rel'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x24c): undefined reference to `__aarch64_ldadd8_rel'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x374): undefined reference to `__aarch64_ldadd8_relax'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x3a0): undefined reference to `__aarch64_ldadd4_acq'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x3d0): undefined reference to `__aarch64_cas4_acq'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x3e4): undefined reference to `__aarch64_ldadd8_rel'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x418): undefined reference to `__aarch64_ldadd8_rel'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x46c): undefined reference to `__aarch64_swp8_acq_rel'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x4b8): undefined reference to `__aarch64_swp4_rel'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x4cc): undefined reference to `__aarch64_ldadd8_rel'
untitled1.a81abd85-cgu.0:(.text.unlikely._ZN3std4sync4once4Once10call_inner17h1ad0eb23ff315876E+0x4f8): undefined reference to `__aarch64_ldadd8_rel'
/home/liyuan/untitled1/target/aarch64-unknown-linux-gnu/release/deps/untitled1-0800db29db292089.untitled1.a81abd85-cgu.0.rcgu.o: In function `core::ptr::drop_in_place<std::thread::Thread>':
untitled1.a81abd85-cgu.0:(.text._ZN4core3ptr40drop_in_place$LT$std..thread..Thread$GT$17h24d04784a5e3917cE+0x10): undefined reference to `__aarch64_ldadd8_rel'
collect2: error: ld returned 1 exit status

= help: 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 https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `untitled1` due to previous error

Is this because the build-std tool does not support aarch64?

12101111 commented 2 years ago

I also found this in r/rust. I thought this is a bug of zig at that time, but now I find it's a regression of rust.

Test with the config in my reply

> cargo bisect-rustc  --verbose --with-src --start 2021-01-01
...

searched toolchains nightly-2021-01-01 through nightly-2021-10-29

********************************************************************************
Regression in nightly-2021-10-05
********************************************************************************

...

get_commits_between returning commits, len: 7
  commit[0] 2021-10-03UTC: Auto merge of #89486 - rusticstuff:docker_letsencrypt_ca_update, r=Mark-Simulacrum
  commit[1] 2021-10-03UTC: Auto merge of #88175 - camsteffen:let-desugar-span, r=Manishearth
  commit[2] 2021-10-04UTC: Auto merge of #89165 - jkugelman:read-to-end-overallocation, r=joshtriplett
  commit[3] 2021-10-04UTC: Auto merge of #89512 - Manishearth:rollup-meh9x7r, r=Manishearth
  commit[4] 2021-10-04UTC: Auto merge of #89489 - FabianWolff:issue-89485, r=oli-obk
  commit[5] 2021-10-04UTC: Auto merge of #88834 - the8472:char-count, r=joshtriplett
  commit[6] 2021-10-04UTC: Auto merge of #89530 - workingjubilee:rollup-ua14iq6, r=workingjubilee
validated commits found, specifying toolchains
...
********************************************************************************
Regression in 003d8d3f56848b6f3833340e859b089a09aea36a
********************************************************************************

So It's pr https://github.com/rust-lang/rust/pull/83655 via https://github.com/rust-lang/rust/commit/003d8d3f56848b6f3833340e859b089a09aea36a

It also cause another breakage: https://github.com/rust-lang/rust/issues/89626

SparrowLii commented 2 years ago

This problem can currently be solved by adding the compilation parameter -Ctarget-feature=-outline-atomics, so I think this issue can be closed.

ehuss commented 2 years ago

I'm going to reopen. We want build-std to "just work", and not working on a tier-1 platform without a special option isn't the kind of experience we would like.

I'm still uncertain about the solution here. I don't want to hard-code special rules inside cargo. I also don't want to require building C code. I don't yet fully understand this situation, though. rust-lang/rust#83655 contains some more discussion.

workingjubilee commented 1 year ago

This was a mistake on my part, my apologies. It will be corrected.

jyn514 commented 1 year ago

This will be fixed by https://github.com/rust-lang/rust/pull/102579.

jyn514 commented 11 months ago

https://github.com/rust-lang/rust/pull/113269 has landed :)

workingjubilee commented 11 months ago

Ah, thank you so much!