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]

[patch] Don't use a temporary directory in the lto plugin


Now that lto1 understands foo.a@123, the plugin produces only one
temporary file: the argument list. With this patch we drop the
temporary directory and just use make_temp_file.

2009-11-04  Rafael Avila de Espindola  <espindola@google.com>

	* lto-plugin.c (temp_obj_dir_name): Remove.
	(arguments_file_name): New.
	(free_2): Free arguments_file_name instead of temp_obj_dir_name.
	(exec_lto_wrapper):  Create arguments file with make_temp_file.
	(cleanup_handler): Don't remove the temporary directory. Remove the
	arguments file.
	(onload): Don't create the temporary directory.


Cheers,
-- 
Rafael Ãvila de EspÃndola
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 3cf4e7c..4e22d6d 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -72,7 +72,7 @@ struct plugin_file_info
 };
 
 
-static char *temp_obj_dir_name;
+static char *arguments_file_name;
 static ld_plugin_register_claim_file register_claim_file;
 static ld_plugin_add_symbols add_symbols;
 static ld_plugin_register_all_symbols_read register_all_symbols_read;
@@ -291,8 +291,9 @@ free_2 (void)
   claimed_files = NULL;
   num_claimed_files = 0;
 
-  free (temp_obj_dir_name);
-  temp_obj_dir_name = NULL;
+  if (arguments_file_name)
+    free (arguments_file_name);
+  arguments_file_name = NULL;
 
   if (resolution_file)
     {
@@ -374,7 +375,6 @@ exec_lto_wrapper (char *argv[])
   int t;
   int status;
   char *at_args;
-  char *args_name;
   FILE *args;
   FILE *wrapper_output;
   char *new_argv[3];
@@ -382,11 +382,11 @@ exec_lto_wrapper (char *argv[])
   const char *errmsg;
 
   /* Write argv to a file to avoid a command line that is too long. */
-  t = asprintf (&at_args, "@%s/arguments", temp_obj_dir_name);
-  check (t >= 0, LDPL_FATAL, "asprintf failed");
+  arguments_file_name = make_temp_file("");
+  check (arguments_file_name, LDPL_FATAL,
+         "Failed to generate a temorary file name");
 
-  args_name = at_args + 1;
-  args = fopen (args_name, "w");
+  args = fopen (arguments_file_name, "w");
   check (args, LDPL_FATAL, "could not open arguments file");
 
   t = writeargv (&argv[1], args);
@@ -394,6 +394,9 @@ exec_lto_wrapper (char *argv[])
   t = fclose (args);
   check (t == 0, LDPL_FATAL, "could not close arguments file");
 
+  at_args = concat ("@", arguments_file_name, NULL);
+  check (at_args, LDPL_FATAL, "could not allocate");
+
   new_argv[0] = argv[0];
   new_argv[1] = at_args;
   new_argv[2] = NULL;
@@ -426,8 +429,6 @@ exec_lto_wrapper (char *argv[])
 
   pex_free (pex);
 
-  t = unlink (args_name);
-  check (t == 0, LDPL_FATAL, "could not unlink arguments file");
   free (at_args);
 }
 
@@ -511,25 +512,15 @@ static enum ld_plugin_status
 cleanup_handler (void)
 {
   int t;
-  char *arguments;
-  struct stat buf;
 
   if (debug)
     return LDPS_OK;
 
-  /* If we are being called from an error handler, it is possible
-     that the arguments file is still exists. */
-  t = asprintf (&arguments, "%s/arguments", temp_obj_dir_name);
-  check (t >= 0, LDPL_FATAL, "asprintf failed");
-  if (stat(arguments, &buf) == 0)
-    {
-      t = unlink (arguments);
-      check (t == 0, LDPL_FATAL, "could not unlink arguments file");
-    }
-  free (arguments);
-
-  t = rmdir (temp_obj_dir_name);
-  check (t == 0, LDPL_FATAL, "could not remove temporary directory");
+  if (arguments_file_name)
+  {
+    t = unlink (arguments_file_name);
+    check (t == 0, LDPL_FATAL, "could not unlink arguments file");
+  }
 
   free_2 ();
   return LDPS_OK;
@@ -651,7 +642,6 @@ onload (struct ld_plugin_tv *tv)
 {
   struct ld_plugin_tv *p;
   enum ld_plugin_status status;
-  char *t;
 
   unsigned version = elf_version (EV_CURRENT);
   check (version != EV_NONE, LDPL_FATAL, "invalid ELF version");
@@ -715,8 +705,5 @@ onload (struct ld_plugin_tv *tv)
 	     "could not register the all_symbols_read callback");
     }
 
-  temp_obj_dir_name = strdup ("tmp_objectsXXXXXX");
-  t = mkdtemp (temp_obj_dir_name);
-  assert (t == temp_obj_dir_name);
   return LDPS_OK;
 }

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