public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC-11.2.0 libatomic for bare-metal (riscv64-unknown-elf)
@ 2021-08-21 20:56 Aileen Honess
  2021-08-24 21:30 ` Jim Wilson
  0 siblings, 1 reply; 3+ messages in thread
From: Aileen Honess @ 2021-08-21 20:56 UTC (permalink / raw)
  To: gcc-help

Hi,

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.

How can I use __atomic_store(), __atomic_exchange(), etc. on RISCV-64 bare-metal?

Thanks!
Aileen

PS: Of course RISCV supports atomic memory operations with full spectrum of dedicated instructions.  They are defined in the “A” ISA extension, but supported by all RISC-V processors I know of.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: GCC-11.2.0 libatomic for bare-metal (riscv64-unknown-elf)
  2021-08-21 20:56 GCC-11.2.0 libatomic for bare-metal (riscv64-unknown-elf) Aileen Honess
@ 2021-08-24 21:30 ` Jim Wilson
  2021-08-24 21:43   ` Aileen Honess
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Wilson @ 2021-08-24 21:30 UTC (permalink / raw)
  To: Aileen Honess; +Cc: gcc-help

On Sat, Aug 21, 2021 at 1:56 PM Aileen Honess <aileen@brekersystems.com>
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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: GCC-11.2.0 libatomic for bare-metal (riscv64-unknown-elf)
  2021-08-24 21:30 ` Jim Wilson
@ 2021-08-24 21:43   ` Aileen Honess
  0 siblings, 0 replies; 3+ messages in thread
From: Aileen Honess @ 2021-08-24 21:43 UTC (permalink / raw)
  To: Jim Wilson; +Cc: gcc-help

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@sifive.com>
Sent: Tuesday, August 24, 2021 2:30 PM
To: Aileen Honess<mailto:aileen@brekersystems.com>
Cc: gcc-help@gcc.gnu.org<mailto:gcc-help@gcc.gnu.org>
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@brekersystems.com<mailto:aileen@brekersystems.com>> 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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-24 21:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-21 20:56 GCC-11.2.0 libatomic for bare-metal (riscv64-unknown-elf) Aileen Honess
2021-08-24 21:30 ` Jim Wilson
2021-08-24 21:43   ` Aileen Honess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).