summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2017-07-21 13:29:47 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2017-07-31 17:02:56 -0400
commit9242c8b331a3571debb04b6485b0783386371838 (patch)
tree8f98355b12e1fe08395e2581b5441bd8272d59ef /pkgs/build-support
parent0c37778c2c17fb40407f6432ff009cd7ae5b17b1 (diff)
downloadnixlib-9242c8b331a3571debb04b6485b0783386371838.tar
nixlib-9242c8b331a3571debb04b6485b0783386371838.tar.gz
nixlib-9242c8b331a3571debb04b6485b0783386371838.tar.bz2
nixlib-9242c8b331a3571debb04b6485b0783386371838.tar.lz
nixlib-9242c8b331a3571debb04b6485b0783386371838.tar.xz
nixlib-9242c8b331a3571debb04b6485b0783386371838.tar.zst
nixlib-9242c8b331a3571debb04b6485b0783386371838.zip
cc-wrapper: Use two scripts instead of patch
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/cc-wrapper/default.nix22
-rw-r--r--pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash95
-rw-r--r--pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.patch140
3 files changed, 103 insertions, 154 deletions
diff --git a/pkgs/build-support/cc-wrapper/default.nix b/pkgs/build-support/cc-wrapper/default.nix
index c178204f9fb5..371db540b0ab 100644
--- a/pkgs/build-support/cc-wrapper/default.nix
+++ b/pkgs/build-support/cc-wrapper/default.nix
@@ -296,20 +296,14 @@ stdenv.mkDerivation {
         ln -s $ldPath/${prefix}as $out/bin/${prefix}as
       fi
 
-      wrap ${prefix}ld ${if !useMacosReexportHack
-      then preWrap ./ld-wrapper.sh
-      else stdenv.mkDerivation {
-        name = "patched-ld-wrapper-src";
-        patches = [ ./macos-sierra-reexport-hack.patch ];
-        unpackPhase = ''
-          src=$PWD
-          cp ${./ld-wrapper.sh} ld-wrapper.sh
-        '';
-        buildPhase = "";
-        installPhase = ''
-          cp ld-wrapper.sh $out
-        '';
-      }} ''${ld:-$ldPath/${prefix}ld}
+    '' + (if !useMacosReexportHack then ''
+      wrap ${prefix}ld ${./ld-wrapper.sh} ''${ld:-$ldPath/${prefix}ld}
+    '' else ''
+      export ldWrapper="$out/bin/${prefix}ld" innerLd="${prefix}ld-reexport-delegate"
+      wrap "$innerLd" ${./macos-sierra-reexport-hack.bash} ''${ld:-$ldPath/${prefix}ld}
+      wrap "${prefix}ld" ${./ld-wrapper.sh} "$out/bin/$innerLd"
+      unset ldWrapper
+    '') + ''
 
       if [ -e ${binutils_bin}/bin/${prefix}ld.gold ]; then
         wrap ${prefix}ld.gold ${preWrap ./ld-wrapper.sh} ${binutils_bin}/bin/${prefix}ld.gold
diff --git a/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash b/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash
new file mode 100644
index 000000000000..548be0c4dd45
--- /dev/null
+++ b/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.bash
@@ -0,0 +1,95 @@
+#! @shell@
+
+set -eu -o pipefail
+
+path_backup="$PATH"
+if [ -n "@coreutils_bin@" ]; then
+  PATH="@coreutils_bin@/bin"
+fi
+
+declare -r recurThreshold=300
+
+declare overflowCount=0
+for ((n=0; n < $#; ++n)); do
+    case "${!n}" in
+        -l*) let overflowCount+=1 ;;
+        -reexport-l*) let overflowCount+=1 ;;
+        *) ;;
+    esac
+done
+
+declare -a allArgs=()
+
+if (( "$overflowCount" <= "$recurThreshold" )); then
+    allArgs=("$@")
+else
+    declare -a childrenLookup=() childrenLink=()
+
+    while (( $# )); do
+        case "$1" in
+            -L/*)
+                childrenLookup+=("$1")
+                allArgs+=("$1")
+                ;;
+            -L)
+                echo "cctools LD does not support '-L foo' or '-l foo'" >&2
+                exit 1
+                ;;
+            -l)
+                echo "cctools LD does not support '-L foo' or '-l foo'" >&2
+                exit 1
+                ;;
+            -lto_library)  allArgs+=("$1") ;;
+                # We aren't linking any "to_library"
+            -lSystem)      allArgs+=("$1") ;;
+                # Special case as indirection seems like a bad idea for something
+                # so fundamental. Can be removed for simplicity.
+            -l?*)          childrenLink+=("$1") ;;
+            -reexport-l?*) childrenLink+=("$1") ;;
+            *)             allArgs+=("$1") ;;
+        esac
+
+        shift
+    done
+
+    declare n=0
+    while (( $n < "${#childrenLink[@]}" )); do
+        if [[ "${childrenLink[n]}" = -l* ]]; then
+            childrenLink[n]="-reexport${childrenLink[n]}"
+        fi
+        let ++n
+    done
+    unset n
+
+    declare -r outputNameLibless=$(basename $( \
+        if [[ -z "${outputName:+isUndefined}" ]]; then
+            echo unnamed
+        elif [[ "${outputName:0:3}" = lib ]]; then
+            echo "${outputName:3}"
+        else
+            echo "${outputName}"
+        fi))
+    declare -ra children=("$outputNameLibless-reexport-delegate-0" \
+                          "$outputNameLibless-reexport-delegate-1")
+
+    mkdir -p "$out/lib"
+
+    # first half of libs
+    @ldWrapper@ -macosx_version_min 10.10 -arch x86_64 -dylib \
+      -o "$out/lib/lib${children[0]}.dylib" \
+      -install_name "$out/lib/lib${children[0]}.dylib" \
+      "${childrenLookup[@]}" \
+      "${childrenLink[@]:0:$((${#childrenLink[@]} / 2 ))}"
+
+    # second half of libs
+    @ldWrapper@ -macosx_version_min 10.10 -arch x86_64 -dylib \
+      -o "$out/lib/lib${children[1]}.dylib" \
+      -install_name "$out/lib/lib${children[1]}.dylib" \
+      "${childrenLookup[@]}" \
+      "${childrenLink[@]:$((${#childrenLink[@]} / 2 ))}"
+
+    allArgs+=("-L$out/lib" "-l${children[0]}" "-l${children[1]}")
+fi
+
+PATH="$path_backup"
+exec @prog@ "${allArgs[@]}"
diff --git a/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.patch b/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.patch
deleted file mode 100644
index 031c5640f541..000000000000
--- a/pkgs/build-support/cc-wrapper/macos-sierra-reexport-hack.patch
+++ /dev/null
@@ -1,140 +0,0 @@
---- a/ld-wrapper.sh
-+++ b/ld-wrapper.sh
-@@ -101,35 +101,115 @@ if [ "$NIX_DONT_SET_RPATH" != 1 ]; then
-     rpath=""
- 
-     # First, find all -L... switches.
--    allParams=("${params[@]}" ${extra[@]})
-+    declare -ar allParams=("${extraBefore[@]}" "${params[@]}" "${extra[@]}")
-+    declare -a allParamsPost=() childrenLookup=() childrenLink=()
-+
-+    declare -r recurThreshold=300
-+
-+    declare overflowCount=0
-+    for p in "${allParams[@]}"; do
-+        case "$p" in
-+            -o)
-+                declare -r outputName="$p2"
-+                ;;
-+            (-l*)
-+                let overflowCount+=1
-+                ;;
-+            *) ;;
-+        esac
-+    done
-+
-+    if (( "$overflowCount" > "$recurThreshold" )); then
-+       declare -r linkIndirect="1"
-+    else
-+       declare -r linkIndirect=""
-+    fi
-+
-+    function append_Ls() {
-+        if [[ -n "$linkIndirect" ]]; then
-+            childrenLookup+=("$@")
-+        fi
-+        allParamsPost+=("$@")
-+    }
-+
-+    function append_ls() {
-+        local p
-+        if (( $# == 2 )); then p="$2"; else p="${1:2}"; fi
-+        if [[ -n "$linkIndirect" && "$p" != "-lto_library" && "$p" != "-lSystem" ]]; then
-+            childrenLink+=("$@")
-+        else
-+            allParamsPost+=("$@")
-+        fi
-+    }
-+
-     n=0
-     while [ $n -lt ${#allParams[*]} ]; do
-         p=${allParams[n]}
-         p2=${allParams[$((n+1))]}
-+
-         if [ "${p:0:3}" = -L/ ]; then
-             addToLibPath ${p:2}
-+            append_Ls "$p"
-         elif [ "$p" = -L ]; then
-             addToLibPath ${p2}
-+            append_Ls "$p" "$p2"
-             n=$((n + 1))
-         elif [ "$p" = -l ]; then
-             addToLibs ${p2}
-+            append_ls "$p" "$p2"
-             n=$((n + 1))
-         elif [ "${p:0:2}" = -l ]; then
-             addToLibs ${p:2}
-+            append_ls "$p"
-         elif [ "$p" = -dynamic-linker ]; then
-             # Ignore the dynamic linker argument, or it
-             # will get into the next 'elif'. We don't want
-             # the dynamic linker path rpath to go always first.
-+            allParamsPost+=("$p" "$p2")
-             n=$((n + 1))
-         elif [[ "$p" =~ ^[^-].*\.so($|\.) ]]; then
-             # This is a direct reference to a shared library, so add
-             # its directory to the rpath.
-             path="$(dirname "$p")";
-             addToRPath "${path}"
-+            allParamsPost+=("$p")
-+        else
-+            allParamsPost+=("$p")
-         fi
-+
-         n=$((n + 1))
-     done
- 
-+    if [[ "$linkIndirect" ]]; then
-+        while (( $n < "${#childrenLink[@]}" )); do
-+            childrenLink[n]="-reexport${childrenLink[n]}"
-+        done
-+        declare -r outputNameLibless=$(basename $(
-+            if [[ "${outputName:0:3}" = lib ]]; then
-+                echo "${outputName:3}"
-+            else
-+                echo "${outputName:-unnamed}"
-+            fi))
-+        declare -ra children=("$outputNameLibless-reexport-delegate-0" \
-+                              "$outputNameLibless-reexport-delegate-1")
-+
-+        mkdir -p "$out/lib"
-+
-+        # first half of libs
-+        "$0" -dylib -o "$out/lib/lib${children[0]}.dylib" \
-+             -install_name "$out/lib/lib${children[0]}.dylib" \
-+             "${childrenLookup[@]}" \
-+             "${childrenLink[@]::$((${#childrenLink[@]} / 2 ))}"
-+
-+        # second half of libs
-+        "$0" -dylib -o "$out/lib/lib${children[1]}.dylib" \
-+             -install_name "$out/lib/lib${children[1]}.dylib" \
-+             "${childrenLookup[@]}" \
-+             "${childrenLink[@]:$((${#childrenLink[@]} / 2 ))}"
-+
-+        allParamsPost+=("-L$out/lib" "-l${children[0]}" "-l${children[1]}")
-+    fi
-+
-     # Second, for each directory in the library search path (-L...),
-     # see if it contains a dynamic library used by a -l... flag.  If
-     # so, add the directory to the rpath.
-@@ -170,12 +243,8 @@ fi
- 
- # Optionally print debug info.
- if [ -n "$NIX_DEBUG" ]; then
--  echo "original flags to @prog@:" >&2
--  for i in "${params[@]}"; do
--      echo "  $i" >&2
--  done
--  echo "extra flags to @prog@:" >&2
--  for i in ${extra[@]}; do
-+  echo "flags to @prog@:" >&2
-+  for i in "${allParamsPost[@]}"; do
-       echo "  $i" >&2
-   done
- fi
-@@ -185,4 +254,4 @@ if [ -n "$NIX_LD_WRAPPER_EXEC_HOOK" ]; then
- fi
- 
- PATH="$path_backup"
--exec @prog@ ${extraBefore[@]} "${params[@]}" ${extra[@]}
-+exec @prog@ "${allParamsPost[@]}"