From be82985f1271a8a3c7bde1179a7c883987c6f4cc Mon Sep 17 00:00:00 2001 From: Jacek Danecki Date: Fri, 12 Apr 2019 16:09:54 +0200 Subject: [PATCH] Spectre mitigation for gcc and clang Resolves: NEO-3038 https://github.com/intel/compute-runtime/pull/159 Change-Id: If464949242afa6fbca85a0533eb874f276164646 Signed-off-by: Jacek Danecki --- CMakeLists.txt | 32 +++++++++++++++++-- .../docker/Dockerfile-fedora-28-copr-gcc-8 | 3 +- .../docker/Dockerfile-fedora-29-copr-gcc-8 | 3 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de092ee184f7e..cf155613f374e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -540,8 +540,8 @@ 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) @@ -549,7 +549,35 @@ if(MSVC) 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) diff --git a/scripts/docker/Dockerfile-fedora-28-copr-gcc-8 b/scripts/docker/Dockerfile-fedora-28-copr-gcc-8 index b6faa5b4ef19d..d2f49424cf080 100644 --- a/scripts/docker/Dockerfile-fedora-28-copr-gcc-8 +++ b/scripts/docker/Dockerfile-fedora-28-copr-gcc-8 @@ -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"] diff --git a/scripts/docker/Dockerfile-fedora-29-copr-gcc-8 b/scripts/docker/Dockerfile-fedora-29-copr-gcc-8 index 3190beba84ce8..d441d856cdd4b 100644 --- a/scripts/docker/Dockerfile-fedora-29-copr-gcc-8 +++ b/scripts/docker/Dockerfile-fedora-29-copr-gcc-8 @@ -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"]