From d8efcb39b8d0f04ac352b385a37ab92834f1c673 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 8 Nov 2023 05:50:33 -0800 Subject: [PATCH] FEX: Only pass CPU tunables to FEXCore and FEXLoader This fixes an issue where CPU tunables were ending up in the thunk generator which means if your CPU doesn't support all the features on the *Builder* then it would crash with SIGILL. This was happening with Canonical's runners because they typically only support ARMv8.2 but we are compiling packages to run on ARMv8.4 devices. cc: FEX-2311.1 --- CMakeLists.txt | 11 ++++++----- FEXCore/Source/CMakeLists.txt | 2 ++ Source/Tools/FEXLoader/CMakeLists.txt | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b20f18d85..5c293c6d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -293,10 +293,11 @@ if(ENABLE_WERROR OR ENABLE_STRICT_WERROR) endif() endif() +set(FEX_TUNE_COMPILE_FLAGS) if (NOT TUNE_ARCH STREQUAL "generic") check_cxx_compiler_flag("-march=${TUNE_ARCH}" COMPILER_SUPPORTS_ARCH_TYPE) if(COMPILER_SUPPORTS_ARCH_TYPE) - add_compile_options("-march=${TUNE_ARCH}") + list(APPEND FEX_TUNE_COMPILE_FLAGS "-march=${TUNE_ARCH}") else() message(FATAL_ERROR "Trying to compile arch type '${TUNE_ARCH}' but the compiler doesn't support this") endif() @@ -309,7 +310,7 @@ if (TUNE_CPU STREQUAL "native") # Clang can not currently check for native Apple M1 type in hypervisor. Currently disabled check_cxx_compiler_flag("-mcpu=native" COMPILER_SUPPORTS_CPU_TYPE) if(COMPILER_SUPPORTS_CPU_TYPE) - add_compile_options("-mcpu=native") + list(APPEND FEX_TUNE_COMPILE_FLAGS "-mcpu=native") endif() else() # Due to an oversight in llvm, it declares any reasonably new Kryo CPU to only be ARMv8.0 @@ -323,19 +324,19 @@ if (TUNE_CPU STREQUAL "native") check_cxx_compiler_flag("-mcpu=${AARCH64_CPU}" COMPILER_SUPPORTS_CPU_TYPE) if(COMPILER_SUPPORTS_CPU_TYPE) - add_compile_options("-mcpu=${AARCH64_CPU}") + list(APPEND FEX_TUNE_COMPILE_FLAGS "-mcpu=${AARCH64_CPU}") endif() endif() else() check_cxx_compiler_flag("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) if(COMPILER_SUPPORTS_MARCH_NATIVE) - add_compile_options("-march=native") + list(APPEND FEX_TUNE_COMPILE_FLAGS "-march=native") endif() endif() else() check_cxx_compiler_flag("-mcpu=${TUNE_CPU}" COMPILER_SUPPORTS_CPU_TYPE) if(COMPILER_SUPPORTS_CPU_TYPE) - add_compile_options("-mcpu=${TUNE_CPU}") + list(APPEND FEX_TUNE_COMPILE_FLAGS "-mcpu=${TUNE_CPU}") else() message(FATAL_ERROR "Trying to compile cpu type '${TUNE_CPU}' but the compiler doesn't support this") endif() diff --git a/FEXCore/Source/CMakeLists.txt b/FEXCore/Source/CMakeLists.txt index 59b69a6bd..3dc311003 100644 --- a/FEXCore/Source/CMakeLists.txt +++ b/FEXCore/Source/CMakeLists.txt @@ -362,6 +362,7 @@ function(AddObject Name Type) add_library(${Name} ${Type} ${SRCS}) target_link_libraries(${Name} FEXCore_Base) + target_compile_options(${Name} PRIVATE ${FEX_TUNE_COMPILE_FLAGS}) AddDefaultOptionsToTarget(${Name}) set_target_properties(${Name} PROPERTIES OUTPUT_NAME FEXCore) @@ -370,6 +371,7 @@ endfunction() function(AddLibrary Name Type) add_library(${Name} ${Type} $) target_link_libraries(${Name} FEXCore_Base) + target_compile_options(${Name} PRIVATE ${FEX_TUNE_COMPILE_FLAGS}) set_target_properties(${Name} PROPERTIES OUTPUT_NAME FEXCore) if (MINGW_BUILD) # Mingw build isn't building a linux shared library, so it can't have a SONAME. diff --git a/Source/Tools/FEXLoader/CMakeLists.txt b/Source/Tools/FEXLoader/CMakeLists.txt index 9fc8c8d26..29864bfc0 100644 --- a/Source/Tools/FEXLoader/CMakeLists.txt +++ b/Source/Tools/FEXLoader/CMakeLists.txt @@ -37,6 +37,7 @@ if (NOT MINGW_BUILD) ${PTHREAD_LIB} fmt::fmt ) + target_compile_options(${NAME} PRIVATE ${FEX_TUNE_COMPILE_FLAGS}) target_compile_definitions(${NAME} PRIVATE -DFEXLOADER_AS_INTERPRETER=${AsInterpreter}) if (CMAKE_BUILD_TYPE MATCHES "RELEASE")