Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

riscv32i: __atomic_load_4 is referenced in libcompiler_builtins #92897

Closed
xobs opened this issue Jan 14, 2022 · 7 comments
Closed

riscv32i: __atomic_load_4 is referenced in libcompiler_builtins #92897

xobs opened this issue Jan 14, 2022 · 7 comments
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xobs
Copy link
Contributor

xobs commented Jan 14, 2022

The atomic function __atomic_load_4 is getting referenced somehow in libcompiler_builtins. I'm not sure how to trigger the linker issue, however we've started running into it on CI:

https://ci.betrusted.io/job/betrusted-ec-fw/117/console

22:12:25   = note: "rust-lld" "-flavor" "gnu" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/deps/sw-d670ba951948c61d.sw.eb99c8ab-cgu.0.rcgu.o" "--as-needed" "-L" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/deps" "-L" "/var/lib/jenkins/workspace/betrusted-ec/target/release/deps" "-L" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/build/sw-5aeb8f44ae52ec32/out" "-L" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/build/riscv-3af36cb162907fdc/out" "-L" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/build/riscv-rt-10c1a68888f3c71a/out" "-L" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/build/riscv-rt-10c1a68888f3c71a/out" "-L" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/build/wfx_sys-435e2ecbf8d2b6bf/out" "-L" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/build/vexriscv-ef796b3ba7eaa702/out" "-L" "/var/lib/jenkins/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32i-unknown-none-elf/lib" "-Bstatic" "/tmp/rustct4qDCB/libriscv_rt-23b03c226d1df842.rlib" "/tmp/rustct4qDCB/libvexriscv-abccfdbcb773d5aa.rlib" "/tmp/rustct4qDCB/libwfx_sys-b5ebfbb5dde2c0d0.rlib" "/tmp/rustct4qDCB/libriscv-5c53201af539b932.rlib" "/var/lib/jenkins/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32i-unknown-none-elf/lib/libcompiler_builtins-6af234694b8e479b.rlib" "-Bdynamic" "-znoexecstack" "-L" "/var/lib/jenkins/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32i-unknown-none-elf/lib" "-o" "/var/lib/jenkins/workspace/betrusted-ec/target/riscv32i-unknown-none-elf/release/deps/sw-d670ba951948c61d" "--gc-sections" "-Tmemory.x" "-Tlink.x" "-Map=betrusted-ec.map"
22:12:25   = note: rust-lld: error: undefined symbol: __atomic_load_4
22:12:25           >>> referenced by uint_macros.rs:1222 (/rustc/02072b482a8b5357f7fb5e5637444ae30e423c40/library/core/src/num/uint_macros.rs:1222)
22:12:25           >>>               compiler_builtins-6af234694b8e479b.compiler_builtins.3786cd3d-cgu.96.rcgu.o:(memcpy) in archive /var/lib/jenkins/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv32i-unknown-none-elf/lib/libcompiler_builtins-6af234694b8e479b.rlib

Version it worked on

It used to work on Rust 1.57.1, however it has broken on Rust 1.58.0.

@xobs xobs added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jan 14, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 14, 2022
@xobs
Copy link
Contributor Author

xobs commented Jan 14, 2022

More information: This symbol is clearly present in the object files. Inside libcompiler_builtins-6af234694b8e479b.rlib there is an object file compiler_builtins-6af234694b8e479b.compiler_builtins.3786cd3d-cgu.96.rcgu.o. This contains references to this function, even though it doesn't appear to actually be used:

riscv64-unknown-elf-readelf.exe -a .\compiler_builtins-6af234694b8e479b.compiler_builtins.3786cd3d-cgu.96.rcgu.o | rg __atomic
0000009c  00017913 R_RISCV_CALL_PLT  00000000   __atomic_load_4 + 0
000000b4  00017913 R_RISCV_CALL_PLT  00000000   __atomic_load_4 + 0
00000158  00017913 R_RISCV_CALL_PLT  00000000   __atomic_load_4 + 0
   377: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND __atomic_load_4

Note that I previously opened #85736, however this seems to be different because it doesn't involve LTO and I can tell that libcompiler_builtins is actually getting shipped with these references in place.

@xobs
Copy link
Contributor Author

xobs commented Jan 14, 2022

A workaround we've done to get it to at least compile on 1.58.0 is to add this code somewhere in the project:

#[no_mangle]
pub fn __atomic_load_4(arg: *const usize, _ordering: usize) -> usize {
    unsafe { *arg }
}

bunnie added a commit to betrusted-io/gateware that referenced this issue Jan 14, 2022
bunnie added a commit to betrusted-io/betrusted-soc that referenced this issue Jan 14, 2022
This only affects the simulation infrastructure, but it is a real
issue for betrusted-ec, which currently only builds under rustc-1.57.
@Amanieu
Copy link
Member

Amanieu commented Jan 14, 2022

This is fixed by rust-lang/compiler-builtins@e0187f1 which is included in compiler-builtins version 0.1.54. However Rust 1.58.0 uses compiler_builtins 0.1.53.

bunnie added a commit to betrusted-io/betrusted-ec that referenced this issue Jan 15, 2022
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 20, 2022
@apiraino
Copy link
Contributor

apiraino commented Feb 3, 2022

Nominating for stable backport as per Zulip discussion

@rustbot label +stable-nominated

@rustbot rustbot added the stable-nominated Nominated for backporting to the compiler in the stable channel. label Feb 3, 2022
@apiraino apiraino added stable-nominated Nominated for backporting to the compiler in the stable channel. and removed stable-nominated Nominated for backporting to the compiler in the stable channel. labels Feb 3, 2022
@apiraino
Copy link
Contributor

apiraino commented Feb 3, 2022

Stable backport of rust-lang/compiler-builtins@e0187f1 approved as per compiler team on Zulip

@rustbot label +stable-accepted

@rustbot rustbot added the stable-accepted Accepted for backporting to the compiler in the stable channel. label Feb 3, 2022
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 9, 2022
@cyrozap
Copy link

cyrozap commented Jun 5, 2022

I was having the same issue, but updating to rustc 1.59.0 (and later versions) fixed it for me.

@Mark-Simulacrum
Copy link
Member

Based on the dates I believe this should be fixed across all channels at this point, so going to go ahead and close.

@Mark-Simulacrum Mark-Simulacrum removed stable-nominated Nominated for backporting to the compiler in the stable channel. stable-accepted Accepted for backporting to the compiler in the stable channel. labels Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants