diff mbox series

[1/1] toolchain/Config.in: enable libatomic with BR2_BINFMT_FLAT

Message ID 20240307122806.102726-1-fontaine.fabrice@gmail.com
State New
Headers show
Series [1/1] toolchain/Config.in: enable libatomic with BR2_BINFMT_FLAT | expand

Commit Message

Fabrice Fontaine March 7, 2024, 12:28 p.m. UTC
Enable libatomic with BR2_BINFMT_FLAT to avoid the following build
failure with libopenssl and
BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV7M_UCLIBC_STABLE:

/home/buildroot/autobuild/run/instance-2/output-1/host/opt/ext-toolchain/arm-buildroot-uclinux-uclibcgnueabi/bin/ld.real: ./libcrypto.a(libcrypto-lib-threads_pthread.o): in function `CRYPTO_atomic_or':
threads_pthread.c:(.text+0xfa): undefined reference to `__atomic_is_lock_free'

Indeed, bootlin armv7m is an uclibc toolchain compiled with atomic
support through libatomic

This build failure is probably raised since activation of threads in
static builds by commit ea3e60229bc5647e587685023de475276e28584d

Fixes:
 - http://autobuild.buildroot.org/results/d25e898f9715bf6a21284807361a57735a7a2e1d
 - http://autobuild.buildroot.org/results/e37ed5ad6ba41d610bffe9c234f699e203ef5069

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
 toolchain/Config.in | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

Comments

Thomas Petazzoni March 7, 2024, 12:49 p.m. UTC | #1
Hello Fabrice,

On Thu,  7 Mar 2024 13:28:06 +0100
Fabrice Fontaine <fontaine.fabrice@gmail.com> wrote:

> Enable libatomic with BR2_BINFMT_FLAT to avoid the following build
> failure with libopenssl and
> BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV7M_UCLIBC_STABLE:
> 
> /home/buildroot/autobuild/run/instance-2/output-1/host/opt/ext-toolchain/arm-buildroot-uclinux-uclibcgnueabi/bin/ld.real: ./libcrypto.a(libcrypto-lib-threads_pthread.o): in function `CRYPTO_atomic_or':
> threads_pthread.c:(.text+0xfa): undefined reference to `__atomic_is_lock_free'
> 
> Indeed, bootlin armv7m is an uclibc toolchain compiled with atomic
> support through libatomic
> 
> This build failure is probably raised since activation of threads in
> static builds by commit ea3e60229bc5647e587685023de475276e28584d
> 
> Fixes:
>  - http://autobuild.buildroot.org/results/d25e898f9715bf6a21284807361a57735a7a2e1d
>  - http://autobuild.buildroot.org/results/e37ed5ad6ba41d610bffe9c234f699e203ef5069
> 
> Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>

Thanks for the patch. Do we know since when there is support for
libatomic for platforms that use the FLAT binary format? Is this
specific to ARM/FLAT, or applicable to all configurations that use the
FLAT binary format?

Thomas
Fabrice Fontaine March 7, 2024, 5:18 p.m. UTC | #2
Hello,

Le jeu. 7 mars 2024 à 13:49, Thomas Petazzoni
<thomas.petazzoni@bootlin.com> a écrit :
>
> Hello Fabrice,
>
> On Thu,  7 Mar 2024 13:28:06 +0100
> Fabrice Fontaine <fontaine.fabrice@gmail.com> wrote:
>
> > Enable libatomic with BR2_BINFMT_FLAT to avoid the following build
> > failure with libopenssl and
> > BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV7M_UCLIBC_STABLE:
> >
> > /home/buildroot/autobuild/run/instance-2/output-1/host/opt/ext-toolchain/arm-buildroot-uclinux-uclibcgnueabi/bin/ld.real: ./libcrypto.a(libcrypto-lib-threads_pthread.o): in function `CRYPTO_atomic_or':
> > threads_pthread.c:(.text+0xfa): undefined reference to `__atomic_is_lock_free'
> >
> > Indeed, bootlin armv7m is an uclibc toolchain compiled with atomic
> > support through libatomic
> >
> > This build failure is probably raised since activation of threads in
> > static builds by commit ea3e60229bc5647e587685023de475276e28584d
> >
> > Fixes:
> >  - http://autobuild.buildroot.org/results/d25e898f9715bf6a21284807361a57735a7a2e1d
> >  - http://autobuild.buildroot.org/results/e37ed5ad6ba41d610bffe9c234f699e203ef5069
> >
> > Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
>
> Thanks for the patch. Do we know since when there is support for
> libatomic for platforms that use the FLAT binary format? Is this
> specific to ARM/FLAT, or applicable to all configurations that use the
> FLAT binary format?

Nope, I don't know. I didn't find any clue in uclibc-ng github history.

