2017-08-28 20:56:08 +02:00
|
|
|
# Binutils Wrapper hygiene
|
|
|
|
#
|
|
|
|
# See comments in cc-wrapper's setup hook. This works exactly the same way.
|
|
|
|
|
2017-08-03 18:45:06 +02:00
|
|
|
set -u
|
|
|
|
|
2017-08-28 17:33:08 +02:00
|
|
|
# Skip setup hook if we're neither a build-time dep, nor, temporarily, doing a
|
|
|
|
# native compile.
|
|
|
|
#
|
|
|
|
# TODO(@Ericson2314): No native exception
|
2018-05-13 17:31:24 +02:00
|
|
|
[[ -z ${strictDeps-} ]] || (( "$hostOffset" < 0 )) || return 0
|
2017-08-03 18:45:06 +02:00
|
|
|
|
2017-08-28 20:56:08 +02:00
|
|
|
bintoolsWrapper_addLDVars () {
|
2018-05-07 19:07:19 +02:00
|
|
|
# See ../setup-hooks/role.bash
|
|
|
|
local role_post role_pre
|
2018-06-02 01:42:05 +02:00
|
|
|
getHostRoleEnvHook
|
2017-08-28 20:56:08 +02:00
|
|
|
|
|
|
|
if [[ -d "$1/lib64" && ! -L "$1/lib64" ]]; then
|
2018-05-07 19:07:19 +02:00
|
|
|
export NIX_${role_pre}LDFLAGS+=" -L$1/lib64"
|
2017-08-28 20:56:08 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -d "$1/lib" ]]; then
|
2018-07-21 15:22:17 +02:00
|
|
|
# Don't add the /lib directory if it actually doesn't contain any libraries. For instance,
|
|
|
|
# Python and Haskell packages often only have directories like $out/lib/ghc-8.4.3/ or
|
|
|
|
# $out/lib/python3.6/, so having them in LDFLAGS just makes the linker search unnecessary
|
|
|
|
# directories and bloats the size of the environment variable space.
|
|
|
|
if [[ -n "$(echo $1/lib/lib*)" ]]; then
|
|
|
|
export NIX_${role_pre}LDFLAGS+=" -L$1/lib"
|
|
|
|
fi
|
2017-08-28 20:56:08 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-05-07 19:07:19 +02:00
|
|
|
# See ../setup-hooks/role.bash
|
|
|
|
getTargetRole
|
|
|
|
getTargetRoleWrapper
|
2017-08-28 20:56:08 +02:00
|
|
|
|
2017-08-03 18:45:06 +02:00
|
|
|
addEnvHooks "$targetOffset" bintoolsWrapper_addLDVars
|
2017-08-28 20:56:08 +02:00
|
|
|
|
|
|
|
# shellcheck disable=SC2157
|
|
|
|
if [ -n "@bintools_bin@" ]; then
|
|
|
|
addToSearchPath _PATH @bintools_bin@/bin
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shellcheck disable=SC2157
|
|
|
|
if [ -n "@libc_bin@" ]; then
|
|
|
|
addToSearchPath _PATH @libc_bin@/bin
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shellcheck disable=SC2157
|
|
|
|
if [ -n "@coreutils_bin@" ]; then
|
|
|
|
addToSearchPath _PATH @coreutils_bin@/bin
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Export tool environment variables so various build systems use the right ones.
|
|
|
|
|
|
|
|
export NIX_${role_pre}BINTOOLS=@out@
|
|
|
|
|
|
|
|
for cmd in \
|
|
|
|
ar as ld nm objcopy objdump readelf ranlib strip strings size windres
|
|
|
|
do
|
|
|
|
if
|
|
|
|
PATH=$_PATH type -p "@targetPrefix@${cmd}" > /dev/null
|
|
|
|
then
|
|
|
|
upper_case="$(echo "$cmd" | tr "[:lower:]" "[:upper:]")"
|
|
|
|
export "${role_pre}${upper_case}=@targetPrefix@${cmd}";
|
|
|
|
export "${upper_case}${role_post}=@targetPrefix@${cmd}";
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-04-11 20:00:13 +02:00
|
|
|
# If unset, assume the default hardening flags.
|
|
|
|
: ${NIX_HARDENING_ENABLE="fortify stackprotector pic strictoverflow format relro bindnow"}
|
|
|
|
export NIX_HARDENING_ENABLE
|
|
|
|
|
2017-08-28 20:56:08 +02:00
|
|
|
# No local scope in sourced file
|
|
|
|
unset -v role_pre role_post cmd upper_case
|
2017-08-03 18:45:06 +02:00
|
|
|
set +u
|