c11: --as-needed -latomic on riscv but not others
Fri Dec 17 20:00:47 GMT 2021
On Thu, Dec 16, 2021 at 11:48 PM Mathieu Malaterre <email@example.com> wrote:
> So if I understand the discussion correctly gcc is now adding by
> default `--as-needed -latomic` for riscv arch to support c11/atomics.
> What I fail to understand is why something identical was not applied
> to powerpc/armel and mipsel ?
RISC-V is the only major target that does not support subword atomics.
Some ports have hardware support for subword atomics. Some ports like PPC
lack hardware support for subword atomics but have gcc patterns to
implement them using full word atomic instructions. RISC-V has neither.
So anything using subword atomics on RISC-V will fail to link unless
-latomic is used, but will link fine on all other major targets.
Unfortunately, there are many package maintainers that refuse to add
-latomic to their packages because x86/arm doesn't need it. So we modified
the compiler to add the necessary -latomic option. However, in the FSF
tree, we only add -latomic when -pthread is used, because pthread
definitely needs subword atomic support. Though convincing people to use
the -pthread option is another issue, some package maintainers refuse to
use it even though the gcc docs say it is required. It looks like you have
a modified source tree that is adding the -latomic always which is one way
to fix that problem.
Adding gcc patterns to expand subword atomics into sequences of code using
full word atomic instructions would be a better fix, but it is a
complicated one. There are issues with the libstdc++ ABI changing, and
issues of how exactly we test the patch, and issues with writing it and
proving it is correct as the RISC-V memory consistency spec is
complicated. This has been a known problem for over 4 years, and no one
has volunteered to fix it yet.
More information about the Gcc-help