Gcc 4.1/4.2 generates wrong DWARF info when it fails to inline a static function.
Testcase????
Created attachment 10877 [details] A testcase This is the preprocess Linux kernel code for gcc 4.1 and 4.2. There are many static functions, like pageout, have DWARF2 info like: <1><9aee>: Abbrev Number: 78 (DW_TAG_subprogram) DW_AT_sibling : <9bd1> DW_AT_name : (indirect string, offset: 0x44b6): pageout DW_AT_decl_file : 1 DW_AT_decl_line : 318 DW_AT_prototyped : 1 DW_AT_type : <8df5> DW_AT_inline : 1 (inlined) where pageout isn't inlined at all. Gcc 3.4.6 generates: <1><8eb1>: Abbrev Number: 84 (DW_TAG_subprogram) DW_AT_sibling : <8fe0> DW_AT_name : (indirect string, offset: 0x4182): pageout DW_AT_decl_file : 1 DW_AT_decl_line : 295 DW_AT_prototyped : 1 DW_AT_type : <84b0> DW_AT_low_pc : 0x318 DW_AT_high_pc : 0x3e4 DW_AT_frame_base : 1 byte block: 54 (DW_OP_reg4)
Next time don't attach a tar ball, please.
The debug info looks OK to me, though it is more verbose than it needs to be. I think you may be reading the debug info wrong. The entry you are looking at is the abstract origin for pageout. If you take the offset of this entry, 9aee in your case, and search for that, you will find the real debug info for pageout, which has an abstract origin attribute pointing at the 9aee entry. I get slightly different addresses, but here is what I get .uleb128 0x4e # (DIE (0x9af3) DW_TAG_subprogram) .long 0x9bd6 # DW_AT_sibling .long .LASF1677 # DW_AT_name: "pageout" .byte 0x1 # DW_AT_decl_file .value 0x13e # DW_AT_decl_line .byte 0x1 # DW_AT_prototyped .long 0x8df5 # DW_AT_type .byte 0x1 # DW_AT_inline ... .uleb128 0x3e # (DIE (0x9bd6) DW_TAG_subprogram) .long 0x9d39 # DW_AT_sibling .long 0x9af3 # DW_AT_abstract_origin .long .LFB813 # DW_AT_low_pc .long .LFE813 # DW_AT_high_pc .long .LLST34 # DW_AT_frame_base So the debug info is correct, in the sense it correctly describes the program. The debug is more verbose than it should be though, since there is no need for the abstract origin if the function was never inlined. This is due to problems with cgraph. Now that cgraph controls when and how we emit code for functions, we really need to move the debug output calls into cgraph, so that functions are finalized by cgraph before we try to emit debug info for them. There are a few other bugzilla bug reports concerning the same issue, though it may not be easy to find them. It is probably also not easy to fix this. See cgraph_function_possibly_inlined_p. What is the real bug that you are trying to report here? Are you complaining because the debug info is unnecessarily verbose? Do you have a debugger that doesn't handle this debug info correctly?
I should mention that your testcase uses -Os, and -Os enables -finline-functions-called-once. This is why the function is marked as "inline". If you don't want this feature, you can turn it off. Also, -fno-unit-at-a-time is expected to disappear at some point, so problems that only appear with this option may not be worth fixing if they are too hard to fix. Using both -finline-functions-called-once and -fno-unit-at-a-time is contradictory, so it isn't surprising there is a problem. We could try to detect that and turn one of them off, possibly with a warning.
Created attachment 10888 [details] small testcase Compile this with ./xgcc -B./ -Os -fno-unit-at-a-time -g -dA -S tmp.c -fverbose-asm and notice that we have an abstract_origin die for sub, even though it was never inlined. Also notice the -finline* options listed at the top of the .s file. These are enabled by -Os.
This problem concerns quasi-invalid debug information in an obscure compilation mode; P2.
This issue will not be resolved in GCC 4.1.0; retargeted at GCC 4.1.1.
Will not be fixed in 4.1.1; adjust target milestone to 4.1.2.
Could this be fixed by rejecting -finline-functions-called-once if -fno-unit-at-a-time is given? A patch to do this should be quite trivial.
Created attachment 14899 [details] Reject combination of -fno-unit-at-a-time and -finline-functions-called-once Untested, but shows how easy it should be to "fix" this bug by disallowing this strange combination of flags.
Subject: Bug 26364 Author: rguenth Date: Wed Jan 9 10:33:55 2008 New Revision: 131423 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=131423 Log: 2008-01-09 Steven Bosscher <stevenb.gcc@gmail.com> PR debug/26364 * opts.c (decode_options): Disable inlining of functions called once if not in unit-at-a-time mode. Modified: trunk/gcc/ChangeLog trunk/gcc/opts.c
Fixed on the trunk.
Closing 4.1 branch.
Closing 4.2 branch, fixed in 4.3.