Skip to contentSkip to conversation

toolchain: introduce BR2_TOOLCHAIN_HAS_LIBATOMIC

PATCH New Thomas Petazzoni 2 participants 5 messages Mar 6, 2016 – Mar 20, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 toolchain: introduce BR2_TOOLCHAIN_HAS_LIBATOMIC

Until now, we were assuming that whenever you have gcc 4.8, libatomic is available. It turns out that this is not correct, since libatomic will not be available if thread support is disabled in the toolchain.

Therefore, __atomic_*() intrinsics may not be available even if the toolchain uses gcc 4.8.

To solve this problem, we introduce a BR2_TOOLCHAIN_HAS_LIBATOMIC boolean, which indicates whether the toolchain has libatomic. It is the case when you are using gcc >= 4.8 *and* thread support is enabled. We then use this new BR2_TOOLCHAIN_HAS_LIBATOMIC to define BR2_TOOLCHAIN_HAS_ATOMIC.

As explained in the comment, on certain architectures, libatomic is technically not needed to provide the __atomic_*() intrinsics since they might be all built-in. However, since libatomic is only absent in non-thread capable toolchains, it is not worth making things more complex for such seldomly used configuration.

Note that we are introducing the intermediate BR2_TOOLCHAIN_HAS_LIBATOMIC option because it will be useful on its own for certain packages.

---
 toolchain/toolchain-common.in | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
toolchain/toolchain-common.in +15 -2
index 1b7b416..596d1eb 100644
@@ -373,15 +373,28 @@ config BR2_TOOLCHAIN_HAS_SYNC_8
 	default y if BR2_TOOLCHAIN_ARM_HAS_SYNC_8
 	default y if BR2_TOOLCHAIN_X86_HAS_SYNC_8
 
+# libatomic is available since gcc 4.8, when thread support is
+# enabled.
+config BR2_TOOLCHAIN_HAS_LIBATOMIC
+	bool
+	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 && \
+		BR2_TOOLCHAIN_HAS_THREADS
+
 # __atomic intrinsics are available:
 # - with gcc 4.8, either through built-ins or libatomic, on all
-#   architectures
+#   architectures. Since we don't want to separate the cases where
+#   libatomic is needed vs. not needed, we simplify thing and only
+#   support situations where libatomic is available, even if on some
+#   architectures libatomic is not strictly needed as all __atomic
+#   intrinsics might be built-in. But the only case where libatomic is
+#   not available is when thread support is disabled, which is pretty
+#   unlikely.
 # - with gcc 4.7, libatomic did not exist, so only built-ins are
 #   available. This means that __atomic can only be used in a subset
 #   of the architectures
 config BR2_TOOLCHAIN_HAS_ATOMIC
 	bool
-	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
+	default y if BR2_TOOLCHAIN_HAS_LIBATOMIC
 	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_7 && BR2_arm
 	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_7 && BR2_armeb
 	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_7 && BR2_xtensa
Signature · 1 line
2.6.4
#1 lore raw

PATCH 1/2 toolchain: introduce BR2_TOOLCHAIN_HAS_LIBATOMIC

Hello,

Quoted 19 lines · Thomas Petazzoni

Until now, we were assuming that whenever you have gcc 4.8, libatomic is available. It turns out that this is not correct, since libatomic will not be available if thread support is disabled in the toolchain.

Therefore, __atomic_*() intrinsics may not be available even if the toolchain uses gcc 4.8.

To solve this problem, we introduce a BR2_TOOLCHAIN_HAS_LIBATOMIC boolean, which indicates whether the toolchain has libatomic. It is the case when you are using gcc >= 4.8 *and* thread support is enabled. We then use this new BR2_TOOLCHAIN_HAS_LIBATOMIC to define BR2_TOOLCHAIN_HAS_ATOMIC.

As explained in the comment, on certain architectures, libatomic is technically not needed to provide the __atomic_*() intrinsics since they might be all built-in. However, since libatomic is only absent in non-thread capable toolchains, it is not worth making things more complex for such seldomly used configuration.

Quoted 8 lines

Note that we are introducing the intermediate BR2_TOOLCHAIN_HAS_LIBATOMIC option because it will be useful on its own for certain packages.

---
 toolchain/toolchain-common.in | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

