build: fix linking against -latomic when building for riscv #20938

pull fanquake wants to merge 2 commits into bitcoin:master from fanquake:fix_riscv_atomic_usage changing 2 files +4 −0
  1. fanquake commented at 3:01 AM on January 15, 2021: member

    Since the merge of #19937, riscv builds have been failing, due to a link issue with std::atomic_exchange in bitcoin-util:

      CXXLD    bitcoin-util
    bitcoin_util-bitcoin-util.o: In function `grind_task':
    /home/ubuntu/build/bitcoin/distsrc-riscv64-linux-gnu/src/bitcoin-util.cpp:98: undefined reference to `__atomic_exchange_1'
    collect2: error: ld returned 1 exit status
    
    

    We have a macro that tries to determine when -latomic is required, however it doesn't quite work well enough, as it's currently determining it isn't needed:

    ./autogen.sh
    ./configure --prefix=/home/ubuntu/bitcoin/depends/riscv64-linux-gnu
    ...
    checking whether std::atomic can be used without link library... yes
    

    This PR adds a call to std::atomic_exchange to the macro, which will get us properly linked against -latomic on riscv:

    checking whether std::atomic can be used without link library... no
    checking whether std::atomic needs -latomic... yes
    

    Also adds an <atomic> include to bitcoin-util.cpp.

  2. add std::atomic include to bitcoin-util.cpp 2c010b9c56
  3. build: improve macro for testing -latomic requirement
    riscv builds are currently failing because -latomic isn't being linked
    against, when it is needed:
    ```bash
    /home/ubuntu/build/bitcoin/distsrc-riscv64-linux-gnu/src/bitcoin-util.cpp:98: undefined reference to `__atomic_exchange_1'
    ```
    
    This exteneds our macro to ensure that -latomic is linked against when
    required.
    54ce4fac80
  4. fanquake added the label Build system on Jan 15, 2021
  5. fanquake renamed this:
    Fix linking against -latomic when building for riscv
    build: fix linking against -latomic when building for riscv
    on Jan 15, 2021
  6. MarcoFalke added the label Needs gitian build on Jan 15, 2021
  7. laanwj commented at 11:40 AM on January 18, 2021: member

    Testing this. Doing a compile on the SiFive Unleashed is a bit slow, so give it some time.

    Master without this PR:

    configure:5619: checking whether std::atomic can be used without link library
    configure:5637: g++ -std=c++17 -o conftest -g -O2   conftest.cpp  >&5
    configure:5637: $? = 0
    configure:5639: result: yes
    

    Now trying a build of master to see if it fails. Will then try with this PR.

    Edit: this clang issue seems related: https://reviews.llvm.org/D69869 . The conclusion is the same—RISC-V GCC needs libatomic for some atomic operations, but not others.

    Edit2: i got some awful, unrelated DWARF error during linking, i think my build toolchain is messed up

    Edit3: reproduced

    /usr/bin/ld: bitcoin_util-bitcoin-util.o: in function `.L0 ':
    /data/src/bitcoin/src/bitcoin-util.cpp:102: undefined reference to `__atomic_exchange_1'
    collect2: error: ld returned 1 exit status
    gmake[2]: *** [Makefile:5562: bitcoin-util] Error 1
    gmake[2]: *** Waiting for unfinished jobs....
    
  8. laanwj commented at 5:32 PM on January 18, 2021: member

    Tested ACK 54ce4fac80689621dcbcc76169b2b00b179ee743

  9. laanwj merged this on Jan 18, 2021
  10. laanwj closed this on Jan 18, 2021

  11. MarcoFalke removed the label Needs gitian build on Jan 18, 2021
  12. sidhujag referenced this in commit f2485c00b8 on Jan 20, 2021
  13. fanquake deleted the branch on Feb 6, 2021
  14. luke-jr referenced this in commit 594eb77f73 on Jun 27, 2021
  15. furszy referenced this in commit f2b45fded0 on Jan 9, 2022
  16. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-26 06:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me