diff options
Diffstat (limited to 'nixpkgs/pkgs/build-support/bintools-wrapper')
5 files changed, 83 insertions, 75 deletions
diff --git a/nixpkgs/pkgs/build-support/bintools-wrapper/add-flags.sh b/nixpkgs/pkgs/build-support/bintools-wrapper/add-flags.sh index e5c0556556c..e99beb38158 100644 --- a/nixpkgs/pkgs/build-support/bintools-wrapper/add-flags.sh +++ b/nixpkgs/pkgs/build-support/bintools-wrapper/add-flags.sh @@ -1,32 +1,32 @@ # See cc-wrapper for comments. var_templates_list=( - NIX+IGNORE_LD_THROUGH_GCC - NIX+LDFLAGS - NIX+LDFLAGS_BEFORE - NIX+LDFLAGS_AFTER - NIX+LDFLAGS_HARDEN - NIX+HARDENING_ENABLE + NIX_IGNORE_LD_THROUGH_GCC + NIX_LDFLAGS + NIX_LDFLAGS_BEFORE + NIX_LDFLAGS_AFTER + NIX_LDFLAGS_HARDEN + NIX_HARDENING_ENABLE ) var_templates_bool=( - NIX+SET_BUILD_ID - NIX+DONT_SET_RPATH + NIX_SET_BUILD_ID + NIX_DONT_SET_RPATH ) accumulateRoles for var in "${var_templates_list[@]}"; do - mangleVarList "$var" ${role_infixes[@]+"${role_infixes[@]}"} + mangleVarList "$var" ${role_suffixes[@]+"${role_suffixes[@]}"} done for var in "${var_templates_bool[@]}"; do - mangleVarBool "$var" ${role_infixes[@]+"${role_infixes[@]}"} + mangleVarBool "$var" ${role_suffixes[@]+"${role_suffixes[@]}"} done if [ -e @out@/nix-support/libc-ldflags ]; then - NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/libc-ldflags)" + NIX_LDFLAGS_@suffixSalt@+=" $(< @out@/nix-support/libc-ldflags)" fi if [ -e @out@/nix-support/libc-ldflags-before ]; then - NIX_@infixSalt@_LDFLAGS_BEFORE="$(< @out@/nix-support/libc-ldflags-before) $NIX_@infixSalt@_LDFLAGS_BEFORE" + NIX_LDFLAGS_BEFORE_@suffixSalt@="$(< @out@/nix-support/libc-ldflags-before) $NIX_LDFLAGS_BEFORE_@suffixSalt@" fi -export NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET=1 +export NIX_BINTOOLS_WRAPPER_FLAGS_SET_@suffixSalt@=1 diff --git a/nixpkgs/pkgs/build-support/bintools-wrapper/add-hardening.sh b/nixpkgs/pkgs/build-support/bintools-wrapper/add-hardening.sh index b7180870860..5e49b7bd905 100644 --- a/nixpkgs/pkgs/build-support/bintools-wrapper/add-hardening.sh +++ b/nixpkgs/pkgs/build-support/bintools-wrapper/add-hardening.sh @@ -5,7 +5,7 @@ declare -A hardeningEnableMap=() # Intentionally word-split in case 'NIX_HARDENING_ENABLE' is defined in Nix. The # array expansion also prevents undefined variables from causing trouble with # `set -u`. -for flag in ${NIX_@infixSalt@_HARDENING_ENABLE-}; do +for flag in ${NIX_HARDENING_ENABLE_@suffixSalt@-}; do hardeningEnableMap["$flag"]=1 done diff --git a/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix b/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix index 5cc99c6412a..1aab26532a4 100644 --- a/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix +++ b/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix @@ -45,7 +45,7 @@ let coreutils_bin = if nativeTools then "" else getBin coreutils; # See description in cc-wrapper. - infixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config; + suffixSalt = replaceStrings ["-" "."] ["_" "_"] targetPlatform.config; # The dynamic linker has different names on different platforms. This is a # shell glob that ought to match it. @@ -83,7 +83,7 @@ stdenv.mkDerivation { shell = getBin shell + shell.shellPath or ""; gnugrep_bin = if nativeTools then "" else gnugrep; - inherit targetPrefix infixSalt; + inherit targetPrefix suffixSalt; outputs = [ "out" ] ++ optionals propagateDoc ([ "man" ] ++ optional (bintools ? info) "info"); @@ -95,9 +95,9 @@ stdenv.mkDerivation { (mapc (lambda (arg) (when (file-directory-p (concat arg "/lib")) - (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib"))) + (setenv "NIX_LDFLAGS_${suffixSalt}" (concat (getenv "NIX_LDFLAGS_${suffixSalt}") " -L" arg "/lib"))) (when (file-directory-p (concat arg "/lib64")) - (setenv "NIX_${infixSalt}_LDFLAGS" (concat (getenv "NIX_${infixSalt}_LDFLAGS") " -L" arg "/lib64")))) + (setenv "NIX_LDFLAGS_${suffixSalt}" (concat (getenv "NIX_LDFLAGS_${suffixSalt}") " -L" arg "/lib64")))) '(${concatStringsSep " " (map (pkg: "\"${pkg}\"") pkgs)})) ''; }; @@ -132,15 +132,15 @@ stdenv.mkDerivation { ldPath="${bintools_bin}/bin" '' + # Solaris needs an additional ld wrapper. + optionalString (targetPlatform.isSunOS && nativePrefix != "") '' - # Solaris needs an additional ld wrapper. ldPath="${nativePrefix}/bin" exec="$ldPath/${targetPrefix}ld" wrap ld-solaris ${./ld-solaris-wrapper.sh} '') + # Create a symlink to as (the assembler). + '' - # Create a symlink to as (the assembler). if [ -e $ldPath/${targetPrefix}as ]; then ln -s $ldPath/${targetPrefix}as $out/bin/${targetPrefix}as fi @@ -200,26 +200,29 @@ stdenv.mkDerivation { ]; postFixup = + ## + ## General libc support + ## optionalString (libc != null) ('' - ## - ## General libc support - ## - - echo "-L${libc_lib}${libc.libdir or "/lib"}" > $out/nix-support/libc-ldflags + touch "$out/nix-support/libc-ldflags" + echo "-L${libc_lib}${libc.libdir or "/lib"}" >> $out/nix-support/libc-ldflags echo "${libc_lib}" > $out/nix-support/orig-libc echo "${libc_dev}" > $out/nix-support/orig-libc-dev + '' - ## - ## Dynamic linker support - ## - + ## + ## Dynamic linker support + ## + + '' if [[ -z ''${dynamicLinker+x} ]]; then echo "Don't know the name of the dynamic linker for platform '${targetPlatform.config}', so guessing instead." >&2 local dynamicLinker="${libc_lib}/lib/ld*.so.?" fi + '' - # Expand globs to fill array of options + # Expand globs to fill array of options + + '' dynamicLinker=($dynamicLinker) case ''${#dynamicLinker[@]} in @@ -228,53 +231,56 @@ stdenv.mkDerivation { *) echo "Multiple dynamic linkers found for platform '${targetPlatform.config}'." >&2;; esac - if [ -n "''${dynamicLinker:-}" ]; then + if [ -n "''${dynamicLinker-}" ]; then echo $dynamicLinker > $out/nix-support/dynamic-linker '' + (if targetPlatform.isDarwin then '' printf "export LD_DYLD_PATH=%q\n" "$dynamicLinker" >> $out/nix-support/setup-hook - '' else '' + '' else '' if [ -e ${libc_lib}/lib/32/ld-linux.so.2 ]; then echo ${libc_lib}/lib/32/ld-linux.so.2 > $out/nix-support/dynamic-linker-m32 fi - - local ldflagsBefore=(-dynamic-linker "$dynamicLinker") - '') + '' - fi - + '' # The dynamic linker is passed in `ldflagsBefore' to allow # explicit overrides of the dynamic linker by callers to ld # (the *last* value counts, so ours should come first). - printWords "''${ldflagsBefore[@]}" > $out/nix-support/libc-ldflags-before + + '' + echo -dynamic-linker "$dynamicLinker" >> $out/nix-support/libc-ldflags-before + '') + '' + fi '') - + optionalString (!nativeTools) '' - ## - ## User env support - ## + # Ensure consistent LC_VERSION_MIN_MACOSX and remove LC_UUID. + + optionalString stdenv.targetPlatform.isMacOS '' + echo "-macosx_version_min 10.12 -sdk_version 10.12 -no_uuid" >> $out/nix-support/libc-ldflags-before + '' - # Propagate the underling unwrapped bintools so that if you - # install the wrapper, you get tools like objdump (same for any - # binaries of libc). + ## + ## User env support + ## + + # Propagate the underling unwrapped bintools so that if you + # install the wrapper, you get tools like objdump (same for any + # binaries of libc). + + optionalString (!nativeTools) '' printWords ${bintools_bin} ${if libc == null then "" else libc_bin} > $out/nix-support/propagated-user-env-packages '' + ## + ## Man page and info support + ## + optionalString propagateDoc ('' - ## - ## Man page and info support - ## - ln -s ${bintools.man} $man '' + optionalString (bintools ? info) '' ln -s ${bintools.info} $info '') - + '' - ## - ## Hardening support - ## + ## + ## Hardening support + ## - # some linkers on some platforms don't support specific -z flags + # some linkers on some platforms don't support specific -z flags + + '' export hardening_unsupported_flags="" if [[ "$($ldPath/${targetPrefix}ld -z now 2>&1 || true)" =~ un(recognized|known)\ option ]]; then hardening_unsupported_flags+=" bindnow" @@ -299,15 +305,18 @@ stdenv.mkDerivation { '' + '' + for flags in "$out/nix-support"/*flags*; do + substituteInPlace "$flags" --replace $'\n' ' ' + done + substituteAll ${./add-flags.sh} $out/nix-support/add-flags.sh substituteAll ${./add-hardening.sh} $out/nix-support/add-hardening.sh - substituteAll ${../wrapper-common/utils.bash} $out/nix-support/utils.bash - - ## - ## Extra custom steps - ## + substituteAll ${if stdenv.isDarwin then ../wrapper-common/utils.bash.darwin else ../wrapper-common/utils.bash} $out/nix-support/utils.bash '' + ## + ## Extra custom steps + ## + extraBuildCommands; inherit dynamicLinker expand-response-params; diff --git a/nixpkgs/pkgs/build-support/bintools-wrapper/ld-wrapper.sh b/nixpkgs/pkgs/build-support/bintools-wrapper/ld-wrapper.sh index ed2f00a8974..81b5a90edd5 100644 --- a/nixpkgs/pkgs/build-support/bintools-wrapper/ld-wrapper.sh +++ b/nixpkgs/pkgs/build-support/bintools-wrapper/ld-wrapper.sh @@ -16,7 +16,7 @@ fi source @out@/nix-support/utils.bash -if [ -z "${NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET:-}" ]; then +if [ -z "${NIX_BINTOOLS_WRAPPER_FLAGS_SET_@suffixSalt@:-}" ]; then source @out@/nix-support/add-flags.sh fi @@ -24,7 +24,7 @@ fi # Optionally filter out paths not refering to the store. expandResponseParams "$@" if [[ "${NIX_ENFORCE_PURITY:-}" = 1 && -n "${NIX_STORE:-}" - && ( -z "$NIX_@infixSalt@_IGNORE_LD_THROUGH_GCC" || -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ) ]]; then + && ( -z "$NIX_IGNORE_LD_THROUGH_GCC_@suffixSalt@" || -z "${NIX_LDFLAGS_SET_@suffixSalt@:-}" ) ]]; then rest=() nParams=${#params[@]} declare -i n=0 @@ -60,12 +60,12 @@ source @out@/nix-support/add-hardening.sh extraAfter=() extraBefore=(${hardeningLDFlags[@]+"${hardeningLDFlags[@]}"}) -if [ -z "${NIX_@infixSalt@_LDFLAGS_SET:-}" ]; then - extraAfter+=($NIX_@infixSalt@_LDFLAGS) - extraBefore+=($NIX_@infixSalt@_LDFLAGS_BEFORE) +if [ -z "${NIX_LDFLAGS_SET_@suffixSalt@:-}" ]; then + extraAfter+=($NIX_LDFLAGS_@suffixSalt@) + extraBefore+=($NIX_LDFLAGS_BEFORE_@suffixSalt@) fi -extraAfter+=($NIX_@infixSalt@_LDFLAGS_AFTER) +extraAfter+=($NIX_LDFLAGS_AFTER_@suffixSalt@) # Specify the target emulation if nothing is passed in ("-m" overrides this # environment variable). Ensures we never blindly fallback on targeting the host @@ -84,8 +84,8 @@ declare -A libs declare -i relocatable=0 link32=0 if - [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ] \ - || [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ] \ + [ "$NIX_DONT_SET_RPATH_@suffixSalt@" != 1 ] \ + || [ "$NIX_SET_BUILD_ID_@suffixSalt@" = 1 ] \ || [ -e @out@/nix-support/dynamic-linker-m32 ] then prev= @@ -144,7 +144,7 @@ if [ -e "@out@/nix-support/dynamic-linker-m32" ] && (( "$link32" )); then fi # Add all used dynamic libraries to the rpath. -if [ "$NIX_@infixSalt@_DONT_SET_RPATH" != 1 ]; then +if [ "$NIX_DONT_SET_RPATH_@suffixSalt@" != 1 ]; then # 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. @@ -186,7 +186,7 @@ fi # Only add --build-id if this is a final link. FIXME: should build gcc # with --enable-linker-build-id instead? -if [ "$NIX_@infixSalt@_SET_BUILD_ID" = 1 ] && ! (( "$relocatable" )); then +if [ "$NIX_SET_BUILD_ID_@suffixSalt@" = 1 ] && ! (( "$relocatable" )); then extraAfter+=(--build-id) fi diff --git a/nixpkgs/pkgs/build-support/bintools-wrapper/setup-hook.sh b/nixpkgs/pkgs/build-support/bintools-wrapper/setup-hook.sh index a714bd151c9..7e9547b96c2 100644 --- a/nixpkgs/pkgs/build-support/bintools-wrapper/setup-hook.sh +++ b/nixpkgs/pkgs/build-support/bintools-wrapper/setup-hook.sh @@ -10,11 +10,11 @@ bintoolsWrapper_addLDVars () { # See ../setup-hooks/role.bash - local role_post role_pre + local role_post getHostRoleEnvHook if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then - export NIX_${role_pre}LDFLAGS+=" -L$1/lib64" + export NIX_LDFLAGS${role_post}+=" -L$1/lib64" fi if [[ -d "$1/lib" ]]; then @@ -24,7 +24,7 @@ bintoolsWrapper_addLDVars () { # directories and bloats the size of the environment variable space. local -a glob=( $1/lib/lib* ) if [ "${#glob[*]}" -gt 0 ]; then - export NIX_${role_pre}LDFLAGS+=" -L$1/lib" + export NIX_LDFLAGS${role_post}+=" -L$1/lib" fi fi } @@ -52,7 +52,7 @@ fi # Export tool environment variables so various build systems use the right ones. -export NIX_${role_pre}BINTOOLS=@out@ +export NIX_BINTOOLS${role_post}=@out@ for cmd in \ ar as ld nm objcopy objdump readelf ranlib strip strings size windres @@ -60,7 +60,6 @@ do if PATH=$_PATH type -p "@targetPrefix@${cmd}" > /dev/null then - export "${role_pre}${cmd^^}=@targetPrefix@${cmd}"; export "${cmd^^}${role_post}=@targetPrefix@${cmd}"; fi done @@ -70,4 +69,4 @@ done export NIX_HARDENING_ENABLE # No local scope in sourced file -unset -v role_pre role_post cmd upper_case +unset -v role_post cmd upper_case |