Open Atry opened 2 years ago
confirmed. nix-support/cc-ldflags
is being set incorrectly somewhere in https://github.com/NixOS/nixpkgs/tree/master/pkgs/build-support/cc-wrapper. I've been digging around a lot in there recently and would be happy to fix it, unless you want to take a crack!
this should do the trick: https://github.com/NixOS/nixpkgs/pull/193355. I am a little worried about cross compilation, but will check that out.
I need to build it locally, so should know by the end of the day
Here is the section of the builder that are moving the sanitizer and C++ standard library shared objects into place:
It might be the case that this should be fixed in GCC rather than the compiler wrapper. I don't have a good enough understanding of the cross compilation infrastructure to make that call.
So this does seem like an issue with where the native gcc is moving these shared objects. Here is an environment which uses clang to cross compile for 64 bit arm:
{ nixpkgs ? <nixpkgs>
, pkgs ? (import nixpkgs {}).pkgsCross.aarch64-multiplatform
}:
( pkgs.mkShell.override { stdenv = pkgs.llvmPackages_latest.stdenv;} )
{}
In this environment, we have
$ cat cc-ldflags
-L/nix/store/2ywip1q8w21m0rxx7vhdjawy902vqsdf-aarch64-unknown-linux-gnu-stage-final-gcc-debug-9.3.0/lib/gcc/aarch64-unknown-linux-gnu/9.3.0
-L/nix/store/b0qsfcpsppz6wkipjh8wzncnnwxyg6ib-aarch64-unknown-linux-gnu-stage-final-gcc-debug-9.3.0-lib/aarch64-unknown-linux-gnu/lib
-L/nix/store/awzsfm1gkh9cwrynjl0z98ydxjhm3kzg-clang-13.0.1-lib/aarch64-unknown-linux-gnu/lib
and that second path is populated with the expected shared library files. In this case, that third path is missing and /nix/store/awzsfm1gkh9cwrynjl0z98ydxjhm3kzg-clang-13.0.1-lib/lib
is filled with x86-64
files.
This example is kind of contrived, since you probably are going to be using static libs for cross compiling
Also, for this environment, the C++ standard library headers are missing, so it can't compile programs using the C++ standard lib anyway, but that is another issue.
Describe the bug
clang++ should not statically link with the standard C++ library by default
Steps To Reproduce
Steps to reproduce the behavior:
Expected behavior
clang++ should dynamically link with the standard C++ library by default. For example, on Debian the program is linked with GLIBCXX_3.4 by default:
Additional context
nix-support/cc-ldflags
in theclang-wrapper
now includes a non-existing path:As a result, clang++ cannot find
libstdc++.so
from search path.As a workaround, you can add
gcc-unwrapped.lib
to library search path:Now the program is dynamically linked with the standard C++ library
Notify maintainers
@primeos @dtzWill @7c6f434c @lovek323
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result.