Fix bootstrap comparison failure

Previously, bootstrap comparison failed when promoting symbols to
global because:

1. Randomness was used for promotion.
2. Order matters when partial linking, and such order was also random.

This commit fixes those issues.

gcc/ChangeLog:
2020-08-07  Giuliano Belinasssi <giuliano.belinassi@usp.br>

	* cgraphunit.c (childno): New variable.
	(maybe_compile_in_parallel): Store current child number.
	* gcc.c (sort_asm_files): New function.
	* toplev.c (init_additional_asm_names_file): Output child number.
	* toplev.h (init_additional_asm_names_file): Update interface.
	* tree.c (get_file_function_name): Do not use randomness when
	promoting names.
This commit is contained in:
Giuliano Belinassi 2020-08-07 19:06:02 -03:00
parent c3b38f65b5
commit 542730f087
6 changed files with 63 additions and 24 deletions

View File

@ -1,3 +1,13 @@
2020-08-07 Giuliano Belinasssi <giuliano.belinassi@usp.br>
* cgraphunit.c (childno): New variable.
(maybe_compile_in_parallel): Store current child number.
* gcc.c (sort_asm_files): New function.
* toplev.c (init_additional_asm_names_file): Output child number.
* toplev.h (init_additional_asm_names_file): Update interface.
* tree.c (get_file_function_name): Do not use randomness when
promoting names.
2020-08-06 Giuliano Belinasssi <giuliano.belinassi@usp.br>
* symtab.c (change_decl_assembler_name): Remove RTL output if

View File

@ -2765,7 +2765,12 @@ static bool is_number (const char *str)
return true;
}
static bool maybe_compile_in_parallel (void)
/* If forked, which child am I? */
static int childno = -1;
static bool
maybe_compile_in_parallel (void)
{
struct symtab_node *node;
int partitions, i, j;
@ -2901,6 +2906,7 @@ static bool maybe_compile_in_parallel (void)
pids[j] = fork ();
if (pids[j] == 0)
{
childno = j;
lto_apply_partition_mask (ltrans_partitions[j]);
return true;
}
@ -2966,7 +2972,7 @@ symbol_table::compile (const char *name)
/* Output everything. */
init_asm_output (name);
if (split_outputs)
handle_additional_asm (true);
handle_additional_asm (childno);
switch_to_section (text_section);
(*debug_hooks->assembly_start) ();

View File

@ -3311,6 +3311,26 @@ static bool has_hidden_E (int argc, const char *argv[])
return false;
}
static void
sort_asm_files (vec <char *> *_lines)
{
vec <char *> &lines = *_lines;
int i, n = lines.length ();
char **temp_buf = XALLOCAVEC (char *, n);
for (i = 0; i < n; i++)
temp_buf[i] = lines[i];
for (i = 0; i < n; i++)
{
char *no_str = strtok (temp_buf[i], " ");
char *name = strtok (NULL, "");
int pos = atoi (no_str);
lines[pos] = name;
}
}
/* Append -fsplit-output=<tempfile> to all calls to compilers. Return true
if a additional call to LD is required to merge the resulting files. */
@ -3383,6 +3403,8 @@ static void append_split_outputs (extra_arg_storer *storer,
parallelize. */
}
sort_asm_files (&additional_asm_files);
if (n_commands != 1)
fatal_error (input_location,
"Auto parallelism is unsupported when piping commands");

View File

@ -915,33 +915,34 @@ init_additional_asm_names_file (void)
/* Reinitialize the assembler file and store it in the additional asm file. */
void handle_additional_asm (bool child)
void
handle_additional_asm (int childno)
{
gcc_assert (split_outputs);
if (child)
{
const char *temp_asm_name = make_temp_file (".s");
asm_file_name = temp_asm_name;
if (childno < 0)
return;
if (asm_out_file == stdout)
fatal_error (UNKNOWN_LOCATION, "Unexpected asm output to stdout");
const char *temp_asm_name = make_temp_file (".s");
asm_file_name = temp_asm_name;
fclose (asm_out_file);
if (asm_out_file == stdout)
fatal_error (UNKNOWN_LOCATION, "Unexpected asm output to stdout");
asm_out_file = fopen (temp_asm_name, "w");
if (!asm_out_file)
fatal_error (UNKNOWN_LOCATION, "Unable to create asm output file.");
}
fclose (asm_out_file);
/* Reopen file as append mode. Here we assume that write to append file is
atomic, as it is in Linux. */
additional_asm_filenames = fopen (split_outputs, "a");
if (!additional_asm_filenames)
fatal_error (UNKNOWN_LOCATION, "Unable open the temporary asm files container.");
asm_out_file = fopen (temp_asm_name, "w");
if (!asm_out_file)
fatal_error (UNKNOWN_LOCATION, "Unable to create asm output file");
fprintf (additional_asm_filenames, "%s\n", asm_file_name);
fclose (additional_asm_filenames);
/* Reopen file as append mode. Here we assume that write to append file is
atomic, as it is in Linux. */
additional_asm_filenames = fopen (split_outputs, "a");
if (!additional_asm_filenames)
fatal_error (UNKNOWN_LOCATION, "Unable to open the temporary asm files container");
fprintf (additional_asm_filenames, "%d %s\n", childno, asm_file_name);
fclose (additional_asm_filenames);
}
/* A helper function; used as the reallocator function for cpp's line

View File

@ -105,6 +105,6 @@ extern void parse_alignment_opts (void);
extern void initialize_rtl (void);
extern void init_additional_asm_names_file (void);
extern void handle_additional_asm (bool);
extern void handle_additional_asm (int);
#endif /* ! GCC_TOPLEV_H */

View File

@ -9686,8 +9686,7 @@ get_file_function_name (const char *type)
q = (char *) alloca (9 + 19 + len + 1);
memcpy (q, file, len + 1);
snprintf (q + len, 9 + 19 + 1, "_%08X_" HOST_WIDE_INT_PRINT_HEX,
crc32_string (0, name), get_random_seed (false));
snprintf (q + len, 9 + 19 + 1, "_%08X", crc32_string (0, name));
p = q;
}
@ -9700,6 +9699,7 @@ get_file_function_name (const char *type)
Use a global object (which is already required to be unique over
the program) rather than the file name (which imposes extra
constraints). */
sprintf (buf, FILE_FUNCTION_FORMAT, type, p);
filter_name (buf);