* elf-bfd.h (_bfd_elf_check_kept_section): New.
* elf.c (assign_section_numbers): When sh_link points to a
discarded section, call _bfd_elf_check_kept_section to see if
the kept section can be used. Otherwise reject sh_link
pointing to discarded section.
* elflink.c (_bfd_elf_check_kept_section): New.
(elf_link_input_bfd): Use it.
+2005-03-31 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elf-bfd.h (_bfd_elf_check_kept_section): New.
+
+ * elf.c (assign_section_numbers): When sh_link points to a
+ discarded section, call _bfd_elf_check_kept_section to see if
+ the kept section can be used. Otherwise reject sh_link
+ pointing to discarded section.
+
+ * elflink.c (_bfd_elf_check_kept_section): New.
+ (elf_link_input_bfd): Use it.
+
2005-04-01 Alan Modra <amodra@bigpond.net.au>
* elf64-ppc.c (ppc64_elf_edit_toc): Account for dynamic relocs
(bfd *, struct bfd_section *);
extern void bfd_elf_set_group_contents
(bfd *, asection *, void *);
+extern asection *_bfd_elf_check_kept_section
+ (asection *);
extern void _bfd_elf_link_just_syms
(asection *, struct bfd_link_info *);
extern bfd_boolean _bfd_elf_copy_private_header_data
}
else
{
- s = elf_shdrp[elfsec]->bfd_section->output_section;
+ s = elf_shdrp[elfsec]->bfd_section;
+ if (elf_discarded_section (s))
+ {
+ asection *kept;
+ (*_bfd_error_handler)
+ (_("%B: sh_link of section `%A' points to discarded section `%A' of `%B'"),
+ abfd, d->this_hdr.bfd_section,
+ s, s->owner);
+ /* Point to the kept section if it has
+ the same size as the discarded
+ one. */
+ kept = _bfd_elf_check_kept_section (s);
+ if (kept == NULL)
+ {
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ }
+ s = s->output_section;
BFD_ASSERT (s != NULL);
d->this_hdr.sh_link = elf_section_data (s)->this_idx;
}
return NULL;
}
+/* Check if the kept section of a discarded section SEC can be used
+ to replace it. Return the replacement if it is OK. Otherwise return
+ NULL. */
+
+asection *
+_bfd_elf_check_kept_section (asection *sec)
+{
+ asection *kept;
+
+ kept = sec->kept_section;
+ if (kept != NULL)
+ {
+ if (elf_sec_group (sec) != NULL)
+ kept = match_group_member (sec, kept);
+ if (kept != NULL && sec->size != kept->size)
+ kept = NULL;
+ }
+ return kept;
+}
+
/* Link an input file into the linker output file. This function
handles all the sections and relocations of the input file at once.
This is so that we only have to read the local symbols once, and
discarded section. */
if ((sec = *ps) != NULL && elf_discarded_section (sec))
{
- asection *kept;
-
BFD_ASSERT (r_symndx != 0);
if (action & COMPLAIN)
{
is that we warn in non-debug sections, and
debug sections tend to come after other
sections. */
- kept = sec->kept_section;
- if (kept != NULL && (action & PRETEND))
+ if (action & PRETEND)
{
- if (elf_sec_group (sec) != NULL)
- kept = match_group_member (sec, kept);
- if (kept != NULL
- && sec->size == kept->size)
+ asection *kept;
+
+ kept = _bfd_elf_check_kept_section (sec);
+ if (kept != NULL)
{
*ps = kept;
continue;