From 04b92be60de34ea70ad877d5260bed3e4ed8a48f Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Tue, 15 Jul 2025 16:27:04 +0200 Subject: [PATCH 1/2] [SYCL][CMake] Properly enable `-pie` hardening flag We rely on CMake to set the right set of compliation and link flags to enable positition independent code and position independent execution. Before this commit, necessary compliation flags were applied just fine, but link flags were missing. To get link flags, some extra CMake functions should be called. --- llvm/cmake/modules/AddSecurityFlags.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/cmake/modules/AddSecurityFlags.cmake b/llvm/cmake/modules/AddSecurityFlags.cmake index ca8c03a3dbf94..765270ae9bfcc 100644 --- a/llvm/cmake/modules/AddSecurityFlags.cmake +++ b/llvm/cmake/modules/AddSecurityFlags.cmake @@ -135,6 +135,9 @@ macro(append_common_extra_security_flags) # explicitly requested if (NOT CMAKE_POSITION_INDEPENDENT_CODE) message(FATAL_ERROR "To enable all necessary security flags, CMAKE_POSITION_INDEPENDENT_CODE must be set to ON") + else() + include(CheckPIESupported) + check_pie_supported() endif() if(is_msvc) From 2a4318cfc0a71456d6e81702188458a118d56665 Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Tue, 15 Jul 2025 18:56:50 +0200 Subject: [PATCH 2/2] Apply comments --- llvm/cmake/modules/AddSecurityFlags.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/cmake/modules/AddSecurityFlags.cmake b/llvm/cmake/modules/AddSecurityFlags.cmake index 765270ae9bfcc..5edbf4ee47e6e 100644 --- a/llvm/cmake/modules/AddSecurityFlags.cmake +++ b/llvm/cmake/modules/AddSecurityFlags.cmake @@ -133,11 +133,11 @@ macro(append_common_extra_security_flags) # Position Independent Execution # We rely on CMake to set the right -fPIE flags for us, but it must be # explicitly requested - if (NOT CMAKE_POSITION_INDEPENDENT_CODE) - message(FATAL_ERROR "To enable all necessary security flags, CMAKE_POSITION_INDEPENDENT_CODE must be set to ON") - else() + if (CMAKE_POSITION_INDEPENDENT_CODE) include(CheckPIESupported) check_pie_supported() + else() + message(FATAL_ERROR "To enable all necessary security flags, CMAKE_POSITION_INDEPENDENT_CODE must be set to ON") endif() if(is_msvc)