llvm20: add patch from Brad Smith for OpenMP

This commit is contained in:
Jérôme Duval
2025-03-24 18:49:24 +01:00
parent 8c69447473
commit 8e9336c319
2 changed files with 329 additions and 14 deletions

View File

@@ -30,7 +30,7 @@ other than the ones listed above.
HOMEPAGE="https://www.llvm.org/"
COPYRIGHT="2003-2025 University of Illinois at Urbana-Champaign"
LICENSE="Apache v2 with LLVM Exception"
REVISION="2"
REVISION="3"
SOURCE_URI="https://github.com/llvm/llvm-project/releases/download/llvmorg-$portVersion/llvm-project-$portVersion.src.tar.xz"
CHECKSUM_SHA256="4579051e3c255fb4bb795d54324f5a7f3ef79bd9181e44293d7ee9a7f62aad9a"
SOURCE_DIR="llvm-project-$portVersion.src"
@@ -540,6 +540,20 @@ REQUIRES_libunwind_devel="
haiku${secondaryArchSuffix}_devel
"
SUMMARY_openmp="LLVM Openmp implementation"
DESCRIPTION_openmp="Clang fully supports OpenMP 4.5, almost all of 5.0 and \
most of 5.1/2."
PROVIDES_openmp="
llvm20${secondaryArchSuffix}_openmp = $portVersion
devel:libarcher$secondaryArchSuffix = 1
devel:libomp$secondaryArchSuffix = 1
lib:libarcher$secondaryArchSuffix = 1
lib:libomp$secondaryArchSuffix = 1
"
REQUIRES_openmp="
haiku$secondaryArchSuffix
"
BUILD_REQUIRES="
haiku${secondaryArchSuffix}_devel
devel:libz$secondaryArchSuffix
@@ -588,9 +602,10 @@ BUILD()
-DCMAKE_SKIP_RPATH=YES \
-DLLVM_ENABLE_RTTI=ON -DLLVM_LINK_LLVM_DYLIB=YES \
-DLIBUNWIND_ENABLE_STATIC=OFF \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt" \
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld;compiler-rt;openmp" \
-DLLVM_ENABLE_RUNTIMES="libunwind" \
-DLLVM_TARGETS_TO_BUILD="AArch64;AMDGPU;ARM;RISCV;WebAssembly;X86"
-DLLVM_TARGETS_TO_BUILD="AArch64;AMDGPU;ARM;RISCV;WebAssembly;X86" \
-DLIBOMP_INSTALL_ALIASES=OFF
cmake --build build $jobArgs
}
@@ -724,6 +739,18 @@ INSTALL()
mv $prefix/include/* $includeDir/
rmdir $prefix/include
rm $libDir/libarcher_static.a
ln -srf $libDir/libomp.so $developLibDir/
ln -srf $libDir/libarcher.so $developLibDir/
# openmp package
packageEntries openmp \
$developLibDir/libarcher* \
$developLibDir/libomp* \
$libDir/clang/20/include/omp*.h \
$libDir/libarcher* \
$libDir/libomp* \
$libDir/cmake/openmp
# clang package
packageEntries clang \
@@ -806,5 +833,5 @@ TEST()
else
export LIBRARY_PATH=$LIBRARY_PATH:$sourceDir/build/lib
fi
ninja -C build check-llvm check-compiler-rt check-unwind
ninja -C build check-openmp check-llvm check-compiler-rt check-unwind
}

View File

@@ -1,4 +1,4 @@
From 246380662c69e2892493a1a276491ad6758620cf Mon Sep 17 00:00:00 2001
From 02731acd2c3cdfcc4b821ea11d239d933c855f0a Mon Sep 17 00:00:00 2001
From: Calvin Hill <calvin@hakobaito.co.uk>
Date: Sun, 9 Sep 2018 16:11:42 +0100
Subject: llvm: import header dir suffix patch from 3dEyes
@@ -24,7 +24,7 @@ index d5b76b1..df3fb59 100644
2.45.2
From 5a72436bdafab942f499301c6a4938614a9d6594 Mon Sep 17 00:00:00 2001
From 2966463873c41e12d04aeee3ff4e21888f0a67e5 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sat, 3 Apr 2021 23:23:24 +0200
Subject: lld: MachO needs libunwind somehow, disable
@@ -118,7 +118,7 @@ index d6800fa..d2bac9f 100644
2.45.2
From 5c2c4c70f2574ffc1bb9f425585d3e7de844d392 Mon Sep 17 00:00:00 2001
From e51f14e826cebba4d6a3c92f2038ed576a21db41 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= <jerome.duval@gmail.com>
Date: Mon, 18 Jul 2016 14:13:19 +0200
Subject: clang: support for secondary arch.
@@ -213,7 +213,7 @@ index af74f43..fa3f8cb 100644
2.45.2
From a928d4890a0981c170ee73e7a68b0bcc652a3707 Mon Sep 17 00:00:00 2001
From 7ebd6764fcdad160b6bca94ef5117955ae3e111b Mon Sep 17 00:00:00 2001
From: David Karoly <karolyd577@gmail.com>
Date: Thu, 21 Sep 2023 17:44:12 +0000
Subject: fix build on x86 secondary arch
@@ -236,7 +236,7 @@ index 4312411..04db3fb 100644
2.45.2
From 8e9d517121af20b27ebe6a3db978ac6bdbd261cc Mon Sep 17 00:00:00 2001
From 8ec09943cb3349bf8e6bcfabad3fa70302bcfa9d Mon Sep 17 00:00:00 2001
From: David Karoly <david.karoly@outlook.com>
Date: Mon, 6 Nov 2023 14:24:21 +0100
Subject: clang: Haiku: patch for analyzer scripts
@@ -298,7 +298,7 @@ index d01aebb..43ba8c3 100755
2.45.2
From 3cb4dca2a1310b0665b3387cbcccf5081b8b82d4 Mon Sep 17 00:00:00 2001
From e1d8ff2835290c25f6889c701215e9e32f37fa7f Mon Sep 17 00:00:00 2001
From: Brad Smith <brad@comstyle.com>
Date: Mon, 10 Jun 2024 11:13:29 +0200
Subject: A slightly better llvm-config diff that doesn't use #ifdef.
@@ -344,7 +344,7 @@ index df3fb59..30cb748 100644
2.45.2
From 88cdc4cf53eec21c89b65ba3542635c4b3d624aa Mon Sep 17 00:00:00 2001
From dd2fd7143d80bafeee9daee53ce6014beb58326c Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sun, 19 May 2024 10:31:55 +0200
Subject: Allow linking gcc compiled code with lld
@@ -370,7 +370,7 @@ index a1e9eca..cc563d7 100644
2.45.2
From a9e7dab82fa1952557b0da7724ba2eeef3b7f854 Mon Sep 17 00:00:00 2001
From f9b37b57bf9b3703676e57a2d58d3fdbd00809f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= <jerome.duval@gmail.com>
Date: Thu, 6 Feb 2025 21:08:43 +0100
Subject: Haiku: Address sanitizer on x86_64
@@ -1829,7 +1829,7 @@ index bf3c2c2..a9be974 100644
#include "sanitizer_common.h"
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_haiku.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_haiku.cpp
new file mode 100644
index 0000000..90ed6b3
index 0000000..8505633
--- /dev/null
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_procmaps_haiku.cpp
@@ -0,0 +1,99 @@
@@ -1879,7 +1879,7 @@ index 0000000..90ed6b3
+ return false;
+
+ segment->start = (uptr)info.address;
+ segment->end = (uptr)(info.address + info.size);
+ segment->end = (uptr)info.address + info.size;
+ segment->offset = 0;
+ segment->protection = 0;
+ if (info.protection & B_READ_AREA)
@@ -2029,3 +2029,291 @@ index bbe7040..9289b99 100644
--
2.45.2
From c10c5257e1bcbb14c2656d0120742cb2a73296c9 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad@comstyle.com>
Date: Sun, 15 Dec 2024 10:26:32 +0000
Subject: [OpenMP] Add support for Haiku
diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 04bf6c3..9cac18d 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -1361,6 +1361,10 @@ extern kmp_uint64 __kmp_now_nsec();
/* TODO: tune for KMP_OS_OPENBSD */
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
+#elif KMP_OS_HAIKU
+/* TODO: tune for KMP_OS_HAIKU */
+#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
+#define KMP_NEXT_WAIT 512U /* susequent number of spin-tests */
#elif KMP_OS_HURD
/* TODO: tune for KMP_OS_HURD */
#define KMP_INIT_WAIT 1024U /* initial number of spin-tests */
diff --git a/openmp/runtime/src/kmp_ftn_entry.h b/openmp/runtime/src/kmp_ftn_entry.h
index 9bd3ac9..9c8be5f 100644
--- a/openmp/runtime/src/kmp_ftn_entry.h
+++ b/openmp/runtime/src/kmp_ftn_entry.h
@@ -582,7 +582,8 @@ int FTN_STDCALL KMP_EXPAND_NAME(FTN_GET_THREAD_NUM)(void) {
int gtid;
#if KMP_OS_DARWIN || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || \
+ KMP_OS_AIX
gtid = __kmp_entry_gtid();
#elif KMP_OS_WINDOWS
if (!__kmp_init_parallel ||
diff --git a/openmp/runtime/src/kmp_platform.h b/openmp/runtime/src/kmp_platform.h
index 9c22151..f0191df 100644
--- a/openmp/runtime/src/kmp_platform.h
+++ b/openmp/runtime/src/kmp_platform.h
@@ -22,6 +22,7 @@
#define KMP_OS_OPENBSD 0
#define KMP_OS_DARWIN 0
#define KMP_OS_WINDOWS 0
+#define KMP_OS_HAIKU 0
#define KMP_OS_HURD 0
#define KMP_OS_SOLARIS 0
#define KMP_OS_WASI 0
@@ -73,6 +74,11 @@
#define KMP_OS_OPENBSD 1
#endif
+#if (defined __HAIKU__)
+#undef KMP_OS_HAIKU
+#define KMP_OS_HAIKU 1
+#endif
+
#if (defined __GNU__)
#undef KMP_OS_HURD
#define KMP_OS_HURD 1
@@ -94,14 +100,14 @@
#endif
#if (1 != KMP_OS_LINUX + KMP_OS_DRAGONFLY + KMP_OS_FREEBSD + KMP_OS_NETBSD + \
- KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HURD + \
- KMP_OS_SOLARIS + KMP_OS_WASI + KMP_OS_AIX)
+ KMP_OS_OPENBSD + KMP_OS_DARWIN + KMP_OS_WINDOWS + KMP_OS_HAIKU + \
+ KMP_OS_HURD + KMP_OS_SOLARIS + KMP_OS_WASI + KMP_OS_AIX)
#error Unknown OS
#endif
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HURD || KMP_OS_SOLARIS || \
- KMP_OS_WASI || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_DARWIN || KMP_OS_HAIKU || KMP_OS_HURD || \
+ KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
#undef KMP_OS_UNIX
#define KMP_OS_UNIX 1
#endif
diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index 2c8d930..f3eea77 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -8951,8 +8951,8 @@ __kmp_determine_reduction_method(
KMP_ARCH_VE || KMP_ARCH_S390X || KMP_ARCH_WASM
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD || \
- KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HAIKU || \
+ KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
int teamsize_cutoff = 4;
@@ -8976,15 +8976,15 @@ __kmp_determine_reduction_method(
#else
#error "Unknown or unsupported OS"
#endif // KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD ||
- // KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HURD ||
- // KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
+ // KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_DARWIN || KMP_OS_HAIKU ||
+ // KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
#elif KMP_ARCH_X86 || KMP_ARCH_ARM || KMP_ARCH_AARCH || KMP_ARCH_MIPS || \
KMP_ARCH_WASM || KMP_ARCH_PPC || KMP_ARCH_AARCH64_32
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_HURD || KMP_OS_SOLARIS || \
- KMP_OS_WASI || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_WINDOWS || KMP_OS_HAIKU || KMP_OS_HURD || \
+ KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
// basic tuning
diff --git a/openmp/runtime/src/kmp_wrapper_getpid.h b/openmp/runtime/src/kmp_wrapper_getpid.h
index d31c6e8..6b41dfc 100644
--- a/openmp/runtime/src/kmp_wrapper_getpid.h
+++ b/openmp/runtime/src/kmp_wrapper_getpid.h
@@ -17,7 +17,7 @@
// On Unix-like systems (Linux* OS and OS X*) getpid() is declared in standard
// headers.
-#if !defined(KMP_OS_AIX)
+#if !defined(KMP_OS_AIX) && !defined(KMP_OS_HAIKU)
#include <sys/syscall.h>
#endif
#include <sys/types.h>
@@ -36,6 +36,9 @@
#elif KMP_OS_AIX
#include <pthread.h>
#define __kmp_gettid() pthread_self()
+#elif KMP_OS_HAIKU
+#include <OS.h>
+#define __kmp_gettid() find_thread(NULL)
#elif defined(SYS_gettid)
// Hopefully other Unix systems define SYS_gettid syscall for getting os thread
// id
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp
index bdb7a12..df00dea 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/runtime/src/z_Linux_util.cpp
@@ -32,7 +32,7 @@
#if KMP_OS_AIX
#include <sys/ldr.h>
#include <libperfstat.h>
-#else
+#elif !KMP_OS_HAIKU
#include <sys/syscall.h>
#endif
#include <sys/time.h>
@@ -465,7 +465,7 @@ void __kmp_terminate_thread(int gtid) {
static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
int stack_data;
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
+ KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
int status;
size_t size = 0;
void *addr = 0;
@@ -517,7 +517,7 @@ static kmp_int32 __kmp_set_stack_info(int gtid, kmp_info_t *th) {
return TRUE;
}
#endif /* KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD \
- || KMP_OS_HURD || KMP_OS_SOLARIS */
+ || KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS */
/* Use incremental refinement starting from initial conservative estimate */
TCW_PTR(th->th.th_info.ds.ds_stacksize, 0);
TCW_PTR(th->th.th_info.ds.ds_stackbase, &stack_data);
@@ -532,7 +532,8 @@ static void *__kmp_launch_worker(void *thr) {
#endif /* KMP_BLOCK_SIGNALS */
void *exit_val;
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || \
+ KMP_OS_AIX
void *volatile padding = 0;
#endif
int gtid;
@@ -581,7 +582,8 @@ static void *__kmp_launch_worker(void *thr) {
#endif /* KMP_BLOCK_SIGNALS */
#if KMP_OS_LINUX || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || \
- KMP_OS_OPENBSD || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_AIX
+ KMP_OS_OPENBSD || KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || \
+ KMP_OS_AIX
if (__kmp_stkoffset > 0 && gtid > 0) {
padding = KMP_ALLOCA(gtid * __kmp_stkoffset);
(void)padding;
@@ -1902,7 +1904,7 @@ static int __kmp_get_xproc(void) {
__kmp_type_convert(sysconf(_SC_NPROCESSORS_CONF), &(r));
#elif KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_OPENBSD || \
- KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
+ KMP_OS_HAIKU || KMP_OS_HURD || KMP_OS_SOLARIS || KMP_OS_WASI || KMP_OS_AIX
__kmp_type_convert(sysconf(_SC_NPROCESSORS_ONLN), &(r));
@@ -2400,6 +2402,9 @@ int __kmp_is_address_mapped(void *addr) {
}
KMP_INTERNAL_FREE(loadQueryBuf);
+#elif KMP_OS_HAIKU
+
+ found = 1;
#else
#error "Unknown or unsupported OS"
@@ -2515,6 +2520,10 @@ int __kmp_get_load_balance(int max) {
glb_running_threads = running_threads;
return running_threads;
+#elif KMP_OS_HAIKU
+
+int __kmp_get_load_balance(int max) {
+ return -1;
}
#else // Linux* OS
diff --git a/openmp/runtime/test/lit.cfg b/openmp/runtime/test/lit.cfg
index 14c7468..6c5c2fc 100644
--- a/openmp/runtime/test/lit.cfg
+++ b/openmp/runtime/test/lit.cfg
@@ -19,6 +19,9 @@ def prepend_dynamic_library_path(path):
elif config.operating_system == 'Darwin':
name = 'DYLD_LIBRARY_PATH'
sep = ':'
+ elif config.operating_system == 'Haiku':
+ name = 'LIBRARY_PATH'
+ sep = ':'
elif target_arch == 've':
name = 'VE_LD_LIBRARY_PATH'
sep = ':'
@@ -60,10 +63,11 @@ config.test_flags_use_compiler_omp_h = flags
# extra libraries
libs = ""
-if config.has_libm:
- libs += " -lm"
-if config.has_libatomic:
- libs += " -latomic"
+if config.operating_system != 'Haiku':
+ if config.has_libm:
+ libs += " -lm"
+ if config.has_libatomic:
+ libs += " -latomic"
# Allow REQUIRES / UNSUPPORTED / XFAIL to work
config.target_triple = [ ]
diff --git a/openmp/tools/multiplex/ompt-multiplex.h b/openmp/tools/multiplex/ompt-multiplex.h
index a73f2b3..4c17802 100644
--- a/openmp/tools/multiplex/ompt-multiplex.h
+++ b/openmp/tools/multiplex/ompt-multiplex.h
@@ -21,7 +21,9 @@
#endif
#include <dlfcn.h>
#include <errno.h>
+#ifndef __HAIKU__
#include <execinfo.h>
+#endif
#include <inttypes.h>
#include <omp-tools.h>
#include <omp.h>
--
2.45.2
From d6643f6469eec1c6d32a0718549ad14e02d9e6ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= <jerome.duval@gmail.com>
Date: Mon, 24 Mar 2025 21:41:12 +0100
Subject: install headers in clang/../include/ where clang searches them
diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake
index d92bc0e..4268fbb 100644
--- a/compiler-rt/cmake/base-config-ix.cmake
+++ b/compiler-rt/cmake/base-config-ix.cmake
@@ -119,7 +119,7 @@ endif()
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_BINDIR}")
set(COMPILER_RT_INSTALL_BINARY_DIR "${default_install_path}" CACHE PATH
"Path where built compiler-rt executables should be installed.")
-extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_INCLUDEDIR}")
+extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "include")
set(COMPILER_RT_INSTALL_INCLUDE_DIR "${default_install_path}" CACHE PATH
"Path where compiler-rt headers should be installed.")
extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_DATADIR}")
--
2.45.2