Skip to content

Commit b659fd9

Browse files
authored
[UR] Always enable pie for gcc (#17567)
Ubuntu's GCC enables pie by default and it turns out we can't build with it disabled. Just force it to be enabled for now.
1 parent 19f3039 commit b659fd9

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

unified-runtime/CMakeLists.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
# Copyright (C) 2022-2023 Intel Corporation
1+
# Copyright (C) 2022-2025 Intel Corporation
22
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

66
cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR)
77
project(unified-runtime VERSION 0.12.0)
8+
cmake_policy(SET CMP0083 NEW) # PROPERTY POSITION_INDEPENDENT_CODE
89

910
# Check if unified runtime is built as a standalone project.
1011
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR UR_STANDALONE_BUILD)
1112
set(UR_STANDALONE_BUILD TRUE)
1213
endif()
1314

15+
# Ubuntu's gcc uses --enable-default-pie. For the sake of a consistent build
16+
# across different gcc versions, set it globally for all targets
17+
# https://wiki.ubuntu.com/ToolChain/CompilerFlags#A-fPIE
18+
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
19+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
20+
endif()
21+
1422
include(GNUInstallDirs)
1523
include(CheckCXXSourceCompiles)
1624
include(CMakePackageConfigHelpers)
@@ -151,9 +159,6 @@ if(UR_ENABLE_TRACING)
151159

152160
FetchContent_MakeAvailable(xpti)
153161

154-
# set -fPIC for xpti since we are linking it with a shared library
155-
set_target_properties(xpti PROPERTIES POSITION_INDEPENDENT_CODE ON)
156-
157162
# fetch the xptifw dispatcher, mostly used for testing
158163
# these variables need to be set for xptifw to compile
159164
set(XPTI_SOURCE_DIR ${xpti_SOURCE_DIR})

unified-runtime/cmake/helpers.cmake

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ function(add_ur_target_compile_options name)
9999
-Wunused-parameter
100100

101101
# Hardening options
102-
-fPIC
103102
-fstack-protector-strong
104103
-fvisibility=hidden
105104

@@ -172,15 +171,7 @@ function(add_ur_target_link_options name)
172171
endfunction()
173172

174173
function(add_ur_target_exec_options name)
175-
if(NOT MSVC)
176-
if(NOT APPLE)
177-
if(CMAKE_BUILD_TYPE STREQUAL "Release")
178-
target_link_options(${name} PRIVATE
179-
$<$<CXX_COMPILER_ID:GNU>:-pie>
180-
)
181-
endif()
182-
endif()
183-
elseif(MSVC)
174+
if(MSVC)
184175
target_link_options(${name} PRIVATE
185176
LINKER:/ALLOWISOLATION
186177
)

0 commit comments

Comments
 (0)