From 41fb5d3d9a264c88ff9864a1eec9e3cca374bbe5 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sat, 24 Aug 2024 18:32:28 +1000 Subject: [PATCH] CMake: Enable PIC on Linux Otherwise ASLR does not work. Also stops LTO builds crashing in the middle of Qt on Fedora. --- CMakeLists.txt | 7 +++++++ scripts/deps/build-dependencies-linux.sh | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b4e9ba6df..7eaa3b4fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,13 @@ detect_cache_line_size() # Build options. Depends on system attributes. include(DuckStationBuildOptions) +# Enable PIC on Linux, otherwise the builds do not support ASLR. +if(LINUX OR BSD) + include(CheckPIESupported) + check_pie_supported() + set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) +endif() + # Set _DEBUG macro for Debug builds. set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") diff --git a/scripts/deps/build-dependencies-linux.sh b/scripts/deps/build-dependencies-linux.sh index eafaf2bd2..bc038b0e0 100755 --- a/scripts/deps/build-dependencies-linux.sh +++ b/scripts/deps/build-dependencies-linux.sh @@ -143,7 +143,7 @@ echo "Building libbacktrace..." rm -fr "libbacktrace-$LIBBACKTRACE" unzip "$LIBBACKTRACE.zip" cd "libbacktrace-$LIBBACKTRACE" -./configure --prefix="$INSTALLDIR" +./configure --prefix="$INSTALLDIR" --with-pic make make install cd ..