Home | History | Annotate | Download | only in ld-elf
      1 # Test the assigment of sections to segments.
      2 #
      3 # Copyright (C) 2008-2016 Free Software Foundation, Inc.
      4 # Contributed by Red Hat.
      5 #
      6 # This file is part of the GNU Binutils.
      7 #
      8 # This program is free software; you can redistribute it and/or modify
      9 # it under the terms of the GNU General Public License as published by
     10 # the Free Software Foundation; either version 3 of the License, or
     11 # (at your option) any later version.
     12 #
     13 # This program is distributed in the hope that it will be useful,
     14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16 # GNU General Public License for more details.
     17 #
     18 # You should have received a copy of the GNU General Public License
     19 # along with this program; if not, write to the Free Software
     20 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     21 # MA 02110-1301, USA.
     22 
     23 set testname "assignment of ELF sections to segments"
     24 
     25 if {! [is_elf_format] } {
     26     unsupported $testname
     27     return
     28 }
     29 
     30 if {   ! [ld_assemble $as $srcdir/$subdir/sec-to-seg1.s tmpdir/sec-to-seg1.o]
     31     || ! [ld_assemble $as $srcdir/$subdir/sec-to-seg2.s tmpdir/sec-to-seg2.o]} then {
     32     unresolved $testname
     33     return
     34 }
     35 
     36 proc sec_to_seg_test { testname scriptname same_seg } {
     37     global srcdir
     38     global subdir
     39     global ld
     40     global exec_output
     41     global READELF
     42 
     43     if {! [ld_simple_link $ld tmpdir/sec-to-seg "-T $srcdir/$subdir/$scriptname tmpdir/sec-to-seg1.o tmpdir/sec-to-seg2.o"] } then {
     44 	fail $testname
     45 	return 0
     46     }
     47 
     48     send_log "$READELF --program-headers --section-headers tmpdir/sec-to-seg\n"
     49     set exec_output [run_host_cmd "$READELF" "--program-headers --section-headers tmpdir/sec-to-seg"]
     50 
     51     if { $same_seg == 1 } {
     52       if {! [regexp ".*.sec1 .sec2" $exec_output] } {
     53 	  fail $testname
     54 	  return 0
     55       }
     56     } else {
     57       if {  [regexp ".*.sec1 .sec2" $exec_output] } {
     58 	  fail $testname
     59 	  return 0
     60       }
     61     }
     62 
     63     pass $testname
     64     return 1
     65 }
     66 
     67 # Assuming a pagesize of 0x1000 then:
     68 #
     69 # Test  Sec1 End  Sec 2 Start    Expected Result
     70 # ----  --------  -----------    ---------------
     71 #  A    00001042   00001043      Both sections on same page: assign to same segment.
     72 #  B    00001042   00002044      Sections on adjacent pages: assign to same segment.
     73 #  C    00001042   00003044      Sections on disjoint pages: assign to separate segments.
     74 
     75 # These targets have a pagesize of 1, so they will always end up
     76 # placing the two sections in separate segments in the B test.
     77 if {    [istarget avr-*-*]
     78      || [istarget cr16-*-*]
     79      || [istarget crx-*-*]
     80      || [istarget dlx-*-*]
     81      || [istarget ft32-*-*]
     82      || [istarget h8300-*-*]
     83      || [istarget i960-*-*]
     84      || [istarget ip2k-*-*]
     85      || [istarget m32r-*-*]
     86      || [istarget m88k-*-*]
     87      || [istarget moxie-*-*]
     88      || [istarget msp430-*-*]
     89      || [istarget mt-*-*]
     90      || [istarget visium-*-*]
     91     } {
     92     set B_test_same_seg 0
     93 } else {
     94     set B_test_same_seg 1
     95 }
     96 
     97 sec_to_seg_test "assignment of ELF sections to segments (same page)"      "sec-to-seg-script-same-page.t" 1
     98 sec_to_seg_test "assignment of ELF sections to segments (adjacent pages)" "sec-to-seg-script-adjoining-pages.t" $B_test_same_seg
     99 sec_to_seg_test "assignment of ELF sections to segments (disjoint pages)" "sec-to-seg-script-disjoint-pages.t" 0
    100 
    101 
    102 # FIXME: Add more tests to check other rules of section to segment assignment.
    103