Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UR] Always enable pie for gcc #17567

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions unified-runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Copyright (C) 2022-2023 Intel Corporation
# Copyright (C) 2022-2025 Intel Corporation
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR)
project(unified-runtime VERSION 0.12.0)
cmake_policy(SET CMP0083 NEW) # PROPERTY POSITION_INDEPENDENT_CODE

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

# Ubuntu's gcc uses --enable-default-pie. For the sake of a consistent build
# across different gcc versions, set it globally for all targets
# https://wiki.ubuntu.com/ToolChain/CompilerFlags#A-fPIE
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

include(GNUInstallDirs)
include(CheckCXXSourceCompiles)
include(CMakePackageConfigHelpers)
@@ -151,9 +159,6 @@ if(UR_ENABLE_TRACING)

FetchContent_MakeAvailable(xpti)

# set -fPIC for xpti since we are linking it with a shared library
set_target_properties(xpti PROPERTIES POSITION_INDEPENDENT_CODE ON)

# fetch the xptifw dispatcher, mostly used for testing
# these variables need to be set for xptifw to compile
set(XPTI_SOURCE_DIR ${xpti_SOURCE_DIR})
11 changes: 1 addition & 10 deletions unified-runtime/cmake/helpers.cmake
Original file line number Diff line number Diff line change
@@ -99,7 +99,6 @@ function(add_ur_target_compile_options name)
-Wunused-parameter

# Hardening options
-fPIC
-fstack-protector-strong
-fvisibility=hidden

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

function(add_ur_target_exec_options name)
if(NOT MSVC)
if(NOT APPLE)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_link_options(${name} PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-pie>
)
endif()
endif()
elseif(MSVC)
if(MSVC)
target_link_options(${name} PRIVATE
LINKER:/ALLOWISOLATION
)