4db5ec08328610ac8f03f28b1ced25705ce05397
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / binutils.exp
1 # Expect script for binutils tests
2 # Copyright (C) 2006-2018 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program 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 # Written by H.J. Lu (hongjiu.lu@intel.com)
22 #
23
24 # Make sure that binutils can correctly handle ld output in ELF.
25
26 if { ![istarget *-*-linux*]
27 && ![istarget *-*-nacl*]
28 && ![istarget *-*-gnu*]} {
29 return
30 }
31
32 # The optional test_name argument provides a mechanism for the caller
33 # to hardwire the test name. This is important if ld_options contains
34 # absolute path names because the default test name is constructed
35 # from the prog_name and ld_options and we do not want absolute paths
36 # to appear in the test_name. The optional readelf_options can be
37 # used to specify different options for readelf.
38 proc binutils_test { prog_name ld_options test {test_name ""} {readelf_options "-l"}} {
39 global as
40 global ld
41 global READELF
42 global objcopy
43 global strip
44 global srcdir
45 global subdir
46 global link_output
47
48 eval set prog \$$prog_name
49
50 if { "$test_name" == "" } {
51 set test_name "$prog_name $ld_options ($test)"
52 }
53
54 if { ![ld_assemble $as $srcdir/$subdir/$test.s tmpdir/$test.o ] } {
55 unresolved "$test_name"
56 return
57 }
58
59 if { ![ld_link $ld tmpdir/$test "$ld_options -z stack-size=0 tmpdir/$test.o"] } {
60 if { [string match "*not supported*" $link_output]
61 || [string match "*unrecognized option*" $link_output]
62 || [string match "*-z relro ignored*" $link_output] } {
63 unsupported "$ld_options is not supported by this target"
64 } else {
65 unresolved "$test_name"
66 }
67 return
68 }
69
70 send_log "$READELF $readelf_options --wide tmpdir/$test > tmpdir/$test.exp\n"
71 set got [remote_exec host "$READELF $readelf_options --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.exp"]
72 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
73 send_log "$got\n"
74 unresolved "$test_name"
75 return
76 }
77
78 if [string match "*-z relro*" $ld_options] {
79 # These targets set TEXT_DYNAMIC and therefore have `.dynamic'
80 # in the (read-only) text segment rather than data segment.
81 set relro_dynamic [expr !([istarget "hppa64*-*-*"] \
82 || ([istarget "mips*-*-*"] \
83 && ![istarget "*-*-vxworks*"]))]
84 # These targets have `.got' in regular data even though they do
85 # not have `.got' there.
86 set relro_gotplt [expr [istarget "mips*-*-*"]]
87 # These targets do not set NO_SMALL_DATA or DATA_GOT and therefore
88 # have `.got' in (read-write) small data rather than regular data.
89 set relro_got [expr !([istarget "alpha*-*-*"] \
90 || [istarget "hppa*-*-linux-*"] \
91 || [istarget "hppa*-*-netbsd*"] \
92 || [istarget "hppa*-*-openbsd*"] \
93 || [istarget "metag-*-*"] \
94 || [istarget "mips*-*-*"] \
95 || [istarget "nios2*-*-*"] \
96 || [istarget "or1k-*-*"] \
97 || [istarget "riscv*-*-*"] \
98 || [istarget "sh*-*-*"] \
99 || [istarget "x86_64-*-rdos*"])]
100 # Check if GNU_RELRO segment is generated.
101 set got [remote_exec host "grep GNU_RELRO tmpdir/$test.exp"]
102 if { ![string match "*GNU_RELRO*" $got] } then {
103 set got [remote_exec host "cat tmpdir/$test.exp"]
104 if { [string match "*.data.rel.ro*" $got]
105 || ($relro_dynamic && [string match "*.dynamic*" $got])
106 || ($relro_gotplt && [string match "*.got.plt*" $got])
107 || ($relro_got && [string match "*.got*" $got])
108 || [string match "*.eh_frame*" $got]
109 || [string match "*.gcc_except_table*" $got]
110 || [string match "*.exception_ranges*" $got]
111 || [string match "*.ctors*" $got]
112 || [string match "*.dtors*" $got]
113 || [string match "*.tdata*" $got]
114 || [string match "*.preinit_array*" $got]
115 || [string match "*.init_array*" $got]
116 || [string match "*.fini_array*" $got] } then {
117 # Fail if GNU_RELRO segment isn't generated, but should.
118 fail "$test_name"
119 return
120 }
121 }
122 }
123
124 send_log "$prog tmpdir/$test\n"
125 set got [remote_exec host "$prog tmpdir/$test"]
126 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
127 send_log "$got\n"
128 fail "$test_name"
129 return
130 }
131
132 send_log "$READELF $readelf_options --wide tmpdir/$test > tmpdir/$test.out\n"
133 set got [remote_exec host "$READELF $readelf_options --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
134 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
135 send_log "$got\n"
136 unresolved "$test_name"
137 return
138 }
139
140 if { [catch {exec cmp tmpdir/$test.exp tmpdir/$test.out}] } then {
141 send_log "tmpdir/$test.exp tmpdir/$test.out differ.\n"
142 fail "$test_name"
143 return
144 }
145
146 pass "$test_name"
147 }
148
149 binutils_test strip "-z max-page-size=0x200000" maxpage1
150 binutils_test strip "-z max-page-size=0x200000 -z common-page-size=0x100000" maxpage1
151 binutils_test strip "-z max-page-size=0x100000" maxpage1
152 binutils_test strip "-z max-page-size=0x100000 -z common-page-size=0x1000" maxpage1
153
154 binutils_test strip "" maxpage1
155 binutils_test strip "-shared" maxpage1
156 binutils_test objcopy "" maxpage1
157 binutils_test objcopy "-shared" maxpage1
158
159 binutils_test strip "-z relro" relro1
160 binutils_test strip "-z relro -shared" relro1
161 binutils_test objcopy "-z relro" relro1
162 binutils_test objcopy "-z relro -shared" relro1
163 if { ([istarget "i?86-*-elf*"]
164 || [istarget "i?86-*-linux*"]
165 || [istarget "i?86-*-gnu*"]
166 || [istarget "x86_64-*-linux*"]
167 || [istarget "amd64-*-linux*"]
168 || [istarget "i?86-*nacl*"]
169 || [istarget "x86_64-*nacl*"]) } {
170 binutils_test strip "-z relro -shared" relro2
171 binutils_test objcopy "-z relro -shared" relro2
172 }
173
174 binutils_test strip "-T ${srcdir}/${subdir}/lma.lnk" lma "strip -T lma.lnk"
175
176 set tls_tests { "tdata1" "tdata2" }
177 # hppa64 has its own .tbss section, with different flags.
178 if { ![istarget "hppa64-*-*"] } {
179 lappend tls_tests "tdata3" "tbss1" "tbss2" "tbss3"
180 }
181 set tls_opts {
182 "-z noseparate-code"
183 "-z separate-code"
184 "-z relro"
185 "-shared -z noseparate-code"
186 "-shared -z separate-code"
187 "-shared -z relro"
188 "-z max-page-size=0x100000"
189 "-z max-page-size=0x100000 -z common-page-size=0x1000"
190 }
191
192 foreach testitem $tls_tests {
193 foreach testopt $tls_opts {
194 binutils_test objcopy $testopt $testitem
195 }
196 }
197
198 binutils_test strip "-s" gap "" "-lS"
This page took 0.042003 seconds and 3 git commands to generate.