This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Enable the use of a resolution file


Cary noticed I forgot to include the patch. Attached.


Cheers,
-- 
Rafael Ãvila de EspÃndola
diff --git a/gcc/lto/lang.opt b/gcc/lto/lang.opt
index f383d7c..a8b7916 100644
--- a/gcc/lto/lang.opt
+++ b/gcc/lto/lang.opt
@@ -36,7 +36,7 @@ fwpa
 LTO Report Var(flag_wpa) Optimization
 Run the link-time optimizer in whole program analysis (WPA) mode.
 
-resolution
+fresolution
 LTO Separate
 The resolution file
 
diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c
index 04d4230..486338f 100644
--- a/gcc/lto/lto-lang.c
+++ b/gcc/lto/lto-lang.c
@@ -622,7 +622,7 @@ lto_handle_option (size_t scode, const char *arg, int value ATTRIBUTE_UNUSED)
 
   switch (code)
     {
-    case OPT_resolution:
+    case OPT_fresolution:
       resolution_file_name = arg;
       result = 1;
       break;
diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c
index d8c49cf..323f6b3 100644
--- a/gcc/lto/lto.c
+++ b/gcc/lto/lto.c
@@ -284,6 +284,7 @@ lto_resolution_read (FILE *resolution, const char *file_name)
 
   for (i = 0; i < num_symbols; i++)
     {
+      int t;
       unsigned index;
       char r_str[27];
       enum ld_plugin_symbol_resolution r;
@@ -291,7 +292,9 @@ lto_resolution_read (FILE *resolution, const char *file_name)
       unsigned int lto_resolution_str_len =
 	sizeof (lto_resolution_str) / sizeof (char *);
 
-      fscanf (resolution, "%u %26s", &index, r_str);
+      t = fscanf (resolution, "%u %26s %*[^\n]\n", &index, r_str);
+      if (t != 2)
+        internal_error ("Invalid line in the resolution file.");
       if (index > max_index)
 	max_index = index;
 
@@ -303,9 +306,8 @@ lto_resolution_read (FILE *resolution, const char *file_name)
 	      break;
 	    }
 	}
-      if (j >= lto_resolution_str_len)
-	internal_error ("tried to read past the end of the linker resolution "
-			"file");
+      if (j == lto_resolution_str_len)
+	internal_error ("Invalid resolution in the resolution file.");
 
       VEC_safe_grow_cleared (ld_plugin_symbol_resolution_t, heap, ret,
 			     index + 1);
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index e8e88cb..c9c9c48 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -310,9 +310,6 @@ write_resolution (void)
   unsigned int i;
   FILE *f;
 
-  if (!resolution_file)
-    return;
-
   f = fopen (resolution_file, "w");
   check (f, LDPL_FATAL, "could not open file");
 
@@ -334,7 +331,7 @@ write_resolution (void)
 	{
 	  uint32_t slot = symtab->slots[j];
 	  unsigned int resolution = syms[j].resolution;
-	  fprintf (f, "%d %s\n", slot, lto_resolution_str[resolution]);
+	  fprintf (f, "%d %s %s \n", slot, lto_resolution_str[resolution], syms[j].name);
 	}
     }
   fclose (f);
@@ -452,7 +449,7 @@ static enum ld_plugin_status
 all_symbols_read_handler (void)
 {
   unsigned i;
-  unsigned num_lto_args = num_claimed_files + lto_wrapper_num_args + 1;
+  unsigned num_lto_args = num_claimed_files + lto_wrapper_num_args + 2 + 1;
   char **lto_argv;
   const char **lto_arg_ptr;
   if (num_claimed_files == 0)
@@ -468,6 +465,9 @@ all_symbols_read_handler (void)
   lto_arg_ptr = (const char **) lto_argv;
   assert (lto_wrapper_argv);
 
+  resolution_file = make_temp_file ("");
+  printf("resolution: %s\n", resolution_file);
+
   write_resolution ();
 
   free_1 ();
@@ -475,6 +475,9 @@ all_symbols_read_handler (void)
   for (i = 0; i < lto_wrapper_num_args; i++)
     *lto_arg_ptr++ = lto_wrapper_argv[i];
 
+  *lto_arg_ptr++ = "-fresolution";
+  *lto_arg_ptr++ = resolution_file;
+
   for (i = 0; i < num_claimed_files; i++)
     {
       struct plugin_file_info *info = &claimed_files[i];
@@ -522,6 +525,12 @@ cleanup_handler (void)
       check (t == 0, LDPL_FATAL, "could not unlink arguments file");
     }
 
+  if (resolution_file)
+    {
+      t = unlink (resolution_file);
+      check (t == 0, LDPL_FATAL, "could not unlink resolution file");
+    }
+
   free_2 ();
   return LDPS_OK;
 }
@@ -613,10 +622,6 @@ process_option (const char *option)
     debug = 1;
   else if (strcmp (option, "-nop") == 0)
     nop = 1;
-  else if (!strncmp (option, "-resolution=", strlen("-resolution=")))
-    {
-      resolution_file = strdup (option + strlen("-resolution="));
-    }
   else if (!strncmp (option, "-pass-through=", strlen("-pass-through=")))
     {
       num_pass_through_items++;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]