This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: Adjust segment memory size for the SHT_NOBITS section
On Fri, Mar 02, 2007 at 01:32:12PM +1030, Alan Modra wrote:
> Then of course you'd have to wonder why the code wasn't written that
> way in the first place. Please do some digging to find out why.
I got curious and had a look myself. It looks like my patch
http://sources.redhat.com/ml/binutils/2004-09/msg00225.html is at
fault here. Previously, both SEC_LOAD and !SEC_LOAD sections
adjusted p_memsz based on their lmas. Following that adjustment,
there was another based on vma.
I think we can just do the one based on lma, because if the lma to vma
relationship changes then map_sections_to_segments will choose a new
segment. Of course, the user can specify segment mapping, lma, and
vma, but we can't do much except warn if the mapping is not
self-consistent. Oh, and really old code had this note on the vma
based adjustment.
/* The section VMA must equal the file position
modulo the page size. FIXME: I'm not sure if
this adjustment is really necessary. We used to
not have the SEC_LOAD case just above, and then
this was necessary, but now I'm not sure. */
This is what I have in mind. I'll run some tests before applying,
eg. build glibc and gdb and run their tests as well as the binutils
testsuite.
* elf.c (assign_file_positions_for_load_sections): Don't
adjust p_memsz for !SEC_LOAD section vma modulo page size.
Instead, use the same lma based adjustment for SEC_LOAD
sections.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.377
diff -u -p -r1.377 elf.c
--- bfd/elf.c 23 Feb 2007 11:47:47 -0000 1.377
+++ bfd/elf.c 2 Mar 2007 12:16:50 -0000
@@ -4495,11 +4495,13 @@ assign_file_positions_for_load_sections
if (p->p_type == PT_LOAD
|| p->p_type == PT_TLS)
{
- bfd_signed_vma adjust;
+ bfd_signed_vma adjust = sec->lma - (p->p_paddr + p->p_filesz);
- if ((flags & SEC_LOAD) != 0)
+ if ((flags & SEC_LOAD) != 0
+ || ((flags & SEC_ALLOC) != 0
+ && ((flags & SEC_THREAD_LOCAL) == 0
+ || p->p_type == PT_TLS)))
{
- adjust = sec->lma - (p->p_paddr + p->p_filesz);
if (adjust < 0)
{
(*_bfd_error_handler)
@@ -4507,25 +4509,13 @@ assign_file_positions_for_load_sections
abfd, sec, (unsigned long) sec->lma);
adjust = 0;
}
- off += adjust;
- p->p_filesz += adjust;
- p->p_memsz += adjust;
- }
- /* .tbss is special. It doesn't contribute to p_memsz of
- normal segments. */
- else if ((flags & SEC_ALLOC) != 0
- && ((flags & SEC_THREAD_LOCAL) == 0
- || p->p_type == PT_TLS))
- {
- /* The section VMA must equal the file position
- modulo the page size. */
- bfd_size_type page = align;
- if (page < maxpagesize)
- page = maxpagesize;
- adjust = vma_page_aligned_bias (sec->vma,
- p->p_vaddr + p->p_memsz,
- page);
p->p_memsz += adjust;
+
+ if ((flags & SEC_LOAD) != 0)
+ {
+ off += adjust;
+ p->p_filesz += adjust;
+ }
}
}
--
Alan Modra
IBM OzLabs - Linux Technology Centre