RE: GCC-11.2.0 libatomic for bare-metal (riscv64-unknown-elf)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you Mr. Wilson!

Indeed, I feel that I stepped unknowingly into this well-known (to others) issue…
Consider open-coding subword atomics or move to libgcc · Issue #12 · riscv/riscv-gcc (github.com)<https://github.com/riscv/riscv-gcc/issues/12>

I’m going to tackle your last recommendation because I do need these routines.  I had hoped that compiler built-ins (via stdatomic.h) would give me a jump start.

I presume the same status is true for clang 12?  They haven’t implemented these atomic built-ins either?

Thanks!
--
Aileen Honess           https://brekersystems.com/support

From: Jim Wilson<mailto:jimw@xxxxxxxxxx>
Sent: Tuesday, August 24, 2021 2:30 PM
To: Aileen Honess<mailto:aileen@xxxxxxxxxxxxxxxxx>
Cc: gcc-help@xxxxxxxxxxx<mailto:gcc-help@xxxxxxxxxxx>
Subject: Re: GCC-11.2.0 libatomic for bare-metal (riscv64-unknown-elf)

On Sat, Aug 21, 2021 at 1:56 PM Aileen Honess <aileen@xxxxxxxxxxxxxxxxx<mailto:aileen@xxxxxxxxxxxxxxxxx>> wrote:
When I configure and create a gcc cross-compiler for aarch64-unknown-elf, I get a valid and working libatomic.  Critically, this contains implementations of the methods that underlie the gcc atomic builtins (__atomic_load(), etc.).  I mean things like '__atomic_fetch_and_1()'.
When I do similar for riscv64-unknown-elf, I do not get libatomic. The “configure.tgt” for libatomic says that the platform is UNSUPPORTED.  The build continues, but if I use the atomic builtins, I’ll get undefined references to those underlying functions.

libatomic fails to build for all *-elf targets.  So it is failing to build for both aarch64-elf and riscv-elf.  The difference here is that rv32 only has atomic support for 32-bit words, and rv64 only has atomic support for 32-bit words and 64-bit double words.  Whereas aarch64 v8.1-a has atomic support for all integer types, so can emit code directly for operations like __atomic_fetch_and_1.  If compiling for RISC-V or armv8.0 then you will get calls to functions for unsupported types.  aarch64 apparently has a library somewhere to implement these functions for *-elf toolchains.  RISC-V does not yet.  We have long term plans to open code the char and short operations using lr.[wd] and sc.[wd] but we don't know when this work will be done.

Meanwhile, you should avoid char/short atomic operations.  Or you could write your own library routines.  You could take the linux riscv libatomic and disassemble it to get the code you need.

Jim






[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux