From e59c8b12d1b97d903ca288e6f0f5a5d9d152786a Mon Sep 17 00:00:00 2001 From: iverbin Date: Thu, 25 Feb 2016 12:23:52 +0000 Subject: gcc/ PR driver/68463 * config/gnu-user.h (CRTOFFLOADBEGIN): Define. Add crtoffloadbegin.o if offloading is enabled and -fopenacc or -fopenmp is specified. (CRTOFFLOADEND): Likewise. (GNU_USER_TARGET_STARTFILE_SPEC): Add CRTOFFLOADBEGIN. (GNU_USER_TARGET_ENDFILE_SPEC): Add CRTOFFLOADEND. * lto-wrapper.c (offloadbegin, offloadend): Remove static vars. (offload_objects_file_name): New static var. (tool_cleanup): Remove offload_objects_file_name file. (find_offloadbeginend): Replace with ... (find_crtoffloadtable): ... this. (run_gcc): Remove offload_argc and offload_argv. Get offload_objects_file_name from -foffload-objects=... option. Read names of object files with offload from this file, pass them to compile_images_for_offload_targets. Don't call find_offloadbeginend and don't pass offloadbegin and offloadend to the linker. Don't pass offload non-LTO files to the linker, because now they're not claimed. libgcc/ PR driver/68463 * Makefile.in (crtoffloadtable$(objext)): New rule. * configure.ac (extra_parts): Add crtoffloadtable$(objext) if enable_offload_targets is not empty. * configure: Regenerate. * offloadstuff.c: Move __OFFLOAD_TABLE__ from crtoffloadend to crtoffloadtable. libgomp/ PR driver/68463 * testsuite/libgomp.oacc-c-c++-common/parallel-dims-2.c: Remove. lto-plugin/ PR driver/68463 * lto-plugin.c (struct plugin_offload_file): New. (offload_files): Change type. (offload_files_last, offload_files_last_obj): New. (offload_files_last_lto): New. (free_2): Adjust accordingly. (all_symbols_read_handler): Don't add offload files to lto_arg_ptr. Don't call free_1 for offload_files. Write names of object files with offloading to the temporary file. Add new option to lto_arg_ptr. (claim_file_handler): Don't claim file if it contains offload sections without LTO sections. If it contains offload sections, add to the list. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@233712 138bc75d-0d04-0410-961f-82ee72b054a4 --- lto-plugin/ChangeLog | 14 +++++ lto-plugin/lto-plugin.c | 140 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 127 insertions(+), 27 deletions(-) (limited to 'lto-plugin') diff --git a/lto-plugin/ChangeLog b/lto-plugin/ChangeLog index 4ebccb71df85..d2cd98675bc7 100644 --- a/lto-plugin/ChangeLog +++ b/lto-plugin/ChangeLog @@ -1,3 +1,17 @@ +2016-02-25 Ilya Verbin + + PR driver/68463 + * lto-plugin.c (struct plugin_offload_file): New. + (offload_files): Change type. + (offload_files_last, offload_files_last_obj): New. + (offload_files_last_lto): New. + (free_2): Adjust accordingly. + (all_symbols_read_handler): Don't add offload files to lto_arg_ptr. + Don't call free_1 for offload_files. Write names of object files with + offloading to the temporary file. Add new option to lto_arg_ptr. + (claim_file_handler): Don't claim file if it contains offload sections + without LTO sections. If it contains offload sections, add to the list. + 2016-01-15 Martin Liska * lto-plugin.c (all_symbols_read_handler): Assign default diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c index 1ed0f0863c01..51afc528d059 100644 --- a/lto-plugin/lto-plugin.c +++ b/lto-plugin/lto-plugin.c @@ -129,6 +129,14 @@ struct plugin_file_info struct plugin_symtab conflicts; }; +/* List item with name of the file with offloading. */ + +struct plugin_offload_file +{ + char *name; + struct plugin_offload_file *next; +}; + /* Until ASM_OUTPUT_LABELREF can be hookized and decoupled from stdio file streams, we do simple label translation here. */ @@ -152,8 +160,16 @@ static ld_plugin_add_symbols add_symbols; static struct plugin_file_info *claimed_files = NULL; static unsigned int num_claimed_files = 0; -static struct plugin_file_info *offload_files = NULL; -static unsigned int num_offload_files = 0; +/* List of files with offloading. */ +static struct plugin_offload_file *offload_files; +/* Last file in the list. */ +static struct plugin_offload_file *offload_files_last; +/* Last non-archive file in the list. */ +static struct plugin_offload_file *offload_files_last_obj; +/* Last LTO file in the list. */ +static struct plugin_offload_file *offload_files_last_lto; +/* Total number of files with offloading. */ +static unsigned num_offload_files; static char **output_files = NULL; static unsigned int num_output_files = 0; @@ -351,14 +367,6 @@ free_2 (void) 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++) free (output_files[i]); free (output_files); @@ -367,8 +375,12 @@ free_2 (void) claimed_files = NULL; num_claimed_files = 0; - free (offload_files); - offload_files = NULL; + while (offload_files) + { + struct plugin_offload_file *ofld = offload_files; + offload_files = offload_files->next; + free (ofld); + } num_offload_files = 0; free (arguments_file_name); @@ -625,8 +637,7 @@ static enum ld_plugin_status all_symbols_read_handler (void) { unsigned i; - unsigned num_lto_args - = num_claimed_files + num_offload_files + lto_wrapper_num_args + 2; + unsigned num_lto_args = num_claimed_files + lto_wrapper_num_args + 3; char **lto_argv; const char *linker_output_str = NULL; const char **lto_arg_ptr; @@ -646,7 +657,6 @@ all_symbols_read_handler (void) write_resolution (); free_1 (claimed_files, num_claimed_files); - free_1 (offload_files, num_offload_files); for (i = 0; i < lto_wrapper_num_args; i++) *lto_arg_ptr++ = lto_wrapper_argv[i]; @@ -671,16 +681,38 @@ all_symbols_read_handler (void) break; } *lto_arg_ptr++ = xstrdup (linker_output_str); - for (i = 0; i < num_claimed_files; i++) + + if (num_offload_files > 0) { - struct plugin_file_info *info = &claimed_files[i]; + FILE *f; + char *arg; + char *offload_objects_file_name; + struct plugin_offload_file *ofld; + + offload_objects_file_name = make_temp_file (".ofldlist"); + check (offload_objects_file_name, LDPL_FATAL, + "Failed to generate a temporary file name"); + f = fopen (offload_objects_file_name, "w"); + check (f, LDPL_FATAL, "could not open file with offload objects"); + fprintf (f, "%u\n", num_offload_files); + + /* Skip the dummy item at the start of the list. */ + ofld = offload_files->next; + while (ofld) + { + fprintf (f, "%s\n", ofld->name); + ofld = ofld->next; + } + fclose (f); - *lto_arg_ptr++ = info->name; + arg = concat ("-foffload-objects=", offload_objects_file_name, NULL); + check (arg, LDPL_FATAL, "could not allocate"); + *lto_arg_ptr++ = arg; } - for (i = 0; i < num_offload_files; i++) + for (i = 0; i < num_claimed_files; i++) { - struct plugin_file_info *info = &offload_files[i]; + struct plugin_file_info *info = &claimed_files[i]; *lto_arg_ptr++ = info->name; } @@ -1007,18 +1039,72 @@ claim_file_handler (const struct ld_plugin_input_file *file, int *claimed) xrealloc (claimed_files, num_claimed_files * sizeof (struct plugin_file_info)); claimed_files[num_claimed_files - 1] = lto_file; + + *claimed = 1; } - if (obj.found == 0 && obj.offload == 1) + if (offload_files == NULL) { - num_offload_files++; - offload_files = - xrealloc (offload_files, - num_offload_files * sizeof (struct plugin_file_info)); - offload_files[num_offload_files - 1] = lto_file; + /* Add dummy item to the start of the list. */ + offload_files = xmalloc (sizeof (struct plugin_offload_file)); + offload_files->name = NULL; + offload_files->next = NULL; + offload_files_last = offload_files; } - *claimed = 1; + /* If this is an LTO file without offload, and it is the first LTO file, save + the pointer to the last offload file in the list. Further offload LTO + files will be inserted after it, if any. */ + if (*claimed && obj.offload == 0 && offload_files_last_lto == NULL) + offload_files_last_lto = offload_files_last; + + if (obj.offload == 1) + { + /* Add file to the list. The order must be exactly the same as the final + order after recompilation and linking, otherwise host and target tables + with addresses wouldn't match. If a static library contains both LTO + and non-LTO objects, ld and gold link them in a different order. */ + struct plugin_offload_file *ofld + = xmalloc (sizeof (struct plugin_offload_file)); + ofld->name = lto_file.name; + ofld->next = NULL; + + if (*claimed && offload_files_last_lto == NULL && file->offset != 0 + && gold_version == -1) + { + /* ld only: insert first LTO file from the archive after the last real + object file immediately preceding the archive, or at the begin of + the list if there was no real objects before archives. */ + if (offload_files_last_obj != NULL) + { + ofld->next = offload_files_last_obj->next; + offload_files_last_obj->next = ofld; + } + else + { + ofld->next = offload_files->next; + offload_files->next = ofld; + } + } + else if (*claimed && offload_files_last_lto != NULL) + { + /* Insert LTO file after the last LTO file in the list. */ + ofld->next = offload_files_last_lto->next; + offload_files_last_lto->next = ofld; + } + else + /* Add non-LTO file or first non-archive LTO file to the end of the + list. */ + offload_files_last->next = ofld; + + if (ofld->next == NULL) + offload_files_last = ofld; + if (file->offset == 0) + offload_files_last_obj = ofld; + if (*claimed) + offload_files_last_lto = ofld; + num_offload_files++; + } goto cleanup; -- cgit v1.2.3