[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread cvs-commit at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #25 from CVS Commits  ---
The master branch has been updated by Richard Biener :

https://gcc.gnu.org/g:c6ef9d8d3f11221df1ea6358b8d4e79e42f074fb

commit r11-2455-gc6ef9d8d3f11221df1ea6358b8d4e79e42f074fb
Author: Richard Biener 
Date:   Thu Jul 30 11:46:43 2020 +0200

debug/96383 - emit debug info for used external functions

This makes sure to emit full declaration DIEs including
formal parameters for used external functions.  This helps
debugging when debug information of the external entity is
not available and also helps external tools cross-checking
ABI compatibility which was the bug reporters use case.

For cc1 this affects debug information size as follows:

 VM SIZE FILE SIZE
 ++ GROWING   ++
  [ = ]   0 .debug_info   +1.63Mi  +1.3%
  [ = ]   0 .debug_str +263Ki  +3.4%
  [ = ]   0 .debug_abbrev  +101Ki  +4.9%
  [ = ]   0 .debug_line   +5.71Ki  +0.0%
   +44% +16 [Unmapped]+48  +1.2%

 -- SHRINKING --
  [ = ]   0 .debug_loc   -213  -0.0%
  -0.0% -48 .text -48  -0.0%
  [ = ]   0 .debug_ranges -16  -0.0%

  -0.0% -32 TOTAL +1.99Mi  +0.6%

and DWARF compression via DWZ can only shave off minor bits
here.

Previously we emitted no DIEs for external functions at all
unless they were referenced via DW_TAG_GNU_call_site which
for some GCC revs caused a regular DIE to appear and since
GCC 4.9 only a stub without formal parameters.  This means
at -O0 we did not emit any DIE for external functions
but with optimization we emitted stubs.

2020-07-30  Richard Biener  

PR debug/96383
* langhooks-def.h (lhd_finalize_early_debug): Declare.
(LANG_HOOKS_FINALIZE_EARLY_DEBUG): Define.
(LANG_HOOKS_INITIALIZER): Amend.
* langhooks.c: Include cgraph.h and debug.h.
(lhd_finalize_early_debug): Default implementation from
former code in finalize_compilation_unit.
* langhooks.h (lang_hooks::finalize_early_debug): Add.
* cgraphunit.c (symbol_table::finalize_compilation_unit):
Call the finalize_early_debug langhook.

gcc/c-family/
* c-common.h (c_common_finalize_early_debug): Declare.
* c-common.c: Include debug.h.
(c_common_finalize_early_debug): finalize_early_debug langhook
implementation generating debug for extern declarations.

gcc/c/
* c-objc-common.h (LANG_HOOKS_FINALIZE_EARLY_DEBUG):
Define to c_common_finalize_early_debug.

gcc/cp/
* cp-objcp-common.h (LANG_HOOKS_FINALIZE_EARLY_DEBUG):
Define to c_common_finalize_early_debug.

gcc/testsuite/
* gcc.dg/debug/dwarf2/pr96383-1.c: New testcase.
* gcc.dg/debug/dwarf2/pr96383-2.c: Likewise.

libstdc++-v3/
* testsuite/20_util/assume_aligned/3.cc: Use -g0.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #24 from rguenther at suse dot de  ---
On Fri, 31 Jul 2020, jakub at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383
> 
> --- Comment #23 from Jakub Jelinek  ---
> I guess one question is what will e.g. LTO do when merging a DECL_IGNORED
> DECL_EXTERNAL FUNCTION_DECL with !DECL_IGNORED definition.

And also what other side effects the flag has, like no GNU_call_site
tags for a call to such function maybe?  Who knows.  I'm posting the
langhook variant now

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #23 from Jakub Jelinek  ---
I guess one question is what will e.g. LTO do when merging a DECL_IGNORED
DECL_EXTERNAL FUNCTION_DECL with !DECL_IGNORED definition.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread ebotcazou at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #22 from Eric Botcazou  ---
On the other hand, if all it takes to avoid the new DIEs is to set the
DECL_IGNORED_P flag, then it might be simpler to go ahead with the change and
set the flag in Ada more often.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #21 from rguenther at suse dot de  ---
On Fri, 31 Jul 2020, jakub at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383
> 
> --- Comment #20 from Jakub Jelinek  ---
> lang_hooks.finalize_early_debug_info ?
> In the default definition move there just the
>   /* Emit early debug for reachable functions, and by consequence,
>  locally scoped symbols.  */
>   struct cgraph_node *cnode;
>   FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
> (*debug_hooks->early_global_decl) (cnode->decl);
> and for c-family do what you were testing?

Hmm, works for me I guess.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #20 from Jakub Jelinek  ---
lang_hooks.finalize_early_debug_info ?
In the default definition move there just the
  /* Emit early debug for reachable functions, and by consequence,
 locally scoped symbols.  */
  struct cgraph_node *cnode;
  FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (cnode)
(*debug_hooks->early_global_decl) (cnode->decl);
and for c-family do what you were testing?

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #19 from rguenther at suse dot de  ---
On Fri, 31 Jul 2020, jakub at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383
> 
> --- Comment #18 from Jakub Jelinek  ---
> (In reply to rguent...@suse.de from comment #17)
> > Well, not sure - FEs do quite a good job with unused warnings by
> > simply tracking things with TREE_USED so I guess global extern decls
> > can be tracked as used/unused as well by FEs and what is a use
> > (and worth emitting debug for) may be better decided by the FE,
> > say for offsetof (X, m) we maybe want debug info for X even if it
> > is not otherwise used?
> 
> Perhaps for C, but for C++ with thousands of inline functions everywhere 
> pretty
> much everything is TREE_USED.

True...

So we could add 
lang_hooks.finalize_fndecl_referenced_from_final_symboltable ()

with the default implementation registering debug for nodes
with bodies and for C/C++ override this to also register debug
for externals?  Not sure if we should hand it the cgraph node
or whether FEs should figure out whether it is an alias or
thunk in their own representation.

Ada could leave it as default or do nothing in it.

We need a better name though.  Not sure if we need to ever do
sth else from that hook and thus make it sepecific for debug
emission...

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #18 from Jakub Jelinek  ---
(In reply to rguent...@suse.de from comment #17)
> Well, not sure - FEs do quite a good job with unused warnings by
> simply tracking things with TREE_USED so I guess global extern decls
> can be tracked as used/unused as well by FEs and what is a use
> (and worth emitting debug for) may be better decided by the FE,
> say for offsetof (X, m) we maybe want debug info for X even if it
> is not otherwise used?

Perhaps for C, but for C++ with thousands of inline functions everywhere pretty
much everything is TREE_USED.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread rguenther at suse dot de
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #17 from rguenther at suse dot de  ---
On Fri, 31 Jul 2020, jakub at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383
> 
> --- Comment #15 from Jakub Jelinek  ---
> Unless we want for C/C++ to emit DW_AT_external DIEs for all function
> prototypes that appear in the TU, we need ME help, because only there we
> analyze the callgraph and prune  cgraph nodes that are unreachable.

Well, not sure - FEs do quite a good job with unused warnings by
simply tracking things with TREE_USED so I guess global extern decls
can be tracked as used/unused as well by FEs and what is a use
(and worth emitting debug for) may be better decided by the FE,
say for offsetof (X, m) we maybe want debug info for X even if it
is not otherwise used?

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread ebotcazou at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #16 from Eric Botcazou  ---
> So, for Ada, would you like to preserve current behavior rather than what
> Richard's patch does?
> If so, can't we have a langhook that decides that?
> I don't know much about Ada, but would think that having the prototypes even
> for functions defined in other shared libraries if they are called or
> referenced in the TU is useful even for Ada.

This yields useless duplication in 99.99% of the cases though and the debug
info is already large enough.  Can't you do this from the front-end instead,
for the c-family of compilers?

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #15 from Jakub Jelinek  ---
Unless we want for C/C++ to emit DW_AT_external DIEs for all function
prototypes that appear in the TU, we need ME help, because only there we
analyze the callgraph and prune  cgraph nodes that are unreachable.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #14 from Richard Biener  ---
(In reply to Jakub Jelinek from comment #13)
> (In reply to Eric Botcazou from comment #12)
> > > So with the attached 'updated patch' I see
> > > 
> > > === gnat tests ===
> > > 
> > > 
> > > Running target unix/
> > > FAIL: gnat.dg/debug11_pkg.adb scan-assembler-not foreign_imported_func
> > > FAIL: gnat.dg/debug9.adb scan-assembler-times (DIE 
> > > (0x[a-f0-9]*)
> > > DW_
> > > TAG_type_unit) 0
> > > 
> > > where the first FAIL seems obvious from the name of 
> > > 'foreign_imported_func'
> > > and the changed outcome is expected and OK?
> > 
> > The annoying thing is the discrepancy with the variable case; in other
> > words, the patch is undercutting gnat_write_global_declarations
> > (utils.c:5913).

Ah, indeed.

> So, for Ada, would you like to preserve current behavior rather than what
> Richard's patch does?
> If so, can't we have a langhook that decides that?
> I don't know much about Ada, but would think that having the prototypes even
> for functions defined in other shared libraries if they are called or
> referenced in the TU is useful even for Ada.

I think that we need that loop in cgraphunit.c at all shows that frontends
are not enough in control...  The middle-end cannot really make the best
decision on what declarations are worth emitting debug info for so what
Ada does looks best here and maybe other FEs should follow suit...

Note that Ada does this even when -fsyntax-only (if it supports that).

I don't remember exactly but I think we've chosen to emit function DIEs
during unit finalization instead of at rest_of_decl_compilation time
because of ordering issues (FEs call rest_of_decl_compilation very much
too often...).

The most simplistic langhook would be to ask the FE whether a specific
decl should get debug info (but we have DECL_IGNORED for this already ...?).

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #13 from Jakub Jelinek  ---
(In reply to Eric Botcazou from comment #12)
> > So with the attached 'updated patch' I see
> > 
> > === gnat tests ===
> > 
> > 
> > Running target unix/
> > FAIL: gnat.dg/debug11_pkg.adb scan-assembler-not foreign_imported_func
> > FAIL: gnat.dg/debug9.adb scan-assembler-times (DIE (0x[a-f0-9]*)
> > DW_
> > TAG_type_unit) 0
> > 
> > where the first FAIL seems obvious from the name of 'foreign_imported_func'
> > and the changed outcome is expected and OK?
> 
> The annoying thing is the discrepancy with the variable case; in other
> words, the patch is undercutting gnat_write_global_declarations
> (utils.c:5913).

So, for Ada, would you like to preserve current behavior rather than what
Richard's patch does?
If so, can't we have a langhook that decides that?
I don't know much about Ada, but would think that having the prototypes even
for functions defined in other shared libraries if they are called or
referenced in the TU is useful even for Ada.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-31 Thread ebotcazou at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #12 from Eric Botcazou  ---
> So with the attached 'updated patch' I see
> 
> === gnat tests ===
> 
> 
> Running target unix/
> FAIL: gnat.dg/debug11_pkg.adb scan-assembler-not foreign_imported_func
> FAIL: gnat.dg/debug9.adb scan-assembler-times (DIE (0x[a-f0-9]*)
> DW_
> TAG_type_unit) 0
> 
> where the first FAIL seems obvious from the name of 'foreign_imported_func'
> and the changed outcome is expected and OK?

The annoying thing is the discrepancy with the variable case; in other words,
the patch is undercutting gnat_write_global_declarations (utils.c:5913).

> For the second FAIL I see type units for system__secondary_stack_* types
> and the extra subroutines are likely the invoked system__secondary_stack_*
> functions like
> 
>  <1><77>: Abbrev Number: 38 (DW_TAG_subprogram)
> <78>   DW_AT_external: 1
> <78>   DW_AT_name: (indirect string, offset: 0x47):
> system__secondar
> y_stack__ss_release
> <7c>   DW_AT_decl_file   : 2
> <7d>   DW_AT_decl_line   : 95
> <7e>   DW_AT_decl_column : 14
> <7f>   DW_AT_sibling : <0x8e>
>  <2><83>: Abbrev Number: 39 (DW_TAG_formal_parameter)
> <84>   DW_AT_name: m
> <86>   DW_AT_decl_file   : 2
> <87>   DW_AT_decl_line   : 95
> <88>   DW_AT_decl_column : 26
> <89>   DW_AT_type: <0x8e>
>  <2><8d>: Abbrev Number: 0
> 
> note they are not DECL_ARTIFICIAL and also not DECL_IGNORED.  Now the
> testcase tries to test sth else than no type units at all as its
> comment explains.

Yes, I agree that there is probably a missing DECL_IGNORED here.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-30 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

Richard Biener  changed:

   What|Removed |Added

 CC||ebotcazou at gcc dot gnu.org

--- Comment #11 from Richard Biener  ---
So with the attached 'updated patch' I see

=== gnat tests ===


Running target unix/
FAIL: gnat.dg/debug11_pkg.adb scan-assembler-not foreign_imported_func
FAIL: gnat.dg/debug9.adb scan-assembler-times (DIE (0x[a-f0-9]*)
DW_
TAG_type_unit) 0

where the first FAIL seems obvious from the name of 'foreign_imported_func'
and the changed outcome is expected and OK?

For the second FAIL I see type units for system__secondary_stack_* types
and the extra subroutines are likely the invoked system__secondary_stack_*
functions like

 <1><77>: Abbrev Number: 38 (DW_TAG_subprogram)
<78>   DW_AT_external: 1
<78>   DW_AT_name: (indirect string, offset: 0x47):
system__secondar
y_stack__ss_release
<7c>   DW_AT_decl_file   : 2
<7d>   DW_AT_decl_line   : 95
<7e>   DW_AT_decl_column : 14
<7f>   DW_AT_sibling : <0x8e>
 <2><83>: Abbrev Number: 39 (DW_TAG_formal_parameter)
<84>   DW_AT_name: m
<86>   DW_AT_decl_file   : 2
<87>   DW_AT_decl_line   : 95
<88>   DW_AT_decl_column : 26
<89>   DW_AT_type: <0x8e>
 <2><8d>: Abbrev Number: 0

note they are not DECL_ARTIFICIAL and also not DECL_IGNORED.  Now the
testcase tries to test sth else than no type units at all as its
comment explains.

[Bug debug/96383] [8/9/10/11 Regression] Full ABI information missing from GCC compiled C

2020-07-30 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96383

--- Comment #10 from Richard Biener  ---
Created attachment 48960
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48960=edit
updated patch

Avoid aliases and thunks, avoid not declared builtins w/o body.  Updates
stats for cc1 to

FILE SIZEVM SIZE
 --  -- 
  +1.0% +1.21Mi  [ = ]   0.debug_info
  +4.4% +92.0Ki  [ = ]   0.debug_abbrev
  +0.1% +6.76Ki  [ = ]   0.debug_str
  +0.0% +5.80Ki  [ = ]   0.debug_line
  +0.0%+426  [ = ]   0.debug_loc
  +0.0%+144  [ = ]   0.debug_ranges
  +0.0% +80  +0.0% +80.text
  +0.0% +52  [ = ]   0.strtab
  +0.0% +32  +0.0% +32.rodata
  +0.0% +24  [ = ]   0.symtab
  +0.0% +16  +0.0% +16.eh_frame
  +0.0%  +8  +0.0%  +8.eh_frame_hdr
  -1.9%-138  [ = ]   0[Unmapped]
  +0.4% +1.31Mi  +0.0%+136TOTAL

and after applying DWZ to both:

FILE SIZEVM SIZE
 --  -- 
  +1.0%  +751Ki  [ = ]   0.debug_info
  +4.8% +87.8Ki  [ = ]   0.debug_abbrev
  +0.1% +6.76Ki  [ = ]   0.debug_str
  +0.0% +5.80Ki  [ = ]   0.debug_line
  +0.0%+426  [ = ]   0.debug_loc
  +0.0%+144  [ = ]   0.debug_ranges
  +0.0% +80  +0.0% +80.text
  +0.0% +52  [ = ]   0.strtab
  +0.0% +32  +0.0% +32.rodata
  +0.0% +24  [ = ]   0.symtab
  +0.0% +16  +0.0% +16.eh_frame
  +0.0%  +8  +0.0%  +8.eh_frame_hdr
  -1.9%-137  [ = ]   0[Unmapped]
  +0.3%  +852Ki  +0.0%+136TOTAL