Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

undefined reference to __atomic_load_4 when compiling the agb crate #100619

Closed
Lymia opened this issue Aug 16, 2022 · 3 comments · Fixed by #100621
Closed

undefined reference to __atomic_load_4 when compiling the agb crate #100619

Lymia opened this issue Aug 16, 2022 · 3 comments · Fixed by #100621
Assignees
Labels
A-atomic Area: Atomics, barriers, and sync primitives C-bug Category: This is a bug. O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state O-bare-metal Target: Rust without an operating system

Comments

@Lymia
Copy link
Contributor

Lymia commented Aug 16, 2022

If you try to compile the agb crate with just build-roms, it fails with the following error:

+ cargo build --release --target thumbv4t-none-eabi
   Compiling the-purple-night v0.1.0 (/home/aino/data/projects/crates/agb/examples/the-purple-night)
error: linking with `arm-none-eabi-ld` failed: exit status: 1
  |
  = note: "arm-none-eabi-ld" "/tmp/rustconD6i5/symbols.o" "/home/aino/data/projects/crates/agb/target/thumbv4t-none-eabi/release/deps/the_purple_night-b8ba75b4faeb98b5.the_purple_night.62ef94b1-cgu.0.rcgu.o" "--as-needed" "-L" "/home/aino/data/projects/crates/agb/target/thumbv4t-none-eabi/release/deps" "-L" "/home/aino/data/projects/crates/agb/target/release/deps" "-L" "/home/aino/data/projects/crates/agb/target/thumbv4t-none-eabi/release/build/agb-5ac9222d9e5ae2ce/out" "-L" "/home/aino/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv4t-none-eabi/lib" "--start-group" "--end-group" "-Bstatic" "/home/aino/data/projects/crates/agb/target/thumbv4t-none-eabi/release/deps/libcompiler_builtins-3b5407e0191965f8.rlib" "-Bdynamic" "--eh-frame-hdr" "-znoexecstack" "-L" "/home/aino/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/thumbv4t-none-eabi/lib" "-o" "/home/aino/data/projects/crates/agb/target/thumbv4t-none-eabi/release/deps/the_purple_night-b8ba75b4faeb98b5" "--gc-sections" "-O1" "-Tgba.ld"
  = note: arm-none-eabi-ld: /home/aino/data/projects/crates/agb/target/thumbv4t-none-eabi/release/deps/libcompiler_builtins-3b5407e0191965f8.rlib(compiler_builtins-3b5407e0191965f8.compiler_builtins.01837706-cgu.0.rcgu.o): in function `compiler_builtins::mem::memmove':
          compiler_builtins.01837706-cgu.0:(.text._ZN17compiler_builtins3mem7memmove17h382c238f4a6131d3E+0x66): undefined reference to `__atomic_load_4'
          arm-none-eabi-ld: compiler_builtins.01837706-cgu.0:(.text._ZN17compiler_builtins3mem7memmove17h382c238f4a6131d3E+0xe8): undefined reference to `__atomic_load_4'
          
  = 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 `the-purple-night` due to previous error
error: Recipe `_build-rom` failed with exit code 101
error: Recipe `build-roms` failed on line 51 with exit code 101

This seems to be a regression from nightly-2022-08-12 to nightly-2022-08-13, and my best guess for the change that caused it is this pull request: #99464

@Lymia Lymia added the C-bug Category: This is a bug. label Aug 16, 2022
@Lymia Lymia changed the title undefined reference to __atomic_load_4' when compiling the agb` crate undefined reference to __atomic_load_4 when compiling the agb crate Aug 16, 2022
@taiki-e
Copy link
Member

taiki-e commented Aug 16, 2022

Filed #100621 to fix this.
FYI, a short-term workaround is to enable the atomics-32 target feature (-C target-feature=+atomics-32).

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 17, 2022
Pass +atomics-32 feature for {arm,thumb}v4t-none-eabi

Similar to rust-lang@89582e8, but for ARMv4t.
Pre-v6 ARM target does not have atomic CAS, except for Linux and Android where atomic CAS is provided by compiler-builtins. So, there is a similar issue as thumbv6m.

I have confirmed that enabling the `atomics-32` target feature fixes the problem in the project affected by this issue. (taiki-e/portable-atomic#28 (comment))

Closes rust-lang#100619

r? `@nikic`
cc `@Lokathor`
@workingjubilee workingjubilee added O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state A-atomic Area: Atomics, barriers, and sync primitives O-bare-metal Target: Rust without an operating system labels Aug 17, 2022
@bors bors closed this as completed in 64cd657 Aug 17, 2022
@John-Nagle
Copy link

Possibly related: https://users.rust-lang.org/t/cross-compile-works-in-debug-mode-fails-in-release-mode/89574

This is seen cross-compiling from Linux to Windows. Giant 1MB linker error message related to atomic_load, only in release mode, for target x86_64-pc-windows-gnu. Failing in rustc 1.67.1 stable. Currently asking for help comments; will file an issue in a day or two if nobody reports a known fix.

@taiki-e
Copy link
Member

taiki-e commented Feb 20, 2023

@John-Nagle
Since native atomic ops exist in x86_64, I don't believe this and #92897 are related to your problem.

Given that rend3 has enabled thin LTO, your problem may be related to #98302.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-atomic Area: Atomics, barriers, and sync primitives C-bug Category: This is a bug. O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state O-bare-metal Target: Rust without an operating system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants