Re: c11: --as-needed -latomic on riscv but not others

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

 



On Fri, 17 Dec 2021, 07:49 Mathieu Malaterre, <malat@xxxxxxxxxx> wrote:

> Hi all,
>
> I am staring at the following discussion, which eventually was resolved
> with:
>
> *
> https://github.com/riscv-collab/riscv-gcc/issues/12#issuecomment-276587351
>
> Copied here for convenience (*).
>
> 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 ?
>

Probably because it was a decision by the risc-v target maintainers, who
can decide what they want for their target, but not for other targets.



> Typically on mipsel (Debian gcc 11.2.0 toolchain):
>
> % cat a.c
> _Atomic(long long) ll;
>
> int main(void)
> {
>         ++ll;
>         return 0;
> }
>
> Result in:
>
> % gcc a.c
> /usr/bin/ld: /tmp/ccsr7u8u.o: in function `main':
> a.c:(.text+0x54): undefined reference to `__atomic_fetch_add_8'
> /usr/bin/ld: a.c:(.text+0x5c): undefined reference to
> `__atomic_fetch_add_8'
> collect2: error: ld returned 1 exit status
>
> So currently, gcc wants the developer to add explicitly `--as-needed
> -latomic` to the linker to get c11/atomics support. Would it make
> sense to patch gcc so that `--as-needed -latomic` is added also for
> those arches (powerpc, armel, mipsel...).
>
> Thanks for comments,
> -M
>
> (*)
>
> diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
> index d77ba3fcf27..1fab15fc081 100644
> --- a/gcc/config/riscv/linux.h
> +++ b/gcc/config/riscv/linux.h
> @@ -24,6 +24,12 @@ along with GCC; see the file COPYING3.  If not see
>
>  #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-riscv" XLEN_SPEC "-"
> ABI_SPEC ".so.1"
>
> +/* Because RISC-V only has word-sized atomics, it requries libatomic where
> +   others do not.  So link libatomic by default, as needed.  */
> +#undef LIB_SPEC
> +#define LIB_SPEC GNU_USER_TARGET_LIB_SPEC \
> +  " " LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION \
> +
>  #define LINK_SPEC "\
>  -melf" XLEN_SPEC "lriscv \
>  %{shared} \
>



[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