This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: Properly set the output maxpagesize when rewriting program header


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?

Thanks.


H.J.
---
2012-11-20  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.

diff --git a/bfd/elf.c b/bfd/elf.c
index b8bb6d3..557c3d5 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -6272,6 +6272,8 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd)
 static bfd_boolean
 copy_private_bfd_data (bfd *ibfd, bfd *obfd)
 {
+  bfd_vma maxpagesize = 0;
+
   if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
     return TRUE;
@@ -6300,10 +6302,18 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
 	   section = section->next)
 	section->segment_mark = FALSE;
 
+      /* Find the maximum alignment of input PT_LOAD segments.  */
       num_segments = elf_elfheader (ibfd)->e_phnum;
       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;
+
+      for (i = 0, segment = elf_tdata (ibfd)->phdr;
+	   i < num_segments;
+	   i++, segment++)
 	{
 	  /* PR binutils/3535.  The Solaris linker always sets the p_paddr
 	     and p_memsz fields of special segments (DYNAMIC, INTERP) to 0
@@ -6356,6 +6366,12 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
     }
 
 rewrite:
+  /* When rewriting program header, set the output maxpagesize to the
+     maximum alignment of input PT_LOAD segments.  */ 
+  if (maxpagesize &&
+      maxpagesize != get_elf_backend_data (obfd)->maxpagesize)
+    bfd_emul_set_maxpagesize (obfd->xvec->name, maxpagesize);
+
   return rewrite_elf_program_header (ibfd, obfd);
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]