Skip to contentSkip to conversation

compiler-rt: Use specific arm architecture instead of 'arm'

PATCH In review Jan Strater-Büddefeld 2 participants 2 messages Sep 25

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compiler-rt: Use specific arm architecture instead of 'arm'

Fixes [YOCTO #16424]

The build system of compiler-rt can auto-detect some architectures like 'armv6m' via the -march compiler flag.
For other targets, the arch type to build for must be set via the target triple CMAKE_C_COMPILER_TARGET.
Before this commit, the arch type was simply 'arm'.

This commit also removes setting the variable COMPILER_RT_DEFAULT_TARGET_ARCH because it is overridden anyway.

AI-Generated: Uses GitHub Copilot

---
 .../recipes-devtools/clang/compiler-rt_git.bb | 22 +++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
meta/recipes-devtools/clang/compiler-rt_git.bb +13 -9
index a265c2aa93..d6c06302c2 100644
@@ -49,13 +49,18 @@ TOOLCHAIN = "clang"
 TOOLCHAIN_NATIVE = "clang"
 
 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')
+    import re
+    
+    tune_args = d.getVar('TUNE_CCARGS_MARCH') or ''
+
+    match = re.search(r'-march=(\S+)', tune_args)
+    arch = match.group(1) if match else d.getVar('HOST_ARCH')
+
+    return arch
+
+def get_compiler_rt_target(bb, d):
+    host_sys = d.getVar('HOST_SYS')
+    return get_compiler_rt_arch(bb, d) + '-' + host_sys.split('-', 1)[1]
 
 INSTALL_VER ?= "${MAJOR_VER}.${MINOR_VER}.${PATCH_VER}${VER_SUFFIX}"
 INSTALL_VER:class-native = "${@oe.utils.trim_version("${PV}", 1)}"
@@ -78,7 +83,6 @@ 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=${@get_compiler_rt_arch(bb, d)} \
                   -DLLVM_ENABLE_RUNTIMES=${RUNTIMES} \
                   -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX} \
                   -DLLVM_APPEND_VC_REV=OFF \
@@ -86,7 +90,7 @@ EXTRA_OECMAKE += "-DCMAKE_BUILD_TYPE=RelWithDebInfo \
                   -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
                   -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF \
                   -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-                  -DCMAKE_C_COMPILER_TARGET=${HOST_SYS} \
+                  -DCMAKE_C_COMPILER_TARGET=${@get_compiler_rt_target(bb, d)} \
                   -DCOMPILER_RT_INSTALL_PATH=${nonarch_libdir}/clang/${INSTALL_VER} \
                   ${@bb.utils.contains("TC_CXX_RUNTIME", "llvm", "${LLVMLIBGCCOPTS}", "", d)} \
 "
Signature · 1 line
2.55.0
#1 lore raw
Quoted 37 lines · Jan Strater-Büddefeld via lists.openembedded.org

Fixes [YOCTO #16424]

The build system of compiler-rt can auto-detect some architectures like 'armv6m' via the -march compiler flag.
For other targets, the arch type to build for must be set via the target triple CMAKE_C_COMPILER_TARGET.
Before this commit, the arch type was simply 'arm'.

This commit also removes setting the variable COMPILER_RT_DEFAULT_TARGET_ARCH because it is overridden anyway.

AI-Generated: Uses GitHub Copilot

---
 .../recipes-devtools/clang/compiler-rt_git.bb | 22 +++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
meta/recipes-devtools/clang/compiler-rt_git.bb +0 -1
index a265c2aa93..d6c06302c2 100644
@@ -49,13 +49,18 @@ TOOLCHAIN = "clang"
 TOOLCHAIN_NATIVE = "clang"
 
 def get_compiler_rt_arch(bb, d):
-    if bb.utils.contains('TUNE_FEATURES', 'armv5 thumb dsp', True, False,

d):

meta/recipes-devtools/clang/compiler-rt_git.bb +0 -2
-        return 'armv5te'
-    elif bb.utils.contains('TUNE_FEATURES', 'armv4 thumb', True, False,

d):

meta/recipes-devtools/clang/compiler-rt_git.bb +0 -2
-        return 'armv4t'
-    elif bb.utils.contains('TUNE_FEATURES', 'arm vfp

callconvention-hard', True, False, d):

meta/recipes-devtools/clang/compiler-rt_git.bb TOOLCHAIN = "clang" · line 54

Quoted 5 lines
meta/recipes-devtools/clang/compiler-rt_git.bb +3 -2
-        return 'armhf'
-    return d.getVar('HOST_ARCH')
+    import re
+
+    tune_args = d.getVar('TUNE_CCARGS_MARCH') or ''

new dependency on TUNE_CCARGS_MARCH causes the do_configure basehash mismatch for native variant.

meta/recipes-devtools/clang/compiler-rt_git.bb TOOLCHAIN = "clang" · line 63

Quoted 10 lines
meta/recipes-devtools/clang/compiler-rt_git.bb +9 -0
+
+    match = re.search(r'-march=(\S+)', tune_args)
+    arch = match.group(1) if match else d.getVar('HOST_ARCH')
+
+    return arch
+
+def get_compiler_rt_target(bb, d):
+    host_sys = d.getVar('HOST_SYS')
+    return get_compiler_rt_arch(bb, d) + '-' + host_sys.split('-', 1)[1]

It does target the right bug, but it causes a build regression and a
native/nativesdk sstate signature regression
Pre-Thumb-2 ARM tunes (armv4t, armv5te, armv6) fail to build compiler-rt. because CMAKE_C_COMPILER_TARGET=arm..
makes compiler-rt pick the Thumb-2 optimized FP assembly which needs armv6t2 at minimum, problem is diagnosed
rightly, but the fix is too broad.

also check if -march values are valid triple arch components and regex also doesn't limit itself to 32-bit ARM
I think the this will cause library name to change and has to match what the clang driver looks up.

The TC_CXX_RUNTIME=llvm crtbegin/crtend symlinks use get_compiler_rt_arch(), which now returns names like armv7-a or armv8-a that compiler-rt never produces.

Quoted 38 lines

INSTALL_VER ?= "${MAJOR_VER}.${MINOR_VER}.${PATCH_VER}${VER_SUFFIX}" INSTALL_VER:class-native = "${@oe.utils.trim_version("${PV}", 1)}"

meta/recipes-devtools/clang/compiler-rt_git.bb +1 -3
@@ -78,7 +83,6 @@ 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=${@get_compiler_rt_arch(bb, d)} \
                   -DLLVM_ENABLE_RUNTIMES=${RUNTIMES} \
                   -DLLVM_LIBDIR_SUFFIX=${LLVM_LIBDIR_SUFFIX} \
                   -DLLVM_APPEND_VC_REV=OFF \
@@ -86,7 +90,7 @@ EXTRA_OECMAKE += "-DCMAKE_BUILD_TYPE=RelWithDebInfo \
                   -DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON \
                   -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF \
                   -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-                  -DCMAKE_C_COMPILER_TARGET=${HOST_SYS} \
+                  -DCMAKE_C_COMPILER_TARGET=${@get_compiler_rt_target(bb,
 d)} \
 
 -DCOMPILER_RT_INSTALL_PATH=${nonarch_libdir}/clang/${INSTALL_VER} \
                   ${@bb.utils.contains("TC_CXX_RUNTIME", "llvm",

"${LLVMLIBGCCOPTS}", "", d)} \
"
--
2.55.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#246621):
https://lists.openembedded.org/g/openembedded-core/message/246621
Mute This Topic: https://lists.openembedded.org/mt/121427261/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [ [email protected]]
-=-=-=-=-=-=-=-=-=-=-=-