Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider emitting DWARF aranges #45246

Closed
cuviper opened this issue Oct 12, 2017 · 5 comments · Fixed by #66532
Closed

Consider emitting DWARF aranges #45246

cuviper opened this issue Oct 12, 2017 · 5 comments · Fixed by #66532
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cuviper
Copy link
Member

cuviper commented Oct 12, 2017

I recently discovered that the elfutils eu-addr2line doesn't resolve locations for Rust functions. It turns out that they are expecting .debug_aranges to be valid and complete, and even treat its absence as if there are no addresses covered at all. But rustc doesn't emit aranges with its debuginfo, or at least not by default.

If you see a .debug_aranges section in your rust binaries today, that's probably only from objects compiled by GCC, like jemalloc. Try eu-readelf -waranges to see what CUs and symbols are covered. Thus even when .debug_aranges does exist, it's not necessarily complete.

Clang doesn't emit aranges by default either, but it does have the -gdwarf-aranges option to do so. This turns into the LLVM option -generate-arange-section. So it turns out that Rust can have aranges too, using rustc -Cllvm-args=-generate-arange-section. Great!

It would be nice if this were the default though. The data is usually not very big, but it can let tools map an address to the right CU very quickly, reducing the slower DIE traversals.

@nagisa nagisa added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 13, 2017
@TimNN TimNN added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Oct 17, 2017
Centril added a commit to Centril/rust that referenced this issue Nov 20, 2019
…rister

Generate DWARF address ranges for faster lookups

This adds a new option `-Zgenerate-arange-section`, enabled by default,
corresponding to LLVM's `-generate-arange-section`. This creates a
`.debug_aranges` section with DWARF address ranges, which some tools
depend on to optimize address lookups (elfutils [22288], [25173]).

This only has effect when debuginfo is enabled, and the additional data
is small compared to the other debug sections. For example, libstd.so
with full debuginfo is about 11MB, with just 61kB in aranges.

[22288]: https://sourceware.org/bugzilla/show_bug.cgi?id=22288
[25173]: https://sourceware.org/bugzilla/show_bug.cgi?id=25173

Closes rust-lang#45246.
r? @michaelwoerister
@bors bors closed this as completed in a5d624d Nov 20, 2019
@dwblaikie
Copy link

Hey folks - I'm the one who turned off aranges by default in clang some time ago & I'd generally like to see less use of aranges (because it takes up extra space & so far as I know, provides little benefit)

The data is usually not very big,

Under what conditions/situations are you assessing that? In object files, the relocations for aranges can be quite significant - especially compared to the more compact rnglist encoding in use in DWARFv5 and if using Split DWARF (since the aranges don't have the more dense rnglist encoding - and there's not much other DWARF in the .o/executable file, so aranges take up quite a bit more space)

(i'll gather some data on this & follow up)

but it can let tools map an address to the right CU very quickly, reducing the slower DIE traversals.

Do you have pointers to tools that perform significantlty better (& data/numbers would be great too) on debug info with aranges compared to debug info without aranges?

I generally don't understand/haven't seen a concrete example of where aranges help compared to reading CU level ranges from the CU DIEs - parsing only the root DIEs in CUs isn't super expensive and contains all the address data you'd find in aranges (well, it doesn't include non-code addresses (global variables) - but GCC doesn't put those in aranges anyway, so most tools probably aren't expecting to find/use those there anyway)

@dwblaikie
Copy link

(oh, seems it was Eric who turned them off - but I /think/ it was based on conversations he and I were having around that time: llvm/llvm-project@02dbadb )

@dwblaikie
Copy link

Aranges doesn't take up a lot of space, admittedly, even in the worst case I can think of:
Clang self-host, -O0, -gz, -gsplit-dwarf, object files (so, including relocations): 22.2% growth of debug info (.debug_* and .rela.debug_* sections) - which is pretty significant.
An optimized build: 4.8% growth

Linked (but uncompressed - happens to be what data I have/how we use debug info at Google by default) size:
-O0: 18.5% increase in debug info size
-O3: 3.98% increase in debug info size

@cuviper
Copy link
Member Author

cuviper commented Nov 9, 2021

Hi @dwblaikie! I don't have much context in my head anymore about size or performance, but my concern at the time was mostly about making sure elfutils works with Rust binaries, per their bug 22288 linked above. Even if you never use the elfutils command-line tools that mimic binutils, the libraries are still commonly used by tools like perf. If I could get you interested in that angle, I'm sure it would be nice to have gcc/clang/rustc all on the same page with appropriate tool support.

@dwblaikie
Copy link

Contributing to elfutils is a bit outside my wheelhouse (myself/my employer have no use of them in the areas I support) - though happy to provide guidance/advice.

goes to test eu-addr2line Yeah, I guess, by the looks of it, eu-addr2line just flat-out assumes .debug_aranges is present and complete? That seems wrong. It's not required by the DWARF spec (insofar as the DWARF spec requires anything) - as speculated on that bug, it'd be suitable for eu-addr2line to walk the CUs and skip any that are covered by .debug_aranges, but those that aren't covered should be parsed (a short parse to just collect ranges from the root CU DIE should be adequate for most cases - though some producers might not even include that, so a fully general implementation would, in the absence of CU address ranges, go and check child DIEs too)

Looks like binutils addr2line and llvm's llvm-symbolizer handle this OK - seems like an outright bug in eu-addr2line that should be fixed there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants