Fixes ld.lld: error: relocation R_X86_64_PC32 cannot be used against symbol '__cpu_model'; recompile with -fPIC
Check CPUID directly instead, avoiding the __cpu_model reference entirely. Signed-off-by: Khem Raj <[email protected]> --- ...uiltin_cpu_supports-for-avx2-detecti.patch | 56 +++++++++++++++++++ meta/recipes-graphics/mesa/mesa.inc | 1 + 2 files changed, 57 insertions(+) create mode 100644 meta/recipes-graphics/mesa/files/0001-addrlib-avoid-builtin_cpu_supports-for-avx2-detecti.patch diff --git a/meta/recipes-graphics/mesa/files/0001-addrlib-avoid-builtin_cpu_supports-for-avx2-detecti.patch b/meta/recipes-graphics/mesa/files/0001-addrlib-avoid-builtin_cpu_supports-for-avx2-detecti.patch new file mode 100644 index 0000000000..7234f76b39 --- /dev/null +++ b/meta/recipes-graphics/mesa/files/0001-addrlib-avoid-builtin_cpu_supports-for-avx2-detecti.patch @@ -0,0 +1,56 @@ +From: Khem Raj <[email protected]> +Date: Thu, 13 Aug 2026 00:00:00 +0000 +Subject: [PATCH] addrlib: avoid __builtin_cpu_supports for avx2 detection + +__builtin_cpu_supports("avx2") lowers to a PC-relative reference to the +libgcc/compiler-rt __cpu_model global. With clang+lld, linking that +reference into a shared library fails because __cpu_model is treated as +preemptible there: + + relocation R_X86_64_PC32 cannot be used against symbol '__cpu_model'; + recompile with -fPIC + +Check CPUID directly instead, which avoids the __cpu_model reference +entirely and works with both GCC and Clang. + +Upstream-Status: Submitted [https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/43820] +Signed-off-by: Khem Raj <[email protected]> +--- + src/amd/addrlib/src/core/addrswizzlersimd.h | 15 +++++++++++++-- + 1 file changed, 13 insertions(+), 2 deletions(-) + +diff --git a/src/amd/addrlib/src/core/addrswizzlersimd.h b/src/amd/addrlib/src/core/addrswizzlersimd.h +index fd53e40..ce30204 100644 +--- a/src/amd/addrlib/src/core/addrswizzlersimd.h ++++ b/src/amd/addrlib/src/core/addrswizzlersimd.h +@@ -57,6 +57,8 @@ + #if ADDR_HAS_AVX2 + #if _MSC_VER + #include <Windows.h> ++#else ++#include <cpuid.h> + #endif + #include <immintrin.h> + +@@ -85,7 +87,18 @@ static inline bool CpuSupportsAvx2() { + #if _MSC_VER + return IsProcessorFeaturePresent(PF_AVX2_INSTRUCTIONS_AVAILABLE); + #elif defined(__GNUC__) +- return __builtin_cpu_supports("avx2"); ++ // __builtin_cpu_supports() lowers to a PC-relative reference to the ++ // libgcc/compiler-rt __cpu_model global, which some clang+lld ++ // configurations reject when linking into a shared library (the ++ // symbol is treated as preemptible: "relocation R_X86_64_PC32 cannot ++ // be used against symbol '__cpu_model'"). Check CPUID directly instead. ++ unsigned int eax, ebx, ecx, edx; ++ if (__get_cpuid_max(0, nullptr) < 7) ++ { ++ return false; ++ } ++ __cpuid_count(7, 0, eax, ebx, ecx, edx); ++ return (ebx & bit_AVX2) != 0; + #else + #error "What platform is this?" + #endif +-- +2.43.0 diff --git a/meta/recipes-graphics/mesa/mesa.inc b/meta/recipes-graphics/mesa/mesa.inc index a139ebb176..8ee7db50ed 100644 --- a/meta/recipes-graphics/mesa/mesa.inc +++ b/meta/recipes-graphics/mesa/mesa.inc @@ -19,6 +19,7 @@ SRC_URI = "https://archive.mesa3d.org/mesa-${PV}.tar.xz \ file://0001-freedreno-don-t-encode-build-path-into-binaries.patch \ file://0001-src-intel-compiler-jay-jay_ir.h-do-not-used-typed-en.patch \ file://0001-src-util-u_math.c-do-not-use-arm-fpu-instructions-if.patch \ + file://0001-addrlib-avoid-builtin_cpu_supports-for-avx2-detecti.patch \ " SRC_URI[sha256sum] = "efd4bb08cdb7c365a812cd4e6c9202ab55b2f22cdcd13c7d6c4f9647b799a4ef"
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#243635): https://lists.openembedded.org/g/openembedded-core/message/243635 Mute This Topic: https://lists.openembedded.org/mt/120795718/21656 Group Owner: [email protected] Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
