Skip to content

Commit

Permalink
Fixes _FORTIFY_SOURCE warnings and CMakePresets.
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusferrao committed May 14, 2024
1 parent d64a07f commit 2c286f9
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 26 deletions.
57 changes: 40 additions & 17 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"name": "conf-common",
"description": "General settings that apply to all configurations",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}"
},
Expand All @@ -28,7 +29,7 @@
"sourceDir": "$env{HOME}/.vs/$ms{projectDirName}"
},
"jetbrains.com/clion": {
"toolchain": "CloysterHPC RHEL9 Dev"
"toolchain": "OpenCATTUS RHEL9 Dev"
}
}
},
Expand Down Expand Up @@ -108,20 +109,18 @@
}
},
{
"name": "linux-clang-release",
"name": "rhel9-clang-release",
"displayName": "clang Release",
"description": "Target Linux OS with the clang compiler, release build type",
"hidden": true,
"inherits": "conf-linux-clang-common",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "linux-clang-debug",
"name": "rhel9-clang-debug",
"displayName": "clang Debug",
"description": "Target Linux OS with the clang compiler, debug build type",
"hidden": true,
"inherits": "conf-linux-clang-common",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
Expand All @@ -130,24 +129,34 @@
],
"buildPresets": [
{
"name": "rhel9-gcc-release",
"name": "rhel9-gcc-release-build",
"displayName": "gcc build release",
"configurePreset": "rhel9-gcc-release"
},
{
"name": "rhel9-gcc-debug",
"name": "rhel9-gcc-debug-build",
"displayName": "gcc build debug",
"configurePreset": "rhel9-gcc-debug"
},
{
"name": "rhel9-gcc-toolset-13-release",
"name": "rhel9-gcc-toolset-13-release-build",
"displayName": "gcc toolset 13 build release",
"configurePreset": "rhel9-gcc-toolset-13-release"
},
{
"name": "rhel9-gcc-toolset-13-debug",
"name": "rhel9-gcc-toolset-13-debug-build",
"displayName": "gcc toolset 13 build debug",
"configurePreset": "rhel9-gcc-toolset-13-debug"
},
{
"name": "rhel9-clang-release-build",
"displayName": "clang build debug",
"configurePreset": "rhel9-clang-release"
},
{
"name": "rhel9-clang-debug-build",
"displayName": "clang build debug",
"configurePreset": "rhel9-clang-debug"
}
],
"testPresets": [
Expand All @@ -164,32 +173,46 @@
}
},
{
"name": "test-linux-gcc-debug",
"name": "test-rhel9-gcc-release",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "rhel9-gcc-release"
},
{
"name": "test-rhel9-gcc-debug",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "rhel9-gcc-debug"
},
{
"name": "test-rhel9-gcc-toolset-13-release",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "linux-gcc-debug"
"configurePreset": "rhel9-gcc-toolset-13-release"
},
{
"name": "test-linux-gcc-release",
"name": "test-rhel9-gcc-toolset-13-debug",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "linux-gcc-release"
"configurePreset": "rhel9-gcc-toolset-13-debug"
},
{
"name": "test-linux-clang-debug",
"name": "test-rhel9-clang-release",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "linux-clang-debug"
"configurePreset": "rhel9-clang-release"
},
{
"name": "test-linux-clang-release",
"name": "test-rhel9-clang-debug",
"displayName": "Strict",
"description": "Enable output and stop on failure",
"inherits": "test-common",
"configurePreset": "linux-clang-release"
"configurePreset": "rhel9-clang-debug"
}
]
}
15 changes: 13 additions & 2 deletions cmake/Hardening.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ macro(
set(NEW_CXX_DEFINITIONS "${NEW_CXX_DEFINITIONS} -D_GLIBCXX_ASSERTIONS")
message(STATUS "*** GLIBC++ Assertions (vector[], string[], ...) enabled")

set(NEW_COMPILE_OPTIONS "${NEW_COMPILE_OPTIONS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3")
message(STATUS "*** g++/clang _FORTIFY_SOURCE=3 enabled")
# Only enable _FORTIFY_SOURCE if not running in DEBUG mode.
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "*** g++ _FORTIFY_SOURCE is not defined due to DEBUG mode")
else()
# If running GCC and version is lower than 12 set _FORTIFY_SOURCE to 2.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12)
set(NEW_COMPILE_OPTIONS "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2")
message(STATUS "*** g++ _FORTIFY_SOURCE=2 enabled (GCC < 12)")
else()
set(NEW_COMPILE_OPTIONS "-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3")
message(STATUS "*** g++/clang _FORTIFY_SOURCE=3 enabled")
endif()
endif()

# check_cxx_compiler_flag(-fpie PIE)
#if(PIE)
Expand Down
30 changes: 24 additions & 6 deletions cmake/_FORTIFY_SOURCE.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
#ifdef _FORTIFY_SOURCE
#if _FORTIFY_SOURCE < 3
#undef _FORTIFY_SOURCE
#define _FORTIFY_SOURCE 3
#endif
// If in DEBUG mode, remove _FORTIFY_SOURCE
#ifndef NDEBUG
#ifdef _FORTIFY_SOURCE
#undef _FORTIFY_SOURCE
#endif
#else
#define _FORTIFY_SOURCE 3
#if defined(__GNUC__) && (__GNUC__ < 12)
#ifdef _FORTIFY_SOURCE
#if _FORTIFY_SOURCE < 2
#undef _FORTIFY_SOURCE
#define _FORTIFY_SOURCE 2
#endif
#else
#define _FORTIFY_SOURCE 2
#endif
#else
#ifdef _FORTIFY_SOURCE
#if _FORTIFY_SOURCE < 3
#undef _FORTIFY_SOURCE
#define _FORTIFY_SOURCE 3
#endif
#else
#define _FORTIFY_SOURCE 3
#endif
#endif
#endif
2 changes: 1 addition & 1 deletion setupDevEnvironment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ case $(cut -f 3 -d : /etc/system-release-cpe) in
esac

# Build toolset, packages and utils
dnf -y install git gcc-c++ cmake ccache cppcheck rsync
dnf -y install rsync git gcc-c++ ninja-build cmake ccache cppcheck

if [ "$os_version" = "8" ]; then
dnf -y install python3 python3-pip\* llvm-toolset compiler-rt \
Expand Down

0 comments on commit 2c286f9

Please sign in to comment.