Set output maxpagesize when rewriting program header

bfd/

	PR binutils/14493
	* elf.c (copy_elf_program_header): When rewriting program
	header, set the output maxpagesize to the maximum alignment
	of input PT_LOAD segments.

2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>

	PR binutils/14493
	* ld-elf/maxpage5.d: New file.
	* ld-elf/maxpage5.s: Likewise.
	* ld-elf/maxpage5.t: Likewise.
This commit is contained in:
H.J. Lu 2012-11-21 21:31:18 +00:00
parent a3f548ed85
commit f1d8578513
6 changed files with 75 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2012-11-21 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/14493
* elf.c (copy_elf_program_header): When rewriting program
header, set the output maxpagesize to the maximum alignment
of input PT_LOAD segments.
2012-11-21 Roland McGrath <mcgrathr@google.com>
* elf-nacl.c (segment_nonexecutable_and_has_contents): Renamed to ...

View File

@ -6356,6 +6356,26 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
}
rewrite:
if (ibfd->xvec == obfd->xvec)
{
/* When rewriting program header, set the output maxpagesize to
the maximum alignment of input PT_LOAD segments. */
Elf_Internal_Phdr *segment;
unsigned int i;
unsigned int num_segments = elf_elfheader (ibfd)->e_phnum;
bfd_vma maxpagesize = 0;
for (i = 0, segment = elf_tdata (ibfd)->phdr;
i < num_segments;
i++, segment++)
if (segment->p_type == PT_LOAD
&& maxpagesize < segment->p_align)
maxpagesize = segment->p_align;
if (maxpagesize != get_elf_backend_data (obfd)->maxpagesize)
bfd_emul_set_maxpagesize (bfd_get_target (obfd), maxpagesize);
}
return rewrite_elf_program_header (ibfd, obfd);
}

View File

@ -1,3 +1,10 @@
2012-11-21 H.J. Lu <hongjiu.lu@intel.com>
PR binutils/14493
* ld-elf/maxpage5.d: New file.
* ld-elf/maxpage5.s: Likewise.
* ld-elf/maxpage5.t: Likewise.
2012-11-21 Roland McGrath <mcgrathr@google.com>
* ld-elf/comm-data.exp: Add XFAIL for arm*-*-* targets, referring

View File

@ -0,0 +1,18 @@
#source: maxpage5.s
#as: --32
#ld: -z max-page-size=0x200000 -T maxpage5.t
#objcopy_linked_file: -R .foo
#readelf: -l --wide
#target: x86_64-*-linux* i?86-*-linux-gnu
#...
Program Headers:
Type.*
LOAD +0x[0-9a-f]+ .*0x200000
NOTE +0x[0-9a-f]+ .*
#...
Segment Sections...
00[ \t]+.text *
01[ \t]+.note *
#pass

View File

@ -0,0 +1,8 @@
.globl _entry
.text
_entry:
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.section .foo,"awx",%progbits
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.section .note,"",%note
.byte 0

View File

@ -0,0 +1,15 @@
OUTPUT_FORMAT("elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(_entry)
PHDRS
{
data PT_LOAD;
note PT_NOTE;
}
SECTIONS
{
.text : { *(.text) } :data
.foo : { *(.foo) } :data
.note : { *(.note) } :note
/DISCARD/ : { *(*) }
}