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: linker bug 10515


Alan Modra wrote:

Yes.  You would need overlapping PT_LOAD segments if more than one
could have PHDRS.  I suppose that would be possible with overlays but
I doubt the existing code supports it.

Thanks. Like this? tested on powerpc-elf.


nathan


-- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery

2009-10-06  Nathan Sidwell  <nathan@codesourcery.com>

	ld/
	* ldlang.c (lang_new_phdr): Check PHDRS and FILEHDR in loadable
	segments do not appear after a different loadable segment.
	* ld.texinfo (PHDRS): Document order of processing segments.
	Document where PHDRS and FILEHDR may appear.

	ld/testsuite/
	* ld-scripts/phdrs3.d: New.
	* ld-scripts/phdrs3.t: New.
	* ld-scripts/phdrs3.exp: New.

Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.248
diff -c -3 -p -r1.248 ld.texinfo
*** ld.texinfo	23 Sep 2009 13:54:28 -0000	1.248
--- ld.texinfo	6 Oct 2009 11:01:59 -0000
*************** The @var{name} is used only for referenc
*** 4710,4716 ****
  of the linker script.  It is not put into the output file.  Program
  header names are stored in a separate name space, and will not conflict
  with symbol names, file names, or section names.  Each program header
! must have a distinct name.
  
  Certain program header types describe segments of memory which the
  system loader will load from the file.  In the linker script, you
--- 4710,4717 ----
  of the linker script.  It is not put into the output file.  Program
  header names are stored in a separate name space, and will not conflict
  with symbol names, file names, or section names.  Each program header
! must have a distinct name.  The headers are processed in order and it
! is usual for them to map to sections in ascending load address order.
  
  Certain program header types describe segments of memory which the
  system loader will load from the file.  In the linker script, you
*************** segment at all.
*** 4734,4744 ****
  
  @kindex FILEHDR
  @kindex PHDRS
! You may use the @code{FILEHDR} and @code{PHDRS} keywords appear after
  the program header type to further describe the contents of the segment.
  The @code{FILEHDR} keyword means that the segment should include the ELF
  file header.  The @code{PHDRS} keyword means that the segment should
! include the ELF program headers themselves.
  
  The @var{type} may be one of the following.  The numbers indicate the
  value of the keyword.
--- 4735,4746 ----
  
  @kindex FILEHDR
  @kindex PHDRS
! You may use the @code{FILEHDR} and @code{PHDRS} keywords after
  the program header type to further describe the contents of the segment.
  The @code{FILEHDR} keyword means that the segment should include the ELF
  file header.  The @code{PHDRS} keyword means that the segment should
! include the ELF program headers themselves.  If applied to a loadable
! segment (@code{PT_LOAD}), it must be the first loadable segment.
  
  The @var{type} may be one of the following.  The numbers indicate the
  value of the keyword.
Index: ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.320
diff -c -3 -p -r1.320 ldlang.c
*** ldlang.c	29 Sep 2009 02:24:56 -0000	1.320
--- ldlang.c	6 Oct 2009 11:02:04 -0000
*************** lang_new_phdr (const char *name,
*** 6765,6770 ****
--- 6765,6771 ----
  	       etree_type *flags)
  {
    struct lang_phdr *n, **pp;
+   bfd_boolean hdrs;
  
    n = (struct lang_phdr *) stat_alloc (sizeof (struct lang_phdr));
    n->next = NULL;
*************** lang_new_phdr (const char *name,
*** 6774,6782 ****
    n->phdrs = phdrs;
    n->at = at;
    n->flags = flags;
  
    for (pp = &lang_phdr_list; *pp != NULL; pp = &(*pp)->next)
!     ;
    *pp = n;
  }
  
--- 6775,6790 ----
    n->phdrs = phdrs;
    n->at = at;
    n->flags = flags;
+   
+   hdrs = n->type == 1 && (phdrs || filehdr);
  
    for (pp = &lang_phdr_list; *pp != NULL; pp = &(*pp)->next)
!     if (hdrs && (*pp)->type == 1)
!       {
! 	einfo (_("%X%P:%S: PHDRS and FILEHDR are only permitted for the first PT_LOAD segment\n"));
! 	hdrs = FALSE;
!       }
! 
    *pp = n;
  }
  
Index: testsuite/ld-scripts/phdrs3.d
===================================================================
RCS file: testsuite/ld-scripts/phdrs3.d
diff -N testsuite/ld-scripts/phdrs3.d
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/ld-scripts/phdrs3.d	6 Oct 2009 11:02:06 -0000
***************
*** 0 ****
--- 1,4 ----
+ # name: PHDRS headers
+ # source: phdrs.s
+ # ld: -T phdrs3.t
+ # error: \A[^ \n:]*:[^:\n]*:5: PHDRS and FILEHDR are only permitted for the first PT_LOAD segment\Z
Index: testsuite/ld-scripts/phdrs3.exp
===================================================================
RCS file: testsuite/ld-scripts/phdrs3.exp
diff -N testsuite/ld-scripts/phdrs3.exp
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/ld-scripts/phdrs3.exp	6 Oct 2009 11:02:06 -0000
***************
*** 0 ****
--- 1,38 ----
+ # Test PHDRS in a linker script.
+ # By Nathan Sidwell <nathan@codesourcery.com>
+ #   Copyright 2009 Free Software Foundation, Inc.
+ #
+ # This file is part of the GNU Binutils.
+ #
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 3 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+ # MA 02110-1301, USA.
+ 
+ # PHDRS is only meaningful for ELF.
+ if ![is_elf_format] {
+     return
+ }
+ 
+ load_lib ld-lib.exp
+ 
+ set testname "PHDRS headers"
+ 
+ set old_ldflags $LDFLAGS
+ if { [istarget spu*-*-*] } {
+     set LDFLAGS "$LDFLAGS --no-overlays"
+ }
+ 
+ run_dump_test "phdrs3"
+ 
+ set LDFLAGS $old_ldflags
Index: testsuite/ld-scripts/phdrs3.t
===================================================================
RCS file: testsuite/ld-scripts/phdrs3.t
diff -N testsuite/ld-scripts/phdrs3.t
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/ld-scripts/phdrs3.t	6 Oct 2009 11:02:06 -0000
***************
*** 0 ****
--- 1,16 ----
+ PHDRS
+ {
+   data PT_LOAD ;
+   header PT_PHDR PHDRS ; /* OK */
+   text PT_LOAD FILEHDR PHDRS ;
+ }
+ 
+ SECTIONS
+ {
+   /* This test will fail on architectures where the startaddress below
+      is less than the constant MAXPAGESIZE.  */
+   . = 0x800000 + SIZEOF_HEADERS;
+   .text : { *(.text) } :text
+   .data : { *(.data) } :data
+   /DISCARD/ : { *(.*) }
+ }

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