summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorDanny Wilson <danny@prime.vc>2013-02-23 13:59:59 +0000
committerDanny Wilson <danny@onlinetouch.nl>2013-02-28 20:04:02 +0100
commit15e865ac09c93093c9cada2f247b14dba084c71a (patch)
tree352ed3af8ac0f5234e03be2d35c75899afa422a6 /pkgs/build-support
parentbcaea92a1217f6adb79bdb400f2bfffef97955ed (diff)
downloadnixpkgs-15e865ac09c93093c9cada2f247b14dba084c71a.tar
nixpkgs-15e865ac09c93093c9cada2f247b14dba084c71a.tar.gz
nixpkgs-15e865ac09c93093c9cada2f247b14dba084c71a.tar.bz2
nixpkgs-15e865ac09c93093c9cada2f247b14dba084c71a.tar.lz
nixpkgs-15e865ac09c93093c9cada2f247b14dba084c71a.tar.xz
nixpkgs-15e865ac09c93093c9cada2f247b14dba084c71a.tar.zst
nixpkgs-15e865ac09c93093c9cada2f247b14dba084c71a.zip
GCC 4.7.2 + updated libraries compiles on Illumos/SmartOS!
- Add solaris native ld support to GCC build wrapper
- Add solaris ld wrapper that fixes -L argument order
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/gcc-wrapper/builder.sh21
-rw-r--r--pkgs/build-support/gcc-wrapper/default.nix1
-rw-r--r--pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh40
3 files changed, 60 insertions, 2 deletions
diff --git a/pkgs/build-support/gcc-wrapper/builder.sh b/pkgs/build-support/gcc-wrapper/builder.sh
index ed7ad0a50b7..e7c3400e9f7 100644
--- a/pkgs/build-support/gcc-wrapper/builder.sh
+++ b/pkgs/build-support/gcc-wrapper/builder.sh
@@ -66,13 +66,23 @@ else
     echo "$gccCFlags" > $out/nix-support/gcc-cflags
     
     gccPath="$gcc/bin"
-    ldPath="$binutils/bin"
+    # On Illumos/Solaris we might prefer native ld
+    if test -n "$nativePrefix"; then
+      ldPath="$nativePrefix/bin"
+    else
+      ldPath="$binutils/bin"
+    fi;
 fi
 
 
 doSubstitute() {
     local src=$1
     local dst=$2
+    local ld="$ldPath/ld"
+    if $ld -V 2>&1 |grep Solaris; then
+      # Use Solaris specific linker wrapper
+      ld="$out/bin/ld-solaris"
+    fi
     # Can't use substitute() here, because replace may not have been
     # built yet (in the bootstrap).
     sed \
@@ -85,7 +95,7 @@ doSubstitute() {
         -e "s^@binutils@^$binutils^g" \
         -e "s^@coreutils@^$coreutils^g" \
         -e "s^@libc@^$libc^g" \
-        -e "s^@ld@^$ldPath/ld^g" \
+        -e "s^@ld@^$ld^g" \
         < "$src" > "$dst" 
 }
 
@@ -174,6 +184,13 @@ ln -s $ldPath/as $out/bin/as
 doSubstitute "$ldWrapper" "$out/bin/ld"
 chmod +x "$out/bin/ld"
 
+# Copy solaris ld wrapper if needed
+if $ldPath/ld -V 2>&1 |grep Solaris; then
+  # Use Solaris specific linker wrapper
+  sed -e "s^@ld@^$ldPath/ld^g" < "$ldSolarisWrapper" > "$out/bin/ld-solaris"
+  chmod +x "$out/bin/ld-solaris"
+fi
+
 
 # Emit a setup hook.  Also store the path to the original GCC and
 # Glibc.
diff --git a/pkgs/build-support/gcc-wrapper/default.nix b/pkgs/build-support/gcc-wrapper/default.nix
index 87617621e64..aa4f6a3944e 100644
--- a/pkgs/build-support/gcc-wrapper/default.nix
+++ b/pkgs/build-support/gcc-wrapper/default.nix
@@ -36,6 +36,7 @@ stdenv.mkDerivation {
   gnatWrapper = ./gnat-wrapper.sh;
   gnatlinkWrapper = ./gnatlink-wrapper.sh;
   ldWrapper = ./ld-wrapper.sh;
+  ldSolarisWrapper = ./ld-solaris-wrapper.sh;
   utils = ./utils.sh;
   addFlags = ./add-flags;
   
diff --git a/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh b/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh
new file mode 100644
index 00000000000..5a7b92b5ad7
--- /dev/null
+++ b/pkgs/build-support/gcc-wrapper/ld-solaris-wrapper.sh
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+set -e
+set -u
+
+# I've also tried adding -z direct and -z lazyload, but it gave too many problems with C++ exceptions :'(
+# Also made sure libgcc would not be lazy-loaded, as suggested here: https://www.illumos.org/issues/2534#note-3
+#   but still no success.
+cmd="@ld@ -z ignore"
+
+args=("$@");
+
+# This loop makes sure all -L arguments are before -l arguments, or ld may complain it cannot find a library.
+# GNU binutils does not have this problem:
+#   http://stackoverflow.com/questions/5817269/does-the-order-of-l-and-l-options-in-the-gnu-linker-matter
+i=0;
+while [[ $i -lt $# ]]; do
+    case "${args[$i]}" in
+        -L)  cmd="$cmd ${args[$i]} ${args[($i+1)]}"; i=($i+1); ;;
+        -L*) cmd="$cmd ${args[$i]}" ;;
+        *)   ;;
+    esac
+    i=($i+1);
+done
+
+i=0;
+while [[ $i -lt $# ]]; do
+    case "${args[$i]}" in
+        -L)  i=($i+1); ;;
+        -L*) ;;
+        *)   cmd="$cmd ${args[$i]}" ;;
+    esac
+    i=($i+1);
+done
+
+# Trace:
+set -x
+exec $cmd
+
+exit 0