ld: better handling of lma region for orphan sections
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / indirect.exp
1 # Expect script for various indirect symbol tests.
2 # Copyright (C) 2012-2017 Free Software Foundation, Inc.
3 #
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.
8 #
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.
13 #
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.
17 #
18
19 #
20 # Written by H.J. Lu (hongjiu.lu@intel.com)
21 #
22
23 # Exclude non-ELF targets.
24
25 if ![is_elf_format] {
26 return
27 }
28
29 # Skip target where -shared is not supported
30
31 if ![check_shared_lib_support] {
32 return
33 }
34
35 # Check if compiler works
36 if { [which $CC] == 0 } {
37 return
38 }
39
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"] } {
42 return
43 }
44
45 proc check_link_message { cmd string testname } {
46 send_log "$cmd\n"
47 verbose "$cmd"
48 catch "exec $cmd" exec_output
49 send_log "$exec_output\n"
50 verbose "$exec_output"
51
52 foreach str $string {
53 if [string match "*$str*" $exec_output] {
54 pass "$testname: $str"
55 } else {
56 fail "$testname: $str"
57 }
58 }
59 }
60
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"
75 return
76 }
77
78 set build_tests {
79 {"Build libindirect1c.so"
80 "-shared" "-fPIC"
81 {indirect1c.c} {} "libindirect1c.so"}
82 {"Build libindirect3c.so"
83 "-shared" "-fPIC"
84 {indirect3c.c} {} "libindirect3c.so"}
85 {"Build libindirect4c.so"
86 "-shared" "-fPIC"
87 {indirect4c.c} {} "libindirect4c.so"}
88 {"Build libpr18720c.so"
89 "-shared" "-fPIC"
90 {pr18720c.c} {} "libpr18720c.so"}
91 {"Build pr18720b1.o"
92 "-r -nostdlib tmpdir/pr18720b.o" ""
93 {dummy.c} {} "pr18720b1.o"}
94 {"Build pr18720a"
95 "tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" ""
96 {check-ptr-eq.c} {{readelf {--dyn-syms} pr18720.rd}} "pr18720a"}
97 {"Build libpr19553b.so"
98 "-shared -Wl,--version-script=pr19553.map" "-fPIC"
99 {pr19553b.c} {} "libpr19553b.so"}
100 {"Build libpr19553c.so"
101 "-shared -Wl,--version-script=pr19553.map" "-fPIC"
102 {pr19553c.c} {} "libpr19553c.so"}
103 {"Build libpr19553d.so"
104 "-shared tmpdir/libpr19553c.so" "-fPIC"
105 {pr19553d.c} {} "libpr19553d.so"}
106 }
107
108 run_cc_link_tests $build_tests
109
110 global ld
111
112 set string ": final link failed: Bad value"
113 set string1 ": local symbol \`foo\' in tmpdir/indirect1b.o is referenced by DSO"
114
115 set testname "Indirect symbol 1a"
116 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/indirect1b.o tmpdir/libindirect1c.so"
117 check_link_message "$cmd" [list $string1 $string] "$testname"
118
119 set testname "Indirect symbol 1b"
120 set cmd "$ld -e start -o tmpdir/indirect1 tmpdir/indirect1a.o tmpdir/libindirect1c.so tmpdir/indirect1b.o"
121 check_link_message "$cmd" [list $string1 $string] "$testname"
122
123 set string ": final link failed: Nonrepresentable section on output"
124 set string2 ": No symbol version section for versioned symbol \`foo@FOO\'"
125 set testname "Indirect symbol 2"
126 set cmd "$ld -shared -o tmpdir/indirect2.so tmpdir/indirect2.o"
127 check_link_message "$cmd" [list $string2 $string] "$testname"
128
129 set run_tests {
130 {"Run with libindirect3c.so 1"
131 "-Wl,--no-as-needed tmpdir/indirect3a.o tmpdir/indirect3b.o tmpdir/libindirect3c.so" ""
132 {dummy.c} "indirect3a" "indirect3.out"}
133 {"Run with libindirect3c.so 2"
134 "-Wl,--no-as-needed tmpdir/indirect3a.o tmpdir/libindirect3c.so tmpdir/indirect3b.o" ""
135 {dummy.c} "indirect3b" "indirect3.out"}
136 {"Run with libindirect3c.so 3"
137 "-Wl,--no-as-needed tmpdir/indirect3b.o tmpdir/libindirect3c.so tmpdir/indirect3a.o" ""
138 {dummy.c} "indirect3c" "indirect3.out"}
139 {"Run with libindirect3c.so 4"
140 "-Wl,--no-as-needed tmpdir/libindirect3c.so tmpdir/indirect3b.o tmpdir/indirect3a.o" ""
141 {dummy.c} "indirect3d" "indirect3.out"}
142 {"Run with libindirect4c.so 1"
143 "-Wl,--no-as-needed tmpdir/indirect4a.o tmpdir/indirect4b.o tmpdir/libindirect4c.so" ""
144 {dummy.c} "indirect4a" "indirect4.out"}
145 {"Run with libindirect4c.so 2"
146 "-Wl,--no-as-needed tmpdir/indirect4a.o tmpdir/libindirect4c.so tmpdir/indirect4b.o" ""
147 {dummy.c} "indirect4b" "indirect4.out"}
148 {"Run with libindirect4c.so 3"
149 "-Wl,--no-as-needed tmpdir/indirect4b.o tmpdir/libindirect4c.so tmpdir/indirect4a.o" ""
150 {dummy.c} "indirect4c" "indirect4.out"}
151 {"Run with libindirect4c.so 4"
152 "-Wl,--no-as-needed tmpdir/libindirect4c.so tmpdir/indirect4b.o tmpdir/indirect4a.o" ""
153 {dummy.c} "indirect4d" "indirect4.out"}
154 {"Run with libpr18720c.so 1"
155 "-Wl,--no-as-needed tmpdir/pr18720a.o tmpdir/pr18720b.o tmpdir/libpr18720c.so" ""
156 {check-ptr-eq.c} "pr18720a" "pr18720.out"}
157 {"Run with libpr18720c.so 2"
158 "-Wl,--no-as-needed tmpdir/pr18720a.o tmpdir/libpr18720c.so tmpdir/pr18720b.o" ""
159 {check-ptr-eq.c} "pr18720b" "pr18720.out"}
160 {"Run with libpr18720c.so 3"
161 "-Wl,--no-as-needed tmpdir/pr18720b.o tmpdir/libpr18720c.so tmpdir/pr18720a.o" ""
162 {check-ptr-eq.c} "pr18720c" "pr18720.out"}
163 {"Run with libpr18720c.so 4"
164 "-Wl,--no-as-needed tmpdir/libpr18720c.so tmpdir/pr18720b.o tmpdir/pr18720a.o" ""
165 {check-ptr-eq.c} "pr18720d" "pr18720.out"}
166 {"Run with libpr18720c.so 5"
167 "-Wl,--no-as-needed tmpdir/libpr18720c.so tmpdir/pr18720b1.o tmpdir/pr18720a.o" ""
168 {check-ptr-eq.c} "pr18720d" "pr18720.out"}
169 {"Run with libpr19553b.so"
170 "-Wl,--no-as-needed tmpdir/libpr19553b.so tmpdir/libpr19553d.so -Wl,-rpath-link,." ""
171 {pr19553a.c} "pr19553b" "pr19553b.out"}
172 {"Run with libpr19553c.so"
173 "-Wl,--no-as-needed tmpdir/libpr19553c.so tmpdir/libpr19553b.so tmpdir/libpr19553d.so" ""
174 {pr19553a.c} "pr19553c" "pr19553c.out"}
175 {"Run with libpr19553d.so"
176 "-Wl,--no-as-needed tmpdir/libpr19553d.so tmpdir/libpr19553b.so -Wl,-rpath-link,." ""
177 {pr19553a.c} "pr19553d" "pr19553d.out"}
178 }
179
180 run_ld_link_exec_tests $run_tests
This page took 0.033665 seconds and 4 git commands to generate.