From 53020534c8cac1f6c039647a623de0c2d36a8af7 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 30 Jan 2007 15:47:19 +0000 Subject: [PATCH] 2007-01-30 H.J. Lu * elf.c (copy_elf_program_header): Start from the first section in a segment and stop when all sections in a segment are accounted for. --- bfd/ChangeLog | 6 ++++++ bfd/elf.c | 17 +++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 07460d4bd9a..f8dcc99f51d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2007-01-30 H.J. Lu + + * elf.c (copy_elf_program_header): Start from the first section + in a segment and stop when all sections in a segment are + accounted for. + 2007-01-29 Julian Brown * bfd-in2.h: Regenerate. diff --git a/bfd/elf.c b/bfd/elf.c index faeb1459ad0..61e61033132 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -5814,7 +5814,7 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd) unsigned int section_count; bfd_size_type amt; Elf_Internal_Shdr *this_hdr; - bfd_vma first_lma = 0; + asection *first_section = NULL; /* FIXME: Do we need to copy PT_NULL segment? */ if (segment->p_type == PT_NULL) @@ -5828,8 +5828,8 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd) this_hdr = &(elf_section_data(section)->this_hdr); if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment)) { - if (!section_count || section->lma < first_lma) - first_lma = section->lma; + if (!first_section) + first_section = section; section_count++; } } @@ -5875,19 +5875,24 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd) if (!map->includes_phdrs && !map->includes_filehdr) /* There is some other padding before the first section. */ - map->p_vaddr_offset = first_lma - segment->p_paddr; + map->p_vaddr_offset = ((first_section ? first_section->lma : 0) + - segment->p_paddr); if (section_count != 0) { unsigned int isec = 0; - for (section = ibfd->sections; + for (section = first_section; section != NULL; section = section->next) { this_hdr = &(elf_section_data(section)->this_hdr); if (ELF_IS_SECTION_IN_SEGMENT_FILE (this_hdr, segment)) - map->sections[isec++] = section->output_section; + { + map->sections[isec++] = section->output_section; + if (isec == section_count) + break; + } } } -- 2.30.2