Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
68 changed files
with
1,039 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# See cc-wrapper for comments. | ||
var_templates_list=( | ||
NIX+IGNORE_LD_THROUGH_GCC | ||
NIX+LDFLAGS | ||
NIX+LDFLAGS_BEFORE | ||
NIX+LDFLAGS_AFTER | ||
NIX+LDFLAGS_HARDEN | ||
) | ||
var_templates_bool=( | ||
NIX+SET_BUILD_ID | ||
NIX+DONT_SET_RPATH | ||
) | ||
|
||
declare -a role_infixes=() | ||
if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_BUILD:-}" ]; then | ||
role_infixes+=(_BUILD_) | ||
fi | ||
if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_HOST:-}" ]; then | ||
role_infixes+=(_) | ||
fi | ||
if [ "${NIX_BINTOOLS_WRAPPER_@infixSalt@_TARGET_TARGET:-}" ]; then | ||
role_infixes+=(_TARGET_) | ||
fi | ||
|
||
for var in "${var_templates_list[@]}"; do | ||
mangleVarList "$var" "${role_infixes[@]}" | ||
done | ||
for var in "${var_templates_bool[@]}"; do | ||
mangleVarBool "$var" "${role_infixes[@]}" | ||
done | ||
|
||
if [ -e @out@/nix-support/libc-ldflags ]; then | ||
NIX_@infixSalt@_LDFLAGS+=" $(< @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" | ||
fi | ||
|
||
export NIX_BINTOOLS_WRAPPER_@infixSalt@_FLAGS_SET=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
hardeningFlags=(relro bindnow) | ||
# Intentionally word-split in case 'hardeningEnable' is defined in | ||
# Nix. Also, our bootstrap tools version of bash is old enough that | ||
# undefined arrays trip `set -u`. | ||
if [[ -v hardeningEnable[@] ]]; then | ||
hardeningFlags+=(${hardeningEnable[@]}) | ||
fi | ||
hardeningLDFlags=() | ||
|
||
declare -A hardeningDisableMap | ||
|
||
# Intentionally word-split in case 'hardeningDisable' is defined in Nix. | ||
for flag in ${hardeningDisable[@]:-IGNORED_KEY} @hardening_unsupported_flags@ | ||
do | ||
hardeningDisableMap[$flag]=1 | ||
done | ||
|
||
if (( "${NIX_DEBUG:-0}" >= 1 )); then | ||
printf 'HARDENING: disabled flags:' >&2 | ||
(( "${#hardeningDisableMap[@]}" )) && printf ' %q' "${!hardeningDisableMap[@]}" >&2 | ||
echo >&2 | ||
fi | ||
|
||
if [[ -z "${hardeningDisableMap[all]:-}" ]]; then | ||
if (( "${NIX_DEBUG:-0}" >= 1 )); then | ||
echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2; | ||
fi | ||
for flag in "${hardeningFlags[@]}" | ||
do | ||
if [[ -z "${hardeningDisableMap[$flag]:-}" ]]; then | ||
case $flag in | ||
pie) | ||
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then | ||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling LDFlags -pie >&2; fi | ||
hardeningLDFlags+=('-pie') | ||
fi | ||
;; | ||
relro) | ||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling relro >&2; fi | ||
hardeningLDFlags+=('-z' 'relro') | ||
;; | ||
bindnow) | ||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling bindnow >&2; fi | ||
hardeningLDFlags+=('-z' 'now') | ||
;; | ||
*) | ||
# Ignore unsupported. Checked in Nix that at least *some* | ||
# tool supports each flag. | ||
;; | ||
esac | ||
fi | ||
done | ||
fi |
Oops, something went wrong.