Use CMAKE_POSITION_INDEPENDENT_CODE=ON instead of -fPIE or -pie #2125
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Followup to #2097, which seems to have somehow broken the hardened-compile task:
My rough understanding of what is happening here is that the explicit
-pie
linker flag ("position-independent executable") being passed viaLDFLAGS
was being applied to shared library targets, which is incorrect (not an executable). It's not clear to me which part of #2097 is responsible for exposing this issue (newer CMake version? use of Ninja?). Nevertheless, this PR proposes avoiding the explicit compiler or linker flags by using the CMake CMAKE_POSITION_INDEPENDENT_CODE variable instead, allowing CMake to apply the appropriate flags according to each target.The only remaining instance of
-fPIE
in the repo is:mongo-c-driver/src/libmongoc/tests/test-mongoc-handshake.c
Line 390 in cfbcdb4
There are no more instances of the
-pie
flag. There are several instances of explicit-fPIC
flags, but replacing these withPOSITION_INDEPENDENT_CODE
(target property) is deferred to another time (not essential to the goal of this PR).