[build2] Fix build on older x86 and arm CPUs

Norbert Lange nolange79 at gmail.com
Wed Dec 20 16:31:53 UTC 2017


Hello,

I tried crosscompiling the debian package, it will error out because
the (lowest denominator) CPU does not have built-in instructions for
atomics.
You can solve this generally by linking with '-latomic
-Wl,--as-needed'. libatomic has fallback implemenations, and
--as-needed will remove the dependency to the library if its unused.

I changed the error to warning, but IMHO its unnecessary now?

Norbert

-------------------------------------------------------------------------------
Description: Older CPUs need libatomic

Add libatomic to ensure the code compiels on older x86 and arm architectures.
If linked with -Wl,--as-needed, the dependecy will be removed if not needed.

Author: Norbert Lange <nolange79 at gmail.com>


--- a/build2/buildfile
+++ b/build2/buildfile
@@ -18,7 +18,7 @@
 obj{b context}: cxx.poptions += -DBUILD2_HOST_TRIPLET=\"$cxx.target\"

 if ($cxx.target.class != "windows")
-  cxx.libs += -lpthread
+  cxx.libs += -lpthread -latomic
 else
 {
   # Adjust stack size (affects all threads).
--- a/build2/target.hxx
+++ b/build2/target.hxx
@@ -1373,7 +1373,7 @@
     //               "timestamp is not lock-free on this architecture");

 #if !defined(ATOMIC_LLONG_LOCK_FREE) || ATOMIC_LLONG_LOCK_FREE != 2
-#  error timestamp is not lock-free on this architecture
+#  warning timestamp is not lock-free on this architecture
 #endif

     // Note that the value is not used to synchronize any other state so we
--- build2-toolchain-0.6.99.orig/libbutl/buildfile
+++ build2-toolchain-0.6.99/libbutl/buildfile
@@ -12,6 +12,9 @@ doc{version}: file{manifest}
 doc{version}: dist  = true
 doc{version}: clean = ($src_root != $out_root)

+if ($cxx.target.class != "windows")
+  cxx.libs += -latomic
+
 # Don't install tests or the INSTALL file.
 #
 dir{tests/}:     install = false



More information about the users mailing list