Home | History | Annotate | Download | only in ld-size
      1 # Expect script for linker support of size relocations.
      2 #
      3 #   Copyright (C) 2013-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 
     23 
     24 # Size relications have only been implemented for the ix86 and x86_64,
     25 # so far.
     26 if {!(([istarget "i?86-*-*"]
     27        || [istarget "x86_64-*-*"])
     28       && ([istarget "*-*-elf*"]
     29 	  || [istarget "*-*-nacl*"]
     30 	  || (([istarget "*-*-linux*"]
     31 	       || [istarget "*-*-gnu*"])
     32 	      && ![istarget "*-*-*aout*"]
     33 	      && ![istarget "*-*-*oldld*"]))) } {
     34     verbose "Size relocations tests not run - no target support"
     35     return
     36 }
     37 
     38 # So as to avoid rewriting every last test case here in a nacl variant,
     39 # we use black magic to massage the generic cases into nacl-variant cases.
     40 if [istarget "*-*-nacl*"] {
     41     # Change all the -melf_i386 to -melf_i386_nacl so linking can succeed.
     42     set options_regsub(ld) {-m(\\S+) -m\\1_nacl}
     43 }
     44 
     45 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
     46 foreach t $test_list {
     47     # We need to strip the ".d", but can leave the dirname.
     48     verbose [file rootname $t]
     49     run_dump_test [file rootname $t]
     50 }
     51 
     52 # We need a native system.
     53 if ![isnative] {
     54     verbose "Native size relocation tests not run - not a native toolchain"
     55     return
     56 }
     57 
     58 # We need a working compiler.
     59 if { [which $CC] == 0 } {
     60     verbose "Native size relocation tests not run - no compiler available"
     61     return
     62 }
     63 
     64 set build_tests {
     65   {"Build libsize-1.so"
     66    "-shared" "-fPIC"
     67    {size-1a.c size-1b.c} {} "libsize-1.so"}
     68   {"Build libsize-2.so"
     69    "-shared" "-fPIC"
     70    {size-2a.c size-2b.c} {} "libsize-2.so"}
     71   {"Build libsize-3a.so"
     72    "-shared" "-fPIC"
     73    {size-3a.c} {} "libsize-3a.so"}
     74   {"Build libsize-3b.so"
     75    "-shared" "-fPIC"
     76    {size-3b.c} {} "libsize-3b.so"}
     77   {"Build libsize-3c.so"
     78    "-shared" "-fPIC"
     79    {size-3c.c} {} "libsize-3c.so"}
     80   {"Build libsize-6b.so"
     81    "-shared" "-fPIC"
     82    {size-6b.c} {} "libsize-6b.so"}
     83   {"Build libsize-7.so"
     84    "-shared" "-fPIC"
     85    {size-7b.c} {} "libsize-7.so"}
     86   {"Build size-7"
     87    "-Wl,--no-as-needed tmpdir/libsize-7.so" ""
     88    {size-7a.c} {{readelf -rW size-7.rd}} "size-7.exe"}
     89   {"Build libsize-8.so"
     90    "-shared" "-fPIC"
     91    {size-8b.c} {} "libsize-8.so"}
     92   {"Build size-8"
     93    "-Wl,--no-as-needed tmpdir/libsize-8.so" ""
     94    {size-8a.c} {{readelf -rW size-8.rd}} "size-8.exe"}
     95   {"Build libsize-9.so"
     96    "-shared" "-fPIC"
     97    {size-9b.c} {{readelf -rW size-9.rd}} "libsize-9.so"}
     98   {"Build libsize-10.so"
     99    "-shared" "-fPIC"
    100    {size-10b.c} {{readelf -rW size-10.rd}} "libsize-10.so"}
    101 }
    102 
    103 run_cc_link_tests $build_tests
    104 
    105 set run_tests {
    106     {"Run size-1"
    107      "tmpdir/libsize-1.so" ""
    108      {size-1.c} "size-1" "size-1.out"}
    109     {"Run size-2"
    110      "tmpdir/libsize-2.so" ""
    111      {size-2.c} "size-2" "size-2.out"}
    112     {"Run size-3a"
    113      "" ""
    114      {size-3.c size-3a.c} "size-3a" "size-3.out"}
    115     {"Run size-3b"
    116      "tmpdir/libsize-3a.so" ""
    117      {size-3.c} "size-3b" "size-3.out"}
    118     {"Run size-3c"
    119      "" ""
    120      {size-3.c size-3b.c} "size-3c" "size-3.out"}
    121     {"Run size-3d"
    122      "tmpdir/libsize-3b.so" ""
    123      {size-3.c} "size-3d" "size-3.out"}
    124     {"Run size-3d"
    125      "" ""
    126      {size-3.c size-3c.c} "size-3d" "size-3.out"}
    127     {"Run size-3e"
    128      "tmpdir/libsize-3c.so" ""
    129      {size-3.c} "size-3e" "size-3.out"}
    130     {"Run size-4a"
    131      "" ""
    132      {size-4a.c size-4b.c} "size-4a" "size-4.out"}
    133     {"Run size-4b"
    134      "" ""
    135      {size-4b.c size-4a.c} "size-4b" "size-4.out"}
    136     {"Run size-5a"
    137      "" ""
    138      {size-5a.c size-5b.c} "size-5a" "size-5.out"}
    139     {"Run size-5b"
    140      "" ""
    141      {size-5b.c size-5a.c} "size-5b" "size-5.out"}
    142     {"Run size-6"
    143      "tmpdir/libsize-6b.so" ""
    144      {size-6a.c} "size-6" "size-6.out"}
    145 }
    146 
    147 run_ld_link_exec_tests [] $run_tests
    148 
    149 # Check if size relocation works at run-time.
    150 catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output
    151 if ![string match "" $exec_output] then {
    152     send_log "No run-time size relocation support: $exec_output\n"
    153     verbose "No run-time size relocation support: $exec_output" 1
    154     return
    155 }
    156 
    157 if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then {
    158     verbose "output is [file_contents "tmpdir/dump.out"]" 2
    159     fail "Run-time size relocation"
    160     return
    161 }
    162 
    163 # Run-time size relocation tests.
    164 set run_time_tests {
    165     {"Run size-8"
    166      "tmpdir/libsize-8.so --hash-styl=gnu" ""
    167      {size-8a.c} "size-8" "size-8.out"}
    168     {"Run size-9"
    169      "tmpdir/libsize-9.so" ""
    170      {size-9a.c} "size-9" "size-9.out"}
    171     {"Run size-10"
    172      "tmpdir/libsize-10.so" ""
    173      {size-10a.c} "size-10" "size-10.out"}
    174 }
    175 
    176 run_ld_link_exec_tests [] $run_time_tests
    177