Fix cxx/linker flags Upstream PR: https://github.com/ROCm/rocm_smi_lib/pull/211 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,7 +95,7 @@ set(CMAKE_CXX_FLAGS # Clang does not set the build-id if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--build-id=sha1") + set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--build-id=sha1") endif() # Use this instead of above for 32 bit @@ -129,10 +129,16 @@ else () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DFORTIFY_SOURCE=2 -fstack-protector-all -Wcast-align") ## More security breach mitigation flags - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -Wl,-z,noexecstack -Wl,-znoexecheap -Wl,-z,relro ") - set(CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -Wtrampolines -Wl,-z,now") + set(HARDENING_LDFLAGS + "${HARDENING_LDFLAGS} -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${HARDENING_LDFLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${HARDENING_LDFLAGS}") + + include(CheckCXXCompilerFlag) + check_cxx_compiler_flag("-Wtrampolines" CXX_SUPPORTS_WTRAMPOLINES) + if (CXX_SUPPORTS_WTRAMPOLINES) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wtrampolines") + endif () endif () set(COMMON_SRC_DIR "${PROJECT_SOURCE_DIR}/src")