aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2018-10-05 23:35:01 +0930
committerAlan Modra <amodra@gmail.com>2018-10-08 20:26:08 +1030
commite0c3dfa2eebcf862d45b05f363a81f57ca30dead (patch)
tree53b4c216b567249473bfeef2360ad007f7eb2559 /bfd
parent00bee008e9f7d0b3adf3278962450944653787f8 (diff)
downloadgdb-e0c3dfa2eebcf862d45b05f363a81f57ca30dead.zip
gdb-e0c3dfa2eebcf862d45b05f363a81f57ca30dead.tar.gz
gdb-e0c3dfa2eebcf862d45b05f363a81f57ca30dead.tar.bz2
SPU overlay headers
Overlay PT_LOAD headers are moved early for reasons explained by comments in spu_elf_modify_segment_map. This patch fixes cases that shouldn't occur in sane SPU executables. * elf32-spu.c (spu_elf_modify_segment_map): Don't insert overlays before segment containing headers.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog5
-rw-r--r--bfd/elf32-spu.c38
2 files changed, 32 insertions, 11 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 4e5eac1..1b51db7 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,10 @@
2018-10-08 Alan Modra <amodra@gmail.com>
+ * elf32-spu.c (spu_elf_modify_segment_map): Don't insert
+ overlays before segment containing headers.
+
+2018-10-08 Alan Modra <amodra@gmail.com>
+
* elf.c (make_mapping): Cope with zero size array at end of
struct elf_segment_map.
(_bfd_elf_map_sections_to_segments): Likewise.
diff --git a/bfd/elf32-spu.c b/bfd/elf32-spu.c
index bb3264f..033db9c 100644
--- a/bfd/elf32-spu.c
+++ b/bfd/elf32-spu.c
@@ -5231,7 +5231,7 @@ spu_elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
{
asection *toe, *s;
struct elf_segment_map *m, *m_overlay;
- struct elf_segment_map **p, **p_overlay;
+ struct elf_segment_map **p, **p_overlay, **first_load;
unsigned int i;
if (info == NULL)
@@ -5290,24 +5290,40 @@ spu_elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
/* Move all overlay segments onto a separate list. */
p = &elf_seg_map (abfd);
p_overlay = &m_overlay;
+ m_overlay = NULL;
+ first_load = NULL;
while (*p != NULL)
{
- if ((*p)->p_type == PT_LOAD && (*p)->count == 1
- && spu_elf_section_data ((*p)->sections[0])->u.o.ovl_index != 0)
+ if ((*p)->p_type == PT_LOAD)
{
- m = *p;
- *p = m->next;
- *p_overlay = m;
- p_overlay = &m->next;
- continue;
+ if (!first_load)
+ first_load = p;
+ if ((*p)->count == 1
+ && spu_elf_section_data ((*p)->sections[0])->u.o.ovl_index != 0)
+ {
+ m = *p;
+ *p = m->next;
+ *p_overlay = m;
+ p_overlay = &m->next;
+ continue;
+ }
}
-
p = &((*p)->next);
}
/* Re-insert overlay segments at the head of the segment map. */
- *p_overlay = elf_seg_map (abfd);
- elf_seg_map (abfd) = m_overlay;
+ if (m_overlay != NULL)
+ {
+ p = first_load;
+ if (*p != NULL && (*p)->p_type == PT_LOAD && (*p)->includes_filehdr)
+ /* It doesn't really make sense for someone to include the ELF
+ file header into an spu image, but if they do the code that
+ assigns p_offset needs to see the segment containing the
+ header first. */
+ p = &(*p)->next;
+ *p_overlay = *p;
+ *p = m_overlay;
+ }
return TRUE;
}