I've applied, after modifying the Config.in comment as suggested by Yann. I've also applied PATCH 2/2, which had Yann's Reviewed-by.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/2 toolchain: introduce BR2_TOOLCHAIN_HAS_LIBATOMIC

In reply to Thomas Petazzoni

Thomas, All,

On 2016-03-06 21:47 +0100, Thomas Petazzoni spake thusly:

Quoted 43 lines

Until now, we were assuming that whenever you have gcc 4.8, libatomic is available. It turns out that this is not correct, since libatomic will not be available if thread support is disabled in the toolchain.

Therefore, __atomic_*() intrinsics may not be available even if the toolchain uses gcc 4.8.

To solve this problem, we introduce a BR2_TOOLCHAIN_HAS_LIBATOMIC boolean, which indicates whether the toolchain has libatomic. It is the case when you are using gcc >= 4.8 *and* thread support is enabled. We then use this new BR2_TOOLCHAIN_HAS_LIBATOMIC to define BR2_TOOLCHAIN_HAS_ATOMIC.

As explained in the comment, on certain architectures, libatomic is technically not needed to provide the __atomic_*() intrinsics since they might be all built-in. However, since libatomic is only absent in non-thread capable toolchains, it is not worth making things more complex for such seldomly used configuration.

Note that we are introducing the intermediate BR2_TOOLCHAIN_HAS_LIBATOMIC option because it will be useful on its own for certain packages.

---
 toolchain/toolchain-common.in | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
toolchain/toolchain-common.in +7 -0
index 1b7b416..596d1eb 100644
@@ -373,15 +373,28 @@ config BR2_TOOLCHAIN_HAS_SYNC_8
 	default y if BR2_TOOLCHAIN_ARM_HAS_SYNC_8
 	default y if BR2_TOOLCHAIN_X86_HAS_SYNC_8
 
+# libatomic is available since gcc 4.8, when thread support is
+# enabled.
+config BR2_TOOLCHAIN_HAS_LIBATOMIC
+	bool
+	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_8 && \
+		BR2_TOOLCHAIN_HAS_THREADS
+

toolchain/toolchain-common.in config BR2_TOOLCHAIN_HAS_SYNC_8 · line 391

Quoted 10 lines
toolchain/toolchain-common.in +7 -1
 # __atomic intrinsics are available:
 # - with gcc 4.8, either through built-ins or libatomic, on all
-#   architectures
+#   architectures. Since we don't want to separate the cases where
+#   libatomic is needed vs. not needed, we simplify thing and only
+#   support situations where libatomic is available, even if on some
+#   architectures libatomic is not strictly needed as all __atomic
+#   intrinsics might be built-in. But the only case where libatomic is
+#   not available is when thread support is disabled, which is pretty
+#   unlikely.

That last sentence got me confused for a while, and your explanations on IRC were really necessary to me to understand it.

What about:

The only case where libatomic is missing entirely is when the toolchain does nto have support for threads. However, a package that does not need threads but still uses atomics is quite a corner case, which does not warrant the added complexity.

Otherwise, I'm fine with this:

    Reviewed-by: "Yann E. MORIN" <[email protected]>

Regards,
Yann E. MORIN.

Quoted 17 lines
toolchain/toolchain-common.in +1 -1
 # - with gcc 4.7, libatomic did not exist, so only built-ins are
 #   available. This means that __atomic can only be used in a subset
 #   of the architectures
 config BR2_TOOLCHAIN_HAS_ATOMIC
 	bool
-	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_8
+	default y if BR2_TOOLCHAIN_HAS_LIBATOMIC
 	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_7 && BR2_arm
 	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_7 && BR2_armeb
 	default y if BR2_TOOLCHAIN_GCC_AT_LEAST_4_7 && BR2_xtensa
Signature · 6 lines
2.6.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#3 lore raw

PATCH 2/2 cairo, icu, webkitgtk24: use BR2_TOOLCHAIN_HAS_LIBATOMIC

In reply to Thomas Petazzoni

This commit modifies the cairo, icu and webkitgtk24 packages to use BR2_TOOLCHAIN_HAS_LIBATOMIC when appropriate.

Fixes:

