Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org,	binutils@sourceware.org
Cc: Nick Clifton <nickc@redhat.com>,	Alan Modra <amodra@gmail.com>,
	Joseph Myers <joseph@codesourcery.com>,
	Simon Marchi <simon.marchi@ericsson.com>
Subject: [PATCH 2/4] libiberty: Sync with GCC
Date: Sat, 16 Jun 2018 03:07:00 -0000	[thread overview]
Message-ID: <20180616030744.12913-3-simon.marchi@polymtl.ca> (raw)
In-Reply-To: <20180616030744.12913-1-simon.marchi@polymtl.ca>

From: Simon Marchi <simon.marchi@ericsson.com>

Also sync include/simple-object.h, which goes together with the change
in libiberty.
---
 include/simple-object.h   |  5 ++++-
 libiberty/ChangeLog       |  7 ++++++
 libiberty/simple-object.c | 45 +++++++++++++++++++++++++++++----------
 3 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/include/simple-object.h b/include/simple-object.h
index db72f86de179..496d8cc107e7 100644
--- a/include/simple-object.h
+++ b/include/simple-object.h
@@ -198,12 +198,15 @@ extern void
 simple_object_release_write (simple_object_write *);
 
 /* Copy LTO debug sections from SRC_OBJECT to DEST.
+   If RENAME is true, rename LTO debug section into debug section (i.e.
+   when producing final binary) and if it is false, keep the sections with
+   original names (when incrementally linking).
    If an error occurs, return the errno value in ERR and an error string.  */
 
 extern const char *
 simple_object_copy_lto_debug_sections (simple_object_read *src_object,
 				       const char *dest,
-				       int *err);
+				       int *err, int rename);
 
 #ifdef __cplusplus
 }
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog
index 19c62699c07a..578da58181f5 100644
--- a/libiberty/ChangeLog
+++ b/libiberty/ChangeLog
@@ -1,3 +1,10 @@
+2018-05-30  Jan Hubicka  <hubicka@ucw.cz>
+
+	* simple-object.c (handle_lto_debug_sections): Add rename parameter.
+	(handle_lto_debug_sections_rename): New function.
+	(handle_lto_debug_sections_norename): New function.
+	(simple_object_copy_lto_debug_sections): Add rename parameter.
+
 2018-05-28  Bernd Edlinger  <bernd.edlinger@hotmail.de>
 
 	* splay-tree.c (splay_tree_compare_strings,
diff --git a/libiberty/simple-object.c b/libiberty/simple-object.c
index 42aa6ac4e609..82a8cff9644b 100644
--- a/libiberty/simple-object.c
+++ b/libiberty/simple-object.c
@@ -251,12 +251,15 @@ simple_object_find_section (simple_object_read *sobj, const char *name,
 }
 
 /* Callback to identify and rename LTO debug sections by name.
-   Returns 1 if NAME is a LTO debug section, 0 if not.  */
+   Returns non-NULL if NAME is a LTO debug section, NULL if not.
+   If RENAME is true it will rename LTO debug sections to non-LTO
+   ones.  */
 
 static char *
-handle_lto_debug_sections (const char *name)
+handle_lto_debug_sections (const char *name, int rename)
 {
-  char *newname = XCNEWVEC (char, strlen (name) + 1);
+  char *newname = rename ? XCNEWVEC (char, strlen (name) + 1)
+	  	         : xstrdup (name);
 
   /* ???  So we can't use .gnu.lto_ prefixed sections as the assembler
      complains about bogus section flags.  Which means we need to arrange
@@ -265,22 +268,24 @@ handle_lto_debug_sections (const char *name)
   /* Also include corresponding reloc sections.  */
   if (strncmp (name, ".rela", sizeof (".rela") - 1) == 0)
     {
-      strncpy (newname, name, sizeof (".rela") - 1);
+      if (rename)
+        strncpy (newname, name, sizeof (".rela") - 1);
       name += sizeof (".rela") - 1;
     }
   else if (strncmp (name, ".rel", sizeof (".rel") - 1) == 0)
     {
-      strncpy (newname, name, sizeof (".rel") - 1);
+      if (rename)
+        strncpy (newname, name, sizeof (".rel") - 1);
       name += sizeof (".rel") - 1;
     }
   /* ???  For now this handles both .gnu.lto_ and .gnu.debuglto_ prefixed
      sections.  */
   /* Copy LTO debug sections and rename them to their non-LTO name.  */
   if (strncmp (name, ".gnu.debuglto_", sizeof (".gnu.debuglto_") - 1) == 0)
-    return strcat (newname, name + sizeof (".gnu.debuglto_") - 1);
+    return rename ? strcat (newname, name + sizeof (".gnu.debuglto_") - 1) : newname;
   else if (strncmp (name, ".gnu.lto_.debug_",
 		    sizeof (".gnu.lto_.debug_") -1) == 0)
-    return strcat (newname, name + sizeof (".gnu.lto_") - 1);
+    return rename ? strcat (newname, name + sizeof (".gnu.lto_") - 1) : newname;
   /* Copy over .note.GNU-stack section under the same name if present.  */
   else if (strcmp (name, ".note.GNU-stack") == 0)
     return strcpy (newname, name);
@@ -289,14 +294,31 @@ handle_lto_debug_sections (const char *name)
      COMDAT sections in objects produced by GCC.  */
   else if (strcmp (name, ".comment") == 0)
     return strcpy (newname, name);
+  free (newname);
   return NULL;
 }
 
+/* Wrapper for handle_lto_debug_sections.  */
+
+static char *
+handle_lto_debug_sections_rename (const char *name)
+{
+  return handle_lto_debug_sections (name, 1);
+}
+
+/* Wrapper for handle_lto_debug_sections.  */
+
+static char *
+handle_lto_debug_sections_norename (const char *name)
+{
+  return handle_lto_debug_sections (name, 0);
+}
+
 /* Copy LTO debug sections.  */
 
 const char *
 simple_object_copy_lto_debug_sections (simple_object_read *sobj,
-				       const char *dest, int *err)
+				       const char *dest, int *err, int rename)
 {
   const char *errmsg;
   simple_object_write *dest_sobj;
@@ -317,9 +339,10 @@ simple_object_copy_lto_debug_sections (simple_object_read *sobj,
   if (! dest_sobj)
     return errmsg;
 
-  errmsg = sobj->functions->copy_lto_debug_sections (sobj, dest_sobj,
-						     handle_lto_debug_sections,
-						     err);
+  errmsg = sobj->functions->copy_lto_debug_sections
+	 	 (sobj, dest_sobj,
+		  rename ? handle_lto_debug_sections_rename
+			 : handle_lto_debug_sections_norename,  err);
   if (errmsg)
     {
       simple_object_release_write (dest_sobj);
-- 
2.17.1


  reply	other threads:[~2018-06-16  3:07 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-16  3:08 [PATCH 0/4] Sync a few directories " Simon Marchi
2018-06-16  3:07 ` Simon Marchi [this message]
2018-06-18  9:25   ` [PATCH 2/4] libiberty: Sync " Nick Clifton
2018-06-16  3:08 ` [PATCH 3/4] zlib: " Simon Marchi
2018-06-16  7:28   ` Andreas Schwab
2018-06-16 11:34     ` Simon Marchi
2018-06-18  9:37       ` Nick Clifton
2018-06-16  3:08 ` [PATCH 4/4] libdecnumber: " Simon Marchi
2018-06-18  9:38   ` Nick Clifton
2018-06-16  3:27 ` [PATCH 1/4] config: " Simon Marchi
2018-06-18  9:23   ` Nick Clifton
2018-06-17  0:50 ` [PATCH 5/4] configure.ac: " Simon Marchi
2018-06-18  9:39   ` Nick Clifton
2018-06-18 13:40 ` [PATCH 0/4] Sync a few directories " Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180616030744.12913-3-simon.marchi@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=joseph@codesourcery.com \
    --cc=nickc@redhat.com \
    --cc=simon.marchi@ericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox