Describe the bug
When using llvmPackages.clangUseLLVM to compile, the linker cannot find libunwind.so.
Steps To Reproduce
Steps to reproduce the behavior:
$ echo "int main() { }" > a.c
$ nix shell nixpkgs#llvmPackages.clangUseLLVM -c clang /tmp/a.c
/nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld: cannot find -l:libunwind.so: No such file or directory
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
Expected behavior
The linker should be able to find libunwind and compile successfully.
Additional context
Run with NIX_DEBUG=1 gives the following:
$ NIX_DEBUG=1 nix shell nixpkgs#llvmPackages.clangUseLLVM -c clang a.c
HARDENING: disabled flags: pie pic format stackprotector fortify strictoverflow
extra flags before to /nix/store/39yzdj9a7l8aw317l8la4kp6aalczsq7-clang-11.1.0/bin/clang:
-Wl\,-dynamic-linker=/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/ld-linux-x86-64.so.2
-target
x86_64-unknown-linux-gnu
original flags to /nix/store/39yzdj9a7l8aw317l8la4kp6aalczsq7-clang-11.1.0/bin/clang:
a.c
extra flags after to /nix/store/39yzdj9a7l8aw317l8la4kp6aalczsq7-clang-11.1.0/bin/clang:
-B/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/
-idirafter
/nix/store/4pqv2mwdn88h7xvsm7a5zplrd8sxzvw0-glibc-2.35-163-dev/include
--gcc-toolchain=/nix/store/1gf2flfqnpqbr1b4p4qz2f72y42bs56r-gcc-11.3.0
-B/nix/store/fbc6m1s0638pf3vk5wgmcsbap8f04nar-clang-11.1.0-lib/lib
-rtlib=compiler-rt
-Wno-unused-command-line-argument
-B/nix/store/lkckixdqkvwscdr5jf0v07w77lhlm70f-compiler-rt-libc-11.1.0/lib
--unwindlib=libunwind
-resource-dir=/nix/store/6bmyzky9i7rd2dp3lxc47rlabrhcl46y-clang-wrapper-11.1.0/resource-root
-B
/nix/store/6bmyzky9i7rd2dp3lxc47rlabrhcl46y-clang-wrapper-11.1.0/resource-root/lib
-B/nix/store/6bmyzky9i7rd2dp3lxc47rlabrhcl46y-clang-wrapper-11.1.0/bin/
-L/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib
-L/nix/store/fbc6m1s0638pf3vk5wgmcsbap8f04nar-clang-11.1.0-lib/lib
HARDENING: disabled flags: relro pie bindnow
extra flags before to /nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld:
''
original flags to /nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld:
--eh-frame-hdr
-m
elf_x86_64
-o
a.out
/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/crt1.o
/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/crti.o
/nix/store/6bmyzky9i7rd2dp3lxc47rlabrhcl46y-clang-wrapper-11.1.0/resource-root/lib/linux/clang_rt.crtbegin-x86_64.o
-L/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib
-L/nix/store/fbc6m1s0638pf3vk5wgmcsbap8f04nar-clang-11.1.0-lib/lib
-L/nix/store/1gf2flfqnpqbr1b4p4qz2f72y42bs56r-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0
-L/nix/store/1gf2flfqnpqbr1b4p4qz2f72y42bs56r-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../lib64
-L/nix/store/1gf2flfqnpqbr1b4p4qz2f72y42bs56r-gcc-11.3.0/lib64/gcc/x86_64-unknown-linux-gnu/11.3.0/../../..
-dynamic-linker=/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/ld-linux-x86-64.so.2
/tmp/a-804f0d.o
/nix/store/6bmyzky9i7rd2dp3lxc47rlabrhcl46y-clang-wrapper-11.1.0/resource-root/lib/linux/libclang_rt.builtins-x86_64.a
--as-needed
-l:libunwind.so
--no-as-needed
-lc
/nix/store/6bmyzky9i7rd2dp3lxc47rlabrhcl46y-clang-wrapper-11.1.0/resource-root/lib/linux/libclang_rt.builtins-x86_64.a
--as-needed
-l:libunwind.so
--no-as-needed
/nix/store/6bmyzky9i7rd2dp3lxc47rlabrhcl46y-clang-wrapper-11.1.0/resource-root/lib/linux/clang_rt.crtend-x86_64.o
/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib/crtn.o
extra flags after to /nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld:
-rpath
/nix/store/4nlgxhb09sdr51nc9hdm8az5b08vzkgx-glibc-2.35-163/lib
/nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld: cannot find -l:libunwind.so: No such file or directory
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
It is clear that the path of libunwind is not added to search path. Maybe we should add -L${targetLlvmLibraries.libunwind}/lib in nixSupport.cc-cflags.
|
clangUseLLVM = wrapCCWith rec { |
|
cc = tools.clang-unwrapped; |
|
libcxx = targetLlvmLibraries.libcxx; |
|
bintools = bintools'; |
|
extraPackages = [ |
|
targetLlvmLibraries.libcxxabi |
|
targetLlvmLibraries.compiler-rt |
|
] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ |
|
targetLlvmLibraries.libunwind |
|
]; |
|
extraBuildCommands = mkExtraBuildCommands cc; |
|
nixSupport.cc-cflags = |
|
[ "-rtlib=compiler-rt" |
|
"-Wno-unused-command-line-argument" |
|
"-B${targetLlvmLibraries.compiler-rt}/lib" |
|
] |
|
++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" |
|
++ lib.optional |
|
(!stdenv.targetPlatform.isWasm && !stdenv.targetPlatform.isFreeBSD && stdenv.targetPlatform.useLLVM or false) |
|
"-lunwind" |
|
++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; |
|
}; |
Notify maintainers
@Ericson2314 @primeos
Metadata
- system:
"x86_64-linux"
- host os:
Linux 6.0.8, NixOS, 22.11 (Raccoon), 22.11pre-git
- multi-user?:
yes
- sandbox:
yes
- version:
nix-env (Nix) 2.11.0
- channels(root):
"nixos-22.05"
- channels(sharzy):
"nixos, nixpkgs"
- nixpkgs:
/home/sharzy/.nix-defexpr/channels/nixpkgs
Describe the bug
When using
llvmPackages.clangUseLLVMto compile, the linker cannot find libunwind.so.Steps To Reproduce
Steps to reproduce the behavior:
Expected behavior
The linker should be able to find libunwind and compile successfully.
Additional context
Run with
NIX_DEBUG=1gives the following:It is clear that the path of libunwind is not added to search path. Maybe we should add
-L${targetLlvmLibraries.libunwind}/libinnixSupport.cc-cflags.nixpkgs/pkgs/development/compilers/llvm/git/default.nix
Lines 151 to 172 in 3a86856
Notify maintainers
@Ericson2314 @primeos
Metadata
"x86_64-linux"Linux 6.0.8, NixOS, 22.11 (Raccoon), 22.11pre-gityesyesnix-env (Nix) 2.11.0"nixos-22.05""nixos, nixpkgs"/home/sharzy/.nix-defexpr/channels/nixpkgs