http://autobuild.buildroot.net/results/ec4/ec4e48c0e4b8fa72d8bb7ef4ad67a166699c0b62/

---
 package/cairo/cairo.mk             | 2 +-
 package/icu/icu.mk                 | 2 +-
 package/webkitgtk24/webkitgtk24.mk | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
package/cairo/cairo.mk +1 -1
index 6b54b28..b6ab54e 100644
@@ -18,7 +18,7 @@ endif
 
 # cairo can use C++11 atomics when available, so we need to link with
 # libatomic for the architectures who need libatomic.
-ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_8),y)
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
 CAIRO_CONF_ENV += LIBS="-latomic"
 endif
 
package/icu/icu.mk +1 -1
index b4574e5..f245da2 100644
@@ -21,7 +21,7 @@ ICU_CONF_OPTS = \
 # When available, icu prefers to use C++11 atomics, which rely on the
 # __atomic builtins. On certain architectures, this requires linking
 # with libatomic starting from gcc 4.8.
-ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_8),y)
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
 ICU_CONF_ENV += LIBS="-latomic"
 endif
 
package/webkitgtk24/webkitgtk24.mk +1 -1
index d8e41b9..0438ceb 100644
@@ -29,7 +29,7 @@ endif
 WEBKITGTK24_CONF_ENV = ac_cv_path_icu_config=$(STAGING_DIR)/usr/bin/icu-config
 
 # Some 32-bit architectures need libatomic support for 64-bit ops
-ifeq ($(BR2_i386)$(BR2_mips)$(BR2_mipsel)$(BR2_sh),y)
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
 WEBKITGTK24_CONF_ENV += LIBS="-latomic"
 endif
 
Signature · 1 line
2.6.4
#4 lore raw

PATCH 2/2 cairo, icu, webkitgtk24: use BR2_TOOLCHAIN_HAS_LIBATOMIC

Thomas, All,

On 2016-03-06 21:47 +0100, Thomas Petazzoni spake thusly:

Quoted 19 lines

This commit modifies the cairo, icu and webkitgtk24 packages to use BR2_TOOLCHAIN_HAS_LIBATOMIC when appropriate.

Fixes:

http://autobuild.buildroot.net/results/ec4/ec4e48c0e4b8fa72d8bb7ef4ad67a166699c0b62/

---
 package/cairo/cairo.mk             | 2 +-
 package/icu/icu.mk                 | 2 +-
 package/webkitgtk24/webkitgtk24.mk | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
package/cairo/cairo.mk +0 -0
index 6b54b28..b6ab54e 100644

package/cairo/cairo.mk endif · line 20

Quoted 3 lines
package/cairo/cairo.mk +0 -0
@@ -18,7 +18,7 @@ endif
 
 # cairo can use C++11 atomics when available, so we need to link with
 # libatomic for the architectures who need libatomic.

Not from this patch, but: s/who/which/ (an architecture is not a person.)

otherwise:

Regards,
Yann E. MORIN.

Quoted 38 lines
package/cairo/cairo.mk +1 -1
-ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_8),y)
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
 CAIRO_CONF_ENV += LIBS="-latomic"
 endif
 
package/icu/icu.mk +1 -1
index b4574e5..f245da2 100644
@@ -21,7 +21,7 @@ ICU_CONF_OPTS = \
 # When available, icu prefers to use C++11 atomics, which rely on the
 # __atomic builtins. On certain architectures, this requires linking
 # with libatomic starting from gcc 4.8.
-ifeq ($(BR2_TOOLCHAIN_GCC_AT_LEAST_4_8),y)
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
 ICU_CONF_ENV += LIBS="-latomic"
 endif
 
package/webkitgtk24/webkitgtk24.mk +1 -1
index d8e41b9..0438ceb 100644
@@ -29,7 +29,7 @@ endif
 WEBKITGTK24_CONF_ENV = ac_cv_path_icu_config=$(STAGING_DIR)/usr/bin/icu-config
 
 # Some 32-bit architectures need libatomic support for 64-bit ops
-ifeq ($(BR2_i386)$(BR2_mips)$(BR2_mipsel)$(BR2_sh),y)
+ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
 WEBKITGTK24_CONF_ENV += LIBS="-latomic"
 endif
 
Signature · 6 lines
2.6.4

_______________________________________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'