bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* Fix link errors on Android 4.3
@ 2023-01-11  9:53 Bruno Haible
  2023-01-11 17:11 ` Bruno Haible
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Haible @ 2023-01-11  9:53 UTC (permalink / raw)
  To: bug-gnulib

Building a testdir on Android 4.3, I see these link errors:

terminal-gcc -mandroid -D__ANDROID__ -std=gnu99  -Wno-error -O2  -L/data/data/com.spartacusrex.spartacuside/files/local/lib -o test-asyncsafe-spin1 test-asyncsafe-spin1.o libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a libtests.a  -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm
../gllib/libgnu.a(asyncsafe-spin.o): In function `asyncsafe_spin_lock':
asyncsafe-spin.c:(.text+0x20): undefined reference to `__sync_val_compare_and_swap_4'
../gllib/libgnu.a(asyncsafe-spin.o): In function `asyncsafe_spin_unlock':
asyncsafe-spin.c:(.text+0x40): undefined reference to `__sync_val_compare_and_swap_4'
collect2: ld returned 1 exit status
make[4]: *** [test-asyncsafe-spin1] Error 1
terminal-gcc -mandroid -D__ANDROID__ -std=gnu99  -Wno-error -O2  -L/data/data/com.spartacusrex.spartacuside/files/local/lib -o test-asyncsafe-spin2 test-asyncsafe-spin2.o libtests.a ../gllib/libgnu.a libtests.a ../gllib/libgnu.a libtests.a     -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm -lm
../gllib/libgnu.a(asyncsafe-spin.o): In function `asyncsafe_spin_lock':
asyncsafe-spin.c:(.text+0x20): undefined reference to `__sync_val_compare_and_swap_4'
../gllib/libgnu.a(asyncsafe-spin.o): In function `asyncsafe_spin_unlock':
asyncsafe-spin.c:(.text+0x40): undefined reference to `__sync_val_compare_and_swap_4'
collect2: ld returned 1 exit status
make[4]: *** [test-asyncsafe-spin2] Error 1

Apparently the runtime support for these GCC built-ins is not contained in
the Android libc for this version.

This patch fixes the errors.


2023-01-11  Bruno Haible  <bruno@clisp.org>

	Fix link errors on Android 4.3.
	* lib/asyncsafe-spin.c: Don't use the GCC >= 4.1 builtins on Android.
	* lib/pthread-spin.c: Likewise.
	* lib/simple-atomic.c: Likewise.

diff --git a/lib/asyncsafe-spin.c b/lib/asyncsafe-spin.c
index 7a74c32077..66e1669924 100644
--- a/lib/asyncsafe-spin.c
+++ b/lib/asyncsafe-spin.c
@@ -136,7 +136,7 @@ do_unlock (asyncsafe_spinlock_t *lock)
 #  elif (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) \
           && !defined __sparc__) \
          || __clang_major__ >= 3) \
-        && !defined __ibmxl__
+        && !defined __ibmxl__ && !defined __ANDROID__
 /* Use GCC built-ins (available in GCC >= 4.1, except on SPARC, and
    clang >= 3.0).
    Documentation:
diff --git a/lib/pthread-spin.c b/lib/pthread-spin.c
index ca3e88755a..e551f733cf 100644
--- a/lib/pthread-spin.c
+++ b/lib/pthread-spin.c
@@ -164,7 +164,7 @@ pthread_spin_destroy (pthread_spinlock_t *lock)
 
 # elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) \
         || __clang_major__ >= 3) \
-       && !defined __ibmxl__
+       && !defined __ibmxl__ && !defined __ANDROID__
 /* Use GCC built-ins (available in GCC >= 4.1 and clang >= 3.0).
    Documentation:
    <https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html>  */
diff --git a/lib/simple-atomic.c b/lib/simple-atomic.c
index 4e52447ed6..ffa126613c 100644
--- a/lib/simple-atomic.c
+++ b/lib/simple-atomic.c
@@ -69,7 +69,7 @@ atomic_compare_and_swap_ptr (uintptr_t volatile *vp,
 # if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) \
        && !defined __sparc__) \
       || __clang_major__ >= 3) \
-     && !defined __ibmxl__
+     && !defined __ibmxl__ && !defined __ANDROID__
 /* Use GCC built-ins (available in GCC >= 4.1, except on SPARC, and
    clang >= 3.0).
    Documentation:





^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: Fix link errors on Android 4.3
  2023-01-11  9:53 Fix link errors on Android 4.3 Bruno Haible
@ 2023-01-11 17:11 ` Bruno Haible
  0 siblings, 0 replies; 2+ messages in thread
From: Bruno Haible @ 2023-01-11 17:11 UTC (permalink / raw)
  To: bug-gnulib

> 2023-01-11  Bruno Haible  <bruno@clisp.org>
> 
> 	Fix link errors on Android 4.3.
> 	* lib/asyncsafe-spin.c: Don't use the GCC >= 4.1 builtins on Android.
> 	* lib/pthread-spin.c: Likewise.
> 	* lib/simple-atomic.c: Likewise.

Actually there's no problem when building with clang, because clang apparently
does not generate a reference to an external function here. So, let me limit
the last change to builds with GCC.

diff --git a/lib/asyncsafe-spin.c b/lib/asyncsafe-spin.c
index 66e1669924..9964473828 100644
--- a/lib/asyncsafe-spin.c
+++ b/lib/asyncsafe-spin.c
@@ -134,9 +134,9 @@ do_unlock (asyncsafe_spinlock_t *lock)
 #   endif
 
 #  elif (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) \
-          && !defined __sparc__) \
+          && !defined __sparc__ && !defined __ANDROID__) \
          || __clang_major__ >= 3) \
-        && !defined __ibmxl__ && !defined __ANDROID__
+        && !defined __ibmxl__
 /* Use GCC built-ins (available in GCC >= 4.1, except on SPARC, and
    clang >= 3.0).
    Documentation:
diff --git a/lib/pthread-spin.c b/lib/pthread-spin.c
index e551f733cf..4031975f0b 100644
--- a/lib/pthread-spin.c
+++ b/lib/pthread-spin.c
@@ -162,9 +162,10 @@ pthread_spin_destroy (pthread_spinlock_t *lock)
   return 0;
 }
 
-# elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) \
+# elif (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) \
+         && !defined __ANDROID__) \
         || __clang_major__ >= 3) \
-       && !defined __ibmxl__ && !defined __ANDROID__
+       && !defined __ibmxl__
 /* Use GCC built-ins (available in GCC >= 4.1 and clang >= 3.0).
    Documentation:
    <https://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html>  */
diff --git a/lib/simple-atomic.c b/lib/simple-atomic.c
index ffa126613c..eab87a3ec2 100644
--- a/lib/simple-atomic.c
+++ b/lib/simple-atomic.c
@@ -67,9 +67,9 @@ atomic_compare_and_swap_ptr (uintptr_t volatile *vp,
    require to link with -latomic.  */
 
 # if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) \
-       && !defined __sparc__) \
+       && !defined __sparc__ && !defined __ANDROID__) \
       || __clang_major__ >= 3) \
-     && !defined __ibmxl__ && !defined __ANDROID__
+     && !defined __ibmxl__
 /* Use GCC built-ins (available in GCC >= 4.1, except on SPARC, and
    clang >= 3.0).
    Documentation:





^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-11 17:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11  9:53 Fix link errors on Android 4.3 Bruno Haible
2023-01-11 17:11 ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).