This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Fix PR 4888
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: binutils at sourceware dot org
- Date: Sat, 4 Aug 2007 17:55:07 +0930
- Subject: Fix PR 4888
The PR 4888 testcase shows the ELF .strtab section being trashed,
caused by objcopy incorrectly copying input sections to the output
when --only-keep-debug. objcopy started doing this with my 2007-05-30
patch, which left the output section flags unchanged and neglected to
change places in objcopy that test these flags.
PR 4888
* objcopy.c (setup_section): Do modify section flags for ELF
STRIP_NONDEBUG (reverting part of 2007-05-30 change). Prevent
header rewrite by twiddling input section flags instead.
Simplify code setting SHT_NOBITS.
Index: binutils/objcopy.c
===================================================================
RCS file: /cvs/src/src/binutils/objcopy.c,v
retrieving revision 1.117
diff -u -p -r1.117 objcopy.c
--- binutils/objcopy.c 5 Jul 2007 16:54:45 -0000 1.117
+++ binutils/objcopy.c 4 Aug 2007 07:19:33 -0000
@@ -2165,6 +2165,7 @@ setup_section (bfd *ibfd, sec_ptr isecti
const char *err;
const char * name;
char *prefix = NULL;
+ bfd_boolean make_nobits;
if (is_strip_section (ibfd, isection))
return;
@@ -2193,12 +2194,26 @@ setup_section (bfd *ibfd, sec_ptr isecti
name = n;
}
+ make_nobits = FALSE;
if (p != NULL && p->set_flags)
flags = p->flags | (flags & (SEC_HAS_CONTENTS | SEC_RELOC));
else if (strip_symbols == STRIP_NONDEBUG
- && obfd->xvec->flavour != bfd_target_elf_flavour
- && (flags & SEC_ALLOC) != 0)
- flags &= ~(SEC_HAS_CONTENTS | SEC_LOAD);
+ && (flags & SEC_ALLOC) != 0
+ && (ibfd->xvec->flavour != bfd_target_elf_flavour
+ || elf_section_type (isection) != SHT_NOTE))
+ {
+ flags &= ~(SEC_HAS_CONTENTS | SEC_LOAD);
+ if (obfd->xvec->flavour == bfd_target_elf_flavour)
+ {
+ make_nobits = TRUE;
+
+ /* Twiddle the input section flags so that it seems to
+ elf.c:copy_private_bfd_data that section flags have not
+ changed between input and output sections. This hack
+ prevents wholesale rewriting of the program headers. */
+ isection->flags &= ~(SEC_HAS_CONTENTS | SEC_LOAD);
+ }
+ }
osection = bfd_make_section_anyway_with_flags (obfd, name, flags);
@@ -2208,13 +2223,7 @@ 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
- && elf_section_type (osection) != SHT_NOTE
- && (ibfd->xvec->flavour != bfd_target_elf_flavour
- || elf_section_type (isection) != SHT_NOTE)
- && (p == NULL || !p->set_flags))
+ if (make_nobits)
elf_section_type (osection) = SHT_NOBITS;
size = bfd_section_size (ibfd, isection);
--
Alan Modra
Australia Development Lab, IBM