echo 'main(){}' | gcc -x c - -g; readelf -WS a.out | grep debug_aranges PASS - exists - gcc (GCC) 4.5.3 20110318 (prerelease) FAIL - does not exist - gcc (GCC) 4.7.0 20110318 (experimental) elfutils relies on it: https://bugzilla.redhat.com/show_bug.cgi?id=688532 Although GDB has never relied on it so there was a suggestion it could be dropped in the favor of .gdb_index (generated and used by GDB itself).
Hmm, maybe because the section would be empty, see PR 42288.
PR 42288 was for GDB and it can be closed I think. I do not see why .debug_aranges would be empty - it contains valid information with gcc-4.5 and even non-trivial such as with multiple CUs: echo 'f(){}' | gcc -x c - -o 1.o -c -g; echo 'main(){}' | gcc 1.o -x c - -g; readelf -WS a.out | grep debug_aranges
elfutils should be more forgiving
See PR46704.
I believe Eric's change was wrong actually, .debug_aranges section has useful content even when !arange_table_in_use. In particular, it describes .text and .text.unlikely sections. So IMHO we want: --- gcc/dwarf2out.c2011-03-17 12:54:51.000000000 +0100 +++ gcc/dwarf2out.c2011-03-18 09:58:06.010366417 +0100 @@ -23664,7 +23664,7 @@ dwarf2out_finish (const char *filename) /* Output the address range information. We only put functions in the arange table, so don't write it out if we don't have any. */ - if (arange_table_in_use) + if (arange_table_in_use || text_section_used || cold_text_section_used) { switch_to_section (debug_aranges_section); output_aranges (); I assume .debug_aranges isn't useful when no code has been emitted and after all, we haven't been emitting it before either. I'm unsure when exactly would be fde_table_in_use different from arange_table_in_use || text_section_used || cold_text_section_used though.
And the PR42288 variant would be if (info_section_emitted) { switch_to_section (debug_aranges_section); output_aranges (); }
I've tried a-charac.ads and fde_table_in_use is 0 in that case, so I wonder how the PR46704 patch could stop emitting .debug_aranges in that case (unless there was some bug that has been fixed since then).
If we want to be extra safe (and for 4.6 we need to be), I think if (fde_table_in_use && info_section_emitted) or if ((arange_table_in_use || text_section_used || cold_text_section_used) && info_section_emitted) are the conditions to use. I think I prefer the latter, which is more explicit on what it is testing, in particular output only if there will be any aranges within the section actually emitted, and when there is a .Ldebug_info0 to point the aranges to.
> I've tried a-charac.ads and fde_table_in_use is 0 in that case, so I wonder how > the PR46704 patch could stop emitting .debug_aranges in that case (unless there > was some bug that has been fixed since then). You need to compile with -fkeep-inline-functions.
Thanks, I see. fde_table_in_use is 2 then, arange_table_in_use is 0, text_section_used 0 and cold_text_section_used 0. So, the #c5 and both #c8 alternatives would fix this issue and not reintroduce the problem with a-charac.ads -O2 -g -fkeep-inline-functions. The only two functions in that CU are DECL_IGNORED, so begin_function debug hook isn't called for them, just begin_prologue, and as the CU is empty (DECL_IGNORED function are ignored for debug info) .debug_info isn't emitted either.
> Thanks, I see. fde_table_in_use is 2 then, arange_table_in_use is 0, > text_section_used 0 and cold_text_section_used 0. So, the #c5 and both #c8 > alternatives would fix this issue and not reintroduce the problem with > a-charac.ads -O2 -g -fkeep-inline-functions. What about testing ranges_by_label_in_use instead?
That is related to .debug_ranges, not .debug_aranges. E.g. in the int main () { return 0; } case ranges_by_label_in_use is 0, not surprisingly, we don't emit .debug_ranges in that case. .debug_ranges is only needed if some function or lexical block or inlined function doesn't have a single range, but multiple ones.
> That is related to .debug_ranges, not .debug_aranges. Ah, OK. Your solution: (arange_table_in_use || text_section_used || cold_text_section_used) seems indeed to be the best one, you might even want to write it as: (text_section_used || cold_text_section_used || arange_table_in_use) to match the layout of output_aranges. Thanks for debugging this.
Author: jakub Date: Fri Mar 18 16:18:05 2011 New Revision: 171150 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171150 Log: PR debug/48176 * dwarf2out.c (dwarf2out_finish): Call output_aranges even when arange_table_in_use is 0, but either text_section_used or cold_text_section_used is true. Don't call it if !info_section_emitted. Modified: trunk/gcc/ChangeLog trunk/gcc/dwarf2out.c
Author: jakub Date: Fri Mar 18 16:22:01 2011 New Revision: 171151 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=171151 Log: PR debug/48176 * dwarf2out.c (dwarf2out_finish): Call output_aranges even when arange_table_in_use is 0, but either text_section_used or cold_text_section_used is true. Don't call it if !info_section_emitted. Modified: branches/gcc-4_6-branch/gcc/ChangeLog branches/gcc-4_6-branch/gcc/dwarf2out.c
Fixed.