mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-24 07:53:19 +00:00
Merge pull request #29580 from obsidiansystems/stdenv-super-debug
stdenv: Provide a way for full `set -x` debugging
This commit is contained in:
commit
87067dc471
@ -1,4 +1,3 @@
|
||||
|
||||
<chapter xmlns="http://docbook.org/ns/docbook"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xml:id="chap-stdenv">
|
||||
@ -188,11 +187,13 @@ genericBuild
|
||||
|
||||
<varlistentry>
|
||||
<term><varname>NIX_DEBUG</varname></term>
|
||||
<listitem><para>If set, <literal>stdenv</literal> will print some
|
||||
debug information during the build. In particular, the
|
||||
<command>gcc</command> and <command>ld</command> wrapper scripts
|
||||
will print out the complete command line passed to the wrapped
|
||||
tools.</para></listitem>
|
||||
<listitem><para>
|
||||
A natural number indicating how much information to log.
|
||||
If set to 1 or higher, <literal>stdenv</literal> will print moderate debug information during the build.
|
||||
In particular, the <command>gcc</command> and <command>ld</command> wrapper scripts will print out the complete command line passed to the wrapped tools.
|
||||
If set to 6 or higher, the <literal>stdenv</literal> setup script will be run with <literal>set -x</literal> tracing.
|
||||
If set to 7 or higher, the <command>gcc</command> and <command>ld</command> wrapper scripts will also be run with <literal>set -x</literal> tracing.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
</variablelist>
|
||||
|
@ -16,14 +16,14 @@ do
|
||||
hardeningDisableMap[$flag]=1
|
||||
done
|
||||
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then
|
||||
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 [[ -n "${NIX_DEBUG:-}" ]]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo 'HARDENING: Is active (not completely disabled with "all" flag)' >&2;
|
||||
fi
|
||||
for flag in "${hardeningFlags[@]}"
|
||||
@ -31,40 +31,40 @@ if [[ -z "${hardeningDisableMap[all]:-}" ]]; then
|
||||
if [[ -z "${hardeningDisableMap[$flag]:-}" ]]; then
|
||||
case $flag in
|
||||
fortify)
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling fortify >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling fortify >&2; fi
|
||||
hardeningCFlags+=('-O2' '-D_FORTIFY_SOURCE=2')
|
||||
;;
|
||||
stackprotector)
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling stackprotector >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling stackprotector >&2; fi
|
||||
hardeningCFlags+=('-fstack-protector-strong' '--param' 'ssp-buffer-size=4')
|
||||
;;
|
||||
pie)
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling CFlags -fPIE >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling CFlags -fPIE >&2; fi
|
||||
hardeningCFlags+=('-fPIE')
|
||||
if [[ ! ("$*" =~ " -shared " || "$*" =~ " -static ") ]]; then
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling LDFlags -pie >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling LDFlags -pie >&2; fi
|
||||
hardeningCFlags+=('-pie')
|
||||
hardeningLDFlags+=('-pie')
|
||||
fi
|
||||
;;
|
||||
pic)
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling pic >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling pic >&2; fi
|
||||
hardeningCFlags+=('-fPIC')
|
||||
;;
|
||||
strictoverflow)
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling strictoverflow >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling strictoverflow >&2; fi
|
||||
hardeningCFlags+=('-fno-strict-overflow')
|
||||
;;
|
||||
format)
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling format >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling format >&2; fi
|
||||
hardeningCFlags+=('-Wformat' '-Wformat-security' '-Werror=format-security')
|
||||
;;
|
||||
relro)
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling relro >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling relro >&2; fi
|
||||
hardeningLDFlags+=('-z' 'relro')
|
||||
;;
|
||||
bindnow)
|
||||
if [[ -n "${NIX_DEBUG:-}" ]]; then echo HARDENING: enabling bindnow >&2; fi
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then echo HARDENING: enabling bindnow >&2; fi
|
||||
hardeningLDFlags+=('-z' 'now')
|
||||
;;
|
||||
*)
|
||||
|
@ -2,6 +2,10 @@
|
||||
set -eu -o pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
||||
set -x
|
||||
fi
|
||||
|
||||
path_backup="$PATH"
|
||||
|
||||
# That @-vars are substituted separately from bash evaluation makes
|
||||
@ -161,7 +165,7 @@ if [ "$*" = -v ]; then
|
||||
fi
|
||||
|
||||
# Optionally print debug info.
|
||||
if [ -n "${NIX_DEBUG:-}" ]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
# Old bash workaround, see ld-wrapper for explanation.
|
||||
echo "extra flags before to @prog@:" >&2
|
||||
printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2
|
||||
|
@ -2,6 +2,10 @@
|
||||
set -eu -o pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# N.B. Gnat is not used during bootstrapping, so we don't need to
|
||||
# worry about the old bash empty array `set -u` workarounds.
|
||||
|
||||
@ -109,7 +113,7 @@ fi
|
||||
#fi
|
||||
|
||||
# Optionally print debug info.
|
||||
if [ -n "${NIX_DEBUG:-}" ]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "extra flags before to @prog@:" >&2
|
||||
printf " %q\n" "${extraBefore[@]}" >&2
|
||||
echo "original flags to @prog@:" >&2
|
||||
|
@ -2,6 +2,10 @@
|
||||
set -eu -o pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
||||
set -x
|
||||
fi
|
||||
|
||||
# N.B. Gnat is not used during bootstrapping, so we don't need to
|
||||
# worry about the old bash empty array `set -u` workarounds.
|
||||
|
||||
@ -24,7 +28,7 @@ extraBefore=()
|
||||
#export NIX_@infixSalt@_LDFLAGS_SET=1
|
||||
|
||||
# Optionally print debug info.
|
||||
if [ -n "${NIX_DEBUG:-}" ]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "extra flags before to @prog@:" >&2
|
||||
printf " %q\n" "${extraBefore[@]}" >&2
|
||||
echo "original flags to @prog@:" >&2
|
||||
|
@ -2,6 +2,10 @@
|
||||
set -eu -o pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
||||
set -x
|
||||
fi
|
||||
|
||||
declare -a args=("$@")
|
||||
# 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
|
||||
|
@ -2,6 +2,10 @@
|
||||
set -eu -o pipefail
|
||||
shopt -s nullglob
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 7 )); then
|
||||
set -x
|
||||
fi
|
||||
|
||||
path_backup="$PATH"
|
||||
|
||||
# phase separation makes this look useless
|
||||
@ -156,7 +160,7 @@ fi
|
||||
|
||||
|
||||
# Optionally print debug info.
|
||||
if [ -n "${NIX_DEBUG:-}" ]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
# Old bash workaround, see above.
|
||||
echo "extra flags before to @prog@:" >&2
|
||||
printf " %q\n" ${extraBefore+"${extraBefore[@]}"} >&2
|
||||
|
@ -1,5 +1,5 @@
|
||||
skip () {
|
||||
if [ -n "${NIX_DEBUG:-}" ]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "skipping impure path $1" >&2
|
||||
fi
|
||||
}
|
||||
|
@ -1,6 +1,10 @@
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
if (( "${NIX_DEBUG:-0}" >= 6 )); then
|
||||
set -x
|
||||
fi
|
||||
|
||||
: ${outputs:=out}
|
||||
|
||||
|
||||
@ -269,7 +273,7 @@ for i in $initialPath; do
|
||||
addToSearchPath PATH "$i/bin"
|
||||
done
|
||||
|
||||
if [ "${NIX_DEBUG:-}" = 1 ]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "initial path: $PATH"
|
||||
fi
|
||||
|
||||
@ -429,7 +433,7 @@ fi
|
||||
|
||||
|
||||
PATH="${_PATH-}${_PATH:+${PATH:+:}}$PATH"
|
||||
if [ "${NIX_DEBUG:-}" = 1 ]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
echo "final path: $PATH"
|
||||
fi
|
||||
|
||||
@ -539,7 +543,7 @@ substituteAll() {
|
||||
local -a args=()
|
||||
|
||||
for varName in $(awk 'BEGIN { for (v in ENVIRON) if (v ~ /^[a-z][a-zA-Z0-9_]*$/) print v }'); do
|
||||
if [ "${NIX_DEBUG:-}" = "1" ]; then
|
||||
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
||||
printf "@%s@ -> %q\n" "${varName}" "${!varName}"
|
||||
fi
|
||||
args+=("--subst-var" "$varName")
|
||||
|
Loading…
Reference in New Issue
Block a user