From 992cf8c97cc71d4ca9a0a11e6604a6716ed4cefc Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Fri, 29 Jul 2022 19:34:00 +0300 Subject: [PATCH] Define __cpuid{ex} only when there's no builtin one (#73065) * Define __cpuid{ex} only when there's no builtin one Fix clang 15 RC1 build: `error: definition of builtin function '__cpuid'` * Add clang-15 autodetection --- eng/common/native/init-compiler.sh | 2 +- src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp | 4 ++++ src/coreclr/vm/amd64/unixstubs.cpp | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/eng/common/native/init-compiler.sh b/eng/common/native/init-compiler.sh index 4b99a9c..41a26d8 100644 --- a/eng/common/native/init-compiler.sh +++ b/eng/common/native/init-compiler.sh @@ -71,7 +71,7 @@ if [[ -z "$CLR_CC" ]]; then # Set default versions if [[ -z "$majorVersion" ]]; then # note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero. - if [[ "$compiler" == "clang" ]]; then versions=( 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 ) + if [[ "$compiler" == "clang" ]]; then versions=( 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5 ) elif [[ "$compiler" == "gcc" ]]; then versions=( 12 11 10 9 8 7 6 5 4.9 ); fi for version in "${versions[@]}"; do diff --git a/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp b/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp index 0c776a2..506c645 100644 --- a/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp @@ -1200,6 +1200,7 @@ extern "C" uint64_t PalGetCurrentThreadIdForLogging() #if defined(HOST_X86) || defined(HOST_AMD64) +#if !__has_builtin(__cpuid) REDHAWK_PALEXPORT void __cpuid(int cpuInfo[4], int function_id) { // Based on the Clang implementation provided in cpuid.h: @@ -1210,7 +1211,9 @@ REDHAWK_PALEXPORT void __cpuid(int cpuInfo[4], int function_id) : "0"(function_id) ); } +#endif +#if !__has_builtin(__cpuidex) REDHAWK_PALEXPORT void __cpuidex(int cpuInfo[4], int function_id, int subFunction_id) { // Based on the Clang implementation provided in cpuid.h: @@ -1221,6 +1224,7 @@ REDHAWK_PALEXPORT void __cpuidex(int cpuInfo[4], int function_id, int subFunctio : "0"(function_id), "2"(subFunction_id) ); } +#endif REDHAWK_PALEXPORT uint32_t REDHAWK_PALAPI xmmYmmStateSupport() { diff --git a/src/coreclr/vm/amd64/unixstubs.cpp b/src/coreclr/vm/amd64/unixstubs.cpp index 517eea9..09d2568 100644 --- a/src/coreclr/vm/amd64/unixstubs.cpp +++ b/src/coreclr/vm/amd64/unixstubs.cpp @@ -10,6 +10,7 @@ extern "C" PORTABILITY_ASSERT("Implement for PAL"); } +#if !__has_builtin(__cpuid) void __cpuid(int cpuInfo[4], int function_id) { // Based on the Clang implementation provided in cpuid.h: @@ -20,7 +21,9 @@ extern "C" : "0"(function_id) ); } +#endif +#if !__has_builtin(__cpuidex) void __cpuidex(int cpuInfo[4], int function_id, int subFunction_id) { // Based on the Clang implementation provided in cpuid.h: @@ -31,6 +34,7 @@ extern "C" : "0"(function_id), "2"(subFunction_id) ); } +#endif DWORD xmmYmmStateSupport() { -- 2.7.4