Only pass -pie when linking executables
CI / build-image (arm64, ubuntu-latest-arm64) (push) Successful in 21s
CI / build-image (amd64, ubuntu-latest-amd64) (push) Successful in 42s
CI / pre-commit (push) Successful in 34s
CI / test (-DCMAKE_BUILD_TYPE=Debug, debug) (push) Failing after 2m22s
CI / release (arm64, ubuntu-latest-arm64) (push) Failing after 2m50s
CI / test (-DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 64-bit-versions) (push) Failing after 2m18s
CI / test (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc) (push) Failing after 2m26s
CI / test (-DUSE_SIMD_FALLBACK=ON, simd-fallback) (push) Failing after 2m16s
CI / release (amd64, ubuntu-latest-amd64) (push) Failing after 2m23s
CI / coverage (push) Failing after 2m16s
CI / build-image (arm64, ubuntu-latest-arm64) (push) Successful in 21s
CI / build-image (amd64, ubuntu-latest-amd64) (push) Successful in 42s
CI / pre-commit (push) Successful in 34s
CI / test (-DCMAKE_BUILD_TYPE=Debug, debug) (push) Failing after 2m22s
CI / release (arm64, ubuntu-latest-arm64) (push) Failing after 2m50s
CI / test (-DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 64-bit-versions) (push) Failing after 2m18s
CI / test (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc) (push) Failing after 2m26s
CI / test (-DUSE_SIMD_FALLBACK=ON, simd-fallback) (push) Failing after 2m16s
CI / release (amd64, ubuntu-latest-amd64) (push) Failing after 2m23s
CI / coverage (push) Failing after 2m16s
Passing -pie globally made the driver link Scrt1.o into shared libraries, which fails with an undefined reference to main.
This commit is contained in:
+6
-2
@@ -61,12 +61,16 @@ if(NOT APPLE)
|
|||||||
add_compile_options(-g -fno-omit-frame-pointer)
|
add_compile_options(-g -fno-omit-frame-pointer)
|
||||||
endif()
|
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()
|
cmake_push_check_state()
|
||||||
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS ${full_relro_flags})
|
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS ${full_relro_flags})
|
||||||
check_cxx_source_compiles("int main(){}" HAS_FULL_RELRO FAIL_REGEX "warning:")
|
check_cxx_source_compiles("int main(){}" HAS_FULL_RELRO FAIL_REGEX "warning:")
|
||||||
if(HAS_FULL_RELRO)
|
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("$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-pie>"
|
||||||
|
${relro_flags})
|
||||||
endif()
|
endif()
|
||||||
cmake_pop_check_state()
|
cmake_pop_check_state()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user