From: Alan Modra <amodra@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>, binutils@sourceware.org
Subject: Re: VMA section overlap warnings for overlays
Date: Sat, 28 Aug 2010 13:39:00 -0000 [thread overview]
Message-ID: <20100828132836.GY15723@bubble.grove.modra.org> (raw)
In-Reply-To: <20100828105631.GW15723@bubble.grove.modra.org>
The real bug was that copy_elf_program_header calculated header_size
from the first section found to be in the segment rather than the
section with the lowest lma. So a one line fix. The rest of this
patch is to cope with (and fix) invalid program header p_paddr values.
I won't commit this immediately as I'd like to run some more tests.
PR binutils/11953
* elf.c (copy_elf_program_header): Calculate map->header_size
from lowest_section, not first_section. Validate program
header p_paddr against section lma. Find lowest_section in
second loop over headers.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.517
diff -u -p -r1.517 elf.c
--- bfd/elf.c 25 Aug 2010 14:53:40 -0000 1.517
+++ bfd/elf.c 28 Aug 2010 12:57:00 -0000
@@ -5870,7 +5870,7 @@ copy_elf_program_header (bfd *ibfd, bfd
bfd_size_type amt;
Elf_Internal_Shdr *this_hdr;
asection *first_section = NULL;
- asection *lowest_section = NULL;
+ asection *lowest_section;
/* Compute how many sections are in this segment. */
for (section = ibfd->sections, section_count = 0;
@@ -5880,10 +5880,8 @@ copy_elf_program_header (bfd *ibfd, bfd
this_hdr = &(elf_section_data(section)->this_hdr);
if (ELF_SECTION_IN_SEGMENT (this_hdr, segment))
{
- if (!first_section)
- first_section = lowest_section = section;
- if (section->lma < lowest_section->lma)
- lowest_section = section;
+ if (first_section == NULL)
+ first_section = section;
section_count++;
}
}
@@ -5937,17 +5935,7 @@ copy_elf_program_header (bfd *ibfd, bfd
phdr_included = TRUE;
}
- if (map->includes_filehdr && first_section)
- /* We need to keep the space used by the headers fixed. */
- map->header_size = first_section->vma - segment->p_vaddr;
-
- if (!map->includes_phdrs
- && !map->includes_filehdr
- && map->p_paddr_valid)
- /* There is some other padding before the first section. */
- map->p_vaddr_offset = ((lowest_section ? lowest_section->lma : 0)
- - segment->p_paddr);
-
+ lowest_section = first_section;
if (section_count != 0)
{
unsigned int isec = 0;
@@ -5960,12 +5948,41 @@ copy_elf_program_header (bfd *ibfd, bfd
if (ELF_SECTION_IN_SEGMENT (this_hdr, segment))
{
map->sections[isec++] = section->output_section;
+ if (section->lma < lowest_section->lma)
+ lowest_section = section;
+ if ((section->flags & SEC_ALLOC) != 0)
+ {
+ bfd_vma seg_off;
+
+ /* Section lmas are set up from PT_LOAD header
+ p_paddr in _bfd_elf_make_section_from_shdr.
+ If this header has a p_paddr that disagrees
+ with the section lma, flag the p_paddr as
+ invalid. */
+ if ((section->flags & SEC_LOAD) != 0)
+ seg_off = this_hdr->sh_offset - segment->p_offset;
+ else
+ seg_off = this_hdr->sh_addr - segment->p_vaddr;
+ if (section->lma - segment->p_paddr != seg_off)
+ map->p_paddr_valid = FALSE;
+ }
if (isec == section_count)
break;
}
}
}
+ if (map->includes_filehdr && lowest_section != NULL)
+ /* We need to keep the space used by the headers fixed. */
+ map->header_size = lowest_section->vma - segment->p_vaddr;
+
+ if (!map->includes_phdrs
+ && !map->includes_filehdr
+ && map->p_paddr_valid)
+ /* There is some other padding before the first section. */
+ map->p_vaddr_offset = ((lowest_section ? lowest_section->lma : 0)
+ - segment->p_paddr);
+
map->count = section_count;
*pointer_to_map = map;
pointer_to_map = &map->next;
--
Alan Modra
Australia Development Lab, IBM
next prev parent reply other threads:[~2010-08-28 13:28 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-16 13:29 David Stubbs
2010-04-21 8:25 ` Alan Modra
2010-04-21 14:44 ` David Stubbs
2010-04-22 1:11 ` Alan Modra
2010-04-22 1:53 ` Alan Modra
2010-04-22 12:39 ` David Stubbs
2010-04-24 2:18 ` Alan Modra
2010-05-07 16:14 ` David Stubbs
2010-05-08 11:49 ` Alan Modra
2010-05-12 13:19 ` David Stubbs
2010-05-13 3:37 ` Alan Modra
2010-07-15 8:11 ` Andreas Schwab
2010-07-15 13:10 ` Alan Modra
2010-07-15 13:46 ` Andreas Schwab
2010-07-15 13:53 ` H.J. Lu
2010-07-15 14:12 ` Andreas Schwab
2010-07-15 14:17 ` H.J. Lu
2010-07-15 14:18 ` Alan Modra
2010-07-15 14:26 ` H.J. Lu
2010-07-15 14:36 ` Andreas Schwab
2010-07-15 19:09 ` H.J. Lu
2010-07-16 7:39 ` Andreas Schwab
2010-07-16 10:04 ` Alan Modra
2010-07-19 12:43 ` Andreas Schwab
2010-07-20 5:45 ` Alan Modra
2010-07-20 14:11 ` Alan Modra
2011-02-24 23:49 ` H.J. Lu
2011-02-25 7:49 ` Alan Modra
2011-02-25 10:17 ` Andreas Schwab
2011-02-25 12:30 ` H.J. Lu
2011-02-25 15:55 ` H.J. Lu
2011-02-25 16:23 ` Andreas Schwab
2011-02-25 16:34 ` H.J. Lu
2010-08-28 1:02 ` H.J. Lu
2010-08-28 11:00 ` Alan Modra
2010-08-28 13:39 ` Alan Modra [this message]
2010-08-28 17:25 ` H.J. Lu
2010-08-30 4:46 ` Alan Modra
2010-08-30 5:11 ` H.J. Lu
2010-08-30 6:30 ` Alan Modra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100828132836.GY15723@bubble.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=hjl.tools@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).