This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: Properly set the output maxpagesize when rewriting program header
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Wed, 21 Nov 2012 05:08:30 -0800
- Subject: Re: PATCH: Properly set the output maxpagesize when rewriting program header
- References: <20121120232753.GA14519@intel.com>
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
On Tue, Nov 20, 2012 at 03:27:53PM -0800, H.J. Lu wrote:
> Hi,
>
> When rewriting program header on input:
>
> [hjl@gnu-6 pr14493b]$ readelf -l libfoo-sun.so
>
> Elf file type is DYN (Shared object file)
> Entry point 0x0
> There are 4 program headers, starting at offset 64
>
> Program Headers:
> Type Offset VirtAddr PhysAddr
> FileSiz MemSiz Flags Align
> LOAD 0x0000000000000000 0x0000000000000000
> 0x0000000000000000
> 0x0000000000000d9c 0x0000000000000d9c R E 10000
> LOAD 0x0000000000000da0 0x0000000000010da0
> 0x0000000000000000
> 0x0000000000000070 0x00000000000000d0 RW 10000
> DYNAMIC 0x0000000000000120 0x0000000000000120
> 0x0000000000000000
> 0x00000000000002c0 0x0000000000000000 RW 0
> LOOS+464e550 0x00000000000003e0 0x00000000000003e0
> 0x0000000000000000
> 0x0000000000000014 0x0000000000000014 R 8
>
> Section to Segment mapping:
> Segment Sections...
> 00 .dynamic .eh_frame_hdr .eh_frame .hash .SUNW_ldynsym .dynsym
> .dynstr .SUNW_version .SUNW_versym .SUNW_dynsymsort .SUNW_reloc
> .rela.plt .plt .text .init .fini .rodata
> 01 .got .fini_array .init_array .data .jcr .bss
> 02
> 03 .eh_frame_hdr
> [hjl@gnu-6 pr14493b]$
>
> we need to set the output maxpagesize to the maximum alignment of input
> PT_LOAD segments. OK to install?
>
Here is the updated patch with a testcase. OK to install?
Thanks.
H.J.
---
bfd/
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.
ld/testsuite/
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.
diff --git a/bfd/elf.c b/bfd/elf.c
index b8bb6d3..8ac21ba 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/ld-elf/maxpage5.d b/ld/testsuite/ld-elf/maxpage5.d
new file mode 100644
index 0000000..9d7b26d
--- /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*
+
+#...
+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/ : { *(*) }
+}