aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2006-06-23 02:58:01 +0000
committerAlan Modra <amodra@gmail.com>2006-06-23 02:58:01 +0000
commit62d7a5f67e8130a28b0555fff3aa27b0b6d3074d (patch)
treee2e3d4570bd1e7f6a008e54ee61aa7fcd320b731 /bfd/elf.c
parent8c2afc38d89578c715b4f0b7340eccd468b755dc (diff)
downloadgdb-62d7a5f67e8130a28b0555fff3aa27b0b6d3074d.zip
gdb-62d7a5f67e8130a28b0555fff3aa27b0b6d3074d.tar.gz
gdb-62d7a5f67e8130a28b0555fff3aa27b0b6d3074d.tar.bz2
PR ld/2754
* elf.c (bfd_elf_mkobject): Don't alloc if already done. Set program_header_size to -1. (_bfd_elf_map_sections_to_segments): Adjust program_header_size check. (assign_file_positions_for_load_sections ): Likewise. (_bfd_elf_sizeof_headers): Use saved program_header_size if available. * elf32-arm.c (elf32_arm_mkobject): Call bfd_elf_mkobject, don't alloc if already done. * elf32-i386.c (elf_i386_mkobject): Likewise. * elf32-ppc.c (ppc_elf_mkobject): Likewise. * elf32-s390.c (elf_s390_mkobject): Likewise. * elf32-sh.c (sh_elf_mkobject): Likewise. * elf64-alpha.c (elf64_alpha_mkobject): Likewise. * elf64-ppc.c (ppc64_elf_mkobject): Likewise. * elf64-s390.c (elf_s390_mkobject): Likewise. * elf64-x86-64.c (elf64_x86_64_mkobject): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_mkobject): Likewise.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r--bfd/elf.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/bfd/elf.c b/bfd/elf.c
index 8a725c3..abb5082 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -209,13 +209,14 @@ bfd_elf_hash (const char *namearg)
bfd_boolean
bfd_elf_mkobject (bfd *abfd)
{
- /* This just does initialization. */
- /* coff_mkobject zalloc's space for tdata.coff_obj_data ... */
- elf_tdata (abfd) = bfd_zalloc (abfd, sizeof (struct elf_obj_tdata));
- if (elf_tdata (abfd) == 0)
- return FALSE;
- /* Since everything is done at close time, do we need any
- initialization? */
+ if (abfd->tdata.any == NULL)
+ {
+ abfd->tdata.any = bfd_zalloc (abfd, sizeof (struct elf_obj_tdata));
+ if (abfd->tdata.any == NULL)
+ return FALSE;
+ }
+
+ elf_tdata (abfd)->program_header_size = (bfd_size_type) -1;
return TRUE;
}
@@ -3852,7 +3853,7 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
{
bfd_size_type phdr_size = elf_tdata (abfd)->program_header_size;
- if (phdr_size == 0)
+ if (phdr_size == (bfd_size_type) -1)
phdr_size = get_program_header_size (abfd, info);
if ((abfd->flags & D_PAGED) == 0
|| sections[0]->lma < phdr_size
@@ -4227,7 +4228,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
elf_elfheader (abfd)->e_phentsize = bed->s->sizeof_phdr;
elf_elfheader (abfd)->e_phnum = alloc;
- if (elf_tdata (abfd)->program_header_size == 0)
+ if (elf_tdata (abfd)->program_header_size == (bfd_size_type) -1)
elf_tdata (abfd)->program_header_size = alloc * bed->s->sizeof_phdr;
else
BFD_ASSERT (elf_tdata (abfd)->program_header_size
@@ -7063,14 +7064,19 @@ _bfd_elf_sizeof_headers (bfd *abfd, struct bfd_link_info *info)
if (!info->relocatable)
{
- struct elf_segment_map *m;
- bfd_size_type phdr_size = 0;
+ bfd_size_type phdr_size = elf_tdata (abfd)->program_header_size;
- for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
- phdr_size += bed->s->sizeof_phdr;
+ if (phdr_size == (bfd_size_type) -1)
+ {
+ struct elf_segment_map *m;
+
+ phdr_size = 0;
+ for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+ phdr_size += bed->s->sizeof_phdr;
- if (phdr_size == 0)
- phdr_size = get_program_header_size (abfd, info);
+ if (phdr_size == 0)
+ phdr_size = get_program_header_size (abfd, info);
+ }
elf_tdata (abfd)->program_header_size = phdr_size;
ret += phdr_size;