1 # Expect script for various indirect symbol tests.
2 # Copyright (C) 2012-2017 Free Software Foundation, Inc.
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20 # Written by H.J. Lu (hongjiu.lu@intel.com)
23 # Exclude non-ELF targets.
29 # Skip target where -shared is not supported
31 if ![check_shared_lib_support] {
35 # Check if compiler works
36 if { [which $CC] == 0 } {
40 # Some bare-metal targets don't support shared libs or PIC.
41 if { ![run_host_cmd_yesno $CC "-shared -fPIC $srcdir/$subdir/dummy.c -o tmpdir/t.so"] } {
45 proc check_link_message { cmd string testname } {
48 catch "exec $cmd" exec_output
49 send_log "$exec_output\n"
50 verbose "$exec_output"
53 if [string match "*$str*" $exec_output] {
54 pass "$testname: $str"
56 fail "$testname: $str"
61 if { ![ld_compile $CC $srcdir/$subdir/indirect1a.c tmpdir/indirect1a.o]
62 || ![ld_compile $CC $srcdir/$subdir/indirect1b.c tmpdir/indirect1b.o]
63 || ![ld_compile "$CC -fPIC" $srcdir/$subdir/indirect2.c tmpdir/indirect2.o]
64 || ![ld_compile $CC $srcdir/$subdir/indirect3a.c tmpdir/indirect3a.o]
65 || ![ld_compile $CC $srcdir/$subdir/indirect3b.c tmpdir/indirect3b.o]
66 || ![ld_compile $CC $srcdir/$subdir/indirect4a.c tmpdir/indirect4a.o]
67 || ![ld_compile $CC $srcdir/$subdir/indirect4b.c tmpdir/indirect4b.o]
68 || ![ld_compile "$CC -O2 -fPIC -I../bfd" $srcdir/$subdir/pr18720a.c tmpdir/pr18720a.o]
69 || ![ld_compile $CC $srcdir/$subdir/pr18720b.c tmpdir/pr18720b.o]
70 || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553d.c tmpdir/pr19553d.o]
71 || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553c.c tmpdir/pr19553c.o]
72 || ![ld_compile "$CC -fPIC" $srcdir/$subdir/pr19553b.c tmpdir/pr19553b.o]
73 || ![ld_compile $CC $srcdir/$subdir/pr19553a.c tmpdir/pr19553a.o] } {
74 unresolved "Indirect symbol tests"
79 {"Build libindirect1c.so"
81 {indirect1c.c} {} "libindirect1c.so"}
82 {"Build libindirect3c.so"
84 {indirect3c.c} {} "libindirect3c.so"}
85 {"Build libindirect4c.so"
87 {indirect4c.c} {} "libindirect4c.so"}
88 {"Build libindirect5.so"
89 "-shared -Wl,--version-script=indirect5.map" "-fPIC"
90 {indirect5b.c} {} "libindirect5.so"}
91 {"Build libpr18720c.so"
93 {pr18720c.c} {} "libpr18720c.so"}
95 "-r -nostdlib tmpdir/pr18720b.o" ""
96 {dummy.c} {} "pr18720b1.o"}
98 "tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" ""
99 {check-ptr-eq.c} {{readelf {--dyn-syms} pr18720.rd}} "pr18720a"}
100 {"Build libpr19553b.so"
101 "-shared -Wl,--version-script=pr19553.map" "-fPIC"
102 {pr19553b.c} {} "libpr19553b.so"}
103 {"Build libpr19553c.so"
104 "-shared -Wl,--version-script=pr19553.map" "-fPIC"
105 {pr19553c.c} {} "libpr19553c.so"}
106 {"Build libpr19553d.so"
107 "-shared tmpdir/libpr19553c.so" "-fPIC"
108 {pr19553d.c} {} "libpr19553d.so"}
111 run_cc_link_tests $build_tests
115 set string ": final link failed: Bad value"
116 set string1 ": local symbol \`foo\' in tmpdir/indirect1b.o is referenced by DSO"
118 set testname "Indirect symbol 1a"
119 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/indirect1b.o tmpdir/libindirect1c.so"
120 check_link_message "$cmd" [list $string1 $string] "$testname"
122 set testname "Indirect symbol 1b"
123 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/libindirect1c.so tmpdir/indirect1b.o"
124 check_link_message "$cmd" [list $string1 $string] "$testname"
126 set string ": final link failed: Nonrepresentable section on output"
127 set string2 ": No symbol version section for versioned symbol \`foo@FOO\'"
128 set testname "Indirect symbol 2"
129 set cmd "$ld -shared -o tmpdir/indirect2.so tmpdir/indirect2.o"
130 check_link_message "$cmd" [list $string2 $string] "$testname"
132 global NOPIE_CFLAGS NOPIE_LDFLAGS
135 {"Run with libindirect3c.so 1"
136 "-Wl,--no-as-needed tmpdir/indirect3a.o tmpdir/indirect3b.o tmpdir/libindirect3c.so" ""
137 {dummy.c} "indirect3a" "indirect3.out"}
138 {"Run with libindirect3c.so 2"
139 "-Wl,--no-as-needed tmpdir/indirect3a.o tmpdir/libindirect3c.so tmpdir/indirect3b.o" ""
140 {dummy.c} "indirect3b" "indirect3.out"}
141 {"Run with libindirect3c.so 3"
142 "-Wl,--no-as-needed tmpdir/indirect3b.o tmpdir/libindirect3c.so tmpdir/indirect3a.o" ""
143 {dummy.c} "indirect3c" "indirect3.out"}
144 {"Run with libindirect3c.so 4"
145 "-Wl,--no-as-needed tmpdir/libindirect3c.so tmpdir/indirect3b.o tmpdir/indirect3a.o" ""
146 {dummy.c} "indirect3d" "indirect3.out"}
147 {"Run with libindirect4c.so 1"
148 "-Wl,--no-as-needed tmpdir/indirect4a.o tmpdir/indirect4b.o tmpdir/libindirect4c.so" ""
149 {dummy.c} "indirect4a" "indirect4.out"}
150 {"Run with libindirect4c.so 2"
151 "-Wl,--no-as-needed tmpdir/indirect4a.o tmpdir/libindirect4c.so tmpdir/indirect4b.o" ""
152 {dummy.c} "indirect4b" "indirect4.out"}
153 {"Run with libindirect4c.so 3"
154 "-Wl,--no-as-needed tmpdir/indirect4b.o tmpdir/libindirect4c.so tmpdir/indirect4a.o" ""
155 {dummy.c} "indirect4c" "indirect4.out"}
156 {"Run with libindirect4c.so 4"
157 "-Wl,--no-as-needed tmpdir/libindirect4c.so tmpdir/indirect4b.o tmpdir/indirect4a.o" ""
158 {dummy.c} "indirect4d" "indirect4.out"}
160 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libindirect5.so" ""
161 {indirect5a.c} "indirect5a" "indirect5.out" "$NOPIE_CFLAGS"}
163 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/indirect5a.o tmpdir/libindirect5.so" ""
164 {dummy.c} "indirect5b" "indirect5.out" "$NOPIE_CFLAGS"}
166 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libindirect5.so" ""
167 {indirect6a.c} "indirect6a" "indirect5.out" "$NOPIE_CFLAGS"}
169 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/indirect6a.o tmpdir/libindirect5.so" ""
170 {dummy.c} "indirect6b" "indirect5.out" "$NOPIE_CFLAGS"}
171 {"Run with libpr18720c.so 1"
172 "-Wl,--no-as-needed tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" ""
173 {check-ptr-eq.c} "pr18720a" "pr18720.out"}
174 {"Run with libpr18720c.so 2"
175 "-Wl,--no-as-needed tmpdir/pr18720a.o tmpdir/libpr18720c.so tmpdir/pr18720b.o" ""
176 {check-ptr-eq.c} "pr18720b" "pr18720.out"}
177 {"Run with libpr18720c.so 3"
178 "-Wl,--no-as-needed tmpdir/pr18720b.o tmpdir/libpr18720c.so tmpdir/pr18720a.o" ""
179 {check-ptr-eq.c} "pr18720c" "pr18720.out"}
180 {"Run with libpr18720c.so 4"
181 "-Wl,--no-as-needed tmpdir/libpr18720c.so tmpdir/pr18720b.o tmpdir/pr18720a.o" ""
182 {check-ptr-eq.c} "pr18720d" "pr18720.out"}
183 {"Run with libpr18720c.so 5"
184 "-Wl,--no-as-needed tmpdir/libpr18720c.so tmpdir/pr18720b1.o tmpdir/pr18720a.o" ""
185 {check-ptr-eq.c} "pr18720d" "pr18720.out"}
186 {"Run with libpr19553b.so"
187 "-Wl,--no-as-needed tmpdir/libpr19553b.so tmpdir/libpr19553d.so -Wl,-rpath-link,." ""
188 {pr19553a.c} "pr19553b" "pr19553b.out"}
189 {"Run with libpr19553c.so"
190 "-Wl,--no-as-needed tmpdir/libpr19553c.so tmpdir/libpr19553b.so tmpdir/libpr19553d.so" ""
191 {pr19553a.c} "pr19553c" "pr19553c.out"}
192 {"Run with libpr19553d.so"
193 "-Wl,--no-as-needed tmpdir/libpr19553d.so tmpdir/libpr19553b.so -Wl,-rpath-link,." ""
194 {pr19553a.c} "pr19553d" "pr19553d.out"}
197 run_ld_link_exec_tests $run_tests
199 # Check that "bar" is not dynamic in the executable
200 proc check_dynamic_syms { test } {
202 set cmd "$nm -D $test > dump.out"
204 catch "exec $cmd" comp_output
205 if ![string match "" $comp_output] then {
206 send_log "$comp_output\n"
209 if { [string match "* bar\n*" [file_contents "dump.out"]] } then {
210 verbose "output is [file_contents "dump.out"]"
216 foreach t [list indirect5a indirect5b indirect6a indirect6b] {
217 set testname [concat $t "dynsym"]
218 if { [check_dynamic_syms tmpdir/$t] } {
225 # PR ld/21402: i386 doesn't support mixing different symbol types in PIE.
226 if {[istarget "i?86-*-*"]} {
230 send_log "$CC -fPIE -pie $srcdir/$subdir/main.c -o tmpdir/pie"
231 catch "exec $CC -fPIE -pie $srcdir/$subdir/main.c -o tmpdir/pie" exec_output
232 send_log "$exec_output"
233 if { ! [string match "" $exec_output] } {
239 "-pie -Wl,--no-as-needed tmpdir/libindirect5.so" ""
240 {indirect5a.c} "indirect5c" "indirect5.out" "-fPIE"}
242 "-pie -Wl,--no-as-needed tmpdir/indirect5a.o tmpdir/libindirect5.so" ""
243 {dummy.c} "indirect5d" "indirect5.out" "-fPIE"}
245 "-pie -Wl,--no-as-needed tmpdir/libindirect5.so" ""
246 {indirect6a.c} "indirect6c" "indirect5.out" "-fPIE"}
248 "-pie -Wl,--no-as-needed tmpdir/indirect6a.o tmpdir/libindirect5.so" "-fPIE"
249 {dummy.c} "indirect6d" "indirect5.out" "-fPIE"}
252 run_ld_link_exec_tests $pie_tests
254 foreach t [list indirect5c indirect5d indirect6c indirect6d] {
255 set testname [concat $t "dynsym"]
256 if { [check_dynamic_syms tmpdir/$t] } {