Hello, this is the (hopefully) last compatibility problem with libbacktrace on SPU: we do not have either the __sync or the __atomic routines (since the SPU is a fundamentally single-threaded target).
There are configure.ac checks for both of these functions, but for cross-compilation, the code assumes they are always available. This patch adds explicit checks for the SPU target and disables those functions for that target, just as is done with other checks. However, the resulting source does not build, since the fallback (abort) defines in internals.h cause compile warnings (made into errors due to -Werror). There are two problems: - "variable set but not used" for some variables used as arguments to the backtrace_atomic_... routines. Fixed by adding dummy uses of the arguments to the fallback definitions of those macros. - "right-hand operand of comma expression has to effect" for two cases where code ignored the return value of __sync_bool_compare_and_swap with a fallback definition of (abort (), 1). I was unable to find a solution solely by modifying the fallback definition. There doesn't appear to be a way to do so using regular macros. Turning the fallback into an inline function doesn't work since it is a type-generic primitive. I guess a statement expression might work, but I'm not sure if GNU extensions are OK here. So I ended up with actually adding (void) casts to the two places where this happens. It seems to me explicitly indicating that it is OK to ignore the return value of __sync_bool_compare_and_swap in those places may be useful anyway. Of course I'd be happy for alternative suggestions how to fix this. Tested on x86_64-linux and spu-elf. OK for mainline? Bye, Ulrich ChangeLog: * configure.ac: For spu-*-* targets, set libbacktrace_cv_sys_sync and libbacktrace_cv_sys_sync to no. * configure: Regenerate. * internals.h [!HAVE_ATOMIC_FUNCTIONS, !HAVE_SYNC_FUNCTIONS] (backtrace_atomic_load_pointer, backtrace_atomic_load_int, backtrace_atomic_store_pointer, backtrace_atomic_store_size_t, backtrace_atomic_store_int): Add dummy uses of arguments. * elf.c (backtrace_initialize): Explicitly cast unused return value of __sync_bool_compare_and_swap to void. * pecoff.c (backtrace_initialize): Likewise. Index: libbacktrace/configure.ac =================================================================== *** libbacktrace/configure.ac (revision 227304) --- libbacktrace/configure.ac (working copy) *************** AC_SUBST(PIC_FLAG) *** 172,178 **** AC_CACHE_CHECK([__sync extensions], [libbacktrace_cv_sys_sync], [if test -n "${with_target_subdir}"; then ! libbacktrace_cv_sys_sync=yes else AC_LINK_IFELSE( [AC_LANG_PROGRAM([int i;], --- 172,181 ---- AC_CACHE_CHECK([__sync extensions], [libbacktrace_cv_sys_sync], [if test -n "${with_target_subdir}"; then ! case "${host}" in ! spu-*-*) libbacktrace_cv_sys_sync=no ;; ! *) libbacktrace_cv_sys_sync=yes ;; ! esac else AC_LINK_IFELSE( [AC_LANG_PROGRAM([int i;], *************** AC_SUBST(BACKTRACE_SUPPORTS_THREADS) *** 194,200 **** AC_CACHE_CHECK([__atomic extensions], [libbacktrace_cv_sys_atomic], [if test -n "${with_target_subdir}"; then ! libbacktrace_cv_sys_atomic=yes else AC_LINK_IFELSE( [AC_LANG_PROGRAM([int i;], --- 197,206 ---- AC_CACHE_CHECK([__atomic extensions], [libbacktrace_cv_sys_atomic], [if test -n "${with_target_subdir}"; then ! case "${host}" in ! spu-*-*) libbacktrace_cv_sys_atomic=no ;; ! *) libbacktrace_cv_sys_atomic=yes ;; ! esac else AC_LINK_IFELSE( [AC_LANG_PROGRAM([int i;], Index: libbacktrace/internal.h =================================================================== *** libbacktrace/internal.h (revision 227304) --- libbacktrace/internal.h (working copy) *************** extern void backtrace_atomic_store_int ( *** 99,109 **** /* We have neither the sync nor the atomic functions. These will never be called. */ ! #define backtrace_atomic_load_pointer(p) (abort(), (void *) NULL) ! #define backtrace_atomic_load_int(p) (abort(), 0) ! #define backtrace_atomic_store_pointer(p, v) abort() ! #define backtrace_atomic_store_size_t(p, v) abort() ! #define backtrace_atomic_store_int(p, v) abort() #endif /* !defined (HAVE_SYNC_FUNCTIONS) */ #endif /* !defined (HAVE_ATOMIC_FUNCTIONS) */ --- 99,109 ---- /* We have neither the sync nor the atomic functions. These will never be called. */ ! #define backtrace_atomic_load_pointer(p) ((void)(p), abort(), (void *) NULL) ! #define backtrace_atomic_load_int(p) ((void)(p), abort(), 0) ! #define backtrace_atomic_store_pointer(p, v) ((void)(p), (void)(v), abort()) ! #define backtrace_atomic_store_size_t(p, v) ((void)(p), (void)(v), abort()) ! #define backtrace_atomic_store_int(p, v) ((void)(p), (void)(v), abort()) #endif /* !defined (HAVE_SYNC_FUNCTIONS) */ #endif /* !defined (HAVE_ATOMIC_FUNCTIONS) */ Index: libbacktrace/elf.c =================================================================== *** libbacktrace/elf.c (revision 227304) --- libbacktrace/elf.c (working copy) *************** backtrace_initialize (struct backtrace_s *** 955,961 **** if (found_sym) backtrace_atomic_store_pointer (&state->syminfo_fn, elf_syminfo); else ! __sync_bool_compare_and_swap (&state->syminfo_fn, NULL, elf_nosyms); } if (!state->threaded) --- 955,962 ---- if (found_sym) backtrace_atomic_store_pointer (&state->syminfo_fn, elf_syminfo); else ! (void) __sync_bool_compare_and_swap (&state->syminfo_fn, ! NULL, elf_nosyms); } if (!state->threaded) Index: libbacktrace/pecoff.c =================================================================== *** libbacktrace/pecoff.c (revision 227304) --- libbacktrace/pecoff.c (working copy) *************** backtrace_initialize (struct backtrace_s *** 916,922 **** if (found_sym) backtrace_atomic_store_pointer (&state->syminfo_fn, coff_syminfo); else ! __sync_bool_compare_and_swap (&state->syminfo_fn, NULL, coff_nosyms); } if (!state->threaded) --- 916,923 ---- if (found_sym) backtrace_atomic_store_pointer (&state->syminfo_fn, coff_syminfo); else ! (void) __sync_bool_compare_and_swap (&state->syminfo_fn, ! NULL, coff_nosyms); } if (!state->threaded) -- Dr. Ulrich Weigand GNU/Linux compilers and toolchain ulrich.weig...@de.ibm.com