diff mbox series

Propagate from gcc: Add linker_output as prefix for LTO temps

Message ID 7502e318-8569-1792-da0f-0e6ca50bbf57@arm.com
State New
Headers show
Series Propagate from gcc: Add linker_output as prefix for LTO temps | expand

Commit Message

Richard Earnshaw (lists) Aug. 1, 2018, 1:25 p.m. UTC
I've ported the attached patch over from GCC's libiberty.

Committed as obvious.

R.
diff mbox series

Patch

From d6d40cc1a5de4d58e1aa35fbb3dbf44b8e28c988 Mon Sep 17 00:00:00 2001
From: marxin <marxin@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 26 Jul 2018 12:13:14 +0000
Subject: [PATCH] Add linker_output as prefix for LTO temps (PR lto/86548).
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.7.4"

This is a multi-part message in MIME format.
--------------2.7.4
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


2018-07-26  Martin Liska  <mliska@suse.cz>

        PR lto/86548
	* libiberty.h (make_temp_file_with_prefix): New function.
2018-07-26  Martin Liska  <mliska@suse.cz>

        PR lto/86548
	* make-temp-file.c (TEMP_FILE): Remove leading 'cc'.
	(make_temp_file): Call make_temp_file_with_prefix with
        first argument set to NULL.
	(make_temp_file_with_prefix): Support also prefix.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@262999 138bc75d-0d04-0410-961f-82ee72b054a4
---
 include/ChangeLog          |  5 +++++
 include/libiberty.h        |  5 +++++
 libiberty/ChangeLog        |  8 ++++++++
 libiberty/make-temp-file.c | 24 ++++++++++++++++++------
 6 files changed, 55 insertions(+), 7 deletions(-)


--------------2.7.4
Content-Type: text/x-patch; name="0001-Add-linker_output-as-prefix-for-LTO-temps-PR-lto-865.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-Add-linker_output-as-prefix-for-LTO-temps-PR-lto-865.patch"

diff --git a/include/libiberty.h b/include/libiberty.h
index dc09e79..0823614 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -239,6 +239,11 @@  extern char *choose_temp_base (void) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
 
 extern char *make_temp_file (const char *) ATTRIBUTE_MALLOC;
 
+/* Return a temporary file name with given PREFIX and SUFFIX
+   or NULL if unable to create one.  */
+
+extern char *make_temp_file_with_prefix (const char *, const char *) ATTRIBUTE_MALLOC;
+
 /* Remove a link to a file unless it is special. */
 
 extern int unlink_if_ordinary (const char *);
diff --git a/libiberty/make-temp-file.c b/libiberty/make-temp-file.c
index 89faed7..21b0545 100644
--- a/libiberty/make-temp-file.c
+++ b/libiberty/make-temp-file.c
@@ -56,7 +56,7 @@  extern int mkstemps (char *, int);
 
 /* Name of temporary file.
    mktemp requires 6 trailing X's.  */
-#define TEMP_FILE "ccXXXXXX"
+#define TEMP_FILE "XXXXXX"
 #define TEMP_FILE_LEN (sizeof(TEMP_FILE) - 1)
 
 #if !defined(_WIN32) || defined(__CYGWIN__)
@@ -181,25 +181,31 @@  string is @code{malloc}ed, and the temporary file has been created.
 */
 
 char *
-make_temp_file (const char *suffix)
+make_temp_file_with_prefix (const char *prefix, const char *suffix)
 {
   const char *base = choose_tmpdir ();
   char *temp_filename;
-  int base_len, suffix_len;
+  int base_len, suffix_len, prefix_len;
   int fd;
 
+  if (prefix == 0)
+    prefix = "cc";
+
   if (suffix == 0)
     suffix = "";
 
   base_len = strlen (base);
+  prefix_len = strlen (prefix);
   suffix_len = strlen (suffix);
 
   temp_filename = XNEWVEC (char, base_len
 			   + TEMP_FILE_LEN
-			   + suffix_len + 1);
+			   + suffix_len
+			   + prefix_len + 1);
   strcpy (temp_filename, base);
-  strcpy (temp_filename + base_len, TEMP_FILE);
-  strcpy (temp_filename + base_len + TEMP_FILE_LEN, suffix);
+  strcpy (temp_filename + base_len, prefix);
+  strcpy (temp_filename + base_len + prefix_len, TEMP_FILE);
+  strcpy (temp_filename + base_len + prefix_len + TEMP_FILE_LEN, suffix);
 
   fd = mkstemps (temp_filename, suffix_len);
   /* Mkstemps failed.  It may be EPERM, ENOSPC etc.  */
@@ -214,3 +220,9 @@  make_temp_file (const char *suffix)
     abort ();
   return temp_filename;
 }
+
+char *
+make_temp_file (const char *suffix)
+{
+  return make_temp_file_with_prefix (NULL, suffix);
+}

--------------2.7.4--