This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: binutils/1321: strip/objcopy don't handle SHF_LINK_ORDER correctly
- From: "H. J. Lu" <hjl at lucon dot org>
- To: binutils at sources dot redhat dot com
- Date: Fri, 9 Sep 2005 12:53:30 -0700
- Subject: PATCH: binutils/1321: strip/objcopy don't handle SHF_LINK_ORDER correctly
This patch makes sure that strip/objcopy also preserve
elf_linked_to_section.
H.J.
---
2005-09-09 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/1321
* elf-bfd.h (_bfd_elf_setup_group_pointers): Renamed to ...
(_bfd_elf_setup_sections): This.
* elf.c: Likewise.
* elfcode.h (elf_object_p): Likewise.
* elf.c (_bfd_elf_setup_sections): Process SHF_LINK_ORDER.
(_bfd_elf_copy_private_section_data): Likewise.
--- bfd/elf-bfd.h.link-order 2005-09-09 12:26:02.000000000 -0700
+++ bfd/elf-bfd.h 2005-09-09 12:27:46.000000000 -0700
@@ -1686,7 +1686,7 @@ extern bfd_boolean _bfd_elf_symbol_refs_
extern bfd_boolean bfd_elf_match_symbols_in_sections
(asection *sec1, asection *sec2);
-extern bfd_boolean _bfd_elf_setup_group_pointers
+extern bfd_boolean _bfd_elf_setup_sections
(bfd *);
extern const bfd_target *bfd_elf32_object_p
--- bfd/elf.c.link-order 2005-09-09 12:26:02.000000000 -0700
+++ bfd/elf.c 2005-09-09 12:30:29.000000000 -0700
@@ -626,12 +626,41 @@ setup_group (bfd *abfd, Elf_Internal_Shd
}
bfd_boolean
-_bfd_elf_setup_group_pointers (bfd *abfd)
+_bfd_elf_setup_sections (bfd *abfd)
{
unsigned int i;
unsigned int num_group = elf_tdata (abfd)->num_group;
bfd_boolean result = TRUE;
+ asection *s;
+ /* Process SHF_LINK_ORDER. */
+ for (s = abfd->sections; s != NULL; s = s->next)
+ {
+ Elf_Internal_Shdr *this_hdr = &elf_section_data (s)->this_hdr;
+ if ((this_hdr->sh_flags & SHF_LINK_ORDER) != 0)
+ {
+ unsigned int elfsec = this_hdr->sh_link;
+ /* FIXME: The old Intel compiler and old strip/objcopy may
+ not set the sh_link or sh_info fields. Hence we could
+ get the situation where elfsec is 0. */
+ if (elfsec == 0)
+ {
+ const struct elf_backend_data *bed
+ = get_elf_backend_data (abfd);
+ if (bed->link_order_error_handler)
+ bed->link_order_error_handler
+ (_("%B: warning: sh_link not set for section `%A'"),
+ abfd, s);
+ }
+ else
+ {
+ this_hdr = elf_elfsections (abfd)[elfsec];
+ elf_linked_to_section (s) = this_hdr->bfd_section;
+ }
+ }
+ }
+
+ /* Process section groups. */
if (num_group == (unsigned) -1)
return result;
@@ -5881,7 +5910,14 @@ _bfd_elf_copy_private_section_data (bfd
/* Set things up for objcopy. The output SHT_GROUP section will
have its elf_next_in_group pointing back to the input group
members. Ignore linker created group section. See
- elfNN_ia64_object_p in elfxx-ia64.c. */
+ elfNN_ia64_object_p in elfxx-ia64.c. We also need to handle
+ elf_linked_to_section for SHF_LINK_ORDER. */
+
+ if ((ihdr->sh_flags & SHF_LINK_ORDER) != 0
+ && elf_linked_to_section (isec) != 0)
+ elf_linked_to_section (osec)
+ = elf_linked_to_section (isec)->output_section;
+
if (elf_sec_group (isec) == NULL
|| (elf_sec_group (isec)->flags & SEC_LINKER_CREATED) == 0)
{
--- bfd/elfcode.h.link-order 2005-09-09 12:26:02.000000000 -0700
+++ bfd/elfcode.h 2005-09-09 12:27:46.000000000 -0700
@@ -791,8 +791,8 @@ elf_object_p (bfd *abfd)
shindex += SHN_HIRESERVE + 1 - SHN_LORESERVE;
}
- /* Set up group pointers. */
- if (! _bfd_elf_setup_group_pointers (abfd))
+ /* Set up ELF sections for SHF_GROUP and SHF_LINK_ORDER. */
+ if (! _bfd_elf_setup_sections (abfd))
goto got_wrong_format_error;
}