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
Regards,
Hrishikesh
On Tue, May 29, 2018 at 11:13 PM, Martin Liška <[email protected]> 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
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" };
+ 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)]);
+ }
+}
+
+/*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)]);
+ }
+ }
+}
\ 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)
{