[binutils-gdb] Stop strip from removing debuglink sections.

Nick Clifton nickc@sourceware.org
Tue Apr 12 12:34:51 GMT 2022


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=278c98c830befc706286b56da9e922e5342d62a9

commit 278c98c830befc706286b56da9e922e5342d62a9
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Apr 12 13:34:06 2022 +0100

    Stop strip from removing debuglink sections.
    
            PR 28992
            * objcopy.c (is_strip_section_1): Do not delete debuglink sections
            when stripping debug information.

Diff:
---
 binutils/ChangeLog |  6 ++++++
 binutils/objcopy.c | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 907959342d2..26103a0279d 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,3 +1,9 @@
+2022-04-12  Nick Clifton  <nickc@redhat.com>
+
+	PR 28992
+	* objcopy.c (is_strip_section_1): Do not delete debuglink sections
+	when stripping debug information.
+
 2022-04-06  Nick Clifton  <nickc@redhat.com>
 
 	PR 28981
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index aaa5aa9b2af..6fb31c8cac7 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1358,8 +1358,20 @@ is_strip_section_1 (bfd *abfd ATTRIBUTE_UNUSED, asection *sec)
 	{
 	  /* By default we don't want to strip .reloc section.
 	     This section has for pe-coff special meaning.   See
-	     pe-dll.c file in ld, and peXXigen.c in bfd for details.  */
-	  if (strcmp (bfd_section_name (sec), ".reloc") != 0)
+	     pe-dll.c file in ld, and peXXigen.c in bfd for details.
+	     Similarly we do not want to strip debuglink sections.  */
+	  const char * kept_sections[] =
+	    {
+	      ".reloc",
+	      ".gnu_debuglink",
+	      ".gnu_debugaltlink"
+	    };
+	  int i;
+
+	  for (i = ARRAY_SIZE (kept_sections);i--;)
+	    if (strcmp (bfd_section_name (sec), kept_sections[i]) == 0)
+	      break;
+	  if (i == -1)
 	    return true;
 	}


More information about the Binutils-cvs mailing list