compiler-rt: Map the COMPILER_RT_DEFAULT_TARGET_ARCH
PATCH 1/2 compiler-rt: Map the COMPILER_RT_DEFAULT_TARGET_ARCH
COMPILER_RT_DEFAULT_TARGET_ARCH is not 1 to 1 match with HOST_ARCH especially for armv5/arm4
Signed-off-by Khem Raj <[email protected]>
--- meta/recipes-devtools/clang/compiler-rt_git.bb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
meta/recipes-devtools/clang/compiler-rt_git.bb +10 -1
@@ -58,6 +58,15 @@ BUILD_CXX = "${CCACHE}clang++ ${BUILD_CC_ARCH}" LDFLAGS += "${COMPILER_RT} ${UNWINDLIB}" CXXFLAGS += "${LIBCPLUSPLUS}" +def get_compiler_rt_arch(bb, d): + if bb.utils.contains('TUNE_FEATURES', 'armv5 thumb dsp', True, False, d): + return 'armv5te' + elif bb.utils.contains('TUNE_FEATURES', 'armv4 thumb', True, False, d): + return 'armv4t' + elif bb.utils.contains('TUNE_FEATURES', 'arm vfp callconvention-hard', True, False, d): + return 'armhf' + return d.getVar('HOST_ARCH') + OECMAKE_TARGET_COMPILE = "compiler-rt" OECMAKE_TARGET_INSTALL = "install-compiler-rt install-compiler-rt-headers" OECMAKE_SOURCEPATH = "${S}/llvm"
@@ -70,7 +79,7 @@ EXTRA_OECMAKE += "-DCMAKE_BUILD_TYPE=RelWithDebInfo \ -DCOMPILER_RT_BUILD_SANITIZERS=OFF \ -DCOMPILER_RT_BUILD_MEMPROF=OFF \ -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ - -DCOMPILER_RT_DEFAULT_TARGET_ARCH=${HOST_ARCH} \ + -DCOMPILER_RT_DEFAULT_TARGET_ARCH=${@get_compiler_rt_arch(bb, d)} \ -DLLVM_ENABLE_RUNTIMES='compiler-rt' \ -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX} \ -DLLVM_APPEND_VC_REV=OFF \
PATCH 2/2 compiler-rt: Exclude sync builtins from build when arm < v6
arm architecture < v6 does not have the dmb support, therefore do not add the sync primitives to compiler-rt builtins build
Signed-off-by Khem Raj <[email protected]>
--- ...ude-sync_fetch_and_-for-any-pre-ARMv.patch | 61 +++++++++++++++++++ meta/recipes-devtools/clang/common.inc | 1 + 2 files changed, 62 insertions(+) create mode 100644 meta/recipes-devtools/clang/clang/0038-compiler-rt-Exclude-sync_fetch_and_-for-any-pre-ARMv.patch
meta/recipes-devtools/clang/clang/0038-compiler-rt-Exclude-sync_fetch_and_-for-any-pre-ARMv.patch new file +61 -0
@@ -0,0 +1,61 @@ +From 5a0daa2dcc2bb39d87c4fcae7036cd8ab7ee6f6d Mon Sep 17 00:00:00 2001 +From: Khem Raj <[email protected]> +Date: Sat, 10 May 2025 14:03:12 -0700 +Subject: [PATCH] compiler-rt: Exclude sync_fetch_and_* for any pre-ARMv6 targets + +Sometimes builds may happen where ABI is not indidated by host_triple +e.g. on Yocto the compiler used is called arm-poky-linux-gnueabi-clang +for all arm32 cross compilers, it passed the ABI flags on cmdline in +addition. e.g. + +-march=armv5te -mfloat-abi=soft +or +-march=armv7-a -mfloat-abi=hard + +compiler-rt's makery tries to add arm to COMPILER_RT_SUPPORTED_ARCH +deducing it from triple name. + +which ends up choosing `arm` as one of compiler-rt arch to build for. +This arch is however using armv7+ defaults and then tried to build sync +builtins using + +arm-poky-linux-gnueabi-clang -march=armv5te -mfloat-abi=soft ... + +Which does not compile correctly, in such cases it should simply +remove the sync builtins from list of things to build similar to what +is done when we use armv4t or armv5t + +set(armv4t_SOURCES ${arm_min_SOURCES}) +set(armv5te_SOURCES ${arm_min_SOURCES}) + +This lets compiler-rt build for arm architectures without depending +upong compiler triple, but instead of poking the compiler for what +it is building for + +Upstream-Status: Submitted [https://github.com/llvm/llvm-project/pull/139411] +Signed-off-by: Khem Raj <[email protected]> +--- + compiler-rt/lib/builtins/CMakeLists.txt | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +--- a/compiler-rt/lib/builtins/CMakeLists.txt ++++ b/compiler-rt/lib/builtins/CMakeLists.txt +@@ -864,6 +864,18 @@ else () + list(JOIN BUILTIN_CFLAGS " " CMAKE_REQUIRED_FLAGS) + set(CMAKE_REQUIRED_FLAGS "${TARGET_${arch}_CFLAGS} ${BUILTIN_CFLAGS_${arch}}") + message(STATUS "Performing additional configure checks with target flags: ${CMAKE_REQUIRED_FLAGS}") ++ # For ARM archs, exclude any sync builtins if dmb or mcr p15, #0, r0, c7, c10, #5 ++ # is not supported ++ if (${arch} MATCHES "^(arm|armhf)$") ++ try_compile_only(COMPILER_RT_HAS_${arch}_SYNC ++ SOURCE "#if __ARM_ARCH < 6 ++ #error DMB is only supported on ARMv6+ ! ++ #endif ++ int main(void) { return 0; }") ++ if(NOT COMPILER_RT_HAS_${arch}_SYNC) ++ list(REMOVE_ITEM ${arch}_SOURCES ${arm_sync_SOURCES}) ++ endif() ++ endif() + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em|armv8m.main|armv8.1m.main)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}")
meta/recipes-devtools/clang/common.inc +1 -0
@@ -57,6 +57,7 @@ SRC_URI = "\ file://0034-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch \ file://0035-llvm-config-remove-LLVM_LDFLAGS-from-ldflags-output.patch \ file://0036-openmp-Do-not-emit-date-and-time-into-generate-files.patch \ + file://0038-compiler-rt-Exclude-sync_fetch_and_-for-any-pre-ARMv.patch \ " # Fallback to no-PIE if not set GCCPIE ??= ""