[GSOC] LTO dump tool project

Martin Liška mliska@suse.cz
Mon Jun 4 19:08:00 GMT 2018


On 06/04/2018 08:13 PM, Hrishikesh Kulkarni wrote:
> Hi,
> 
> -fdump-lto-list will dump all the symbol list

I see extra new lines in the output:

$ lto1 -fdump-lto-list main.o
[..snip..]
Symbol Table
		Name 		Type 		Visibility

            fwrite/15            function             default

               foo/14            function             default

          mystring/12            variable             default

              pole/11            variable             default

              main/13            function             default

> -fdump-lto-list -demangle will dump all the list with symbol names demangled

Good for now. Note that non-demagle version prints function names with order (/$number).
I would not print that.

> -fdump-lto-symbol=foo will dump details of foo

I would really prefer to use symtab_node::debug for now. It presents all details about
symbol instead of current implementation which does: '-fdump-lto-list | grep foo'

> 
> The output(demangled) will be in tabular form like nm:
> Symbol Table
>          Name         Type         Visibility
>                printf            function             default
>                     k            variable             default
>                  main            function             default
>                   bar            function             default
>                   foo            function             default
> 
> I have tried to format the changes according to gnu coding style and
> added required methods in symtab_node.

That's nice that you came up with new symbol_node methods. It's much better.
About the GNU coding style, I still see trailing whitespace:

=== ERROR type #3: there should be no space before a left square bracket (1 error(s)) ===
gcc/symtab.c:818:26:  return visibility_types [DECL_VISIBILITY (decl)];

=== ERROR type #4: trailing whitespace (6 error(s)) ===
gcc/lto/lto-dump.c:40:4:voidâ–ˆ
gcc/lto/lto-dump.c:45:0:â–ˆ
gcc/lto/lto-dump.c:56:52:		fprintf (stderr, "\n%20s",(flag_lto_dump_demangle)â–ˆ
gcc/lto/lto-dump.c:73:53:			fprintf (stderr, "\n%20s",(flag_lto_dump_demangle)â–ˆ
gcc/lto/lto-dump.c:78:2:	}â–ˆ
gcc/lto/lto-dump.c:79:1:}â–ˆ

Martin

