From f1d85785136b9335f837775031f4dba0124462db Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 21 Nov 2012 21:31:18 +0000 Subject: 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 PR binutils/14493 * ld-elf/maxpage5.d: New file. * ld-elf/maxpage5.s: Likewise. * ld-elf/maxpage5.t: Likewise. --- bfd/ChangeLog | 7 +++++++ bfd/elf.c | 20 ++++++++++++++++++++ ld/testsuite/ChangeLog | 7 +++++++ ld/testsuite/ld-elf/maxpage5.d | 18 ++++++++++++++++++ ld/testsuite/ld-elf/maxpage5.s | 8 ++++++++ ld/testsuite/ld-elf/maxpage5.t | 15 +++++++++++++++ 6 files changed, 75 insertions(+) create mode 100644 ld/testsuite/ld-elf/maxpage5.d create mode 100644 ld/testsuite/ld-elf/maxpage5.s create mode 100644 ld/testsuite/ld-elf/maxpage5.t diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 96fdcd4..ff60564 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,10 @@ +2012-11-21 H.J. Lu + + 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 * elf-nacl.c (segment_nonexecutable_and_has_contents): Renamed to ... diff --git a/bfd/elf.c b/bfd/elf.c index b8bb6d3..a936636 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -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); } diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index bebb04e..72d8445 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2012-11-21 H.J. Lu + + PR binutils/14493 + * ld-elf/maxpage5.d: New file. + * ld-elf/maxpage5.s: Likewise. + * ld-elf/maxpage5.t: Likewise. + 2012-11-21 Roland McGrath * ld-elf/comm-data.exp: Add XFAIL for arm*-*-* targets, referring diff --git a/ld/testsuite/ld-elf/maxpage5.d b/ld/testsuite/ld-elf/maxpage5.d new file mode 100644 index 0000000..bcbd39c --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage5.d @@ -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 diff --git a/ld/testsuite/ld-elf/maxpage5.s b/ld/testsuite/ld-elf/maxpage5.s new file mode 100644 index 0000000..93d6b36 --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage5.s @@ -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 diff --git a/ld/testsuite/ld-elf/maxpage5.t b/ld/testsuite/ld-elf/maxpage5.t new file mode 100644 index 0000000..7f19343 --- /dev/null +++ b/ld/testsuite/ld-elf/maxpage5.t @@ -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/ : { *(*) } +} -- cgit v1.1