Guard --nobranchprotection behind a version check
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (push) Successful in 52s
CI / pre-commit (push) Successful in 53s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (push) Failing after 47s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (push) Successful in 1m32s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (push) Successful in 1m25s

Older versions of hardening-check (as shipped by some Ubuntu releases)
don't support --nobranchprotection and error out. Probe --help at
configure time and only add the flag when it's available; old versions
that lack the flag also don't check for branch protection, so omitting
it is safe.
This commit is contained in:
2026-06-14 20:34:29 -04:00
parent 9ea798dba4
commit e8f51eff53
+10
View File
@@ -212,7 +212,17 @@ if(NOT CMAKE_CROSSCOMPILING)
STREQUAL arm64) STREQUAL arm64)
set(hardening_check_arch_flags --nocfprotection) set(hardening_check_arch_flags --nocfprotection)
else() else()
# --nobranchprotection was added in a newer version of hardening-check;
# older versions don't check for it either, so omitting the flag is safe.
execute_process(
COMMAND ${HARDENING_CHECK} --help
OUTPUT_VARIABLE _hardening_check_help
ERROR_VARIABLE _hardening_check_help)
if(_hardening_check_help MATCHES "nobranchprotection")
set(hardening_check_arch_flags --nobranchprotection) set(hardening_check_arch_flags --nobranchprotection)
else()
set(hardening_check_arch_flags "")
endif()
endif() endif()
add_test( add_test(
NAME hardening_check NAME hardening_check