This adds a -ltrans-objects option to lto-plugin that by-passes
lto-wrapper invocation and instead feeds LD the final LTRANS objects
directly from the response file given as argument to the option.
This allows LD issues involving the linker-plugin path to be
debugged in an easier way with just the IR objects (their symtab)
and the LTRANS objects as testcase.
I've tested the path re-building stage2 build/genmatch from an
LTO bootstrap and got a bit-identical executable by adding
-plugin-opt=-ltrans-objects=y to the original collect2 invocation,
seeding y with the final objects as printed by building genmatch
with -save-temps -v.
2021-06-22 Richard Biener <rguenther@suse.de>
lto-plugin/
* lto-plugin.c (ltrans_objects): New global.
(all_symbols_read_handler): If -ltrans-objects was specified,
add the output files from the specified file directly.
(process_option): Handle -ltrans-objects.
This fixes:
lto-plugin.c:642:7: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
lto-plugin/ChangeLog:
* lto-plugin.c (exec_lto_wrapper): Make a temp variable.
2020-09-09 Nick Clifton <nickc@redhat.com>
* lto-plugin.c (struct plugin_symtab): Add last_sym field.
(parse_symtab_extension): Only read as many entries as are
available in the buffer. Store the data read into the symbol
table indexed from last_sym. Increment last_sym.
This patch simplifies (!!!) the logic governing the naming of dump
files and auxiliary output files in the driver, in the compiler, and
in the LTO wrapper. No changes are made to the naming of primary
outputs, there are often ways to restore past behavior, and a number
of inconsistencies are fixed. Some internal options are removed
(-auxbase and -auxbase-strip), sensible existing uses of -dumpdir and
-dumpbase options remain unchanged, additional useful cases are added,
making for what is still admittedly quite complex. Extensive
documentation and testcases provide numerous examples, from normal to
corner cases.
The most visible changes are:
- aux and dump files now always go in the same directory, that
defaults to the directory of the primary output, but that can be
overridden with -dumpdir, -save-temps=*, or, preserving past behavior,
with a -dumpbase with a directory component.
- driver and compiler now have the same notion of naming of auxiliary
outputs, e.g. .dwo files will no longer be in one location while the
debug info suggests they are elsewhere, and -save-temps and .dwo
auxiliary outputs now go in the same location as .su, .ci and
coverage data, with consistent naming.
- explicitly-specified primary output names guide not only the
location of aux and dump outputs: the output base name is also used in
their base name, as a prefix when also linking (e.g. foo.c bar.c -o
foobar creates foobar-foo.dwo and foobar-bar.dwo with -gsplit-dwarf),
or as the base name instead of the input name (foo.c -c -o whatever.o
creates whatever.su rather than foo.su with -fstack-usage). The
preference for the input file base name, quite useful for our
testsuite, can be restored with -dumpbase "". When compiling and
linking tests in the testsuite with additional inputs, we now use this
flag. Files named in dejagnu board ldflags, libs, and ldscripts are
now quoted in the gcc testsuite with -Wl, so that they are not counted
as additional inputs by the compiler driver.
- naming a -dumpbase when compiling multiple sources used to cause
dumps from later compiles to overwrite those of earlier ones; it is
now used as a prefix when compiling multiple sources, like an
executable name above.
- the dumpbase, explicitly specified or computed from output or input
names, now also governs the naming of aux outputs; since aux outputs
usually replaced the suffix from the input name, while dump outputs
append their own additional suffixes, a -dumpbase-ext option is
introduced to enable a chosen suffix to be dropped from dumpbase to
form aux output names.
- LTO dump and aux outputs were quite a mess, sometimes leaking
temporary output names into -save-temps output names, sometimes
conversely generating desirable aux outputs in temporary locations.
They now obey the same logic of compiler aux and dump outputs, landing
in the expected location and taking the linker output name or an
explicit dumpbase overrider into account.
- Naming of -fdump-final-insns outputs now follows the dump file
naming logic for the .gkd files, and the .gk dump files generated in
the second -fcompare-debug compilation get the .gk inserted before the
suffix that -dumpbase-ext drops in aux outputs.
gcc/ChangeLog:
* common.opt (aux_base_name): Define.
(dumpbase, dumpdir): Mark as Driver options.
(-dumpbase, -dumpdir): Likewise.
(dumpbase-ext, -dumpbase-ext): New.
(auxbase, auxbase-strip): Drop.
* doc/invoke.texi (-dumpbase, -dumpbase-ext, -dumpdir):
Document.
(-o): Introduce the notion of primary output, mention it
influences auxiliary and dump output names as well, add
examples.
(-save-temps): Adjust, move examples into -dump*.
(-save-temps=cwd, -save-temps=obj): Likewise.
(-fdump-final-insns): Adjust.
* dwarf2out.c (gen_producer_string): Drop auxbase and
auxbase_strip; add dumpbase_ext.
* gcc.c (enum save_temps): Add SAVE_TEMPS_DUMP.
(save_temps_prefix, save_temps_length): Drop.
(save_temps_overrides_dumpdir): New.
(dumpdir, dumpbase, dumpbase_ext): New.
(dumpdir_length, dumpdir_trailing_dash_added): New.
(outbase, outbase_length): New.
(The Specs Language): Introduce %". Adjust %b and %B.
(ASM_FINAL_SPEC): Use %b.dwo for an aux output name always.
Precede object file with %w when it's the primary output.
(cpp_debug_options): Do not pass on incoming -dumpdir,
-dumpbase and -dumpbase-ext options; recompute them with
%:dumps.
(cc1_options): Drop auxbase with and without compare-debug;
use cpp_debug_options instead of dumpbase. Mark asm output
with %w when it's the primary output.
(static_spec_functions): Drop %:compare-debug-auxbase-opt and
%:replace-exception. Add %:dumps.
(driver_handle_option): Implement -save-temps=*/-dumpdir
mutual overriding logic. Save dumpdir, dumpbase and
dumpbase-ext options. Do not save output_file in
save_temps_prefix.
(adds_single_suffix_p): New.
(single_input_file_index): New.
(process_command): Combine output dir, output base name, and
dumpbase into dumpdir and outbase.
(set_collect_gcc_options): Pass a possibly-adjusted -dumpdir.
(do_spec_1): Optionally dumpdir instead of save_temps_prefix,
and outbase instead of input_basename in %b, %B and in
-save-temps aux files. Handle empty argument %".
(driver::maybe_run_linker): Adjust dumpdir and auxbase.
(compare_debug_dump_opt_spec_function): Adjust gkd dump file
naming. Spec-quote the computed -fdump-final-insns file name.
(debug_auxbase_opt): Drop.
(compare_debug_self_opt_spec_function): Drop auxbase-strip
computation.
(compare_debug_auxbase_opt_spec_function): Drop.
(not_actual_file_p): New.
(replace_extension_spec_func): Drop.
(dumps_spec_func): New.
(convert_white_space): Split-out parts into...
(quote_string, whitespace_to_convert_p): ... these. New.
(quote_spec_char_p, quote_spec, quote_spec_arg): New.
(driver::finalize): Release and reset new variables; drop
removed ones.
* lto-wrapper.c (HAVE_TARGET_EXECUTABLE_SUFFIX): Define if...
(TARGET_EXECUTABLE_SUFFIX): ... is defined; define this to the
empty string otherwise.
(DUMPBASE_SUFFIX): Drop leading period.
(debug_objcopy): Use concat.
(run_gcc): Recognize -save-temps=* as -save-temps too. Obey
-dumpdir. Pass on empty dumpdir and dumpbase with a directory
component. Simplify temp file names.
* opts.c (finish_options): Drop aux base name handling.
(common_handle_option): Drop auxbase-strip handling.
* toplev.c (print_switch_values): Drop auxbase, add
dumpbase-ext.
(process_options): Derive aux_base_name from dump_base_name
and dump_base_ext.
(lang_dependent_init): Compute dump_base_ext along with
dump_base_name. Disable stack usage and callgraph-info during
lto generation and compare-debug recompilation.
gcc/fortran/ChangeLog:
* options.c (gfc_get_option_string): Drop auxbase, add
dumpbase_ext.
gcc/ada/ChangeLog:
* gcc-interface/lang-specs.h: Drop auxbase and auxbase-strip.
Use %:dumps instead of -dumpbase. Add %w for implicit .s
primary output.
* switch.adb (Is_Internal_GCC_Switch): Recognize dumpdir and
dumpbase-ext. Drop auxbase and auxbase-strip.
lto-plugin/ChangeLog:
* lto-plugin.c (skip_in_suffix): New.
(exec_lto_wrapper): Use skip_in_suffix and concat to build
non-temporary output names.
(onload): Look for -dumpdir in COLLECT_GCC_OPTIONS, and
override link_output_name with it.
contrib/ChangeLog:
* compare-debug: Adjust for .gkd files named as dump files,
with the source suffix rather than the object suffix.
gcc/testsuite/ChangeLog:
* gcc.misc-tests/outputs.exp: New.
* gcc.misc-tests/outputs-0.c: New.
* gcc.misc-tests/outputs-1.c: New.
* gcc.misc-tests/outputs-2.c: New.
* lib/gcc-defs.exp (gcc_adjusted_linker_flags): New.
(gcc_adjust_linker_flags): New.
(dg-additional-files-options): Call it. Pass -dumpbase ""
when there are additional sources.
* lib/profopt.exp (profopt-execute): Pass the executable
suffix with -dumpbase-ext.
* lib/scandump.exp (dump-base): Mention -dumpbase "" use.
* lib/scanltranstree.exp: Adjust dump suffix expectation.
* lib/scanwpaipa.exp: Likewise.
The link phase is always partial (-r) for VxWorks in kernel mode, which
means that it uses incremental LTO linking by default (-flinker-output=rel).
But in this mode the LTO plugin outputs a warning if one of the object files
involved in the link does not contain LTO bytecode, before switching to
nolto-rel mode. We do not do repeated incremental linking for VxWorks so
silence the warning.
lto-plugin/
* lto-plugin.c: Document -linker-output-auto-notlo-rel option.
(linker_output_set): Change type to bool.
(linker_output_known): Likewise.
(linker_output_auto_nolto_rel): New variable.
(all_symbols_read_handler): Take it into account.
<LDPO_REL>: Do not issue the warning if it is set.
(process_option): Process -linker-output-auto-notlo-rel.
(cleanup_handler): Remove unused variable.
(onload) <LDPT_LINKER_OUTPUT>: Adjust to above type change.
gcc/
* gcc.c (LTO_PLUGIN_SPEC): Define if not already.
(LINK_PLUGIN_SPEC): Execute LTO_PLUGIN_SPEC.
* config/vxworks.h (LTO_PLUGIN_SPEC): Define.
This patch makes the lto-plugin follow the same approach
to save-temps as collect2.
-save-temps causes the temp file to be named meaningfully,
and for the relevant input files to be saved in CWD.
-v, —version causes the save actions to be output to stderr.
one can get this to happen by just putting -save-temps, -v on
the regular link line or (for compatibility with the way the
-debug flag works) by appending -plugin-opt=-save-temps, etc.
lto-plugin/
2019-05-15 Iain Sandoe <iain@sandoe.co.uk>
* lto-plugin.c (exec_lto_wrapper): Make the wrapper
arguments filename more user-friendly.
(file_exists, maybe_unlink): New.
(cleanup_handler): Use maybe unlink to handle the
case when temps should be saved.
(process_option): Look for -v, —-version, -save-temps.
(onload): Record the linker output file name.
Check for -v, —-version, -save-temps in the GCC collect
options environment.
From-SVN: r271202
* lto-plugin.c: (non_claimed_files): New static var.
(linker_ouput_known): New static var.
(all_symbols_read_handler): When user specifies linker output do not
imply it; output warning when nonlto-rel mode is forced.
(claim_file_header): Record number of nonclaimed files.
(process_option): Remember if linker output is known
From-SVN: r260960
lto-plugin/
PR lto/81487
* lto-plugin.c (claim_file_handler): Use xasprintf instead of
asprintf.
[hi!=0]: Swap hi and lo arguments supplied to xasprintf.
From-SVN: r250428
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.
From-SVN: r233712
PR lto/67548
* lto-plugin.c (linker_output, linker_output_set): New statics.
(all_symbols_read_handler): Add -flinker-output option.
(onload): Record linker_output info.
* ipa-visibility.c (cgraph_externally_visible_p,
varpool_node::externally_visible_p): When doing incremental linking,
hidden symbols may be still used later.
(update_visibility_by_resolution_info): Do not drop weak during
incremental link.
(function_and_variable_visibility): Fix formating.
* flag-types.h (lto_linker_output): Declare.
* common.opt 9flag_incremental_link): New flag.
* lto-lang.c (lto_post_options): Process flag_lto_linker_output.
* lang.opt (lto_linker_output): New enum.
(flinker_output): New flag.
From-SVN: r230915
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
gcc/
* gcc.c (spec_host_machine, accel_dir_suffix): New variables.
(process_command): Tweak path construction for the possibility
of being configured as an offload compiler.
(driver::maybe_putenv_OFFLOAD_TARGETS): New function.
(driver::main): Call maybe_putenv_OFFLOAD_TARGETS.
(driver::set_up_specs): Tweak path construction for the possibility of
being configured as an offload compiler.
* lto-wrapper.c (OFFLOAD_TARGET_NAMES_ENV): Define.
(offload_names, offloadbegin, offloadend): New static variables.
(free_array_of_ptrs, parse_env_var, access_check, compile_offload_image)
(compile_images_for_offload_targets, copy_file, find_offloadbeginend):
New static functions.
(run_gcc): Determine whether offload sections are present. If so, run
compile_images_for_offload_targets and return the names of new generated
objects to linker. If there are offload sections, but no LTO sections,
then return the copies of input objects without link-time recompilation.
lto-plugin/
* lto-plugin.c (OFFLOAD_SECTION, OFFLOAD_SECTION_LEN): Define.
(struct plugin_objfile): Add new field "offload".
(process_offload_section): New static function.
(claim_file_handler): Claim file if it contains offload sections.
Co-Authored-By: Andrey Turetskiy <andrey.turetskiy@intel.com>
Co-Authored-By: Bernd Schmidt <bernds@codesourcery.com>
Co-Authored-By: Michael Zolotukhin <michael.v.zolotukhin@intel.com>
From-SVN: r217491
2014-04-02 Richard Biener <rguenther@suse.de>
* lto-plugin.c (onload): Fail to load if -fno-use-linker-plugin
is set in COLLECT_GCC_OPTIONS.
From-SVN: r209011
2014-03-28 Richard Biener <rguenther@suse.de>
libiberty/
* simple-object.c (simple_object_internal_read): Handle
EINTR and short reads.
lto-plugin/
* lto-plugin.c (process_symtab): Handle EINTR and short reads.
From-SVN: r208898
PR lto/50616
* lto-plugin.c (PRI_LL): New macro.
(dump_symtab): Use PRI_LL instead of ll in print.
(process_symtab): Use PRI_LL instead of ll in scan.
From-SVN: r184462
Change "if (E) free (E);" to "free (E);" everywhere except in the
libgo/, intl/, zlib/ and classpath/ directories.
Also transform equivalent variants like
"if (E != NULL) free (E);" and allow an extra cast on the
argument to free. Otherwise, the tested and freed "E"
expressions must be identical, modulo white space.
From-SVN: r172785
* lto-plugin.c (gold_version): New static variable.
(all_symbols_read_handler): Don't check pass_through_items if
using gold 1.11 or later.
(onload): Set gold_version if we see LDPT_GOLD_VERSION.
From-SVN: r169237
PR bootstrap/46397
PR bootstrap/46362
* configure.ac: Add AC_TYPE_INT64_T test.
* config.h.in: Regenerate.
* configure: Likewise.
* lto-plugin.c (debug): Use char not bool.
(nop): Likewise.
(check_1): Rename from check, and use int not bool for gate argument.
(check): Macro wrapper for the above to coerce gate argument into
boolean-valued integer in case it has pointer type.
(parse_table_entry): Use 0 not false.
(claim_file_handler): Avoid use of PRIx64 by splitting 64-bit size
into two 32-bit parts and printing as hex ints.
From-SVN: r166601
ChangeLog:
2010-11-03 Ian Lance Taylor <iant@google.com>
Dave Korn <dave.korn.cygwin@gmail.com>
PR lto/46273
* configure.ac: Remove libelf tests. Build lto-plugin on ELF always
and on other supported platforms whenever LTO is enabled.
* configure: Rebuild.
gcc/ChangeLog:
2010-11-03 Ian Lance Taylor <iant@google.com>
PR lto/46273
* gcc/config.gcc: Don't set lto_binary_reader.
* doc/install.texi (Prerequisites): Remove libelf paragraphs.
(Configuration): Mention --disable-lto. Remove --with-libelf
paragraph.
lto-plugin/ChangeLog:
2010-11-03 Dave Korn <dave.korn.cygwin@gmail.com>
PR lto/46273
* lto-plugin.h: Delete.
* lto-plugin-elf.c: Likewise.
* lto-plugin-coff.c: Likewise.
* configure.ac: Don't use libelf, don't source config.gcc.
(LIBELFLIBS): Delete.
(LIBELFINC): Delete.
(LTO_FORMAT): Delete.
(SYM_STYLE): Add AC_DEFINE var, set based on $target.
(config.h): Add AC_CONFIG_HEADERS directive.
* Makefile.am (LIBELFLIBS): Delete.
(LIBELFINC): Delete.
(LTO_FORMAT): Delete.
(DEFS): Import.
(AM_CPPFLAGS): Use it. Don't use LIBELFINC.
(liblto_plugin_la_SOURCES): Don't use LTO_FORMAT, don't include
any object-format-specific source file in the link.
(liblto_plugin_la_LIBADD): Don't use LIBELFLIBS.
* config.h.in: Generate.
* configure: Regenerate.
* Makefile.in: Likewise.
* lto-plugin.c (O_BINARY): Definition moved here from lto-plugin.h.
(LTO_SEGMENT_NAME): New definition.
(LTO_SECTION_PREFIX): Definition moved here from lto-plugin.h.
(LTO_SECTION_PREFIX_LEN): New definition.
(struct sym_aux): Struct definition moved here from lto-plugin.h.
(struct plugin_symtab): Likewise.
(struct plugin_objfile): Likewise.
(struct plugin_objfile): New struct def.
(enum symbol_style): New enum type.
(add_symbols): Make static.
(claimed_files): Likewise.
(num_claimed_files): Likewise.
(sym_style): New global.
(check): Make static.
(parse_table_entry): Likewise. Respect sym_style when extracting
symbol from symtab entry.
(translate): Make static.
(resolve_conflicts): Likewise.
(process_symtab): New function, per-section callback version of
old object-format-specific handling from deleted lto-plugin-elf.c.
(claim_file_handler): Convert ELF-specific version from deleted
lto-plugin-elf.c to simple_object interface and move here.
(process_options): Allow new '-sym-style=' option.
(onload): Don't call deleted onload_format_checks hook.
From-SVN: r166233
ChangeLog:
2010-10-07 Dave Korn <dave.korn.cygwin@gmail.com>
* configure.ac (build_lto_plugin): New shell variable.
(--enable-lto): Turn on by default for all non-ELF platforms that
have had LTO support added so far. Set build_lto_plugin appropriately
for both ELF and non-ELF.
(configdirs): Add lto-plugin or not based on build_lto_plugin.
* configure: Regenerate.
gcc/ChangeLog:
2010-10-07 Dave Korn <dave.korn.cygwin@gmail.com>
* config.host (host_lto_plugin_soname): New shell variable.
* configure.ac (LTOPLUGINSONAME): Add an AC_DEFINE for the above.
* config.in: Regenerate.
* configure: Regenerate.
* gcc.c (main): Use LTOPLUGINSONAME instead of hard-coding name of
LTO plugin shared library.
lto-plugin/ChangeLog:
2010-10-07 Dave Korn <dave.korn.cygwin@gmail.com>
* configure.ac: Source config.gcc to determine lto_binary_reader.
(LTO_FORMAT): New AC_SUBST variable inferred from lto_binary_reader.
* Makefile.am (LTO_FORMAT): Import.
(liblto_plugin_la_SOURCES): Add object format dependent module
defined by LTO_FORMAT.
(liblto_plugin_la_LIBADD): Allow for both PIC and non-PIC libiberty,
and work around libtool warning.
* configure: Regenerate.
* Makefile.in: Likewise.
* lto-plugin.c (struct sym_aux): Move to new lto-plugin.h.
(struct sym_aux): Likewise.
(struct plugin_symtab): Likewise.
(struct plugin_file_info): Likewise.
(LTO_SECTION_PREFIX): Likewise.
(add_symbols): Make non-static.
(claimed_files): Likewise.
(num_claimed_files): Likewise.
(check): Likewise.
(parse_table_entry): Likewise.
(translate): Likewise.
(resolve_conflicts): Likewise.
(process_symtab): Move to new lto-plugin-elf.c object format dependent
source file.
(claim_file_handler): Likewise, and make non-static.
(onload): Call new onload_format_checks function.
* lto-plugin.h: New file.
(LTO_SECTION_PREFIX): Move here.
(struct sym_aux): Likewise.
(struct plugin_symtab): Likewise.
(struct plugin_file_info): Likewise.
(claim_file_handler): Add new function prototype.
(onload_format_checks): Likewise.
(check): Declare extern.
(translate): Likewise.
(parse_table_entry): Likewise.
(resolve_conflicts): Likewise.
(add_symbols): Likewise.
(claimed_files): Likewise.
(num_claimed_files): Likewise.
* lto-plugin-elf.c (process_symtab): Move here.
(claim_file_handler): Likewise, and make non-static.
(onload_format_checks): New function factored out from onload.
* lto-plugin-coff.c (claim_file_handler): New function stub.
(onload_format_checks): Likewise.
From-SVN: r165133