Skip to content

Commit 42c6ffc

Browse files
[SYCL][CMAKE] Refactor -fPIE handling (#19235)
CMake is capable of setting `-fPIE` correctly and we don't need to intervene with that. Without the patch, I see the following errors: ``` FAILED: lib/libze_trace_collector.so : && /usr/bin/clang++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite -strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wextra -fcf-protection=full -Wformat -Wformat-security -fPIC -fPIE -Wno-covered-switch-default -Wall -Wextra -Werror -O2 -g -DNDEBUG -Wl,-z,defs -Wl,-z,nodelete -pie -shared -Wl,-soname,libze_ trace_collector.so -o lib/libze_trace_collector.so tools/sycl/tools/sycl-trace/CMakeFiles/ze_trace_collector.dir/ze_trace_collector.cpp.o -Wl,-rpath,build/lib: lib/libxptifw.so -ldl && : clang++: error: argument unused during compilation: '-pie' [-Werror,-Wunused-command-line-argument] ```
1 parent 9c90cad commit 42c6ffc

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

llvm/cmake/modules/AddSecurityFlags.cmake

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,13 @@ macro(append_common_extra_security_flags)
131131
endif()
132132

133133
# Position Independent Execution
134-
if(is_gcc
135-
OR is_clang
136-
OR (is_icpx AND MSVC))
137-
# The project should be configured with -DCMAKE_POSITION_INDEPENDENT_CODE=ON
138-
add_compile_option_ext("-fPIE" FPIE)
139-
add_link_option_ext("-pie" PIE CMAKE_EXE_LINKER_FLAGS
140-
CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
141-
elseif(is_msvc)
134+
# We rely on CMake to set the right -fPIE flags for us, but it must be
135+
# explicitly requested
136+
if (NOT CMAKE_POSITION_INDEPENDENT_CODE)
137+
message(FATAL_ERROR "To enable all necessary security flags, CMAKE_POSITION_INDEPENDENT_CODE must be set to ON")
138+
endif()
139+
140+
if(is_msvc)
142141
add_link_option_ext("/DYNAMICBASE" DYNAMICBASE CMAKE_EXE_LINKER_FLAGS
143142
CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
144143
endif()

0 commit comments

Comments
 (0)