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:

2) make it an error to have FILEHDRS and/or PHDRS in not-the-first segment of the PHDRS statement.

This is the best option IMO.

This patch does that. We allow FILEHDRS/PHDRS provided it's the first segment, or the previous segment had such headers. The phdrs.t testcase has such an example.


tested on powerpc-elf, ok?

nathan

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

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

	ld/
	* ldlang.c (lang_new_phdr): Check PHDRS and FILEHDR do not appear
	after a non-PHDR/FILEHDR 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	5 Oct 2009 11:57:30 -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,4747 ----
  
  @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.  These may only be applied
! to the first segment, or to a segment that appears immediately after
! another segment containing either @code{PHDRS} or @code{FILEHDR}.
  
  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	5 Oct 2009 11:57:32 -0000
*************** lang_new_phdr (const char *name,
*** 6776,6782 ****
    n->flags = flags;
  
    for (pp = &lang_phdr_list; *pp != NULL; pp = &(*pp)->next)
!     ;
    *pp = n;
  }
  
--- 6776,6787 ----
    n->flags = flags;
  
    for (pp = &lang_phdr_list; *pp != NULL; pp = &(*pp)->next)
!     if ((filehdr || phdrs) && !((*pp)->filehdr || (*pp)->phdrs))
!       {
! 	einfo (_("%X%P:%S: PHDRS and FILEHDR are only permitted if all previous segments contain headers, `%s' does not\n"), (*pp)->name);
! 	filehdr = phdrs = 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	5 Oct 2009 11:57:35 -0000
***************
*** 0 ****
--- 1,4 ----
+ # name: PHDRS headers
+ # source: phdrs.s
+ # ld: -T phdrs3.t
+ # error: \A[^ \n:]*:[^:\n]*:4: PHDRS and FILEHDR are only permitted if all previous segments contain headers, `data' does not\n[^ \n:]*:[^:\n]*:5: PHDRS and FILEHDR are only permitted if all previous segments contain headers, `data' does not\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	5 Oct 2009 11:57:35 -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	5 Oct 2009 11:57:35 -0000
***************
*** 0 ****
--- 1,16 ----
+ PHDRS
+ {
+   data PT_LOAD ;
+   header PT_PHDR PHDRS ;
+   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]