binutils/testsuite/
[external/binutils.git] / binutils / testsuite / lib / binutils-common.exp
1 # Copyright 1993, 1994, 1995, 1996, 1997, 2000, 2001, 2003, 2004, 2006, 2007,
2 # 2009, 2010 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
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 3 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., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 # True if the object format is known to be ELF.
22 #
23 proc is_elf_format {} {
24     if { ![istarget *-*-sysv4*]
25          && ![istarget *-*-unixware*]
26          && ![istarget *-*-elf*]
27          && ![istarget *-*-eabi*]
28          && ![istarget *-*-rtems*]
29          && ![istarget hppa*64*-*-hpux*]
30          && ![istarget ia64-*-hpux*]
31          && ![istarget *-*-linux*]
32          && ![istarget *-*-gnu*]
33          && ![istarget frv-*-uclinux*]
34          && ![istarget bfin-*-uclinux]
35          && ![istarget sh*-*-uclinux*]
36          && ![istarget *-*-irix5*]
37          && ![istarget *-*-irix6*]
38          && ![istarget *-*-netbsd*]
39          && ![istarget *-*-openbsd*]
40          && ![istarget *-*-solaris2*] } {
41         return 0
42     }
43
44     if { [istarget *-*-linux*aout*]
45          || [istarget *-*-linux*oldld*]
46          || [istarget h8500-*-rtems*]
47          || [istarget i960-*-rtems*]
48          || [istarget *-*-rtemscoff*] } {
49         return 0
50     }
51
52     if { ![istarget *-*-netbsdelf*]
53          && ([istarget *-*-netbsd*aout*]
54              || [istarget *-*-netbsdpe*]
55              || [istarget arm*-*-netbsd*]
56              || [istarget sparc-*-netbsd*]
57              || [istarget i*86-*-netbsd*]
58              || [istarget m68*-*-netbsd*]
59              || [istarget vax-*-netbsd*]
60              || [istarget ns32k-*-netbsd*]) } {
61         return 0
62     }
63
64     if { [istarget arm-*-openbsd*]
65          || [istarget i386-*-openbsd\[0-2\].*]
66          || [istarget i386-*-openbsd3.\[0-2\]]
67          || [istarget m68*-*-openbsd*]
68          || [istarget ns32k-*-openbsd*]
69          || [istarget sparc-*-openbsd\[0-2\].*]
70          || [istarget sparc-*-openbsd3.\[0-1\]]
71          || [istarget vax-*-openbsd*] } {
72         return 0
73     }
74
75     return 1
76 }
77
78 # True if the object format is known to be a.out.
79 #
80 proc is_aout_format {} {
81     if { [istarget *-*-netbsdelf]
82          || [istarget sparc64-*-netbsd*]
83          || [istarget sparc64-*-openbsd*] } {
84         return 0
85     }
86     if { [istarget *-*-*\[ab\]out*]
87          || [istarget *-*-linux*oldld*]
88          || [istarget *-*-bsd*]
89          || [istarget *-*-msdos*]
90          || [istarget arm-*-netbsd*]
91          || [istarget arm-*-openbsd*]
92          || [istarget arm-*-riscix*]
93          || [istarget i?86-*-freebsd\[12\]*]
94          || [istarget i?86-*-netbsd*]
95          || [istarget i?86-*-openbsd\[0-2\]*]
96          || [istarget i?86-*-openbsd3.\[0-2\]*]
97          || [istarget i?86-*-vsta]
98          || [istarget i?86-*-mach*]
99          || [istarget m68*-*-netbsd*]
100          || [istarget m68*-*-openbsd*]
101          || [istarget ns32k-*-*]
102          || [istarget pdp11-*-*]
103          || [istarget sparc*-*-sunos4*]
104          || [istarget sparc*-*-netbsd*]
105          || [istarget sparc*-*-openbsd\[0-2\]*]
106          || [istarget sparc*-*-openbsd3.\[0-1\]*]
107          || [istarget sparc*-fujitsu-none]
108          || [istarget vax-dec-ultrix*]
109          || [istarget vax-*-netbsd] } {
110         return 1
111     }
112     return 0
113 }
114
115 # True if the object format is known to be PE COFF.
116 #
117 proc is_pecoff_format {} {
118     if { ![istarget *-*-mingw*]
119          && ![istarget *-*-cygwin*]
120          && ![istarget *-*-cegcc*]
121          && ![istarget *-*-pe*] } {
122         return 0
123     }
124
125     return 1
126 }
127
128 # True if the object format is known to be 64-bit ELF.
129 #
130 proc is_elf64 { binary_file } {
131     global READELF
132     global READELFFLAGS
133
134     set readelf_size ""
135     catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
136
137     if ![string match "" $got] then {
138         return 0
139     }
140
141     if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
142            [file_contents readelf.out] nil readelf_size] } {
143         return 0
144     }
145
146     if { $readelf_size == "64" } {
147         return 1
148     }
149
150     return 0
151 }