From 55d7e31f7e224af1019a0827be522e07de9ddcab Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 12 May 2024 15:10:01 +0000 Subject: [PATCH 1/4] Use hardening flags only for debug builds to avoid conflicts --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b84ebaf9c..eb42827d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -400,9 +400,11 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=array-bounds") # false positives in boost::multiarray during release build, keep as warning-only endif() - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT WIN32) - # For gcc 14+ we can use -fhardened instead - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fstack-clash-protection -fcf-protection=full") + if(CMAKE_BUILD_TYPE MATCHES Debug) + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT WIN32) + # For gcc 14+ we can use -fhardened instead + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fstack-clash-protection -fcf-protection=full") + endif() endif() # Fix string inspection with lldb From 62c2be160a66c84f7c9ba2b772769877c447d7b7 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 12 May 2024 15:10:29 +0000 Subject: [PATCH 2/4] Added changing thread name for FreeBSD --- lib/CThreadHelper.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/CThreadHelper.cpp b/lib/CThreadHelper.cpp index 21f8dc4bb..f7113e58c 100644 --- a/lib/CThreadHelper.cpp +++ b/lib/CThreadHelper.cpp @@ -107,10 +107,14 @@ void setThreadName(const std::string &name) #elif defined(VCMI_APPLE) pthread_setname_np(name.c_str()); +#elif defined(VCMI_FREEBSD) + pthread_setname_np(pthread_self(), name.c_str()); #elif defined(VCMI_HAIKU) rename_thread(find_thread(NULL), name.c_str()); #elif defined(VCMI_UNIX) prctl(PR_SET_NAME, name.c_str(), 0, 0, 0); +#else + #error "Failed to find method to set thread name on this system. Please provide one (or disable this line if you just want code to compile)" #endif } From b207768cf326e6b5de6a222dde46b3e2bd8414f5 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 12 May 2024 17:06:46 +0000 Subject: [PATCH 3/4] Use STREQUAL instead of MATCHES where applicable --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb42827d0..f95a22fd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -365,7 +365,7 @@ if(MINGW OR MSVC) # Prevent compiler issues when building Debug # Assembler might fail with "too many sections" # With big-obj or 64-bit build will take hours - if(CMAKE_BUILD_TYPE MATCHES Debug) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og") endif() endif(MINGW) @@ -400,7 +400,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR NOT WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=array-bounds") # false positives in boost::multiarray during release build, keep as warning-only endif() - if(CMAKE_BUILD_TYPE MATCHES Debug) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT WIN32) # For gcc 14+ we can use -fhardened instead set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fstack-clash-protection -fcf-protection=full") @@ -742,7 +742,7 @@ if(WIN32) "${CMAKE_FIND_ROOT_PATH}/bin/*.dll") endif() - if(CMAKE_BUILD_TYPE MATCHES Debug) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") # Copy debug versions of libraries if build type is debug set(debug_postfix d) endif() From ecb8d17ca8bca8e1aebe7456c3da3de5fc640c3c Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 13 May 2024 12:23:46 +0000 Subject: [PATCH 4/4] Remove flag that requires optimized builds --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f95a22fd0..df7da6311 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -403,7 +403,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR NOT WIN32) if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT WIN32) # For gcc 14+ we can use -fhardened instead - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fstack-clash-protection -fcf-protection=full") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fstack-clash-protection -fcf-protection=full") endif() endif()