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]

Re: [PATCH] program header instability


Alan Modra wrote:

I'm not so keen on never reducing the size.  The thing is that we have
two ways we set the size.  The first is the guess we make in
get_program_header_size (triggerred by SIZEOF_HEADERS in a link
script), the second is the value calculated from a previous iteration
of the segment layout code.  get_program_header_size can make quite a
poor guess.  So I reckon we ought to allow shrinkage on the first
iteration (or maybe first few iterations) of the gld*_map_segments
loop.  Would you mind making that change?

This one seems to to do the trick. Tested on i686-pc-linux-gnu, ok?


nathan

--
Nathan Sidwell    ::   http://www.codesourcery.com   ::         CodeSourcery
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2006-12-27  Nathan Sidwell  <nathan@codesourcery.com>

	* bfd/elf.c (assign_file_positions_for_load_sections): We can
	require fewer phdrs than expected.

	* ld/emultempl/elf-generic.em (gdl_map_segments): Only allow header
	shrinkage for the first few iterations.

	* ld/testsuite/ld-elf/header.d: New.
	* ld/testsuite/ld-elf/header.t: New.
	* ld/testsuite/ld-elf/header.s: New.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.369
diff -c -3 -p -r1.369 elf.c
*** bfd/elf.c	19 Dec 2006 08:49:38 -0000	1.369
--- bfd/elf.c	27 Dec 2006 16:56:53 -0000
*************** assign_file_positions_for_load_sections 
*** 4275,4281 ****
      elf_tdata (abfd)->program_header_size = alloc * bed->s->sizeof_phdr;
    else
      BFD_ASSERT (elf_tdata (abfd)->program_header_size
! 		== alloc * bed->s->sizeof_phdr);
  
    if (alloc == 0)
      {
--- 4275,4281 ----
      elf_tdata (abfd)->program_header_size = alloc * bed->s->sizeof_phdr;
    else
      BFD_ASSERT (elf_tdata (abfd)->program_header_size
! 		>= alloc * bed->s->sizeof_phdr);
  
    if (alloc == 0)
      {
Index: ld/emultempl/elf-generic.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf-generic.em,v
retrieving revision 1.3
diff -c -3 -p -r1.3 elf-generic.em
*** emultempl/elf-generic.em	26 Jul 2006 12:27:12 -0000	1.3
--- emultempl/elf-generic.em	27 Dec 2006 16:54:35 -0000
*************** gld${EMULATION_NAME}_map_segments (bfd_b
*** 60,66 ****
  	    einfo ("%F%P: map sections to segments failed: %E\n");
  
  	  if (phdr_size != elf_tdata (output_bfd)->program_header_size)
! 	    need_layout = TRUE;
  	}
      }
    while (need_layout && --tries);
--- 60,76 ----
  	    einfo ("%F%P: map sections to segments failed: %E\n");
  
  	  if (phdr_size != elf_tdata (output_bfd)->program_header_size)
! 	    {
! 	      if (tries > 6)
! 		/* The first few times we allow any change to
! 		   phdr_size .  */
! 		need_layout = TRUE;
! 	      else if (phdr_size < elf_tdata (output_bfd)->program_header_size)
! 		/* After that we only allow the size to grow.  */
! 		need_layout = TRUE;
! 	      else
! 		elf_tdata (output_bfd)->program_header_size = phdr_size;
! 	    }
  	}
      }
    while (need_layout && --tries);
Index: ld/testsuite/ld-elf/header.d
===================================================================
RCS file: ld/testsuite/ld-elf/header.d
diff -N ld/testsuite/ld-elf/header.d
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-elf/header.d	19 Dec 2006 15:32:08 -0000
***************
*** 0 ****
--- 1,12 ----
+ # ld: -T header.t -z max-page-size=0x10000
+ # objdump: -hpw
+ 
+ #...
+ Program Header:
+     LOAD off    0x0*0000000 vaddr 0x0*0010000 paddr 0x0*0010000 align 2..16
+          filesz 0x0*0010024 memsz 0x0*0010024 flags rwx
+ 
+ Sections:
+ Idx Name          Size      VMA       LMA       File off  Algn  Flags
+   0 .text         0*000ffac  0*0010074  0*0010074  0*0000074  2...  CONTENTS, ALLOC, LOAD, READONLY, CODE
+   1 .data         0*0000004  0*0020020  0*0020020  0*0010020  2...  CONTENTS, ALLOC, LOAD, DATA
Index: ld/testsuite/ld-elf/header.s
===================================================================
RCS file: ld/testsuite/ld-elf/header.s
diff -N ld/testsuite/ld-elf/header.s
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-elf/header.s	19 Dec 2006 15:32:08 -0000
***************
*** 0 ****
--- 1,8 ----
+ 	.text
+ 	.globl main
+ main:
+ 	.rept 0x4000 - 0x15
+ 	.long 0xfedcba98
+ 	.endr
+ 	.data
+ 	.long 0x76543210
Index: ld/testsuite/ld-elf/header.t
===================================================================
RCS file: ld/testsuite/ld-elf/header.t
diff -N ld/testsuite/ld-elf/header.t
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- ld/testsuite/ld-elf/header.t	19 Dec 2006 15:32:08 -0000
***************
*** 0 ****
--- 1,8 ----
+ ENTRY(main)
+ 
+ SECTIONS
+ {
+   . = 0x10000 + SIZEOF_HEADERS;
+   .text : { *(.text) }
+   .data : { *(.data) }
+ }

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