From f5074933b7280ce32e1a756e6468a5321cb885de Mon Sep 17 00:00:00 2001 From: Matthew Bauer Date: Thu, 15 Jul 2021 20:08:33 -0500 Subject: [PATCH] bintools: disable -pie when -r or -Ur are used (#128674) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- pkgs/build-support/bintools-wrapper/add-hardening.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkgs/build-support/bintools-wrapper/add-hardening.sh b/pkgs/build-support/bintools-wrapper/add-hardening.sh index 5e49b7bd905..4d289a334b7 100644 --- a/pkgs/build-support/bintools-wrapper/add-hardening.sh +++ b/pkgs/build-support/bintools-wrapper/add-hardening.sh @@ -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