-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
Description
The Bug
Currently cc-wrapper does add -stdlib=libc++ to libcxx-ldflags but not to libcxx-cxxflags.
This leads to clang appending gcc libstdc++ header search directories to the search path which in turn breaks libc++ headers (#include_next <...> no longer finds libc headers, as intended, but now finds libstdc++ headers).
To Reproduce
nix-shell -p llvmPackages_14.libcxxStdenv.cc --run "echo '#include <string>' | clang++ -c -xc++ -" --pure^ results in errors that look like this:
Click to expand.
In file included from <stdin>:1:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/string:523:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__functional_base:22:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/exception:83:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/cstdlib:85:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/stdlib.h:93:
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/stdlib.h:38:12: error: no member named 'abort' in namespace 'std'
using std::abort;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/stdlib.h:39:12: error: no member named 'atexit' in namespace 'std'
using std::atexit;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/stdlib.h:40:12: error: no member named 'exit' in namespace 'std'
using std::exit;
~~~~~^
In file included from <stdin>:1:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/string:523:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__functional_base:22:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/exception:83:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/cstdlib:85:
/nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/stdlib.h:148:34: error: unknown type name 'ldiv_t'
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
^
/nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/stdlib.h:149:12: error: no member named 'ldiv' in the global namespace
return ::ldiv(__x, __y);
~~^
/nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/stdlib.h:152:34: error: unknown type name 'lldiv_t'
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
^
/nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/stdlib.h:154:12: error: no member named 'lldiv' in the global namespace
return ::lldiv(__x, __y);
~~^
In file included from <stdin>:1:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/string:523:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__functional_base:23:
/nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/new:327:11: error: no member named 'posix_memalign' in the global namespace
(void)::posix_memalign(&__result, __alignment, __size);
~~^
/nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/new:338:5: error: no type named 'free' in the global namespace
::free(__ptr);
~~^
In file included from <stdin>:1:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/string:523:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__functional_base:26:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/utility:236:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/compare:144:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__compare/compare_partial_order_fallback.h:13:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__compare/partial_order.h:14:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__compare/weak_order.h:14:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__compare/strong_order.h:18:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/cmath:308:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/math.h:300:
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:39:12: error: no member named 'acos' in namespace 'std'
using std::acos;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:40:12: error: no member named 'asin' in namespace 'std'
using std::asin;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:41:12: error: no member named 'atan' in namespace 'std'
using std::atan;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:42:12: error: no member named 'atan2' in namespace 'std'
using std::atan2;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:43:12: error: no member named 'cos' in namespace 'std'; did you mean 'ios'?
using std::cos;
~~~~~^
/nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/iosfwd:161:38: note: 'ios' declared here
typedef basic_ios<char> ios;
^
In file included from <stdin>:1:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/string:523:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__functional_base:26:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/utility:236:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/compare:144:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__compare/compare_partial_order_fallback.h:13:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__compare/partial_order.h:14:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__compare/weak_order.h:14:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/__compare/strong_order.h:18:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/cmath:308:
In file included from /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1/math.h:300:
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:44:12: error: no member named 'sin' in namespace 'std'
using std::sin;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:45:12: error: no member named 'tan' in namespace 'std'
using std::tan;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:46:12: error: no member named 'cosh' in namespace 'std'
using std::cosh;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:47:12: error: no member named 'sinh' in namespace 'std'
using std::sinh;
~~~~~^
/nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/math.h:48:12: error: no member named 'tanh' in namespace 'std'
using std::tanh;
~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
The Fix
Passing in --std=libc++ inhibits clang from adding the gcc libstdc++ header directories to the search path and fixes this error:
nix-shell -p llvmPackages_14.libcxxStdenv.cc --run "echo '#include <string>' | clang++ -c -xc++ - --stdlib=libc++" --pureRunning with -v lets us compare the list of search directories:
clang++ -c -xc++ - -v:#include "..." search starts here: #include <...> search starts here: /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include /nix/store/azb7l7hzicncdyz1phnjwy0pjb97ikjl-libcxxabi-14.0.1-dev/include /nix/store/870xakmqvll2paqgn0s2x959wkxd02jm-compiler-rt-libc-14.0.1-dev/include /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1 /nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0 /nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/x86_64-unknown-linux-gnu /nix/store/2lr0fc0ak8rwj0k8n3shcyz1hz63wzma-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../include/c++/11.3.0/backward /nix/store/n93g9kfx1sy6mpiy4z7hzjyf9r7qn9jz-clang-wrapper-14.0.1/resource-root/include /nix/store/k3d8wqlsnmm5270zd19cbs26g7wifxj6-glibc-2.34-210-dev/includeclang++ -c -xc++ - --stdlib=libc++ -v:#include "..." search starts here: #include <...> search starts here: /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include /nix/store/azb7l7hzicncdyz1phnjwy0pjb97ikjl-libcxxabi-14.0.1-dev/include /nix/store/870xakmqvll2paqgn0s2x959wkxd02jm-compiler-rt-libc-14.0.1-dev/include /nix/store/rd7zvb5ic6agrsfkp06w3bahflzb35vg-libcxx-14.0.1-dev/include/c++/v1 /nix/store/n93g9kfx1sy6mpiy4z7hzjyf9r7qn9jz-clang-wrapper-14.0.1/resource-root/include /nix/store/k3d8wqlsnmm5270zd19cbs26g7wifxj6-glibc-2.34-210-dev/include
This (i.e. adding echo "-stdlib=libc++" >> $out/nix-support/libcxx-cxxflags here) seems like an uncontroversial change to me but I thought I'd open an issue about this first just in case I'm missing something obvious or just not using the wrapper compiler correctly.
Notify maintainers
CODEOWNERS for cc-wrapper points to @Ericson2314; apologies if this is incorrect.
Metadata
[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
- host os: `Linux 5.15.63, NixOS, 22.11 (Raccoon), 22.11.20220901.2da64a8`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.11.0`
- nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`Metadata
Metadata
Assignees
Labels
Projects
Status