Skip to content

concurrency_kit broken on powerpc #567

Description

@barracuda156

There are two issues:

  1. Legacy __sync_* built-ins do not support 64-bit atomics on ppc (and provisionally other 32-bit archs). This leads to linking failure:
/bin/sh ../libtool  --tag=CC   --mode=link /opt/local/bin/gcc-mp-14 -Wall -Wextra -Wpointer-arith -Wbad-function-cast -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wcast-align -Wvla   -D_THREAD_SAFE  -O2 -funroll-loops -pipe -Os -std=c99 -arch ppc -lumem      -L/opt/local/lib -Wl,-headerpad_max_install_names -arch ppc -o sysbench sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o sb_histogram.o sb_rand.o sb_thread.o sb_barrier.o sb_lua.o sb_util.o sb_counter.o tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/mutex/libsbmutex.a      -L/opt/local/lib -lluajit-5.1 /opt/local/var/macports/build/sysbench-6c0cefaf/work/sysbench-1.0.20/third_party/concurrency_kit/lib/libck.a -lm 
libtool: link: /opt/local/bin/gcc-mp-14 -Wall -Wextra -Wpointer-arith -Wbad-function-cast -Wstrict-prototypes -Wnested-externs -Wno-format-zero-length -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wcast-align -Wvla -D_THREAD_SAFE -O2 -funroll-loops -pipe -Os -std=c99 -arch ppc -Wl,-headerpad_max_install_names -arch ppc -o sysbench sysbench.o sb_timer.o sb_options.o sb_logger.o db_driver.o sb_histogram.o sb_rand.o sb_thread.o sb_barrier.o sb_lua.o sb_util.o sb_counter.o  /opt/local/lib/libumem.dylib -L/opt/local/lib tests/fileio/libsbfileio.a tests/threads/libsbthreads.a tests/memory/libsbmemory.a tests/cpu/libsbcpu.a tests/mutex/libsbmutex.a -lluajit-5.1 /opt/local/var/macports/build/sysbench-6c0cefaf/work/sysbench-1.0.20/third_party/concurrency_kit/lib/libck.a -lm
Undefined symbols for architecture ppc:
  "___sync_fetch_and_add_8", referenced from:
      _sb_histogram_update in sb_histogram.o
  "___sync_val_compare_and_swap_8", referenced from:
      _sb_more_events in sysbench.o
      _ck_pr_fas_64.constprop.0 in sb_histogram.o
ld: symbol(s) not found for architecture ppc
collect2: error: ld returned 1 exit status

Replacing these with modern __atomic_* built-ins and linking to libatomic will fix this.

  1. macOS-specific: Darwin uses prefixed registers in assembler, so things like or 0, 0, 0 fail to compile. This works:
--- third_party/concurrency_kit/ck/include/gcc/ppc/ck_pr.h	2020-04-24 23:51:47.000000000 +0800
+++ third_party/concurrency_kit/ck/include/gcc/ppc/ck_pr.h	2026-04-23 10:07:20.000000000 +0800
@@ -55,8 +55,8 @@
 ck_pr_stall(void)
 {
 
-	__asm__ __volatile__("or 1, 1, 1;"
-			     "or 2, 2, 2;" ::: "memory");
+	__asm__ __volatile__("or r1, r1, r1;"
+			     "or r2, r2, r2;" ::: "memory");
 	return;
 }
 

--- third_party/concurrency_kit/ck/include/gcc/ppc64/ck_pr.h	2020-04-24 23:51:47.000000000 +0800
+++ third_party/concurrency_kit/ck/include/gcc/ppc64/ck_pr.h	2026-04-23 10:07:33.000000000 +0800
@@ -54,8 +54,8 @@
 ck_pr_stall(void)
 {
 
-	__asm__ __volatile__("or 1, 1, 1;"
-			     "or 2, 2, 2;" ::: "memory");
+	__asm__ __volatile__("or r1, r1, r1;"
+			     "or r2, r2, r2;" ::: "memory");
 	return;
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions