NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.19k stars 14.19k forks source link

debug symbols (`enableDebugging` and `separateDebugInfo`) broken on darwin #207816

Open patryk4815 opened 1 year ago

patryk4815 commented 1 year ago

Describe the bug

environment.enableDebugInfo Or separateDebugInfo Or enableDebugging Not working as excepted. It should produce "package" with debug symbols.

The macOS linker doesn't link debug information into the final binary the way linkers usually do on other Unixen. Rather it leaves the debug information in the .o files and writes a "debug map" into the binary that tells the debugger how to find and link up the debug info read from the .o files. The debug map is stripped when you strip your binary.

Steps To Reproduce

Steps to reproduce the behavior:

$ nix-build -E 'with import <nixpkgs> {}; hello.overrideAttrs (old: { separateDebugInfo = true; })' --no-out-link --keep-failed;

post-installation fixup
gzipping man pages under /nix/store/jz7f3bwrqc5m02a05f5xkd1sixc5w1a0-hello-2.12.1/share/man/
strip is /nix/store/fb4rdxr69sy1vsi98z3njxjzdq3rj3ah-clang-wrapper-11.1.0/bin/strip
stripping (with command strip and flags -S) in  /nix/store/jz7f3bwrqc5m02a05f5xkd1sixc5w1a0-hello-2.12.1/bin
patching script interpreter paths in /nix/store/jz7f3bwrqc5m02a05f5xkd1sixc5w1a0-hello-2.12.1
/nix/store/jz7f3bwrqc5m02a05f5xkd1sixc5w1a0-hello-2.12.1

$ nm -pa /nix/store/jz7f3bwrqc5m02a05f5xkd1sixc5w1a0-hello-2.12.1/bin/hello | grep OSO
//empty

^ debug dir is not created. And debug map is missing.

$ nix-build -E 'with import <nixpkgs> {}; enableDebugging hello'
make[2]: Leaving directory '/private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1'
make[1]: Leaving directory '/private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1'
post-installation fixup
gzipping man pages under /nix/store/dfl5gqgkksg4n8xlxckn3lra4ag8bjg0-hello-2.12.1/share/man/
patching script interpreter paths in /nix/store/dfl5gqgkksg4n8xlxckn3lra4ag8bjg0-hello-2.12.1
/nix/store/dfl5gqgkksg4n8xlxckn3lra4ag8bjg0-hello-2.12.1

$ nm -pa /nix/store/dfl5gqgkksg4n8xlxckn3lra4ag8bjg0-hello-2.12.1/bin/hello | grep OSO                                                                                                          
0000000063a9521c - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/src/hello.o
0000000063a9521c - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(c-strcasecmp.o)
0000000063a9521d - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(close-stream.o)
0000000063a9521d - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(closeout.o)
0000000063a9521d - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(exitfail.o)
0000000063a9521d - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(localcharset.o)
0000000063a9521d - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(progname.o)
0000000063a9521e - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(propername.o)
0000000063a9521e - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(quotearg.o)
0000000063a9521e - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(version-etc.o)
0000000063a9521e - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(version-etc-fsf.o)
0000000063a9521f - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(xmalloc.o)
0000000063a9521f - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(xalloc-die.o)
0000000063a9521f - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(error.o)
0000000063a9521f - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(fpending.o)
0000000063a9521f - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(getopt.o)
0000000063a9521f - 00 0001   OSO /private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/./lib/libhello.a(getopt1.o)

^ debug map was created, but debug symbols missing, because they are in .o files (/private/tmp/nix-build-hello-2.12.1.drv-0/hello-2.12.1/ was removed after build)

Expected behavior

a) Lets disable support for darwin in enableDebugging / separateDebugInfo / enableDebugInfo (and throw exception) b) enableDebugging:

c) separateDebugInfo - don't know if it will work

Notify maintainers

@NixOS/darwin-maintainers

veprbl commented 1 year ago

See also #203380

nixos-discourse commented 1 year ago

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/single-cmakebuildtype-shared-between-derivation-and-dependency/35184/3

n8henrie commented 3 months ago

For rust, one can specify RUSTFLAGS='-C split-debuginfo=packed' and the debug information is then put into a .dSYM directory that can easily be included in $out and seems to work.

https://github.com/NixOS/nixpkgs/issues/262131