> 
> Please find the diff file attached.
> 
> Regards,
> Hrishikesh
> 
> On Mon, Jun 4, 2018 at 2:06 PM, Martin Liška <mliska@suse.cz> wrote:
>> On 06/01/2018 08:59 PM, Hrishikesh Kulkarni wrote:
>>> Hi,
>>> I have pushed the changes to github
>>> (https://github.com/hrisearch/gcc). Added a command line option for
>>> specific dumps of variables and functions used in IL e.g.
>>> -fdump-lto-list=foo will dump:
>>> Call Graph:
>>>
>>> foo/1 (foo)
>>>    Type: function
>>>   visibility: default
>>
>> Hi.
>>
>> Thanks for the next step. I've got some comments about it:
>>
>> - -fdump-lto-list=foo is wrong option name, I would use -fdump-lto-symbol
>>    or something similar.
>>
>> - for -fdump-lto-list I would really prefer to use a format similar to nm:
>>    print a header with column description and then one line for a symbol
>>
>> - think about mangling/demangling of C++ symbols, you can take a look at
>> nm it also has --demangle, --no-demangle
>>
>> - please learn & try to use an autoformat for your editor in order to
>>    fulfill GNU coding style. Following checker will help you:
>>
>> $ ./contrib/check_GNU_style.py /tmp/p
>> === ERROR type #1: dot, space, space, end of comment (6 error(s)) ===
>> gcc/lto/lto-dump.c:38:17:/*Dump everything*/
>> gcc/lto/lto-dump.c:44:41:/*Dump variables and functions used in IL*/
>> gcc/lto/lto-dump.c:73:50:/*Dump specific variables and functions used in IL*/
>> gcc/lto/lto.c:3364:19:  /*Dump everything*/
>> gcc/lto/lto.c:3368:43:  /*Dump variables and functions used in IL*/
>> gcc/lto/lto.c:3372:52:  /*Dump specific variables and functions used in IL*/
>>
>> === ERROR type #2: lines should not exceed 80 characters (11 error(s)) ===
>> gcc/lto/lto-dump.c:51:80:        static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>> gcc/lto/lto-dump.c:56:80:                fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>> gcc/lto/lto-dump.c:57:80:                fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>> gcc/lto/lto-dump.c:66:80:                fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>> gcc/lto/lto-dump.c:67:80:                fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>> gcc/lto/lto-dump.c:80:80:        static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>> gcc/lto/lto-dump.c:87:80:                        fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>> gcc/lto/lto-dump.c:88:80:                        fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>> gcc/lto/lto-dump.c:99:80:                        fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>> gcc/lto/lto-dump.c:100:80:                        fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>> gcc/lto/Make-lang.in:25:80:LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>>
>> === ERROR type #3: there should be exactly one space between function name and parenthesis (15 error(s)) ===
>> gcc/lto/lto-dump.c:39:9:void dump()
>> gcc/lto/lto-dump.c:41:8:        fprintf(stderr, "\nHello World!\n");
>> gcc/lto/lto-dump.c:45:14:void dump_list()
>> gcc/lto/lto-dump.c:74:15:void dump_list2()
>> gcc/lto/lto-dump.c:85:13:               if (!strcmp(flag_lto_dump_list2, cnode->name()))
>> gcc/lto/lto-dump.c:97:16:       if (!strcmp(flag_lto_dump_list2, vnode->name()))
>> gcc/lto/lto-dump.h:23:9:void dump();
>> gcc/lto/lto-dump.h:24:14:void dump_list();
>> gcc/lto/lto-dump.h:25:15:void dump_list2();
>> gcc/lto/lang.opt:67:7:LTO Var(flag_lto_dump)
>> gcc/lto/lang.opt:71:7:LTO Var(flag_lto_dump_list)
>> gcc/lto/lang.opt:75:36:LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
>> gcc/lto/lto.c:3366:8:    dump();
>> gcc/lto/lto.c:3370:13:    dump_list();
>> gcc/lto/lto.c:3374:14:    dump_list2();
>>
>> === ERROR type #4: there should be no space before a left square bracket (4 error(s)) ===
>> gcc/lto/lto-dump.c:59:19:               visibility_types [DECL_VISIBILITY (cnode->decl)]);
>> gcc/lto/lto-dump.c:69:19:               visibility_types [DECL_VISIBILITY (vnode->decl)]);
>> gcc/lto/lto-dump.c:90:20:                       visibility_types [DECL_VISIBILITY (cnode->decl)]);
>> gcc/lto/lto-dump.c:102:20:                      visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>
>> === ERROR type #5: trailing whitespace (5 error(s)) ===
>> gcc/lto/lto-dump.c:50:0:â–ˆ
>> gcc/lto/lto-dump.c:79:0:â–ˆ
>> gcc/lto/lto-dump.c:92:2:        }â–ˆ
>> gcc/lto/lto-dump.c:98:3:                {â–ˆ
>> gcc/lto/lto-dump.c:105:1:}â–ˆ
>>
>> And please try to avoid adding blank lines / remove blank lines in files which you don't modify.
>> Examples: cgraph.c, varpool.c. Note that the checker is not 100% sure, but will help you.
>>
>>>
>>> Regards,
>>> Hrishikesh
>>>
>>> On Tue, May 29, 2018 at 11:13 PM, Martin Liška <mliska@suse.cz> wrote:
>>>> On 05/29/2018 07:38 PM, Martin Liška wrote:
>>>>> $ nm main.o
>>>>> 00000000 T main
>>>>> 00000000 T mystring
>>>>> 00000000 C pole
>>>>
>>>> Or we can be inspired by readelf:
>>>>
>>>> $ readelf -s a.out
>>>> [snip]
>>>> Symbol table '.symtab' contains 74 entries:
>>>>     Num:    Value          Size Type    Bind   Vis      Ndx Name
>>>>      66: 0000000000601250     0 NOTYPE  GLOBAL DEFAULT   24 _end
>>>>      67: 00000000004004b0    43 FUNC    GLOBAL DEFAULT   13 _start
>>>>      68: 0000000000601038     0 NOTYPE  GLOBAL DEFAULT   24 __bss_start
>>>>      69: 0000000000400582    70 FUNC    GLOBAL DEFAULT   13 main
>>>>      70: 0000000000000000     0 FUNC    GLOBAL DEFAULT  UND
>>>> fwrite@@GLIBC_2.2.5
>>>>
>>>> Martin
>>>
>>> specific-symbols-dump.diff
>>>
>>>
>>> diff --git a/gcc/cgraph.c b/gcc/cgraph.c
>>> index 9a7d54d..b868695 100644
>>> --- a/gcc/cgraph.c
>>> +++ b/gcc/cgraph.c
>>> @@ -2234,6 +2234,7 @@ cgraph_node::dump (FILE *f)
>>>       fprintf (f, "  Is instrumented version.\n");
>>>     else if (instrumented_version)
>>>       fprintf (f, "  Has instrumented version.\n");
>>> +
>>>   }
>>>
>>>   /* Dump call graph node NODE to stderr.  */
>>> diff --git a/gcc/lto/Make-lang.in b/gcc/lto/Make-lang.in
>>> index 4695077..465662e 100644
>>> --- a/gcc/lto/Make-lang.in
>>> +++ b/gcc/lto/Make-lang.in
>>> @@ -22,7 +22,7 @@
>>>   # The name of the LTO compiler.
>>>   LTO_EXE = lto1$(exeext)
>>>   # The LTO-specific object files inclued in $(LTO_EXE).
>>> -LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o
>>> +LTO_OBJS = lto/lto-lang.o lto/lto.o lto/lto-object.o attribs.o lto/lto-partition.o lto/lto-symtab.o lto/lto-dump.o
>>>   lto_OBJS = $(LTO_OBJS)
>>>
>>>   # this is only useful in a LTO bootstrap, but this does not work right
>>> diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
>>> index 0a408d3..7600840 100644
>>> --- a/gcc/lto/lang.opt
>>> +++ b/gcc/lto/lang.opt
>>> @@ -63,6 +63,18 @@ fwpa=
>>>   LTO Driver RejectNegative Joined Var(flag_wpa)
>>>   Whole program analysis (WPA) mode with number of parallel jobs specified.
>>>
>>> +fdump
>>> +LTO Var(flag_lto_dump)
>>> +Call the dump function.
>>> +
>>> +fdump-lto-list
>>> +LTO Var(flag_lto_dump_list)
>>> +Call the dump function for variables and function in IL.
>>> +
>>> +fdump-lto-list=
>>> +LTO Driver RejectNegative Joined Var(flag_lto_dump_list2)
>>> +
>>> +
>>>   fresolution=
>>>   LTO Joined
>>>   The resolution file.
>>> diff --git a/gcc/lto/lto-dump.c b/gcc/lto/lto-dump.c
>>> new file mode 100644
>>> index 0000000..90976cb
>>> --- /dev/null
>>> +++ b/gcc/lto/lto-dump.c
>>> @@ -0,0 +1,105 @@
>>> +/* LTO dump tool
>>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>>> +
>>> +This file is part of GCC.
>>> +
>>> +GCC is free software; you can redistribute it and/or modify it under
>>> +the terms of the GNU General Public License as published by the Free
>>> +Software Foundation; either version 3, or (at your option) any later
>>> +version.
>>> +
>>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>> +for more details.
>>> +
>>> +You should have received a copy of the GNU General Public License
>>> +along with GCC; see the file COPYING3.  If not see
>>> +<http://www.gnu.org/licenses/>.  */
>>> +
>>> +#include "config.h"
>>> +#include "system.h"
>>> +#include "coretypes.h"
>>> +#include "target.h"
>>> +#include "function.h"
>>> +#include "basic-block.h"
>>> +#include "tree.h"
>>> +#include "gimple.h"
>>> +#include "cgraph.h"
>>> +#include "lto-streamer.h"
>>> +#include "ipa-utils.h"
>>> +#include "builtins.h"
>>> +#include "alias.h"
>>> +#include "lto-symtab.h"
>>> +#include "stringpool.h"
>>> +#include "attribs.h"
>>> +#include "stdio.h"
>>> +
>>> +/*Dump everything*/
>>> +void dump()
>>> +{
>>> +     fprintf(stderr, "\nHello World!\n");
>>> +}
>>> +
>>> +/*Dump variables and functions used in IL*/
>>> +void dump_list()
>>> +{
>>> +
>>> +     fprintf (stderr, "Call Graph:\n");
>>> +     cgraph_node *cnode;
>>> +
>>> +     static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>>> +     static const char * const visibility_types[] = {
>>> +    "default", "protected", "hidden", "internal" };
>>
>> We have symbol_node class, this can be refactored into methods.
>>
>>> +     FOR_EACH_FUNCTION (cnode)
>>> +     {
>>> +             fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>>> +             fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>>> +             fprintf (stderr, "\n visibility: %s\n",
>>> +             visibility_types [DECL_VISIBILITY (cnode->decl)]);
>>> +     }
>>> +
>>> +     fprintf (stderr, "\nVarpool:\n");
>>> +     varpool_node *vnode;
>>> +    FOR_EACH_VARIABLE (vnode)
>>> +    {
>>> +             fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>>> +             fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>>> +             fprintf (stderr, "\n visibility:%s\n",
>>> +             visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>
>> Maybe content of the loop body can be a function that will print. Now it's copy&paste.
>>
>>> +     }
>>> +}
>>> +
>>> +/*Dump specific variables and functions used in IL*/
>>> +void dump_list2()
>>> +{
>>> +
>>> +     fprintf (stderr, "Call Graph:\n");
>>> +     cgraph_node *cnode;
>>> +
>>> +     static const char * const symtab_type_names[] = {"symbol", "function", "variable"};
>>> +     static const char * const visibility_types[] = {
>>> +    "default", "protected", "hidden", "internal" };
>>> +     FOR_EACH_FUNCTION (cnode)
>>> +     {
>>> +             if (!strcmp(flag_lto_dump_list2, cnode->name()))
>>> +             {
>>> +                     fprintf (stderr, "\n%s (%s)", cnode->dump_asm_name (), cnode->name ());
>>> +                     fprintf (stderr, "\n  Type: %s", symtab_type_names[cnode->type]);
>>> +                     fprintf (stderr, "\n visibility: %s\n",
>>> +                     visibility_types [DECL_VISIBILITY (cnode->decl)]);
>>> +             }
>>> +     }
>>> +     fprintf (stderr, "\nVarpool:\n");
>>> +     varpool_node *vnode;
>>> +    FOR_EACH_VARIABLE (vnode)
>>> +    {
>>> +     if (!strcmp(flag_lto_dump_list2, vnode->name()))
>>> +             {
>>> +                     fprintf (stderr, "\n%s (%s)", vnode->dump_asm_name (), vnode->name ());
>>> +                     fprintf (stderr, "\n  Type: %s", symtab_type_names[vnode->type]);
>>> +                     fprintf (stderr, "\n visibility:%s\n",
>>> +                     visibility_types [DECL_VISIBILITY (vnode->decl)]);
>>> +             }
>>> +     }
>>> +}
>>
>> The whole function is copy&paste. Please come up with new methods for symtab_node and use it.
>>
>> You wrote of the mailing list that you're planning to work on CMD options. But please finish
>> first dumping of symbols. I would recomment to implement option that will print body
>> of a function, which should accept similar dumpflags as we use for dump files:
>>
>> $ ./xgcc -B. -fdump-tree-optimized-blocks=/dev/stdout ~/Programming/testcases/tmp/main.c -c
>>
>> ;; Function main (main, funcdef_no=0, decl_uid=2614, cgraph_uid=0, symbol_order=2)
>>
>> main (int argc, char * * argv)
>> {
>>    int D.2621;
>>    int _1;
>>    int _8;
>>    int _10;
>>
>> ;;   basic block 2, loop depth 0
>> ;;    pred:       ENTRY
>>    foo ();
>>    fwrite (0B, 1, 0, 0B);
>>    pole[11] = 123;
>>    if (argc_7(D) == 1)
>>      goto <bb 3>; [INV]
>>    else
>>      goto <bb 4>; [INV]
>> ;;    succ:       3
>> ;;                4
>> ...
>>
>> $ ./xgcc -B. -fdump-tree-optimized-gimple=/dev/stdout ~/Programming/testcases/tmp/main.c -c
>> int __GIMPLE ()
>> main (int argc, char * * argv)
>> {
>>    int D_2621;
>>    int _1;
>>    int _8;
>>    int _10;
>>
>>    bb_2:
>>    foo ();
>>    fwrite (_Literal (const void * restrict) 0, 1ul, 0ul, _Literal (struct FILE * restrict) 0);
>>    pole[11] = 123;
>>    if (argc_7(D) == 1)
>>      goto bb_3;
>>    else
>>      goto bb_4;
>> ...
>>
>> And I would also do a more verbose symbol dump option that will basically call symbol_node::debug.
>>
>> Thanks,
>> Martin
>>
>>> \ No newline at end of file
>>> diff --git a/gcc/lto/lto-dump.h b/gcc/lto/lto-dump.h
>>> new file mode 100644
>>> index 0000000..0aef8d1
>>> --- /dev/null
>>> +++ b/gcc/lto/lto-dump.h
>>> @@ -0,0 +1,27 @@
>>> +/* LTO dump tool
>>> +   Copyright (C) 2009-2018 Free Software Foundation, Inc.
>>> +
>>> +This file is part of GCC.
>>> +
>>> +GCC is free software; you can redistribute it and/or modify it under
>>> +the terms of the GNU General Public License as published by the Free
>>> +Software Foundation; either version 3, or (at your option) any later
>>> +version.
>>> +
>>> +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
>>> +WARRANTY; without even the implied warranty of MERCHANTABILITY or
>>> +FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>> +for more details.
>>> +
>>> +You should have received a copy of the GNU General Public License
>>> +along with GCC; see the file COPYING3.  If not see
>>> +<http://www.gnu.org/licenses/>.  */
>>> +
>>> +#ifndef GCC_LTO_DUMP_H_
>>> +#define GCC_LTO_DUMP_H_
>>> +
>>> +void dump();
>>> +void dump_list();
>>> +void dump_list2();
>>> +
>>> +#endif
>>> \ No newline at end of file
>>> diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
>>> index d2ccaf6..15a56af 100644
>>> --- a/gcc/lto/lto.c
>>> +++ b/gcc/lto/lto.c
>>> @@ -55,7 +55,7 @@ along with GCC; see the file COPYING3.  If not see
>>>   #include "fold-const.h"
>>>   #include "attribs.h"
>>>   #include "builtins.h"
>>> -
>>> +#include "lto-dump.h"
>>>
>>>   /* Number of parallel tasks to run, -1 if we want to use GNU Make jobserver.  */
>>>   static int lto_parallelism;
>>> @@ -3361,6 +3361,18 @@ lto_main (void)
>>>        command line.  */
>>>     read_cgraph_and_symbols (num_in_fnames, in_fnames);
>>>
>>> +  /*Dump everything*/
>>> +  if (flag_lto_dump)
>>> +    dump();
>>> +
>>> +  /*Dump variables and functions used in IL*/
>>> +  if (flag_lto_dump_list)
>>> +    dump_list();
>>> +
>>> +  /*Dump specific variables and functions used in IL*/
>>> +  if (flag_lto_dump_list2)
>>> +    dump_list2();
>>> +
>>>     timevar_stop (TV_PHASE_STREAM_IN);
>>>
>>>     if (!seen_error ())
>>> diff --git a/gcc/varpool.c b/gcc/varpool.c
>>> index 418753c..77f0adb 100644
>>> --- a/gcc/varpool.c
>>> +++ b/gcc/varpool.c
>>> @@ -239,7 +239,6 @@ varpool_node::dump (FILE *f)
>>>     fprintf (f, "\n");
>>>   }
>>>
>>> -
>>>   /* Dump given varpool node to stderr.  */
>>>   void varpool_node::debug (void)
>>>   {
>>>
>>



More information about the Gcc mailing list