Hi,
On 2022-09-06 09:56, Bo YU wrote:
> Hi,
> On Wed, Aug 31, 2022 at 07:04:53PM +0200, Aurelien Jarno wrote:
> ...
> > reason for limiting the link with -latomic to pthread, but that has been
> > discussed internally before the patch submission to GCC, and has been
> > lost.
> >
> > Anyway this is probably something to try, but the way is done in Arch,
> > i.e. patching the binaries, is ugly. It's probably better to patch the
> > sources that way (completely untested):
> >
> > diff --git a/gcc/config/riscv/linux.h b/gcc/config/riscv/linux.h
> > --- a/gcc/config/riscv/linux.h
> > +++ b/gcc/config/riscv/linux.h
> > @@ -40,7 +40,7 @@ along with GCC; see the file COPYING3. If not see
> > #undef LIB_SPEC
> > #ifdef LD_AS_NEEDED_OPTION
> > #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC \
> > - " %{pthread:" LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION "}"
> > + LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION
> > #else
> > #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC " -latomic "
> > #endif
>
> I have built gcc-12 debian packages with your help and patch:
> https://drive.google.com/drive/folders/1jdqA9mrBea0BHhePVSHkPPOYo6pc7-dq?usp=sharing
>
> I tried it once but it doesn't seem to solve the problem. But there is a
> high probability that there is something wrong with my testing method:
>
> I installed gcc-12/g++-12 by manual on a clean riscv64 chroot and then
> try build thinkfan[0] with dpkg-buildpackage.
>
> I was wondering if it would be simpler to directly manipulate atomic
> statements in a c program also. Or could you help to verify it work or
> not again? The patch attached is full change at this time.I confirm that the issue is still there, it seems that the patch is not applied. The way to verify it is calling gcc -dumpspecs. I have tried to rebuild gcc with the patch, and I ended up with the attached patch, which is a slightly modified version of what I sent you. Unfortunately it doesn't build. It appears that latomic is not built as part of the gcc bootstrap process, so the gcc binary from stage 1 simply doesn't work due to the lack of libatomic... I guess this is 1) why that flag is only enabled for pthread 2) why gentoo is patching the binary instead. Aurelien -- Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
diff -Nru gcc-12-12.2.0/debian/changelog gcc-12-12.2.0/debian/changelog --- gcc-12-12.2.0/debian/changelog 2022-09-08 13:52:13.000000000 +0000 +++ gcc-12-12.2.0/debian/changelog 2022-09-11 11:58:07.000000000 +0000 @@ -1,3 +1,9 @@ +gcc-12 (12.2.0-2+latomic) UNRELEASED; urgency=medium + + * Try to always link with libatomic. + + -- Aurelien Jarno <[email protected]> Sun, 11 Sep 2022 11:58:07 +0000 + gcc-12 (12.2.0-2) unstable; urgency=medium * Update to git 20220908 from the gcc-12 branch. diff -Nru gcc-12-12.2.0/debian/patches/gcc-riscv64-latomic.diff gcc-12-12.2.0/debian/patches/gcc-riscv64-latomic.diff --- gcc-12-12.2.0/debian/patches/gcc-riscv64-latomic.diff 1970-01-01 00:00:00.000000000 +0000 +++ gcc-12-12.2.0/debian/patches/gcc-riscv64-latomic.diff 2022-09-11 11:58:07.000000000 +0000 @@ -0,0 +1,14 @@ +# DP: Always link with -latomic on riscv64, even if -pthread is not used. Since +# glibc 2.34, cmake does not use -pthread anymore. + +--- a/src/gcc/config/riscv/linux.h ++++ b/src/gcc/config/riscv/linux.h +@@ -40,7 +40,7 @@ along with GCC; see the file COPYING3. If not see + #undef LIB_SPEC + #ifdef LD_AS_NEEDED_OPTION + #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC \ +- " %{pthread:" LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION "}" ++ " " LD_AS_NEEDED_OPTION " -latomic " LD_NO_AS_NEEDED_OPTION + #else + #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC " -latomic " + #endif diff -Nru gcc-12-12.2.0/debian/rules.patch gcc-12-12.2.0/debian/rules.patch --- gcc-12-12.2.0/debian/rules.patch 2022-08-22 07:44:25.000000000 +0000 +++ gcc-12-12.2.0/debian/rules.patch 2022-09-11 11:58:01.000000000 +0000 @@ -61,6 +61,7 @@ musl-ssp \ pr79724-revert \ pr104290-followup \ + gcc-riscv64-latomic \ ifneq (,$(filter $(distrelease),precise xenial bionic focal groovy hirsute)) debian_patches += pr100067-revert
signature.asc
Description: PGP signature

