Add Xtensa port
[external/binutils.git] / ld / testsuite / ld-xtensa / lcall.exp
1 # Test Xtensa longcall optimization.
2 # By David Heine, Tensilica, Inc.
3 #   Copyright 2002, 2003
4 #   Free Software Foundation, Inc.
5 #
6 # This file is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 set testname "LCALL"
21
22 set OBJDUMPFLAGS "-dr"
23
24 #
25 # default_ld_objdump
26 #       run objdump on a file
27 #
28 proc default_ld_objdump { objdump object outputfile } {
29     global OBJDUMPFLAGS
30     global objdump_output
31     global host_triplet
32
33     if {[which $objdump] == 0} then {
34         perror "$objdump does not exist"
35         return 0
36     }
37
38     if ![info exists OBJDUMPFLAGS] { set OBJDUMPFLAGS "" }
39
40     verbose -log "$objdump $OBJDUMPFLAGS $object >$outputfile"
41
42     catch "exec $objdump $OBJDUMPFLAGS $object >$outputfile" exec_output
43     set exec_output [prune_warnings $exec_output]
44     if [string match "" $exec_output] then {
45         return 1
46     } else {
47         verbose -log "$exec_output"
48         perror "$object: objdump failed"
49         return 0
50     }
51 }
52
53
54 if ![ld_assemble $as $srcdir/$subdir/lcall1.s tmpdir/lcall1.o] {
55     unresolved $testname
56     return
57 }
58 if ![ld_assemble $as $srcdir/$subdir/lcall2.s tmpdir/lcall2.o] {
59     unresolved $testname
60     return
61 }
62
63 set object "tmpdir/lcall"
64 set outputfile "$object.txt"
65
66 if ![ld_simple_link $ld $object "-T $srcdir/$subdir/lcall.t tmpdir/lcall1.o tmpdir/lcall2.o"] {
67     verbose -log "failure in ld"
68     fail $testname
69     return
70
71
72 if ![default_ld_objdump $objdump $object $outputfile ] {
73     verbose -log "failure in objdump"
74     fail $testname
75     return
76
77
78 set file [open $outputfile r]
79 while { [gets $file line] != -1 } {
80     #   verbose "$line" 2
81     if [regexp "l32r" $line] {
82         verbose -log "Found an l32r in the linked object"
83         verbose -log "$line"
84         fail $testname
85     }
86 }
87 close $file
88 pass $testname
89
90
91 set testname "LCALL2"
92 set file [open $outputfile r]
93 set found 0
94
95 while { [gets $file line] != -1 } {
96     #   verbose "$line" 2
97     if [regexp "^00000004 <label1>:" $line] {
98         set found 1
99     }
100 }
101 close $file
102 if  $found  {
103    pass $testname
104 } else {
105    fail $testname
106 }
107