aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2006-05-27 00:47:45 +0000
committerAlan Modra <amodra@gmail.com>2006-05-27 00:47:45 +0000
commit3f570048d764dc9730cfbcf0b84b707333124f1c (patch)
tree0d017bdf1842c38aff61b0603ecac2b06363d6f1 /bfd
parent6a8d9e540a2f870b5a9bbbc778d47aa50866d5ac (diff)
downloadgdb-3f570048d764dc9730cfbcf0b84b707333124f1c.zip
gdb-3f570048d764dc9730cfbcf0b84b707333124f1c.tar.gz
gdb-3f570048d764dc9730cfbcf0b84b707333124f1c.tar.bz2
bfd/
* elf.c (assign_file_positions_for_load_sections): Retrieve maxpagesize from m->p_align if it is valid. Set p_vaddr, p_paddr and p_align earlier. Revert 2006-05-19 change to p_align. (copy_elf_program_header): Copy p_align. Set p_align_valid. include/elf/ * internal.h (elf_segment_map): Add p_align and p_align_valid.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog8
-rw-r--r--bfd/elf.c73
2 files changed, 54 insertions, 27 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 2d72031..97302a7 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,11 @@
+2006-05-27 Alan Modra <amodra@bigpond.net.au>
+ H.J. Lu <hongjiu.lu@intel.com>
+
+ * elf.c (assign_file_positions_for_load_sections): Retrieve
+ maxpagesize from m->p_align if it is valid. Set p_vaddr,
+ p_paddr and p_align earlier. Revert 2006-05-19 change to p_align.
+ (copy_elf_program_header): Copy p_align. Set p_align_valid.
+
2006-05-26 H.J. Lu <hongjiu.lu@intel.com>
* elf64-x86-64.c (ELF_MINPAGESIZE): Changed to 0x1000.
diff --git a/bfd/elf.c b/bfd/elf.c
index d2124fd..7db3a27 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4111,6 +4111,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
Elf_Internal_Phdr *phdrs;
Elf_Internal_Phdr *p;
file_ptr off, voff;
+ bfd_size_type maxpagesize;
unsigned int count;
unsigned int alloc;
unsigned int i;
@@ -4196,6 +4197,10 @@ assign_file_positions_for_load_sections (bfd *abfd,
if (phdrs == NULL)
return FALSE;
+ maxpagesize = 1;
+ if ((abfd->flags & D_PAGED) != 0)
+ maxpagesize = bed->maxpagesize;
+
off = bed->s->sizeof_ehdr;
off += alloc * bed->s->sizeof_phdr;
@@ -4227,6 +4232,39 @@ assign_file_positions_for_load_sections (bfd *abfd,
p->p_type = m->p_type;
p->p_flags = m->p_flags;
+ if (m->count == 0)
+ p->p_vaddr = 0;
+ else
+ p->p_vaddr = m->sections[0]->vma;
+
+ if (m->p_paddr_valid)
+ p->p_paddr = m->p_paddr;
+ else if (m->count == 0)
+ p->p_paddr = 0;
+ else
+ p->p_paddr = m->sections[0]->lma;
+
+ if (p->p_type == PT_LOAD
+ && (abfd->flags & D_PAGED) != 0)
+ {
+ /* p_align in demand paged PT_LOAD segments effectively stores
+ the maximum page size. When copying an executable with
+ objcopy, we set m->p_align from the input file. Use this
+ value for maxpagesize rather than bed->maxpagesize, which
+ may be different. Note that we use maxpagesize for PT_TLS
+ segment alignment later in this function, so we are relying
+ on at least one PT_LOAD segment appearing before a PT_TLS
+ segment. */
+ if (m->p_align_valid)
+ maxpagesize = m->p_align;
+
+ p->p_align = maxpagesize;
+ }
+ else if (m->count == 0)
+ p->p_align = 1 << bed->s->log_file_align;
+ else
+ p->p_align = 0;
+
if (p->p_type == PT_LOAD
&& m->count > 0)
{
@@ -4244,8 +4282,8 @@ assign_file_positions_for_load_sections (bfd *abfd,
}
align = (bfd_size_type) 1 << align_power;
- if ((abfd->flags & D_PAGED) != 0 && bed->maxpagesize > align)
- align = bed->maxpagesize;
+ if (align < maxpagesize)
+ align = maxpagesize;
adjust = vma_page_aligned_bias (m->sections[0]->vma, off, align);
off += adjust;
@@ -4286,26 +4324,6 @@ assign_file_positions_for_load_sections (bfd *abfd,
return FALSE;
}
- if (m->count == 0)
- p->p_vaddr = 0;
- else
- p->p_vaddr = m->sections[0]->vma;
-
- if (m->p_paddr_valid)
- p->p_paddr = m->p_paddr;
- else if (m->count == 0)
- p->p_paddr = 0;
- else
- p->p_paddr = m->sections[0]->lma;
-
- if (p->p_type == PT_LOAD
- && (abfd->flags & D_PAGED) != 0)
- p->p_align = bed->maxpagesize;
- else if (m->count == 0)
- p->p_align = 1 << bed->s->log_file_align;
- else
- p->p_align = 0;
-
p->p_offset = 0;
p->p_filesz = 0;
p->p_memsz = 0;
@@ -4386,7 +4404,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
sec = *secpp;
flags = sec->flags;
- align = 1 << bfd_get_section_alignment (abfd, sec);
+ align = (bfd_size_type) 1 << bfd_get_section_alignment (abfd, sec);
if (p->p_type == PT_LOAD
|| p->p_type == PT_TLS)
@@ -4416,8 +4434,8 @@ assign_file_positions_for_load_sections (bfd *abfd,
/* The section VMA must equal the file position
modulo the page size. */
bfd_size_type page = align;
- if ((abfd->flags & D_PAGED) != 0 && bed->maxpagesize > page)
- page = bed->maxpagesize;
+ if (page < maxpagesize)
+ page = maxpagesize;
adjust = vma_page_aligned_bias (sec->vma,
p->p_vaddr + p->p_memsz,
page);
@@ -4494,8 +4512,7 @@ assign_file_positions_for_load_sections (bfd *abfd,
if (align > p->p_align
&& (p->p_type != PT_LOAD
- || (abfd->flags & D_PAGED) == 0
- || ((p->p_vaddr - p->p_offset) & (align - 1)) == 0))
+ || (abfd->flags & D_PAGED) == 0))
p->p_align = align;
}
@@ -5800,6 +5817,8 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd)
map->p_flags_valid = 1;
map->p_paddr = segment->p_paddr;
map->p_paddr_valid = 1;
+ map->p_align = segment->p_align;
+ map->p_align_valid = 1;
/* Determine if this segment contains the ELF file header
and if it contains the program headers themselves. */