Hi David!

On Sun, Mar 15, 2020 at 01:55:33PM +0000, David CARLIER wrote:
> Yes surely I had only a raspberry at hand arm64 surely needs too.
> change of approaches.

(...)

--- a/Makefile
+++ b/Makefile
@@ -328,6 +328,12 @@ ifeq ($(TARGET),linux-glibc)
     USE_CPU_AFFINITY USE_THREAD USE_EPOLL USE_FUTEX USE_LINUX_TPROXY          \
     USE_ACCEPT4 USE_LINUX_SPLICE USE_PRCTL USE_THREAD_DUMP USE_NS USE_TFO     \
     USE_GETADDRINFO USE_BACKTRACE)
+  ifneq ($(findstring arm,$(shell uname -m)),)
+    TARGET_LDFLAGS=-latomic
+  endif
+  ifneq ($(findstring aarch64,$(shell uname -m)),)
+    TARGET_LDFLAGS=-latomic
+  endif
 endif

Please no, not like this, it is wrong. Instead of testing the target, it
tests the build machine, which is not necessarily related, especially in
the ARM world where cross-compilation prevails due to the much slower
machines.

This would fail in both directions:
  - it will not correctly add -latomic if I build on my PC for one of
    my ARM machines ;

  - it will incorrectly append -latomic if I build from ARM for my PC.

Instead what needs to be tested is the compiler's default target.

There are two ways to do it properly, which are very close to each other:

  - either you emit all the compiler's pre-defined macros and search for
    your choosen target there:

    $(CC) -E -dM -xc - </dev/null | grep -w __aarch64__

    (not very clean since technically it could match anywhere)

  - or better, you verify that __aarch64__ equals 1 on this compiler:

    echo __aarch64__ | $(CC) -E -xc - | grep -q ^1

When you want to test if any value within a set is set, you can even
do it by testing that a string made of their concatenation changes:

    echo __arm__/__aarch64__ | $(CC) -E -xc - | grep -q __arm__/__aarch64__

If it returns a success, it means that neither define is not set in the
compiler.

So your patch can then be changed to roughly this to simply let "make"
check the output:

+  ifneq ($(shell echo __arm__/__aarch64__ | $(CC) -E -xc - | grep 
'^[^#]'),__arm__/__aarch64__)
+    TARGET_LDFLAGS=-latomic
+  endif

Cheers,
Willy

Reply via email to