Skip to content

riscv32i: __atomic_load_4 is referenced in libcompiler_builtins #92897

Closed

Description

@xobs

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.

Activity

  1. added
    C-bugCategory: This is a bug.
    regression-untriagedUntriaged performance or correctness regression.
    on Jan 14, 2022
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 14, 2022
  3. xobs commented on Jan 14, 2022

    @xobs
    ContributorAuthor

    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.

  4. xobs commented on Jan 14, 2022

    @xobs
    ContributorAuthor

    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 }
    }
  5. Amanieu commented on Jan 14, 2022

    @Amanieu
    Member

    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.

  6. added a commit that references this issue on Jan 15, 2022
  7. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 20, 2022
  8. apiraino commented on Feb 3, 2022

    @apiraino
    Contributor

    Nominating for stable backport as per Zulip discussion

    @rustbot label +stable-nominated

  9. added
    stable-nominatedNominated for backporting to the compiler in the stable channel.
    on Feb 3, 2022
  10. added
    stable-nominatedNominated for backporting to the compiler in the stable channel.
    and removed
    stable-nominatedNominated for backporting to the compiler in the stable channel.
    on Feb 3, 2022
  11. apiraino commented on Feb 3, 2022

    @apiraino
    Contributor

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

    @rustbot label +stable-accepted

  12. added
    stable-acceptedAccepted for backporting to the compiler in the stable channel.
    on Feb 3, 2022
  13. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Feb 9, 2022
  14. cyrozap commented on Jun 5, 2022

    @cyrozap

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

  15. Mark-Simulacrum commented on Jun 5, 2022

    @Mark-Simulacrum
    Member

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

  16. removed
    stable-nominatedNominated for backporting to the compiler in the stable channel.
    stable-acceptedAccepted for backporting to the compiler in the stable channel.
    on Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-untriagedUntriaged performance or correctness regression.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions