about summary refs log tree commit diff
path: root/pkgs/test/cc-wrapper
diff options
context:
space:
mode:
authorJörg Thalheim <joerg@thalheim.io>2020-12-14 07:59:40 +0100
committerJörg Thalheim <joerg@thalheim.io>2020-12-14 15:42:54 +0000
commitccfd26ef14ea213320f0b49db3fb347785b38f06 (patch)
tree94e91db070206c2efa5867f02b3a5f66ee6564ed /pkgs/test/cc-wrapper
parentc2842e5ad427876e2f023ef41ea3500dce630e04 (diff)
bintools-wrapper: skip dynamic linker for static binaries
Currently we set dynamic-linker unconditionally. This breaks
however some static binaries i.e. rust binaries linked against musl.
There is no reason we should set an elf interpreter for static binaries
hence this is skipped if `-static` or `-static-pie` is either passed to
our cc or ld wrapper.
Diffstat (limited to 'pkgs/test/cc-wrapper')
-rw-r--r--pkgs/test/cc-wrapper/default.nix20
1 files changed, 16 insertions, 4 deletions
diff --git a/pkgs/test/cc-wrapper/default.nix b/pkgs/test/cc-wrapper/default.nix
index c0c89d63ffff0..141a5320ef531 100644
--- a/pkgs/test/cc-wrapper/default.nix
+++ b/pkgs/test/cc-wrapper/default.nix
@@ -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
+    $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