Home | History | Annotate | Download | only in ld-scripts
      1 # Test PHDRS in a linker script.
      2 # By Ian Lance Taylor, Cygnus Support.
      3 #   Copyright (C) 1999-2014 Free Software Foundation, Inc.
      4 #
      5 # This file is part of the GNU Binutils.
      6 #
      7 # This program is free software; you can redistribute it and/or modify
      8 # it under the terms of the GNU General Public License as published by
      9 # the Free Software Foundation; either version 3 of the License, or
     10 # (at your option) any later version.
     11 #
     12 # This program is distributed in the hope that it will be useful,
     13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 # GNU General Public License for more details.
     16 #
     17 # You should have received a copy of the GNU General Public License
     18 # along with this program; if not, write to the Free Software
     19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20 # MA 02110-1301, USA.
     21 
     22 # PHDRS is only meaningful for ELF.
     23 if ![is_elf_format] {
     24     return
     25 }
     26 
     27 # This is a very simplistic test.
     28 
     29 set testname "PHDRS"
     30 
     31 set ldopt ""
     32 if { [istarget spu*-*-*] } {
     33     set ldopt "--local-store 0:0"
     34 }
     35 
     36 if ![ld_assemble $as $srcdir/$subdir/phdrs.s tmpdir/phdrs.o] {
     37     unresolved $testname
     38     return
     39 }
     40 
     41 set phdrs_regexp \
     42 ".*Program Header:.*PHDR *off *0x00*34 *vaddr *0x00*800034 *paddr *0x00*800034.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* flags r--.*LOAD *off *0x00* *vaddr *0x00*800000 *paddr *0x00*800000.*filesz *0x00*\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags r-x.*LOAD *off *0x0\[0-9a-f\]* *vaddr *0x00*80*\[0-9a-f\]* *paddr *0x00*80*\[0-9a-f\]*.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags *rw-.*"
     43 
     44 # On a 64 bit ELF format, we need different numbers.
     45 if [is_elf64 tmpdir/phdrs.o] {
     46     set phdrs_regexp \
     47 ".*Program Header:.*PHDR *off *0x00*40 *vaddr *0x00*800040 *paddr *0x00*800040.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* flags r--.*LOAD *off *0x00* *vaddr *0x00*800000 *paddr *0x00*800000.*filesz *0x00*\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags r-x.*LOAD *off *0x0\[0-9a-f\]* *vaddr *0x00*80*\[0-9a-f\]* *paddr *0x00*80*\[0-9a-f\]*.*filesz *0x0\[0-9a-f\]* *memsz *0x0\[0-9a-f\]* *flags *rw-.*"
     48 }
     49 
     50 set ldopt "$ldopt -T $srcdir/$subdir/phdrs.t tmpdir/phdrs.o"
     51 if ![ld_simple_link $ld tmpdir/phdrs $ldopt] {
     52     fail $testname
     53 } else {
     54     if {![is_remote host] && [which $objdump] == 0} {
     55 	unresolved $testname
     56 	return
     57     }
     58     set exec_output [run_host_cmd "$objdump" "--private-headers tmpdir/phdrs"]
     59     set exec_output [prune_warnings $exec_output]
     60     verbose -log $exec_output
     61 
     62     # The RX port sets the p_paddr of loadable segments to 0 in order
     63     # to be compatible with Renesas tools.  When an RX executable is
     64     # loaded into a BFD based tool the code tries to reconstruct the
     65     # correct vaddr and paddr values.  This is not always possible
     66     # however and this test is one example of where the reconstruction
     67     # fails.
     68     setup_xfail rx-*-*
     69 
     70     if [regexp $phdrs_regexp $exec_output] {
     71 	pass $testname
     72     } else {
     73 	fail $testname
     74     }
     75 }
     76