NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.67k stars 13.12k forks source link

Build failure: pkgsLLVM.busybox #314111

Open RossComputerGuy opened 2 months ago

RossComputerGuy commented 2 months ago

Steps To Reproduce

Steps to reproduce the behavior:

  1. build pkgsLLVM.busybox

Build log

build flags: -j80 SHELL=/nix/store/1fzg4cl3k2n9yq80vg6y1vcmvx3qm682-bash-5.2p26/bin/bash SKIP_STRIP=y
applets/usage.c: In function 'main':
applets/usage.c:52:17: warning: ignoring return value of 'write' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |                 write(STDOUT_FILENO, usage_array[i].usage, strlen(usage_array[i].usage) + 1);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clang: warning: optimization flag '-finline-limit=0' is not supported [-Wignored-optimization-argument]
clang: warning: optimization flag '-falign-jumps=1' is not supported [-Wignored-optimization-argument]
clang: warning: optimization flag '-falign-labels=1' is not supported [-Wignored-optimization-argument]
aarch64-unknown-linux-gnu-ld: error: attempted static link of dynamic object /nix/store/2aqakjqjfj5kw644kkmyf3l30hk0x0rf-libunwind-aarch64-unknown-linux-gnu-17.0.6/lib/libunwind.so
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [scripts/Makefile.build:264: applets/built-in.o] Error 1
make: *** [Makefile:372: applets_dir] Error 2

Additional context

Add any other context about the problem here.

Notify maintainers

@TethysSvensson @alyssais

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"aarch64-linux"`
 - host os: `Linux 5.15.156, NixOS, 24.05 (Uakari), 24.05.20240418.bc279bb`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.2`
 - nixpkgs: `/run/current-system/nixpkgs`

Add a :+1: reaction to issues you find important.

pwaller commented 1 month ago

This looks to me like the compiler wrapper isn't respecting -r and/or -nostdlib, and it's inappropriately passing the libunwind shared object. I don't have immediate time to investigate further but did discover this minimal reproducer:

$ nix shell nixpkgs/57d6973abba7ea108bac64ae7629e7431e0199b6#pkgsLLVM.stdenv.cc
$ touch test.c
$ x86_64-unknown-linux-gnu-cc -nostdlib -r -o test.o test.c
x86_64-unknown-linux-gnu-ld: error: attempted static link of dynamic object /nix/store/k3l71w9p5wcbzh0fqcjg0svbap8xla4g-libunwind-x86_64-unknown-linux-gnu-17.0.6/lib/libunwind.so
clang: error: linker command failed with exit code 1 (use -v to see invocation)
paparodeo commented 1 month ago

looks the same as https://github.com/NixOS/nixpkgs/issues/317526 which is due to https://github.com/llvm/llvm-project/issues/94958 (search path prefers .so files with -r). i agree that passing in libunwind unconditionally seems not good.

if one builds libcxx with LLVM_ENABLE_RUNTIMES=libcxx;libcxxabi;libunwind the linker script at libc++.so will result in INPUT(libc++.so.1 -lc++abi -lunwind) but we don't so we add -lunwind unconditionally. it is not clear to me why c code needs libunwind.