From 96bbe339d47d4bc78cc9eaf0845734f80fe2d56b Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Sun, 2 May 2021 14:00:37 -0400 Subject: [PATCH 1/3] Revert "cc-wrapper: -nostdlib does not imply -nostdinc++" This made C++ standard headers passed to be passed when C compiler is executed, which is not a correct fix. This reverts commit 54c7a0f42287f63c2db8086a8ad46ac981364378. --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index b402893100b..d08fd24cd2d 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -132,13 +132,12 @@ if [ "$NIX_ENFORCE_NO_NATIVE_@suffixSalt@" = 1 ]; then fi if [[ "$isCpp" = 1 ]]; then + if [[ "$cppInclude" = 1 ]]; then + NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@" + fi NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@" fi -if [[ "$cppInclude" = 1 ]]; then - NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@" -fi - source @out@/nix-support/add-hardening.sh # Add the flags for the C compiler proper. From d9bad0eae60c9226e4b405943cd67ec72d44b4d1 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Sun, 2 May 2021 14:03:51 -0400 Subject: [PATCH 2/3] cc-wrapper.sh: rename variables cpp -> cxx CPP is the C PreProcessor CXX is C++ --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index d08fd24cd2d..5729fdc75e0 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -25,8 +25,8 @@ dontLink=0 nonFlagArgs=0 cc1=0 # shellcheck disable=SC2193 -[[ "@prog@" = *++ ]] && isCpp=1 || isCpp=0 -cppInclude=1 +[[ "@prog@" = *++ ]] && isCxx=1 || isCxx=0 +cxxInclude=1 cInclude=1 setDynamicLinker=1 @@ -50,15 +50,15 @@ while (( "$n" < "$nParams" )); do dontLink=1 elif [[ "$p" = -x && "$p2" = *-header ]]; then dontLink=1 - elif [[ "$p" = -x && "$p2" = c++* && "$isCpp" = 0 ]]; then - isCpp=1 + elif [[ "$p" = -x && "$p2" = c++* && "$isCxx" = 0 ]]; then + isCxx=1 elif [ "$p" = -nostdlib ]; then - isCpp=-1 + isCxx=-1 elif [ "$p" = -nostdinc ]; then cInclude=0 - cppInclude=0 + cxxInclude=0 elif [ "$p" = -nostdinc++ ]; then - cppInclude=0 + cxxInclude=0 elif [[ "$p" = -static || "$p" = -static-pie ]]; then setDynamicLinker=0 elif [[ "$p" != -?* ]]; then @@ -131,8 +131,8 @@ if [ "$NIX_ENFORCE_NO_NATIVE_@suffixSalt@" = 1 ]; then params=(${rest+"${rest[@]}"}) fi -if [[ "$isCpp" = 1 ]]; then - if [[ "$cppInclude" = 1 ]]; then +if [[ "$isCxx" = 1 ]]; then + if [[ "$cxxInclude" = 1 ]]; then NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@" fi NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@" From 11b744b59c09192c87b0c3f21b32036d7cf0bbf2 Mon Sep 17 00:00:00 2001 From: Dmitry Kalinkin Date: Sun, 2 May 2021 14:07:00 -0400 Subject: [PATCH 3/3] cc-wrapper.sh: make -nostdlib disable the standard C++ library, but not its includes Should be the correct fix for #111970 --- pkgs/build-support/cc-wrapper/cc-wrapper.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 5729fdc75e0..2e62aef4604 100644 --- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -27,6 +27,7 @@ cc1=0 # shellcheck disable=SC2193 [[ "@prog@" = *++ ]] && isCxx=1 || isCxx=0 cxxInclude=1 +cxxLibrary=1 cInclude=1 setDynamicLinker=1 @@ -53,7 +54,7 @@ while (( "$n" < "$nParams" )); do elif [[ "$p" = -x && "$p2" = c++* && "$isCxx" = 0 ]]; then isCxx=1 elif [ "$p" = -nostdlib ]; then - isCxx=-1 + cxxLibrary=0 elif [ "$p" = -nostdinc ]; then cInclude=0 cxxInclude=0 @@ -135,7 +136,9 @@ if [[ "$isCxx" = 1 ]]; then if [[ "$cxxInclude" = 1 ]]; then NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@" fi - NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@" + if [[ "$cxxLibrary" = 1 ]]; then + NIX_CFLAGS_LINK_@suffixSalt@+=" $NIX_CXXSTDLIB_LINK_@suffixSalt@" + fi fi source @out@/nix-support/add-hardening.sh