Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Fix PIE options #26323

Merged
merged 2 commits into from
Aug 23, 2019
Merged

Fix PIE options #26323

merged 2 commits into from
Aug 23, 2019

Conversation

janvorli
Copy link
Member

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.

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.
@janvorli janvorli added this to the 5.0 milestone Aug 22, 2019
@janvorli janvorli requested a review from jkoritzinsky August 22, 2019 20:14
@janvorli janvorli self-assigned this Aug 22, 2019
@janvorli
Copy link
Member Author

cc: @jkotas

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@janvorli
Copy link
Member Author

Hmm, building the native parts of coreclr tests fail, I'm taking a look:

/usr/bin/ld: ../../Common/Platform/libplatformdefines.a(platformdefines.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output

@jkoritzinsky
Copy link
Member

jkoritzinsky commented Aug 22, 2019

The native test build doesn't use the root CMakeLists.txt. Maybe we want to move the set(CMAKE_POSITION_INDEPENDENT_CODE 1) statement into the start of configurecompiler.cmake?

@janvorli
Copy link
Member Author

Ah, I've though it does use it, as it conditionally includes the tests folder. That explains the problem then. @jkoritzinsky your suggestion makes sense, I'll move it there.

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
@janvorli janvorli closed this Aug 23, 2019
@janvorli janvorli reopened this Aug 23, 2019
@jkotas jkotas merged commit f7205db into dotnet:master Aug 23, 2019
@janvorli janvorli deleted the fix-pie branch August 26, 2019 17:36
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* 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


Commit migrated from dotnet/coreclr@f7205db
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants