gcc/gcc/ada/switch.adb
Alexandre Oliva 1dedc12d18 revamp dump and aux output names
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.
2020-05-26 04:30:15 -03:00

272 lines
8.3 KiB
Ada

------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- S W I T C H --
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
-- --
-- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- --
-- ware Foundation; either version 3, or (at your option) any later ver- --
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
-- OUT 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 distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
with Osint; use Osint;
with Output; use Output;
package body Switch is
----------------
-- Bad_Switch --
----------------
procedure Bad_Switch (Switch : Character) is
begin
Osint.Fail ("invalid switch: " & Switch);
end Bad_Switch;
procedure Bad_Switch (Switch : String) is
begin
Osint.Fail ("invalid switch: " & Switch);
end Bad_Switch;
------------------------------
-- Check_Version_And_Help_G --
------------------------------
procedure Check_Version_And_Help_G
(Tool_Name : String;
Initial_Year : String;
Version_String : String := Gnatvsn.Gnat_Version_String)
is
Version_Switch_Present : Boolean := False;
Help_Switch_Present : Boolean := False;
Next_Arg : Natural;
begin
-- First check for --version or --help
Next_Arg := 1;
while Next_Arg < Arg_Count loop
declare
Next_Argv : String (1 .. Len_Arg (Next_Arg));
begin
Fill_Arg (Next_Argv'Address, Next_Arg);
if Next_Argv = Version_Switch then
Version_Switch_Present := True;
elsif Next_Argv = Help_Switch then
Help_Switch_Present := True;
end if;
Next_Arg := Next_Arg + 1;
end;
end loop;
-- If --version was used, display version and exit
if Version_Switch_Present then
Set_Standard_Output;
Display_Version (Tool_Name, Initial_Year, Version_String);
Write_Str (Gnatvsn.Gnat_Free_Software);
Write_Eol;
Write_Eol;
Exit_Program (E_Success);
end if;
-- If --help was used, display help and exit
if Help_Switch_Present then
Set_Standard_Output;
Usage;
Write_Eol;
Write_Line ("Report bugs to report@adacore.com");
Exit_Program (E_Success);
end if;
end Check_Version_And_Help_G;
------------------------------------
-- Display_Usage_Version_And_Help --
------------------------------------
procedure Display_Usage_Version_And_Help is
begin
Write_Str (" --version Display version and exit");
Write_Eol;
Write_Str (" --help Display usage and exit");
Write_Eol;
Write_Eol;
end Display_Usage_Version_And_Help;
---------------------
-- Display_Version --
---------------------
procedure Display_Version
(Tool_Name : String;
Initial_Year : String;
Version_String : String := Gnatvsn.Gnat_Version_String)
is
begin
Write_Str (Tool_Name);
Write_Char (' ');
Write_Str (Version_String);
Write_Eol;
Write_Str ("Copyright (C) ");
Write_Str (Initial_Year);
Write_Char ('-');
Write_Str (Gnatvsn.Current_Year);
Write_Str (", ");
Write_Str (Gnatvsn.Copyright_Holder);
Write_Eol;
end Display_Version;
-------------------------
-- Is_Front_End_Switch --
-------------------------
function Is_Front_End_Switch (Switch_Chars : String) return Boolean is
Ptr : constant Positive := Switch_Chars'First;
begin
return Is_Switch (Switch_Chars)
and then
(Switch_Chars (Ptr + 1) = 'I'
or else (Switch_Chars'Length >= 5
and then Switch_Chars (Ptr + 1 .. Ptr + 4) = "gnat")
or else (Switch_Chars'Length >= 5
and then Switch_Chars (Ptr + 2 .. Ptr + 4) = "RTS"));
end Is_Front_End_Switch;
----------------------------
-- Is_Internal_GCC_Switch --
----------------------------
function Is_Internal_GCC_Switch (Switch_Chars : String) return Boolean is
First : constant Natural := Switch_Chars'First + 1;
Last : constant Natural := Switch_Last (Switch_Chars);
begin
return Is_Switch (Switch_Chars)
and then
(Switch_Chars (First .. Last) = "-param" or else
Switch_Chars (First .. Last) = "dumpdir" or else
Switch_Chars (First .. Last) = "dumpbase" or else
Switch_Chars (First .. Last) = "dumpbase-ext");
end Is_Internal_GCC_Switch;
---------------
-- Is_Switch --
---------------
function Is_Switch (Switch_Chars : String) return Boolean is
begin
return Switch_Chars'Length > 1
and then Switch_Chars (Switch_Chars'First) = '-';
end Is_Switch;
-----------------
-- Switch_Last --
-----------------
function Switch_Last (Switch_Chars : String) return Natural is
Last : constant Natural := Switch_Chars'Last;
begin
if Last >= Switch_Chars'First
and then Switch_Chars (Last) = ASCII.NUL
then
return Last - 1;
else
return Last;
end if;
end Switch_Last;
-----------------
-- Nat_Present --
-----------------
function Nat_Present
(Switch_Chars : String;
Max : Integer;
Ptr : Integer) return Boolean
is
begin
return (Ptr <= Max
and then Switch_Chars (Ptr) in '0' .. '9')
or else
(Ptr < Max
and then Switch_Chars (Ptr) = '='
and then Switch_Chars (Ptr + 1) in '0' .. '9');
end Nat_Present;
--------------
-- Scan_Nat --
--------------
procedure Scan_Nat
(Switch_Chars : String;
Max : Integer;
Ptr : in out Integer;
Result : out Nat;
Switch : Character)
is
begin
Result := 0;
if not Nat_Present (Switch_Chars, Max, Ptr) then
Osint.Fail ("missing numeric value for switch: " & Switch);
end if;
if Switch_Chars (Ptr) = '=' then
Ptr := Ptr + 1;
end if;
while Ptr <= Max and then Switch_Chars (Ptr) in '0' .. '9' loop
Result :=
Result * 10 +
Character'Pos (Switch_Chars (Ptr)) - Character'Pos ('0');
Ptr := Ptr + 1;
if Result > Switch_Max_Value then
Osint.Fail ("numeric value out of range for switch: " & Switch);
end if;
end loop;
end Scan_Nat;
--------------
-- Scan_Pos --
--------------
procedure Scan_Pos
(Switch_Chars : String;
Max : Integer;
Ptr : in out Integer;
Result : out Pos;
Switch : Character)
is
Temp : Nat;
begin
Scan_Nat (Switch_Chars, Max, Ptr, Temp, Switch);
if Temp = 0 then
Osint.Fail ("numeric value out of range for switch: " & Switch);
end if;
Result := Temp;
end Scan_Pos;
end Switch;