This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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] objcopy --only-keep-debug vs SHT_NOTE


This patch changes objcopy --only-keep-debug in two ways.  First, it
preserves the sh_type of saved sections not being otherwise molested.
This, for example, makes unallocated note sections preserved in .debug
files keep their SHT_NOTE type instead of being reset to SHT_PROGBITS.

Second, it does not discard allocated SHT_NOTE sections.  (I am also
making this change in elfutils strip.)  The idea here is that some
SHT_NOTE sections might be used to embed identifying information in
stripped binaries, and by copying these sections into the .debug file
as well, they can be compared and used for matching things up.  (This
is part of a particular nascent plan using notes, but it seems like a
straightforward and harmless change regardless.)

Ok to commit?


Thanks,
Roland

--
2007-05-18  Roland McGrath  <roland@redhat.com>

	* objcopy.c (setup_section): If IBFD is bfd_target_elf_flavour,
	preserve ISECTION's sh_type in OSECTION.  For STRIP_NONDEBUG,
	don't elide ISECTION to SHT_NOBITS if it's SHT_NOTE.

Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.112
diff -B -b -p -u -r1.112 objcopy.c
--- binutils/objcopy.c	18 May 2007 06:36:14 -0000	1.112
+++ binutils/objcopy.c	19 May 2007 18:56:16 -0000
@@ -2176,6 +2176,7 @@ setup_section (bfd *ibfd, sec_ptr isecti
   const char *err;
   const char * name;
   char *prefix = NULL;
+  int elf_sh_type;
 
   if (is_strip_section (ibfd, isection))
     return;
@@ -2204,9 +2205,13 @@ setup_section (bfd *ibfd, sec_ptr isecti
       name = n;
     }
 
+  elf_sh_type = (ibfd->xvec->flavour == bfd_target_elf_flavour
+		 ? elf_section_type (isection) : SHT_NULL);
+
   if (p != NULL && p->set_flags)
     flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC));
-  else if (strip_symbols == STRIP_NONDEBUG && (flags & SEC_ALLOC) != 0)
+  else if (strip_symbols == STRIP_NONDEBUG && (flags & SEC_ALLOC) != 0
+	   && elf_sh_type != SHT_NOTE)
     flags &= ~(SEC_HAS_CONTENTS | SEC_LOAD);
 
   osection = bfd_make_section_anyway_with_flags (obfd, name, flags);
@@ -2217,11 +2222,15 @@ setup_section (bfd *ibfd, sec_ptr isecti
       goto loser;
     }
 
-  if (strip_symbols == STRIP_NONDEBUG
-      && obfd->xvec->flavour == bfd_target_elf_flavour
-      && (flags & SEC_ALLOC) != 0
+  if (obfd->xvec->flavour == bfd_target_elf_flavour
       && (p == NULL || !p->set_flags))
-    elf_section_type (osection) = SHT_NOBITS;
+    {
+      if (strip_symbols == STRIP_NONDEBUG
+	  && (flags & SEC_ALLOC) != 0 && elf_sh_type != SHT_NOTE)
+	elf_sh_type = SHT_NOBITS;
+
+      elf_section_type (osection) = elf_sh_type;
+    }
 
   size = bfd_section_size (ibfd, isection);
   if (copy_byte >= 0)


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