Skip to content

Commit be82985

Browse files
Spectre mitigation for gcc and clang
Resolves: NEO-3038 #159 Change-Id: If464949242afa6fbca85a0533eb874f276164646 Signed-off-by: Jacek Danecki <[email protected]>
1 parent c624787 commit be82985

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

CMakeLists.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,44 @@ if(MSVC)
540540
endif()
541541

542542
# spectre mitigation
543+
include(CheckCXXCompilerFlag)
543544
if(MSVC)
544-
include(CheckCXXCompilerFlag)
545545
check_cxx_compiler_flag(/Qspectre COMPILER_SUPPORTS_QSPECTRE)
546546
check_cxx_compiler_flag(/d2guardspecload COMPILER_SUPPORTS_D2GUARDSPECLOAD)
547547
if(COMPILER_SUPPORTS_QSPECTRE)
548548
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre")
549549
elseif(COMPILER_SUPPORTS_D2GUARDSPECLOAD)
550550
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /d2guardspecload")
551551
else()
552-
message(STATUS "Spectre mitigation is not supported by the compiler")
552+
message(WARNING "Spectre mitigation is not supported by the compiler")
553+
endif()
554+
else()
555+
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
556+
check_cxx_compiler_flag(-mretpoline COMPILER_SUPPORTS_RETPOLINE)
557+
if(COMPILER_SUPPORTS_RETPOLINE)
558+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mretpoline")
559+
else()
560+
message(WARNING "Spectre mitigation -mretpoline flag is not supported by the compiler")
561+
endif()
562+
else()
563+
check_cxx_compiler_flag(-mindirect-branch=thunk COMPILER_SUPPORTS_INDIRECT_BRANCH_THUNK)
564+
if(COMPILER_SUPPORTS_INDIRECT_BRANCH_THUNK)
565+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch=thunk")
566+
else()
567+
message(WARNING "Spectre mitigation -mindirect-branch=thunk flag is not supported by the compiler")
568+
endif()
569+
check_cxx_compiler_flag(-mfunction-return=thunk COMPILER_SUPPORTS_FUNCTION_RETURN_THUNK)
570+
if(COMPILER_SUPPORTS_FUNCTION_RETURN_THUNK)
571+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfunction-return=thunk")
572+
else()
573+
message(WARNING "Spectre mitigation -mfunction-return=thunk flag is not supported by the compiler")
574+
endif()
575+
check_cxx_compiler_flag(-mindirect-branch-register COMPILER_SUPPORTS_INDIRECT_BRANCH_REGISTER)
576+
if(COMPILER_SUPPORTS_INDIRECT_BRANCH_REGISTER)
577+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch-register")
578+
else()
579+
message(WARNING "Spectre mitigation -mindirect-branch-register flag is not supported by the compiler")
580+
endif()
553581
endif()
554582
endif(MSVC)
555583

scripts/docker/Dockerfile-fedora-28-copr-gcc-8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ RUN dnf install -y gcc-c++ cmake ninja-build git pkg-config; \
1111
dnf copr enable -y arturh/intel-opencl; \
1212
dnf --showduplicate list intel-igc-opencl-devel intel-gmmlib-devel; \
1313
dnf install -y intel-igc-opencl-devel intel-gmmlib-devel; \
14-
mkdir /root/build; cd /root/build ; cmake -G Ninja ../neo; \
14+
mkdir /root/build; cd /root/build ; cmake -G Ninja \
15+
-DDO_NOT_RUN_AUB_TESTS=1 -DDONT_CARE_OF_VIRTUALS=1 ../neo; \
1516
ninja -j `nproc`
1617
CMD ["/bin/bash"]

scripts/docker/Dockerfile-fedora-29-copr-gcc-8

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ RUN dnf install -y gcc-c++ cmake ninja-build git pkg-config; \
1111
dnf copr enable -y arturh/intel-opencl; \
1212
dnf --showduplicate list intel-igc-opencl-devel intel-gmmlib-devel; \
1313
dnf install -y intel-igc-opencl-devel intel-gmmlib-devel; \
14-
mkdir /root/build; cd /root/build ; cmake -G Ninja ../neo; \
14+
mkdir /root/build; cd /root/build ; cmake -G Ninja \
15+
-DDO_NOT_RUN_AUB_TESTS=1 -DDONT_CARE_OF_VIRTUALS=1 ../neo; \
1516
ninja -j `nproc`
1617
CMD ["/bin/bash"]

0 commit comments

Comments
 (0)