diff --git a/CMakeLists.txt b/CMakeLists.txt index 30d3f02..3fa03d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,12 +61,16 @@ if(NOT APPLE) add_compile_options(-g -fno-omit-frame-pointer) endif() -set(full_relro_flags "-pie;LINKER:-z,relro,-z,now,-z,noexecstack") +set(relro_flags "LINKER:-z,relro,-z,now,-z,noexecstack") +set(full_relro_flags "-pie;${relro_flags}") cmake_push_check_state() list(APPEND CMAKE_REQUIRED_LINK_OPTIONS ${full_relro_flags}) check_cxx_source_compiles("int main(){}" HAS_FULL_RELRO FAIL_REGEX "warning:") if(HAS_FULL_RELRO) - add_link_options(${full_relro_flags}) + # -pie only applies to executables; passing it when linking a shared library + # makes the driver pull in Scrt1.o, which requires main. + add_link_options("$<$,EXECUTABLE>:-pie>" + ${relro_flags}) endif() cmake_pop_check_state()