Bug 48176 - [4.6/4.7 Regression] .debug_aranges is no longer emitted
Summary: [4.6/4.7 Regression] .debug_aranges is no longer emitted
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-18 05:26 UTC by Jan Kratochvil
Modified: 2011-03-18 19:11 UTC (History)
3 users (show)

See Also:
Host:
Target: x86_64-unknown-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-03-18 09:01:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Kratochvil 2011-03-18 05:26:41 UTC
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).
Comment 1 Andrew Pinski 2011-03-18 06:17:20 UTC
Hmm, maybe because the section would be empty, see PR 42288.
Comment 2 Jan Kratochvil 2011-03-18 06:41:12 UTC
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
Comment 3 Richard Biener 2011-03-18 08:38:39 UTC
elfutils should be more forgiving
Comment 4 Jakub Jelinek 2011-03-18 08:43:35 UTC
See PR46704.
Comment 5 Jakub Jelinek 2011-03-18 09:00:59 UTC
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.
Comment 6 Jakub Jelinek 2011-03-18 09:08:41 UTC
And the PR42288 variant would be 
  if (info_section_emitted)
    {
      switch_to_section (debug_aranges_section);
      output_aranges ();
    }
Comment 7 Jakub Jelinek 2011-03-18 09:20:37 UTC
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).
Comment 8 Jakub Jelinek 2011-03-18 09:32:13 UTC
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.
Comment 9 Eric Botcazou 2011-03-18 09:34:48 UTC
> 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.
Comment 10 Jakub Jelinek 2011-03-18 09:45:45 UTC
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.
Comment 11 Eric Botcazou 2011-03-18 09:51:26 UTC
> 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?
Comment 12 Jakub Jelinek 2011-03-18 09:56:33 UTC
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.
Comment 13 Eric Botcazou 2011-03-18 10:05:32 UTC
> 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.
Comment 14 Jakub Jelinek 2011-03-18 16:18:12 UTC
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
Comment 15 Jakub Jelinek 2011-03-18 16:22:10 UTC
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
Comment 16 Jakub Jelinek 2011-03-18 19:11:54 UTC
Fixed.