aboutsummaryrefslogtreecommitdiff
path: root/gcc/gcc.c
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2020-12-13 08:24:57 +0100
committerBernd Edlinger <bernd.edlinger@hotmail.de>2021-01-04 10:03:19 +0100
commite9f8a554efe497dd46b8953e580d65e5c023e50c (patch)
tree88aae5b2daa92d3a6ceaff7addbd960b656992eb /gcc/gcc.c
parentc48514bea610d9eaae783fec9d513a690723b0f0 (diff)
downloadgcc-e9f8a554efe497dd46b8953e580d65e5c023e50c.zip
gcc-e9f8a554efe497dd46b8953e580d65e5c023e50c.tar.gz
gcc-e9f8a554efe497dd46b8953e580d65e5c023e50c.tar.bz2
Fix -save-temp leaking lto files in /tmp
When linking with -flto and -save-temps, various temporary files are created in /tmp. The same happens when invoking the driver with @file parameter, and using -L or -I options. gcc: 2021-01-04 Bernd Edlinger <bernd.edlinger@hotmail.de> * collect-utils.c (collect_execute): Check dumppfx. * collect2.c (maybe_run_lto_and_relink, do_link): Pass atsuffix to collect_execute. (do_link): Add new parameter atsuffix. (main): Handle -dumpdir option. Skip one argument for -o, -isystem and -B options. * gcc.c (make_at_file): New helper function. (close_at_file): Use it. gcc/testsuite: 2021-01-04 Bernd Edlinger <bernd.edlinger@hotmail.de> * gcc.misc-tests/outputs.exp: Adjust testcase.
Diffstat (limited to 'gcc/gcc.c')
-rw-r--r--gcc/gcc.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/gcc/gcc.c b/gcc/gcc.c
index 42077fb..79084c3 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -2196,6 +2196,32 @@ open_at_file (void)
in_at_file = true;
}
+/* Create a temporary @file name. */
+
+static char *make_at_file (void)
+{
+ static int fileno = 0;
+ char filename[20];
+ const char *base, *ext;
+
+ if (!save_temps_flag)
+ return make_temp_file ("");
+
+ base = dumpbase;
+ if (!(base && *base))
+ base = dumpdir;
+ if (!(base && *base))
+ base = "a";
+
+ sprintf (filename, ".args.%d", fileno++);
+ ext = filename;
+
+ if (base == dumpdir && dumpdir_trailing_dash_added)
+ ext++;
+
+ return concat (base, ext, NULL);
+}
+
/* Close the temporary @file and add @file to the argument list. */
static void
@@ -2211,7 +2237,7 @@ close_at_file (void)
return;
char **argv = (char **) alloca (sizeof (char *) * (n_args + 1));
- char *temp_file = make_temp_file ("");
+ char *temp_file = make_at_file ();
char *at_argument = concat ("@", temp_file, NULL);
FILE *f = fopen (temp_file, "w");
int status;