]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix bootstrap comparison failure
authorGiuliano Belinassi <giuliano.belinassi@usp.br>
Fri, 7 Aug 2020 22:06:02 +0000 (19:06 -0300)
committerGiuliano Belinassi <giuliano.belinassi@usp.br>
Fri, 7 Aug 2020 22:06:02 +0000 (19:06 -0300)
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.

gcc/ChangeLog
gcc/cgraphunit.c
gcc/gcc.c
gcc/toplev.c
gcc/toplev.h
gcc/tree.c

index 2887adcb709ae9f782eb1e4c2b108314f11fdf20..c3a573ee363d30750acda09821f39def3fd8d7fc 100644 (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
index a5d5b86f1919d04da4543be28ec05ee7958cbb46..ef606dbbb8506b0f972cc237a756248b7f5dd4f4 100644 (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) ();
index 88ac31e9e8d2d511677086c80baaa2641ad788bb..852db3f6581feb20bfdd7844ecddebdc7d072dcf 100644 (file)
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -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");
index 057812dbe657ec9eb78d807e970dd1de4f789f71..df26a6404ced37b2e2b5c8aac264494a49bfdb11 100644 (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
index 7159f5ffc069c7699ca3ba2aa6336e81b23c8191..bae7eb453631f6dede819cc77d0c06a5ff73ec63 100644 (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 */
index 32977e57e70d7712eee4bca7c84ab4216638b73e..c1bc8236c5078925ae37f792cc046781ea9419bc 100644 (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);