>
> Thomas
> --
> Thomas Petazzoni, co-owner and CEO, Bootlin
> Embedded Linux and Kernel engineering and training
> https://bootlin.com

Best Regards,

Fabrice
Thomas Petazzoni March 11, 2024, 11:35 a.m. UTC | #3
On Thu, 7 Mar 2024 18:18:24 +0100
Fabrice Fontaine <fontaine.fabrice@gmail.com> wrote:

> > Thanks for the patch. Do we know since when there is support for
> > libatomic for platforms that use the FLAT binary format? Is this
> > specific to ARM/FLAT, or applicable to all configurations that use the
> > FLAT binary format?  
> 
> Nope, I don't know. I didn't find any clue in uclibc-ng github history.

That's because libatomic has nothing to do with the C library.
libatomic is provided by gcc. So if you want to find out why it is now
available for FLAT platforms, you should check the gcc Git history :-)

Best regards,

Thomas
Fabrice Fontaine March 12, 2024, 7:18 a.m. UTC | #4
Hello Thomas,

Le lun. 11 mars 2024 à 12:35, Thomas Petazzoni
<thomas.petazzoni@bootlin.com> a écrit :
>
> On Thu, 7 Mar 2024 18:18:24 +0100
> Fabrice Fontaine <fontaine.fabrice@gmail.com> wrote:
>
> > > Thanks for the patch. Do we know since when there is support for
> > > libatomic for platforms that use the FLAT binary format? Is this
> > > specific to ARM/FLAT, or applicable to all configurations that use the
> > > FLAT binary format?
> >
> > Nope, I don't know. I didn't find any clue in uclibc-ng github history.
>
> That's because libatomic has nothing to do with the C library.
> libatomic is provided by gcc. So if you want to find out why it is now
> available for FLAT platforms, you should check the gcc Git history :-)

After reading gcc git history, I didn't find anything either.
However, I found out some information in buildroot git history [1]:

"The cairo package fails to build on some architectures:
BR2_TOOLCHAIN_HAS_LIBATOMIC is enabled, but libatomic is in fact not
available.
This happens because the gcc logic in libatomic/configure.tgt does not
recognize "uclinux" as a valid OS part of the target tuple, and
therefore it does not build libatomic.
The "uclinux" part of the tuple is used by Buildroot when
BR2_BINFMT_FLAT=y, so we make BR2_TOOLCHAIN_HAS_LIBATOMIC enabled only
if !BR2_BINFMT_FLAT."

So finally this libatomic workaround has nothing to do with FLAT by itself.
The uclinux handling has been fixed but only for arm since gcc 10.1.0 with [2].
So dropping BR2_BINFMT_FLAT will probably raise build failure on other
architectures.

How should I proceed for my v2?
Should I replace !BR2_BINFMT_FLAT by (!BR2_BINFMT_FLAT=y ||
(BR2_TOOLCHAIN_GCC_AT_LEAST_10 && BR2_arm))?
An other option would be to add default y if
BR2_TOOLCHAIN_EXTERNAL_BOOTLIN_ARMV7M_UCLIBC_STABLE (more simple but
ugly).

[1] https://git.buildroot.net/buildroot/commit/?id=b3d1fb26dcadd8c570e2c415ce05398ecc810b32
[2] https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=b1e21e5a5d19b436f948710e09157c5b3244f541

>
> Best regards,
>
> Thomas
> --
> Thomas Petazzoni, co-owner and CEO, Bootlin
> Embedded Linux and Kernel engineering and training
> https://bootlin.com

Best Regards,

Fabrice
diff mbox series

Patch

diff --git a/toolchain/Config.in b/toolchain/Config.in
index 3dd6e83d35..13d1b94fe4 100644
--- a/toolchain/Config.in
+++ b/toolchain/Config.in
@@ -880,15 +880,12 @@  config BR2_TOOLCHAIN_HAS_SYNC_8
 	default y if BR2_TOOLCHAIN_X86_HAS_SYNC_8
 
 # libatomic is available since gcc 4.8, when thread support is
-# enabled. Also, libatomic doesn't recognize "uclinux" as a valid OS
-# part of the tuple, and is therefore not build on uclinux targets,
-# which is why BR2_BINFMT_FLAT configurations are excluded.
+# enabled.
 config BR2_TOOLCHAIN_HAS_LIBATOMIC
 	bool
 	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 && \
 		!BR2_TOOLCHAIN_EXTERNAL_CODESOURCERY_AARCH64 && \
-		BR2_TOOLCHAIN_HAS_THREADS && \
-		!BR2_BINFMT_FLAT
+		BR2_TOOLCHAIN_HAS_THREADS
 
 # __atomic intrinsics are available:
 # - with gcc 4.8, either through built-ins or libatomic, on all