[Openmp-commits] [openmp] [OpenMP] Build libomp on 32-bit PowerPC Linux (PR #227539)

Matt Turner via Openmp-commits openmp-commits at lists.llvm.org
Tue Sep 29 19:48:57 PDT 2026


https://github.com/mattst88 created https://github.com/llvm/llvm-project/pull/227539

kmp_affinity.h has no `sched_{set,get}affinity` syscall numbers for 32-bit PowerPC and stops at its #error. They are the same as on ppc64 (222 and 223), so share that case.

32-bit PowerPC has no 64-bit atomic instructions, so linking libomp.so also fails on undefined `__atomic_*_8` references. Link libatomic, as for MIPS, but only if it exists: other 32-bit PowerPC targets such as OpenBSD (52a02b6d1e0c) may not have it. AIX already links libcompiler_rt for these.

Assisted-by: Claude Code

>From 339f71565cec3d7f40f0fdd9354e73be85a109be Mon Sep 17 00:00:00 2001
From: Matt Turner <mattst88 at gmail.com>
Date: Tue, 29 Sep 2026 20:24:41 -0400
Subject: [PATCH] [OpenMP] Build libomp on 32-bit PowerPC Linux

kmp_affinity.h has no sched_{set,get}affinity syscall numbers for 32-bit
PowerPC and stops at its #error. They are the same as on ppc64 (222 and
223), so share that case.

32-bit PowerPC has no 64-bit atomic instructions, so linking libomp.so
also fails on undefined __atomic_*_8 references. Link libatomic, as for
MIPS, but only if it exists: other 32-bit PowerPC targets such as
OpenBSD (52a02b6d1e0c) may not have it. AIX already links
libcompiler_rt for these.

Assisted-by: Claude Code
---
 openmp/runtime/CMakeLists.txt     | 10 ++++++++++
 openmp/runtime/src/kmp_affinity.h |  2 +-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/openmp/runtime/CMakeLists.txt b/openmp/runtime/CMakeLists.txt
index 0256bfaf4a892..2a461388585f0 100644
--- a/openmp/runtime/CMakeLists.txt
+++ b/openmp/runtime/CMakeLists.txt
@@ -153,6 +153,16 @@ if("${LIBOMP_ARCH}" STREQUAL "mips" OR "${LIBOMP_ARCH}" STREQUAL "mips64")
   set(LIBOMP_LIBFLAGS "${LIBOMP_LIBFLAGS} -latomic")
 endif()
 
+if("${LIBOMP_ARCH}" STREQUAL "ppc" AND NOT "${CMAKE_SYSTEM_NAME}" MATCHES "AIX")
+  # PPC (32-bit) has no 64-bit atomic instructions, so __atomic_load_8, etc.
+  # come from libatomic where the toolchain provides one.
+  include(CheckLibraryExists)
+  check_library_exists(atomic __atomic_load_8 "" LIBOMP_HAVE_LIBATOMIC_8)
+  if(LIBOMP_HAVE_LIBATOMIC_8)
+    set(LIBOMP_LIBFLAGS "${LIBOMP_LIBFLAGS} -latomic")
+  endif()
+endif()
+
 # Should the libomp library and generated headers be copied into the original source exports/ directory
 # Turning this to FALSE aids parallel builds to not interfere with each other.
 # Currently, the testsuite module expects the just built OpenMP library to be located inside the exports/
diff --git a/openmp/runtime/src/kmp_affinity.h b/openmp/runtime/src/kmp_affinity.h
index fa69585f7e2d5..6d814578ca4f2 100644
--- a/openmp/runtime/src/kmp_affinity.h
+++ b/openmp/runtime/src/kmp_affinity.h
@@ -234,7 +234,7 @@ class KMPHwlocAffinity : public KMPAffinity {
 #elif __NR_sched_getaffinity != 204
 #error Wrong code for getaffinity system call.
 #endif /* __NR_sched_getaffinity */
-#elif KMP_ARCH_PPC64
+#elif KMP_ARCH_PPC64 || KMP_ARCH_PPC
 #ifndef __NR_sched_setaffinity
 #define __NR_sched_setaffinity 222
 #elif __NR_sched_setaffinity != 222



More information about the Openmp-commits mailing list