bintools: disable -pie when -r or -Ur are used (#128674)

* bintools: disable -pie when -r or -Ur are used

ld’s -r allows you to partially link object files. When -pie is passed with -r, though, we get:

  ld: -r and -pie may not be used together

Most build systems are intelligent enough to pass -no-pie before -r, but we might as well support those that
don’t.

Note: -pie is not enabled by default in Nixpkgs, but it is when you are using musl. So this solution is really
only useful for musl toolchains.

* bintools-wrapper: Add incremental -i check for pie
This commit is contained in:
Matthew Bauer 2021-07-15 20:08:33 -05:00 committed by GitHub
parent ed4094a728
commit f5074933b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -37,7 +37,7 @@ fi
for flag in "${!hardeningEnableMap[@]}"; do
case $flag in
pie)
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static " || "$*" =~ " -r " || "$*" =~ " -Ur " || "$*" =~ " -i ") ]]; then
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling LDFlags -pie >&2; fi
hardeningLDFlags+=('-pie')
fi