Skip to content

Commit

Permalink
Spectre mitigation for gcc and clang
Browse files Browse the repository at this point in the history
Resolves: NEO-3038
#159

Change-Id: If464949242afa6fbca85a0533eb874f276164646
Signed-off-by: Jacek Danecki <[email protected]>
  • Loading branch information
JacekDanecki authored and Compute-Runtime-Automation committed Apr 17, 2019
1 parent c624787 commit be82985
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
32 changes: 30 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,44 @@ if(MSVC)
endif()

# spectre mitigation
include(CheckCXXCompilerFlag)
if(MSVC)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(/Qspectre COMPILER_SUPPORTS_QSPECTRE)
check_cxx_compiler_flag(/d2guardspecload COMPILER_SUPPORTS_D2GUARDSPECLOAD)
if(COMPILER_SUPPORTS_QSPECTRE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre")
elseif(COMPILER_SUPPORTS_D2GUARDSPECLOAD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /d2guardspecload")
else()
message(STATUS "Spectre mitigation is not supported by the compiler")
message(WARNING "Spectre mitigation is not supported by the compiler")
endif()
else()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
check_cxx_compiler_flag(-mretpoline COMPILER_SUPPORTS_RETPOLINE)
if(COMPILER_SUPPORTS_RETPOLINE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mretpoline")
else()
message(WARNING "Spectre mitigation -mretpoline flag is not supported by the compiler")
endif()
else()
check_cxx_compiler_flag(-mindirect-branch=thunk COMPILER_SUPPORTS_INDIRECT_BRANCH_THUNK)
if(COMPILER_SUPPORTS_INDIRECT_BRANCH_THUNK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch=thunk")
else()
message(WARNING "Spectre mitigation -mindirect-branch=thunk flag is not supported by the compiler")
endif()
check_cxx_compiler_flag(-mfunction-return=thunk COMPILER_SUPPORTS_FUNCTION_RETURN_THUNK)
if(COMPILER_SUPPORTS_FUNCTION_RETURN_THUNK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfunction-return=thunk")
else()
message(WARNING "Spectre mitigation -mfunction-return=thunk flag is not supported by the compiler")
endif()
check_cxx_compiler_flag(-mindirect-branch-register COMPILER_SUPPORTS_INDIRECT_BRANCH_REGISTER)
if(COMPILER_SUPPORTS_INDIRECT_BRANCH_REGISTER)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch-register")
else()
message(WARNING "Spectre mitigation -mindirect-branch-register flag is not supported by the compiler")
endif()
endif()
endif(MSVC)

Expand Down
3 changes: 2 additions & 1 deletion scripts/docker/Dockerfile-fedora-28-copr-gcc-8
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN dnf install -y gcc-c++ cmake ninja-build git pkg-config; \
dnf copr enable -y arturh/intel-opencl; \
dnf --showduplicate list intel-igc-opencl-devel intel-gmmlib-devel; \
dnf install -y intel-igc-opencl-devel intel-gmmlib-devel; \
mkdir /root/build; cd /root/build ; cmake -G Ninja ../neo; \
mkdir /root/build; cd /root/build ; cmake -G Ninja \
-DDO_NOT_RUN_AUB_TESTS=1 -DDONT_CARE_OF_VIRTUALS=1 ../neo; \
ninja -j `nproc`
CMD ["/bin/bash"]
3 changes: 2 additions & 1 deletion scripts/docker/Dockerfile-fedora-29-copr-gcc-8
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN dnf install -y gcc-c++ cmake ninja-build git pkg-config; \
dnf copr enable -y arturh/intel-opencl; \
dnf --showduplicate list intel-igc-opencl-devel intel-gmmlib-devel; \
dnf install -y intel-igc-opencl-devel intel-gmmlib-devel; \
mkdir /root/build; cd /root/build ; cmake -G Ninja ../neo; \
mkdir /root/build; cd /root/build ; cmake -G Ninja \
-DDO_NOT_RUN_AUB_TESTS=1 -DDONT_CARE_OF_VIRTUALS=1 ../neo; \
ninja -j `nproc`
CMD ["/bin/bash"]

0 comments on commit be82985

Please sign in to comment.