From 847b0f48e80e48e8c4a3f5416208e9882e74cb31 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 13 Dec 2025 19:50:34 +0100 Subject: [PATCH 1/4] VMMain: explicitely include unistd on NaCl to please Saigo --- src/shared/VMMain.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/shared/VMMain.cpp b/src/shared/VMMain.cpp index a63574eed2..5c0ab8c68c 100644 --- a/src/shared/VMMain.cpp +++ b/src/shared/VMMain.cpp @@ -34,6 +34,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "common/StackTrace.h" +#if defined(__native_client__) +#include +#endif + IPC::Channel VM::rootChannel; #ifdef BUILD_VM_NATIVE_EXE From 859c81603b09abd2c5e8826e12528d04607ce6a5 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 13 Dec 2025 19:50:51 +0100 Subject: [PATCH 2/4] cmake: disable PIC with NaCl --- cmake/DaemonFlags.cmake | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index 868be61185..657d7a6934 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -476,7 +476,16 @@ else() # Don't set _FORTIFY_SOURCE in debug builds. endif() - try_c_cxx_flag(FPIC "-fPIC") + if (NOT NACL) + # Saigo reports weird errors when building some cgame and sgame arm nexe with PIC: + # > error: Cannot represent a difference across sections + # > error: expected relocatable expression + # Google-built Saigo crashes when building amd64 cgame with PIC: + # > UNREACHABLE executed at llvm/lib/Target/X86/X86ISelLowering.cpp + # Self-built Saigo doesn't crash, maybe because assertions are disabled. + # PIC is not useful with NaCl under any circumstances, so we don't use PIC with NaCl. + try_c_cxx_flag(FPIC "-fPIC") + endif() if (USE_HARDENING) # PNaCl accepts the flags but does not define __stack_chk_guard and __stack_chk_fail. From 5e5f672c80dec60db65813312cf26e7d359f778c Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sat, 13 Dec 2025 23:45:46 +0100 Subject: [PATCH 3/4] cmake: simplify the Saigo arm optimization disablement fix --- cmake/DaemonFlags.cmake | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index 657d7a6934..b6f0cc9394 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -363,14 +363,12 @@ else() endif() if (NACL AND USE_NACL_SAIGO AND SAIGO_ARCH STREQUAL "arm") - # This should be set for every build type because build type flags - # are set after the other custom flags and then have the last word. - # DEBUG should already use -O0 anyway. + # Saigo produces broken arm builds when optimizing them. # See: https://github.com/Unvanquished/Unvanquished/issues/3297 - set_c_cxx_flag("-O0" DEBUG) - set_c_cxx_flag("-O0" RELEASE) - set_c_cxx_flag("-O0" RELWITHDEBINFO) - set_c_cxx_flag("-O0" MINSIZEREL) + # When setting this clang-specific option, we don't have to care + # about the ordering of -O options that may be introduced, + # all -O options added to the command line are ignored. + set_c_cxx_flag("-Xclang -disable-llvm-passes") endif() # Extra debug flags. From 61b9bdd53ae3a14fa4ba494066b7abe915caf63f Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Tue, 9 Dec 2025 07:29:36 +0100 Subject: [PATCH 4/4] cmake: remove GAME_PIE entirely --- CMakeLists.txt | 1 - cmake/DaemonFlags.cmake | 2 +- cmake/DaemonPlatform.cmake | 9 --------- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e339747def..35cf7fa5f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -465,7 +465,6 @@ endif() include(DaemonNacl) if (NACL) add_library(srclibs-nacl-module EXCLUDE_FROM_ALL ${NACLLIST_MODULE}) - set_target_properties(srclibs-nacl-module PROPERTIES POSITION_INDEPENDENT_CODE ${GAME_PIE} FOLDER "libs") set(LIBS_BASE ${LIBS_BASE} srclibs-nacl-module) else() add_library(srclibs-nacl-native EXCLUDE_FROM_ALL ${NACLLIST_NATIVE}) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index b6f0cc9394..7cbb964c73 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -498,7 +498,7 @@ else() try_c_cxx_flag(FNO_STRICT_OVERFLOW "-fno-strict-overflow") try_c_cxx_flag(WSTACK_PROTECTOR "-Wstack-protector") - if (NOT NACL OR (NACL AND GAME_PIE)) + if (NOT NACL) # The -pie flag requires -fPIC: # > ld: error: relocation R_X86_64_64 cannot be used against local symbol; recompile with -fPIC # This flag isn't used on macOS: diff --git a/cmake/DaemonPlatform.cmake b/cmake/DaemonPlatform.cmake index be8f5f1c81..a951f2ad47 100644 --- a/cmake/DaemonPlatform.cmake +++ b/cmake/DaemonPlatform.cmake @@ -40,14 +40,5 @@ else() message( FATAL_ERROR "Platform not supported" ) endif() -if (NACL AND USE_NACL_SAIGO) - # Saigo clang reports weird errors when building some cgame and sgame arm nexe with PIE. - # Saigo clang crashes when building amd64 cgame with PIE, sgame builds properly though. - set(GAME_PIE 0) -else() - set(GAME_PIE 1) -endif() - - include(DaemonArchitecture) include(DaemonCompiler)