diff options
author | Alan Modra <amodra@gmail.com> | 2021-01-14 08:48:49 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-01-14 08:51:29 +1030 |
commit | 4120e4885bd80ac66fb6c643ecc9d15adec92a14 (patch) | |
tree | dc4273cfbfc63dd775faf89fb68bf0ae47208e80 | |
parent | d8d1feb424fe57e54485212698f53fb90edbdf35 (diff) | |
download | gdb-4120e4885bd80ac66fb6c643ecc9d15adec92a14.zip gdb-4120e4885bd80ac66fb6c643ecc9d15adec92a14.tar.gz gdb-4120e4885bd80ac66fb6c643ecc9d15adec92a14.tar.bz2 |
Re: SHF_LINK_ORDER fixup_link_order in ld
PR 27160
* ldelfgen.c (compare_link_order): Protect access of ELF section
data.
(add_link_order_input_section): Remove redundant NULL check.
Use bfd_get_flavour.
(ldelf_map_segments): Use bfd_get_flavour.
-rw-r--r-- | ld/ChangeLog | 9 | ||||
-rw-r--r-- | ld/ldelfgen.c | 18 |
2 files changed, 20 insertions, 7 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index 2dad0b9..60a3103 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2021-01-14 Alan Modra <amodra@gmail.com> + + PR 27160 + * ldelfgen.c (compare_link_order): Protect access of ELF section + data. + (add_link_order_input_section): Remove redundant NULL check. + Use bfd_get_flavour. + (ldelf_map_segments): Use bfd_get_flavour. + 2021-01-13 H.J. Lu <hongjiu.lu@intel.com> * ldelfgen.c (add_link_order_input_section): Check for ELF input diff --git a/ld/ldelfgen.c b/ld/ldelfgen.c index 47e7a2a..df3dae0 100644 --- a/ld/ldelfgen.c +++ b/ld/ldelfgen.c @@ -79,9 +79,8 @@ add_link_order_input_section (lang_input_section_type *is, os_info->isec[os_info->count].idx = os_info->count; os_info->count++; s = is->section; - if (s->owner->xvec->flavour == bfd_target_elf_flavour + if (bfd_get_flavour (s->owner) == bfd_target_elf_flavour && (s->flags & SEC_LINKER_CREATED) == 0 - && elf_section_data (s) != NULL && elf_linked_to_section (s) != NULL) os_info->ordered++; return FALSE; @@ -145,10 +144,15 @@ compare_link_order (const void *a, const void *b) { const struct os_sections_input *ai = a; const struct os_sections_input *bi = b; - asection *asec = elf_linked_to_section (ai->is->section); - asection *bsec = elf_linked_to_section (bi->is->section); + asection *asec = NULL; + asection *bsec = NULL; bfd_vma apos, bpos; + if (bfd_get_flavour (ai->is->section->owner) == bfd_target_elf_flavour) + asec = elf_linked_to_section (ai->is->section); + if (bfd_get_flavour (bi->is->section->owner) == bfd_target_elf_flavour) + bsec = elf_linked_to_section (bi->is->section); + /* Place unordered sections before ordered sections. */ if (asec == NULL || bsec == NULL) { @@ -257,7 +261,7 @@ ldelf_map_segments (bfd_boolean need_layout) lang_relax_sections (need_layout); need_layout = FALSE; - if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour) + if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour) { lang_output_section_statement_type *os; if (!done_link_order_scan) @@ -285,7 +289,7 @@ ldelf_map_segments (bfd_boolean need_layout) } } - if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour + if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour && !bfd_link_relocatable (&link_info)) { bfd_size_type phdr_size; @@ -319,7 +323,7 @@ ldelf_map_segments (bfd_boolean need_layout) if (tries == 0) einfo (_("%F%P: looping in map_segments")); - if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour + if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour && lang_phdr_list == NULL) { /* If we don't have user supplied phdrs, strip zero-sized dynamic |