From 1fbd3bb320fbb226728bb0df7dd3a9e032589c20 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Mon, 13 Jan 2025 05:58:17 +0200 Subject: [PATCH 1/2] set no-PIC no-PIE compile options explicitly in some distros gcc is compiled with -fpic -pie as default, so clearing cxxflags is not enough to prevent PIC/PIE set compile flags '-fno-pic -fno-pie' set link flags '-no-pie -Wl,--no-export-dynamic' for gcc in all CMakeLists --- dep/bzip2/CMakeLists.txt | 4 ++-- rehlds/CMakeLists.txt | 5 ++--- rehlds/HLTV/Console/CMakeLists.txt | 6 ++---- rehlds/HLTV/Core/CMakeLists.txt | 2 +- rehlds/HLTV/DemoPlayer/CMakeLists.txt | 2 +- rehlds/HLTV/Director/CMakeLists.txt | 2 +- rehlds/HLTV/Proxy/CMakeLists.txt | 2 +- rehlds/dedicated/CMakeLists.txt | 6 ++---- rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt | 2 +- 9 files changed, 13 insertions(+), 18 deletions(-) diff --git a/dep/bzip2/CMakeLists.txt b/dep/bzip2/CMakeLists.txt index 50e77a602..d3d9a59f6 100644 --- a/dep/bzip2/CMakeLists.txt +++ b/dep/bzip2/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.1) project(bzip2 C) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g0 -O1 -fno-stack-protector") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic -g0 -O1 -fno-stack-protector") set(BZIP2_SRCS "src/blocksort.c" @@ -21,5 +21,5 @@ include_directories( add_library(bzip2 STATIC ${BZIP2_SRCS}) set_target_properties(bzip2 PROPERTIES - COMPILE_FLAGS "-m32" + COMPILE_FLAGS "-m32 -fno-pic" ) diff --git a/rehlds/CMakeLists.txt b/rehlds/CMakeLists.txt index e48e87d16..e5bc21a37 100644 --- a/rehlds/CMakeLists.txt +++ b/rehlds/CMakeLists.txt @@ -30,8 +30,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") -set(LINK_FLAGS "-m32") +set(COMPILE_FLAGS "-m32 -fno-pic -fno-pie -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32 -no-pie -Wl,--no-export-dynamic") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-rtti -fno-exceptions") @@ -219,7 +219,6 @@ if (CMAKE_BUILD_TYPE MATCHES Unittests) add_subdirectory(../dep/cppunitlite cppunitlite) endif() - set(LINK_FLAGS "${LINK_FLAGS} -no-pie -Wl,--no-export-dynamic") add_executable(engine ${appversion.sh} ${ENGINE_SRCS}) target_link_libraries(engine PRIVATE cppunitlite) else() diff --git a/rehlds/HLTV/Console/CMakeLists.txt b/rehlds/HLTV/Console/CMakeLists.txt index fae3e05a9..4ee46213f 100644 --- a/rehlds/HLTV/Console/CMakeLists.txt +++ b/rehlds/HLTV/Console/CMakeLists.txt @@ -9,8 +9,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Avoid -rdynamic -fPIC options set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") -set(LINK_FLAGS "-m32") +set(COMPILE_FLAGS "-m32 -fno-pic -fno-pie -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32 -no-pie -Wl,--no-export-dynamic") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") @@ -20,8 +20,6 @@ else() set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() -set(LINK_FLAGS "${LINK_FLAGS} -no-pie -Wl,--no-export-dynamic") - # Check Intel C++ compiler if ("$ENV{CXX}" MATCHES "icpc") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") diff --git a/rehlds/HLTV/Core/CMakeLists.txt b/rehlds/HLTV/Core/CMakeLists.txt index 94c45e17c..9bd2f0373 100644 --- a/rehlds/HLTV/Core/CMakeLists.txt +++ b/rehlds/HLTV/Core/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") diff --git a/rehlds/HLTV/DemoPlayer/CMakeLists.txt b/rehlds/HLTV/DemoPlayer/CMakeLists.txt index 27feb5e22..da435a672 100644 --- a/rehlds/HLTV/DemoPlayer/CMakeLists.txt +++ b/rehlds/HLTV/DemoPlayer/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") diff --git a/rehlds/HLTV/Director/CMakeLists.txt b/rehlds/HLTV/Director/CMakeLists.txt index 7f8894540..1977dccac 100644 --- a/rehlds/HLTV/Director/CMakeLists.txt +++ b/rehlds/HLTV/Director/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") diff --git a/rehlds/HLTV/Proxy/CMakeLists.txt b/rehlds/HLTV/Proxy/CMakeLists.txt index 550e049e0..88f91bf21 100644 --- a/rehlds/HLTV/Proxy/CMakeLists.txt +++ b/rehlds/HLTV/Proxy/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") diff --git a/rehlds/dedicated/CMakeLists.txt b/rehlds/dedicated/CMakeLists.txt index 936734cad..9c3d0d515 100644 --- a/rehlds/dedicated/CMakeLists.txt +++ b/rehlds/dedicated/CMakeLists.txt @@ -9,8 +9,8 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Avoid -rdynamic -fPIC options set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") -set(LINK_FLAGS "-m32") +set(COMPILE_FLAGS "-m32 -fno-pic -fno-pie -U_FORTIFY_SOURCE") +set(LINK_FLAGS "-m32 -no-pie -Wl,--no-export-dynamic") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") @@ -20,8 +20,6 @@ else() set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() -set(LINK_FLAGS "${LINK_FLAGS} -no-pie -Wl,--no-export-dynamic") - # Check Intel C++ compiler if ("$ENV{CXX}" MATCHES "icpc") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Qoption,cpp,--treat_func_as_string_literal_cpp") diff --git a/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt b/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt index 2339aae74..31b296f7d 100644 --- a/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt +++ b/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) # Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") -set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") +set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") From 164a648979c7a3ea3f58e12bdb76643fb6d765bb Mon Sep 17 00:00:00 2001 From: anzz1 Date: Thu, 23 Jan 2025 08:19:24 +0200 Subject: [PATCH 2/2] Makefiles: no strict aliasing, no strict overflow Modern GCC no longer use these as default which will lead to bugs caused by wrong optimizations --- dep/bzip2/CMakeLists.txt | 2 +- rehlds/CMakeLists.txt | 2 +- rehlds/HLTV/Console/CMakeLists.txt | 2 +- rehlds/HLTV/Core/CMakeLists.txt | 2 +- rehlds/HLTV/DemoPlayer/CMakeLists.txt | 2 +- rehlds/HLTV/Director/CMakeLists.txt | 2 +- rehlds/HLTV/Proxy/CMakeLists.txt | 2 +- rehlds/dedicated/CMakeLists.txt | 2 +- rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dep/bzip2/CMakeLists.txt b/dep/bzip2/CMakeLists.txt index d3d9a59f6..15412fafe 100644 --- a/dep/bzip2/CMakeLists.txt +++ b/dep/bzip2/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.1) project(bzip2 C) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic -g0 -O1 -fno-stack-protector") +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-pic -g0 -O1 -fno-stack-protector -fno-strict-aliasing -fno-strict-overflow") set(BZIP2_SRCS "src/blocksort.c" diff --git a/rehlds/CMakeLists.txt b/rehlds/CMakeLists.txt index e5bc21a37..ec2f3267d 100644 --- a/rehlds/CMakeLists.txt +++ b/rehlds/CMakeLists.txt @@ -33,7 +33,7 @@ set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -fno-pic -fno-pie -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32 -no-pie -Wl,--no-export-dynamic") -set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-rtti -fno-exceptions") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-rtti -fno-exceptions -fno-strict-aliasing -fno-strict-overflow") # Remove noxref code and data set(COMPILE_FLAGS "${COMPILE_FLAGS} -ffunction-sections -fdata-sections") diff --git a/rehlds/HLTV/Console/CMakeLists.txt b/rehlds/HLTV/Console/CMakeLists.txt index 4ee46213f..018d1da1b 100644 --- a/rehlds/HLTV/Console/CMakeLists.txt +++ b/rehlds/HLTV/Console/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -fno-pic -fno-pie -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32 -no-pie -Wl,--no-export-dynamic") -set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-strict-aliasing -fno-strict-overflow") if (DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") diff --git a/rehlds/HLTV/Core/CMakeLists.txt b/rehlds/HLTV/Core/CMakeLists.txt index 9bd2f0373..8f820d1e6 100644 --- a/rehlds/HLTV/Core/CMakeLists.txt +++ b/rehlds/HLTV/Core/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") -set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-strict-aliasing -fno-strict-overflow") if (DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") diff --git a/rehlds/HLTV/DemoPlayer/CMakeLists.txt b/rehlds/HLTV/DemoPlayer/CMakeLists.txt index da435a672..dd6e4400b 100644 --- a/rehlds/HLTV/DemoPlayer/CMakeLists.txt +++ b/rehlds/HLTV/DemoPlayer/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") -set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-strict-aliasing -fno-strict-overflow") if (DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") diff --git a/rehlds/HLTV/Director/CMakeLists.txt b/rehlds/HLTV/Director/CMakeLists.txt index 1977dccac..c35be56ee 100644 --- a/rehlds/HLTV/Director/CMakeLists.txt +++ b/rehlds/HLTV/Director/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") -set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-strict-aliasing -fno-strict-overflow") if (DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") diff --git a/rehlds/HLTV/Proxy/CMakeLists.txt b/rehlds/HLTV/Proxy/CMakeLists.txt index 88f91bf21..0088dcba5 100644 --- a/rehlds/HLTV/Proxy/CMakeLists.txt +++ b/rehlds/HLTV/Proxy/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") -set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-strict-aliasing -fno-strict-overflow") if (DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") diff --git a/rehlds/dedicated/CMakeLists.txt b/rehlds/dedicated/CMakeLists.txt index 9c3d0d515..fe6038050 100644 --- a/rehlds/dedicated/CMakeLists.txt +++ b/rehlds/dedicated/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -fno-pic -fno-pie -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32 -no-pie -Wl,--no-export-dynamic") -set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-strict-aliasing -fno-strict-overflow") if (DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") diff --git a/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt b/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt index 31b296f7d..dd69d8750 100644 --- a/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt +++ b/rehlds/filesystem/FileSystem_Stdio/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -fno-pic -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32") -set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions") +set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-strict-aliasing -fno-strict-overflow") if (DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb")