diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2019-08-23 17:03:01 +0200 |
---|---|---|
committer | 이형주/Common Platform Lab(SR)/Staff Engineer/삼성전자 <leee.lee@samsung.com> | 2020-04-16 07:36:05 +0900 |
commit | 4feb5cbcbeea277f7addb372b3c632e89f9ed1ae (patch) | |
tree | 1fa7f1dc31867a3872c7df4b46b970150da3f299 /configurecompiler.cmake | |
parent | 9df87a133b0f29f4932f38b7307c87d09ab80d5d (diff) | |
download | coreclr-4feb5cbcbeea277f7addb372b3c632e89f9ed1ae.tar.gz coreclr-4feb5cbcbeea277f7addb372b3c632e89f9ed1ae.tar.bz2 coreclr-4feb5cbcbeea277f7addb372b3c632e89f9ed1ae.zip |
Fix PIE options (#26323)submit/tizen/20200415.223728accepted/tizen/unified/20200416.080052
* Fix PIE options
We were missing passing the -pie linker option. That means that while we
were compiling our code as position independent, the executables
(not shared libraries) were not marked as position independent and
ASLR was not applied to them. They were always loaded to fixed addresses.
This change adds the missing -pie option and also replaces all the individual
settings of -fPIE / -fPIC on the targets we build by a centralized setting
of CMAKE_POSITION_INDEPENDENT_CODE variable that causes cmake to add the
appropriate compiler options everywhere.
* Fix native parts of coreclr tests build
The native parts of the tests are not built using the root CMakeLists.txt
so I am moving enabling the position independent code to configurecompiler.cmake
Change-Id: Ieafff8984ec23e5fdb00fb0c2fb017e53afbce88
Diffstat (limited to 'configurecompiler.cmake')
-rw-r--r-- | configurecompiler.cmake | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/configurecompiler.cmake b/configurecompiler.cmake index 2d995d6416..5d5925c8bf 100644 --- a/configurecompiler.cmake +++ b/configurecompiler.cmake @@ -6,6 +6,9 @@ set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +# All code we build should be compiled as position independent +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + set(CLR_DEFINES_DEBUG_INIT DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1) set(CLR_DEFINES_CHECKED_INIT DEBUG _DEBUG _DBG URTBLDENV_FRIENDLY=Checked BUILDENV_CHECKED=1) set(CLR_DEFINES_RELEASE_INIT NDEBUG URTBLDENV_FRIENDLY=Retail) @@ -333,10 +336,9 @@ elseif (CLR_CMAKE_PLATFORM_UNIX) endif () # -fdata-sections -ffunction-sections: each function has own section instead of one per .o file (needed for --gc-sections) - # -fPIC: enable Position Independent Code normally just for shared libraries but required when linking with address sanitizer # -O1: optimization level used instead of -O0 to avoid compile error "invalid operand for inline asm constraint" - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -fPIC -O1") - set(CMAKE_CXX_FLAGS_CHECKED "${CMAKE_CXX_FLAGS_CHECKED} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -fPIC -O1") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -O1") + set(CMAKE_CXX_FLAGS_CHECKED "${CMAKE_CXX_FLAGS_CHECKED} ${CLR_SANITIZE_CXX_FLAGS} -fdata-sections -ffunction-sections -O1") set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CLR_SANITIZE_LINK_FLAGS}") set(CMAKE_EXE_LINKER_FLAGS_CHECKED "${CMAKE_EXE_LINKER_FLAGS_CHECKED} ${CLR_SANITIZE_LINK_FLAGS}") @@ -346,6 +348,11 @@ elseif (CLR_CMAKE_PLATFORM_UNIX) set(CMAKE_SHARED_LINKER_FLAGS_CHECKED "${CMAKE_SHARED_LINKER_FLAGS_CHECKED} ${CLR_SANITIZE_LINK_FLAGS} -Wl,--gc-sections") endif () endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL DEBUG OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL CHECKED) + + # This linker option causes executables we build to be marked as containing position independent code. + # It is necessary to make ASLR work for executables. + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie" ) + endif(WIN32) # CLR_ADDITIONAL_LINKER_FLAGS - used for passing additional arguments to linker |