-
-
Notifications
You must be signed in to change notification settings - Fork 13.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bintools-wrapper: skip dynamic linker for static binaries #106908
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ if [ -z "${NIX_BINTOOLS_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then | |
source @out@/nix-support/add-flags.sh | ||
fi | ||
|
||
setDynamicLinker=1 | ||
|
||
# Optionally filter out paths not refering to the store. | ||
expandResponseParams "$@" | ||
|
@@ -47,6 +48,11 @@ if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}" | |
# Our ld is not built with sysroot support (Can we fix that?) | ||
: | ||
else | ||
if [[ "$p" = -static || "$p" = -static-pie ]]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few other flags from the man page like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting. Do they have the same semantic. |
||
# Using a dynamic linker for static binaries can lead to crashes. | ||
# This was observed for rust binaries. | ||
setDynamicLinker=0 | ||
fi | ||
rest+=("$p") | ||
fi | ||
n+=1 | ||
|
@@ -63,6 +69,11 @@ extraBefore=(${hardeningLDFlags[@]+"${hardeningLDFlags[@]}"}) | |
if [ -z "${NIX_LDFLAGS_SET_@suffixSalt@:-}" ]; then | ||
extraAfter+=($NIX_LDFLAGS_@suffixSalt@) | ||
extraBefore+=($NIX_LDFLAGS_BEFORE_@suffixSalt@) | ||
# By adding dynamic linker to extraBefore we allow the users set their | ||
# own dynamic linker as NIX_LD_FLAGS will override earlier set flags | ||
if [ "$setDynamicLinker" = 1 ]; then | ||
extraBefore+=("-dynamic-linker" "$NIX_DYNAMIC_LINKER_@suffixSalt@") | ||
fi | ||
fi | ||
|
||
extraAfter+=($NIX_LDFLAGS_AFTER_@suffixSalt@) | ||
|
@@ -134,7 +145,7 @@ then | |
done | ||
fi | ||
|
||
if [ -e "@out@/nix-support/dynamic-linker-m32" ] && (( "$link32" )); then | ||
if [[ "$link32" = "0" && "$setDynamicLinker" = 1 && -e "@out@/nix-support/dynamic-linker-m32" ]]; then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As pointed out in #107253, |
||
# We have an alternate 32-bit linker and we're producing a 32-bit ELF, let's | ||
# use it. | ||
extraAfter+=( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
{ stdenv }: | ||
{ stdenv, glibc }: | ||
with stdenv.lib; | ||
let | ||
# Sanitizers are not supported on Darwin. | ||
# Sanitizer headers aren't available in older libc++ stdenvs due to a bug | ||
sanitizersWorking = | ||
(stdenv.cc.isClang && versionAtLeast (getVersion stdenv.cc.name) "5.0.0") | ||
|| (stdenv.cc.isGNU && stdenv.isLinux); | ||
sanitizersWorking = !stdenv.hostPlatform.isMusl && ( | ||
(stdenv.cc.isClang && versionAtLeast (getVersion stdenv.cc.name) "5.0.0") | ||
|| (stdenv.cc.isGNU && stdenv.isLinux) | ||
); | ||
staticLibc = optionalString (stdenv.hostPlatform.libc == "glibc") "-L ${glibc.static}/lib"; | ||
in stdenv.mkDerivation { | ||
name = "cc-wrapper-test"; | ||
|
||
|
@@ -28,6 +30,16 @@ in stdenv.mkDerivation { | |
./core-foundation-check | ||
''} | ||
|
||
printf "checking whether compiler builds valid static C binaries... " >&2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @LnL7 do I need to disable this on darwin? |
||
$CC ${staticLibc} -static -o cc-static ${./cc-main.c} | ||
./cc-static | ||
# our glibc does not have pie enabled yet. | ||
${optionalString (stdenv.hostPlatform.isMusl && stdenv.cc.isGNU) '' | ||
printf "checking whether compiler builds valid static pie C binaries... " >&2 | ||
$CC ${staticLibc} -static-pie -o cc-static-pie ${./cc-main.c} | ||
./cc-static-pie | ||
''} | ||
|
||
printf "checking whether compiler uses NIX_CFLAGS_COMPILE... " >&2 | ||
mkdir -p foo/include | ||
cp ${./foo.c} foo/include/foo.h | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also allows users to specify their own link loader.