Skip to content

root: separateDebugInfo = true#216864

Merged
symphorien merged 2 commits intoNixOS:masterfrom
ShamrockLee:root-debug-info
Mar 5, 2023
Merged

root: separateDebugInfo = true#216864
symphorien merged 2 commits intoNixOS:masterfrom
ShamrockLee:root-debug-info

Conversation

@ShamrockLee
Copy link
Contributor

@ShamrockLee ShamrockLee commented Feb 17, 2023

Description of changes

Build CERN ROOT with separateDebugInfo = true for easier debugging.

As a data analysis framework, users spend most of the time debugging their C++ analysis code, and errors like Segmentation Violation occur in various situations ranging from going out of bound to file missing due to network error. A call-stack error message with line numbers provides real help.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.05 Release Notes (or backporting 22.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@ShamrockLee ShamrockLee changed the title root: -DCMAKE_BUILD_TYPE=RelWithDebInfo root: cmakeBuildType = "RelWithDebInfo" Feb 17, 2023
@ShamrockLee ShamrockLee marked this pull request as draft February 17, 2023 21:21
@ShamrockLee ShamrockLee marked this pull request as ready for review February 17, 2023 21:26
@ofborg ofborg bot requested a review from veprbl February 17, 2023 22:10
@ofborg ofborg bot added 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Feb 17, 2023
@veprbl
Copy link
Member

veprbl commented Feb 17, 2023

Makes sense, but how much closure space do we have to pay for this?

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 17, 2023

The package size and the closure size grow smaller, which is somewhat strange.

nixpkgs_timeshift on  root-debug-info [$] took 4s
❯ nix path-info -S .#root
/nix/store/ddvxws306q93i377l1s77hfy59hxnj6z-root-6.26.10	1616296880

nixpkgs_timeshift on  root-debug-info [$]
❯ nix path-info -S .?ref=origin/master#root
/nix/store/yscknw8l89m6xv46j4ff0mr7786fv22m-root-6.26.10	1623110720

nixpkgs_timeshift on  root-debug-info [$]
❯ nix path-info -s .#root
/nix/store/ddvxws306q93i377l1s77hfy59hxnj6z-root-6.26.10	 438663432

nixpkgs_timeshift on  root-debug-info [$]
❯ nix path-info -s .?ref=origin/master#root
/nix/store/yscknw8l89m6xv46j4ff0mr7786fv22m-root-6.26.10	 445477272

Update: Just compared the outputs with Meld, and the files are all there, plus two new files:

  • /nix/store/ddvxws306q93i377l1s77hfy59hxnj6z-root-6.26.10/lib/libCore.so-gdb.py
  • /nix/store/ddvxws306q93i377l1s77hfy59hxnj6z-root-6.26.10/lib/libRooFitCore.so-gdb.py

@ShamrockLee
Copy link
Contributor Author

Result of nixpkgs-review run on x86_64-linux 1

1 package failed to build:
  • python311Packages.hepmc3
5 packages built:
  • hepmc3
  • python310Packages.hepmc3
  • root
  • xfitter
  • yoda-with-root

@ShamrockLee
Copy link
Contributor Author

I'm afraid that the debug information has got stripped away. I saw the strip running during the fixUp phase from OfBorg's build log.

Should we use dontStrip to prevent stripping as a whole or set separateDebugInfo = true and add the "debug" output to store the debug information separately?

@veprbl
Copy link
Member

veprbl commented Feb 19, 2023

The separateDebugInfo wouldn't work for builtin stack traces?

@ShamrockLee
Copy link
Contributor Author

The separateDebugInfo wouldn't work for builtin stack traces?

At least I don't know how to make it work.

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 20, 2023

The debug information occupies ~500MB when separated, but we get ~1.5GB size increasing when not splitted. The size of the ROOT derivation without the debug information is ~500MB.

The size increasing directly reflects on the closure size. It simply doubles (from 1.6GB to 3.1GB) after dontStrip = true;.

nixpkgs_timeshift on  root-debug-info [$!]
❯ nix path-info -s .#root
warning: Git tree '/run/media/root/data-btrfs/shamrock-shared/targets/Projects/NixOS/nixpkgs_timeshift' is dirty
/nix/store/gvmgba5jbaqk5fqdybwnl9cql4nnydih-root-6.26.10	1909723000

nixpkgs_timeshift on  root-debug-info [$!] took 3s
❯ nix path-info -S .#root
warning: Git tree '/run/media/root/data-btrfs/shamrock-shared/targets/Projects/NixOS/nixpkgs_timeshift' is dirty
/nix/store/gvmgba5jbaqk5fqdybwnl9cql4nnydih-root-6.26.10	3132206512

nixpkgs_timeshift on  root-debug-info [$!] took 2s
❯ nix path-info -s .?ref=origin/master#root
/nix/store/yscknw8l89m6xv46j4ff0mr7786fv22m-root-6.26.10	 445477272

nixpkgs_timeshift on  root-debug-info [$!]
❯ nix path-info -S .?ref=origin/master#root
/nix/store/yscknw8l89m6xv46j4ff0mr7786fv22m-root-6.26.10	1623110720

@veprbl
Copy link
Member

veprbl commented Feb 20, 2023

The 2-4x increase would be hard to justify. Are you dealing with a large rebuild when setting up for a debug?

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 20, 2023

Just didn't know it's that large. I had thought it would be trivial 😓

I'll ask in the ROOT forum if there's a way to use the separated debug information, as it would hopefully not increase the closure size of root.out and other packages depending on it.

BTW, considering the huge size difference, is there something other than debug symbols that is normally stripped away?

Update: Here's the post in the ROOT Forum: https://root-forum.cern.ch/t/any-way-to-have-roots-builtin-stack-trace-use-seperated-debug-information/53702

@ShamrockLee ShamrockLee marked this pull request as draft February 20, 2023 19:14
@veprbl
Copy link
Member

veprbl commented Feb 22, 2023

If you provide path to separated debug info to the ROOT, that would be a reference, so the closure size won't improve.

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 22, 2023

The closure size of the root.out output built with separateDebugInfo = true shrinks 7MB. Not sure about the optimization level. The shrink of the build may result from the change of optimization strategies. RelWithDebInfo is still a kind of "release" build anyway.

The reference could be made available either through a wrapper package, say, root-debug, or with user-side configuration using home-manager configuration or nixseparatedebuginfod plus corresponding .rc settings. Users who just install the root package should experience no closure size increasing.

A ROOT developer answered in the above forum post that ROOT uses gdb to generate the stack trace. Maybe there's a way to make it show the line number in the stack trace.

Closure size comparison ``` nixpkgs_timeshift (94a5042) [$] ❯ nix path-info -s .?ref=origin/master#root /nix/store/yscknw8l89m6xv46j4ff0mr7786fv22m-root-6.26.10 445477272

nixpkgs_timeshift on  root-debug-info [$]
❯ nix path-info -S .?ref=origin/master#root
/nix/store/yscknw8l89m6xv46j4ff0mr7786fv22m-root-6.26.10 1623110720

nixpkgs_timeshift on  root-debug-info [$]
❯ nix path-info -s .#root
/nix/store/czl2bn94lbx01a1wamvyjgns0a90a7vc-root-6.26.10 438673256

nixpkgs_timeshift on  root-debug-info [$]
❯ nix path-info -S .#root
/nix/store/czl2bn94lbx01a1wamvyjgns0a90a7vc-root-6.26.10 1616306704

</details>

@ShamrockLee
Copy link
Contributor Author

Ah! Here it is:


$ NIX_DEBUG_INFO_DIRS="$(nix path-info .#root.debug)/lib/debug" nix run .#root -- -l
root [0] TFile::Open("nonexistence.root")->GetName();
Error in <TFile::TFile>: file /run/media/root/data-btrfs/shamrock-shared/targets/Projects/NixOS/nixpkgs_timeshift/nonexistence.root does not exist
#0  0x00007f0ea23a89ea in wait4 () from /nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6
#1  0x00007f0ea231a02b in do_system () from /nix/store/lqz6hmd86viw83f9qll2ip87jhb7p1ah-glibc-2.35-224/lib/libc.so.6
#2  0x00007f0ea2ae8815 in TUnixSystem::Exec (shellcmd=<optimized out>, this=0x5cd800) at /build/root-6.26.10/core/unix/src/TUnixSystem.cxx:2104
#3  TUnixSystem::StackTrace (this=0x5cd800) at /build/root-6.26.10/core/unix/src/TUnixSystem.cxx:2395
#4  0x00007f0ea0752448 in cling::MultiplexInterpreterCallbacks::PrintStackTrace (this=<optimized out>) at /build/root-6.26.10/interpreter/cling/lib/Interpreter/MultiplexInterpreterCallbacks.h:158
#5  0x00007f0ea0751cee in cling_runtime_internal_throwIfInvalidPointer (Interp=0x65f3f0, Expr=0x1d49a70, Arg=<optimized out>) at /nix/store/9pgq84sf921xh97gjj2wh7a7clrcrh4m-gcc-12.2.0/include/c++/12.2.0/bits/unique_ptr.h:191
#6  0x00007f0e9b24d083 in ?? ()
#7  0x000000009b24d000 in ?? ()
#8  0x000000000134ea28 in ?? ()
#9  0x000000000134ea30 in ?? ()
#10 0x00007f0ea0751ca0 in ?? () from /nix/store/czl2bn94lbx01a1wamvyjgns0a90a7vc-root-6.26.10/lib/libCling.so
#11 0x000000000065f3f0 in ?? ()
#12 0x00007f0ea1e27890 in ?? () at /build/root-6.26.10/io/io/src/TFile.cxx:4352 from /nix/store/czl2bn94lbx01a1wamvyjgns0a90a7vc-root-6.26.10/lib/libRIO.so
#13 0x00007ffeb30587d0 in ?? ()
#14 0x00007f0ea07be3b8 in cling::IncrementalExecutor::executeWrapper (this=<optimized out>, function=..., returnValue=returnValue
entry=0x7ffeb30587d0) at /build/root-6.26.10/interpreter/cling/lib/Interpreter/IncrementalExecutor.cpp:381
#15 0x00007f0ea0753e21 in cling::Interpreter::RunFunction (this=0x65f3f0, FD=<optimized out>, res=0x7ffeb30587d0) at /nix/store/9pgq84sf921xh97gjj2wh7a7clrcrh4m-gcc-12.2.0/include/c++/12.2.0/bits/basic_string.h:1070
#16 0x00007f0ea0757981 in cling::Interpreter::EvaluateInternal (this=0x65f3f0, input=..., CO=..., V=0x7ffeb30587d0, wrapPoint=<optimized out>) at /build/root-6.26.10/interpreter/cling/lib/Interpreter/Interpreter.cpp:1414
#17 0x00007f0ea0757bb2 in cling::Interpreter::process (this=0x65f3f0, input=..., V=V
entry=0x7ffeb30587d0, T=T
entry=0x0, disableValuePrinting=disableValuePrinting
entry=false) at /build/root-6.26.10/interpreter/cling/lib/Interpreter/Interpreter.cpp:840
#18 0x00007f0ea08021ef in cling::MetaProcessor::process (this=this
entry=0x11d3080, input_line=..., compRes=
0x7ffeb30587bc: cling::Interpreter::kSuccess, result=result
entry=0x7ffeb30587d0, disableValuePrinting=disableValuePrinting
entry=false) at /build/root-6.26.10/interpreter/cling/lib/MetaProcessor/MetaProcessor.cpp:341
#19 0x00007f0ea068c00c in HandleInterpreterException (metaProcessor=0x11d3080, input_line=0x1d438b0 "#line 1 \"ROOT_prompt_0\"\nTFile::Open(\"nonexistence.root\")->GetName();", compRes=
0x7ffeb30587bc: cling::Interpreter::kSuccess, result=0x7ffeb30587d0) at /build/root-6.26.10/core/metacling/src/TCling.cxx:2441
#20 0x00007f0ea06a6528 in TCling::ProcessLine (this=0x65e730, line=<optimized out>, error=0x7ffeb3058b7c) at /nix/store/9pgq84sf921xh97gjj2wh7a7clrcrh4m-gcc-12.2.0/include/c++/12.2.0/bits/unique_ptr.h:191
#21 0x00007f0ea2c8a586 in TRint::ProcessLineNr (this=0x624e70, filestem=0x7f0ea2c9c298 "ROOT_prompt_", line=0x1d43710 "TFile::Open(\"nonexistence.root\")->GetName();", error=0x7ffeb3058b7c) at /build/root-6.26.10/core/rint/src/TRint.cxx:792
#22 0x00007f0ea2c8a97b in TRint::HandleTermInput (this=0x624e70) at /build/root-6.26.10/core/rint/src/TRint.cxx:650
#23 0x00007f0ea2ae4c66 in TUnixSystem::CheckDescriptors (this=this
entry=0x5cd800) at /build/root-6.26.10/core/unix/src/TUnixSystem.cxx:1306
#24 0x00007f0ea2ae7f38 in TUnixSystem::DispatchOneEvent (this=0x5cd800, pendingOnly=<optimized out>) at /build/root-6.26.10/core/unix/src/TUnixSystem.cxx:1061
#25 0x00007f0ea2a082e9 in TSystem::InnerLoop (this=0x5cd800) at /build/root-6.26.10/core/base/src/TSystem.cxx:406
#26 TSystem::Run (this=0x5cd800) at /build/root-6.26.10/core/base/src/TSystem.cxx:356
#27 0x00007f0ea299de73 in TApplication::Run (this=this
entry=0x624e70, retrn=retrn
entry=false) at /build/root-6.26.10/core/base/src/TApplication.cxx:1609
#28 0x00007f0ea2c8c1d0 in TRint::Run (this=this
entry=0x624e70, retrn=retrn
entry=false) at /build/root-6.26.10/core/rint/src/TRint.cxx:501
#29 0x00000000004011bf in main (argc=<optimized out>, argv=0x7ffeb305b028) at /build/root-6.26.10/main/src/rmain.cxx:84
terminate called after throwing an instance of 'cling::InvalidDerefException'
  what():  Trying to dereference null pointer or trying to call routine taking non-null arguments

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: changelog This PR adds or changes release notes 8.has: documentation This PR adds or changes documentation labels Feb 23, 2023
@ShamrockLee ShamrockLee marked this pull request as ready for review February 23, 2023 19:11
@ShamrockLee
Copy link
Contributor Author

@veprbl Do you think it's worth it to split the executable wrapping like what I did in the second commit?
If not, I can drop that PR, and access the .debug output manually.

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 23, 2023

@ofborg build root.unwrapped.debug

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 23, 2023

@ofborg build root-unwrapped.debug

@veprbl
Copy link
Member

veprbl commented Feb 23, 2023

Building against wrapped root by default defeats the purpose of splitting the debug output. Did you mean to provide an optional wrapper?

@github-actions github-actions bot removed 8.has: documentation This PR adds or changes documentation 8.has: changelog This PR adds or changes release notes 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels Feb 23, 2023
@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 23, 2023

@veprbl Yes. It would be something like root-debug aside from 'root'.

BTW, I just observed that separateDebugInfo behaves differently on Darwin -- it doesn't even produce the .debug output like it does on Linux! Not sure how to make a wrapper under such condition.

@ShamrockLee
Copy link
Contributor Author

@ofborg build root.debug

@veprbl
Copy link
Member

veprbl commented Feb 23, 2023

BTW, I just observed that separateDebugInfo behaves differently on Darwin -- it doesn't even produce the .debug output like it does on Linux! Not sure how to make a wrapper under such condition.

Yes, it won't be possible to have that wrapper on macOS, see #203380.

@veprbl Yes. It would be something like root-debug aside from 'root'.

I don't even see a need for the wrapper. You could add a hook in nix-support into root.debug to set NIX_DEBUG_INFO_DIRS.

@ShamrockLee
Copy link
Contributor Author

ShamrockLee commented Feb 25, 2023

Alright, I'll just keep it simple and enable the debug build only on Linux.

I don't even see a need for the wrapper. You could add a hook in nix-support into root.debug to set NIX_DEBUG_INFO_DIRS.

How do I add hooks to a specific output?

BTW, loading the debug information causes the stack trace to take ~25s to show on my laptop (when testing with TFile::Open("nonexistence.root")->GetName()). It would be better to keep it optional.

@symphorien
Copy link
Member

See https://nixos.wiki/wiki/Debug_Symbols for a write up about how to use separate debug info, and https://github.com/edolstra/dwarffs and https://github.com/symphorien/nixseparatedebuginfod for third party projects that make this easier to deal with.

One of the main appeal of separate debug info is that you only download them when you use them, and in the case of root they are sizeable.

@veprbl
Copy link
Member

veprbl commented Feb 25, 2023

How do I add hooks to a specific output?

You'd probably need to hack $debug/nix-support/ yourself. I'd grep nixpkgs for ideas on how it's done.

@ShamrockLee ShamrockLee changed the title root: cmakeBuildType = "RelWithDebInfo" root: separateDebugInfo = true on Linux Mar 4, 2023
@ShamrockLee ShamrockLee requested review from symphorien and removed request for veprbl March 4, 2023 13:17
@ShamrockLee ShamrockLee changed the title root: separateDebugInfo = true on Linux root: separateDebugInfo = true Mar 4, 2023
@ofborg ofborg bot requested a review from veprbl March 4, 2023 19:43
@figsoda figsoda added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Mar 5, 2023
@symphorien symphorien merged commit 768a866 into NixOS:master Mar 5, 2023
@symphorien
Copy link
Member

thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants