This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch] Fix resolution file generation
- From: Rafael Espindola <espindola at google dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Diego Novillo <dnovillo at google dot com>, Cary Coutant <ccoutant at google dot com>
- Date: Wed, 14 Oct 2009 16:08:38 -0400
- Subject: [patch] Fix resolution file generation
This patch fixes some of the issues noted on PR 41550. In particular,
it changes from using a file with a hard coded name to using a plugin
argument. It also fixes a bug: get_symbols reads the syms argument to
find if a symbol is a definition or a use. Because of this, we must
pass it the original symbols, not a freshly allocated table.
I tested this by writing the resolution file for a simple case with 2
files. Is there anyway of adding tests like this to the testsuite?
What it has to do is
*) Compile two C files with -flto
*) Run gold with -plugin-opt=-resolution=foo
*) Run grep on foo
I will update the gcc driver in a next patch. Since nothing is using
the resolution file right now, this shouldn't be a problem.
2009-10-14 Rafael Avila de Espindola <espindola@google.com>
* lto-plugin.c (resolution_file): New.
(free_1): Update comment.
(write_resolution): Write resolution to specified file. Use the
syms array from the symbol table.
(all_symbols_read_handler): Delay call to free_1 past call to
write_resolution.
(process_option): Add a -resolution option.
Cheers,
--
Rafael Ãvila de EspÃndola
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 71b4961..2a18543 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -97,6 +97,7 @@ static unsigned int num_pass_through_items;
static bool debug;
static bool nop;
+static char *resolution_file = NULL;
/* Parse an entry of the IL symbol table. The data to be parsed is pointed
by P and the result is written in ENTRY. The slot number is stored in SLOT.
@@ -228,7 +229,8 @@ translate (Elf_Data *symtab, struct plugin_symtab *out)
out->slots = slots;
}
-/* Free all memory that is no longer needed at the beginning of all_symbols_read. */
+/* Free all memory that is no longer needed after writing the symbol
+ resolution. */
static void
free_1 (void)
@@ -284,12 +286,11 @@ write_resolution (void)
{
unsigned int i;
FILE *f;
- /* FIXME: Disabled for now since we are not using the resolution file. */
- return;
+ if (!resolution_file)
+ return;
- /* FIXME: This should be a temporary file. */
- f = fopen ("resolution", "w");
+ f = fopen (resolution_file, "w");
fprintf (f, "%d\n", num_claimed_files);
@@ -297,8 +298,7 @@ write_resolution (void)
{
struct plugin_file_info *info = &claimed_files[i];
struct plugin_symtab *symtab = &info->symtab;
- struct ld_plugin_symbol *syms = calloc (symtab->nsyms,
- sizeof (struct ld_plugin_symbol));
+ struct ld_plugin_symbol *syms = symtab->syms;
unsigned j;
assert (syms);
@@ -312,7 +312,6 @@ write_resolution (void)
unsigned int resolution = syms[j].resolution;
fprintf (f, "%d %s\n", slot, lto_resolution_str[resolution]);
}
- free (syms);
}
fclose (f);
}
@@ -434,8 +433,6 @@ all_symbols_read_handler (void)
if (num_claimed_files == 0)
return LDPS_OK;
- free_1 ();
-
if (nop)
{
use_original_files ();
@@ -448,6 +445,8 @@ all_symbols_read_handler (void)
write_resolution ();
+ free_1 ();
+
for (i = 0; i < lto_wrapper_num_args; i++)
*lto_arg_ptr++ = lto_wrapper_argv[i];
@@ -608,6 +607,10 @@ process_option (const char *option)
debug = 1;
else if (strcmp (option, "-nop") == 0)
nop = 1;
+ else if (!strncmp (option, "-resolution=", strlen("-resolution=")))
+ {
+ resolution_file = strdup (option + strlen("-resolution="));
+ }
else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
{
num_pass_through_items++;