Commit 443743fd by Ilya Verbin Committed by Ilya Verbin

lto-wrapper.c (compile_offload_image): Start processing in_argv from 0 instead of 1.

gcc/
	* lto-wrapper.c (compile_offload_image): Start processing in_argv
	from 0 instead of 1.
	(run_gcc): Put offload objects into offload_argv, put LTO objects and
	possible preceding arguments into lto_argv.
	Pass offload_argv to compile_images_for_offload_targets instead of argv.
	Use lto_argv for LTO recompilation instead of argv.
lto-plugin/
	* lto-plugin.c (offload_files, num_offload_files): New static variables.
	(free_1): Use arguments instead of global variables.
	(free_2): Free offload_files.
	(all_symbols_read_handler): Add names from offload_files to lto-wrapper
	arguments.
	(claim_file_handler): Do not add file to claimed_files if it contains
	offload sections without LTO sections.  Add it to offload_files instead.

From-SVN: r218543
parent 3f6ad8df
2014-12-09 Ilya Verbin <ilya.verbin@intel.com>
* lto-wrapper.c (compile_offload_image): Start processing in_argv
from 0 instead of 1.
(run_gcc): Put offload objects into offload_argv, put LTO objects and
possible preceding arguments into lto_argv.
Pass offload_argv to compile_images_for_offload_targets instead of argv.
Use lto_argv for LTO recompilation instead of argv.
2014-12-09 Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com> 2014-12-09 Michael Haubenwallner <michael.haubenwallner@ssi-schaefer.com>
* doc/install.texi: Describe --with-aix-soname option. * doc/install.texi: Describe --with-aix-soname option.
...@@ -669,7 +669,7 @@ compile_offload_image (const char *target, const char *compiler_path, ...@@ -669,7 +669,7 @@ compile_offload_image (const char *target, const char *compiler_path,
obstack_ptr_grow (&argv_obstack, filename); obstack_ptr_grow (&argv_obstack, filename);
/* Append names of input object files. */ /* Append names of input object files. */
for (unsigned i = 1; i < in_argc; i++) for (unsigned i = 0; i < in_argc; i++)
obstack_ptr_grow (&argv_obstack, in_argv[i]); obstack_ptr_grow (&argv_obstack, in_argv[i]);
/* Append options from offload_lto sections. */ /* Append options from offload_lto sections. */
...@@ -883,6 +883,8 @@ run_gcc (unsigned argc, char *argv[]) ...@@ -883,6 +883,8 @@ run_gcc (unsigned argc, char *argv[])
int new_head_argc; int new_head_argc;
bool have_lto = false; bool have_lto = false;
bool have_offload = false; bool have_offload = false;
unsigned lto_argc = 0, offload_argc = 0;
char **lto_argv, **offload_argv;
/* Get the driver and options. */ /* Get the driver and options. */
collect_gcc = getenv ("COLLECT_GCC"); collect_gcc = getenv ("COLLECT_GCC");
...@@ -896,6 +898,11 @@ run_gcc (unsigned argc, char *argv[]) ...@@ -896,6 +898,11 @@ run_gcc (unsigned argc, char *argv[])
&decoded_options, &decoded_options,
&decoded_options_count); &decoded_options_count);
/* Allocate arrays for input object files with LTO or offload IL,
and for possible preceding arguments. */
lto_argv = XNEWVEC (char *, argc);
offload_argv = XNEWVEC (char *, argc);
/* Look at saved options in the IL files. */ /* Look at saved options in the IL files. */
for (i = 1; i < argc; ++i) for (i = 1; i < argc; ++i)
{ {
...@@ -918,17 +925,27 @@ run_gcc (unsigned argc, char *argv[]) ...@@ -918,17 +925,27 @@ run_gcc (unsigned argc, char *argv[])
} }
fd = open (argv[i], O_RDONLY); fd = open (argv[i], O_RDONLY);
if (fd == -1) if (fd == -1)
continue; {
lto_argv[lto_argc++] = argv[i];
continue;
}
if (find_and_merge_options (fd, file_offset, LTO_SECTION_NAME_PREFIX,
&fdecoded_options, &fdecoded_options_count,
collect_gcc))
{
have_lto = true;
lto_argv[lto_argc++] = argv[i];
}
if (find_and_merge_options (fd, file_offset, OFFLOAD_SECTION_NAME_PREFIX,
&offload_fdecoded_options,
&offload_fdecoded_options_count, collect_gcc))
{
have_offload = true;
offload_argv[offload_argc++] = argv[i];
}
have_lto
|= find_and_merge_options (fd, file_offset, LTO_SECTION_NAME_PREFIX,
&fdecoded_options, &fdecoded_options_count,
collect_gcc);
have_offload
|= find_and_merge_options (fd, file_offset, OFFLOAD_SECTION_NAME_PREFIX,
&offload_fdecoded_options,
&offload_fdecoded_options_count,
collect_gcc);
close (fd); close (fd);
} }
...@@ -1027,7 +1044,8 @@ run_gcc (unsigned argc, char *argv[]) ...@@ -1027,7 +1044,8 @@ run_gcc (unsigned argc, char *argv[])
if (have_offload) if (have_offload)
{ {
compile_images_for_offload_targets (argc, argv, offload_fdecoded_options, compile_images_for_offload_targets (offload_argc, offload_argv,
offload_fdecoded_options,
offload_fdecoded_options_count, offload_fdecoded_options_count,
decoded_options, decoded_options,
decoded_options_count); decoded_options_count);
...@@ -1119,8 +1137,8 @@ run_gcc (unsigned argc, char *argv[]) ...@@ -1119,8 +1137,8 @@ run_gcc (unsigned argc, char *argv[])
} }
/* Append the input objects and possible preceding arguments. */ /* Append the input objects and possible preceding arguments. */
for (i = 1; i < argc; ++i) for (i = 0; i < lto_argc; ++i)
obstack_ptr_grow (&argv_obstack, argv[i]); obstack_ptr_grow (&argv_obstack, lto_argv[i]);
obstack_ptr_grow (&argv_obstack, NULL); obstack_ptr_grow (&argv_obstack, NULL);
new_argv = XOBFINISH (&argv_obstack, const char **); new_argv = XOBFINISH (&argv_obstack, const char **);
...@@ -1295,6 +1313,8 @@ cont: ...@@ -1295,6 +1313,8 @@ cont:
if (offloadend) if (offloadend)
printf ("%s\n", offloadend); printf ("%s\n", offloadend);
XDELETE (lto_argv);
XDELETE (offload_argv);
obstack_free (&argv_obstack, NULL); obstack_free (&argv_obstack, NULL);
} }
......
2014-12-09 Ilya Verbin <ilya.verbin@intel.com>
* lto-plugin.c (offload_files, num_offload_files): New static variables.
(free_1): Use arguments instead of global variables.
(free_2): Free offload_files.
(all_symbols_read_handler): Add names from offload_files to lto-wrapper
arguments.
(claim_file_handler): Do not add file to claimed_files if it contains
offload sections without LTO sections. Add it to offload_files instead.
2014-11-21 H.J. Lu <hongjiu.lu@intel.com> 2014-11-21 H.J. Lu <hongjiu.lu@intel.com>
PR bootstrap/63784 PR bootstrap/63784
......
...@@ -152,6 +152,9 @@ static ld_plugin_add_symbols add_symbols; ...@@ -152,6 +152,9 @@ static ld_plugin_add_symbols add_symbols;
static struct plugin_file_info *claimed_files = NULL; static struct plugin_file_info *claimed_files = NULL;
static unsigned int num_claimed_files = 0; static unsigned int num_claimed_files = 0;
static struct plugin_file_info *offload_files = NULL;
static unsigned int num_offload_files = 0;
static char **output_files = NULL; static char **output_files = NULL;
static unsigned int num_output_files = 0; static unsigned int num_output_files = 0;
...@@ -313,12 +316,12 @@ translate (char *data, char *end, struct plugin_symtab *out) ...@@ -313,12 +316,12 @@ translate (char *data, char *end, struct plugin_symtab *out)
resolution. */ resolution. */
static void static void
free_1 (void) free_1 (struct plugin_file_info *files, unsigned num_files)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < num_claimed_files; i++) for (i = 0; i < num_files; i++)
{ {
struct plugin_file_info *info = &claimed_files[i]; struct plugin_file_info *info = &files[i];
struct plugin_symtab *symtab = &info->symtab; struct plugin_symtab *symtab = &info->symtab;
unsigned int j; unsigned int j;
for (j = 0; j < symtab->nsyms; j++) for (j = 0; j < symtab->nsyms; j++)
...@@ -346,6 +349,14 @@ free_2 (void) ...@@ -346,6 +349,14 @@ free_2 (void)
free (info->name); free (info->name);
} }
for (i = 0; i < num_offload_files; i++)
{
struct plugin_file_info *info = &offload_files[i];
struct plugin_symtab *symtab = &info->symtab;
free (symtab->aux);
free (info->name);
}
for (i = 0; i < num_output_files; i++) for (i = 0; i < num_output_files; i++)
free (output_files[i]); free (output_files[i]);
free (output_files); free (output_files);
...@@ -354,6 +365,10 @@ free_2 (void) ...@@ -354,6 +365,10 @@ free_2 (void)
claimed_files = NULL; claimed_files = NULL;
num_claimed_files = 0; num_claimed_files = 0;
free (offload_files);
offload_files = NULL;
num_offload_files = 0;
free (arguments_file_name); free (arguments_file_name);
arguments_file_name = NULL; arguments_file_name = NULL;
} }
...@@ -608,10 +623,11 @@ static enum ld_plugin_status ...@@ -608,10 +623,11 @@ static enum ld_plugin_status
all_symbols_read_handler (void) all_symbols_read_handler (void)
{ {
unsigned i; unsigned i;
unsigned num_lto_args = num_claimed_files + lto_wrapper_num_args + 1; unsigned num_lto_args
= num_claimed_files + num_offload_files + lto_wrapper_num_args + 1;
char **lto_argv; char **lto_argv;
const char **lto_arg_ptr; const char **lto_arg_ptr;
if (num_claimed_files == 0) if (num_claimed_files + num_offload_files == 0)
return LDPS_OK; return LDPS_OK;
if (nop) if (nop)
...@@ -626,7 +642,8 @@ all_symbols_read_handler (void) ...@@ -626,7 +642,8 @@ all_symbols_read_handler (void)
write_resolution (); write_resolution ();
free_1 (); free_1 (claimed_files, num_claimed_files);
free_1 (offload_files, num_offload_files);
for (i = 0; i < lto_wrapper_num_args; i++) for (i = 0; i < lto_wrapper_num_args; i++)
*lto_arg_ptr++ = lto_wrapper_argv[i]; *lto_arg_ptr++ = lto_wrapper_argv[i];
...@@ -638,6 +655,13 @@ all_symbols_read_handler (void) ...@@ -638,6 +655,13 @@ all_symbols_read_handler (void)
*lto_arg_ptr++ = info->name; *lto_arg_ptr++ = info->name;
} }
for (i = 0; i < num_offload_files; i++)
{
struct plugin_file_info *info = &offload_files[i];
*lto_arg_ptr++ = info->name;
}
*lto_arg_ptr++ = NULL; *lto_arg_ptr++ = NULL;
exec_lto_wrapper (lto_argv); exec_lto_wrapper (lto_argv);
...@@ -949,16 +973,29 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) ...@@ -949,16 +973,29 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed)
if (obj.found > 1) if (obj.found > 1)
resolve_conflicts (&lto_file.symtab, &lto_file.conflicts); resolve_conflicts (&lto_file.symtab, &lto_file.conflicts);
status = add_symbols (file->handle, lto_file.symtab.nsyms, if (obj.found > 0)
lto_file.symtab.syms); {
check (status == LDPS_OK, LDPL_FATAL, "could not add symbols"); status = add_symbols (file->handle, lto_file.symtab.nsyms,
lto_file.symtab.syms);
check (status == LDPS_OK, LDPL_FATAL, "could not add symbols");
num_claimed_files++;
claimed_files =
xrealloc (claimed_files,
num_claimed_files * sizeof (struct plugin_file_info));
claimed_files[num_claimed_files - 1] = lto_file;
}
if (obj.found == 0 && obj.offload == 1)
{
num_offload_files++;
offload_files =
xrealloc (offload_files,
num_offload_files * sizeof (struct plugin_file_info));
offload_files[num_offload_files - 1] = lto_file;
}
*claimed = 1; *claimed = 1;
num_claimed_files++;
claimed_files =
xrealloc (claimed_files,
num_claimed_files * sizeof (struct plugin_file_info));
claimed_files[num_claimed_files - 1] = lto_file;
goto cleanup; goto cleanup;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment