Commit | Line | Data |
---|---|---|
b811d2c2 | 1 | # Copyright 2010-2020 Free Software Foundation, Inc. |
b8040f19 JK |
2 | |
3 | # This program is free software; you can redistribute it and/or modify | |
4 | # it under the terms of the GNU General Public License as published by | |
5 | # the Free Software Foundation; either version 3 of the License, or | |
6 | # (at your option) any later version. | |
7 | # | |
8 | # This program is distributed in the hope that it will be useful, | |
9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | # GNU General Public License for more details. | |
12 | # | |
13 | # You should have received a copy of the GNU General Public License | |
14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
15 | ||
16 | # This test only works on GNU/Linux. | |
079670b9 | 17 | if { ![isnative] || [is_remote host] || [use_gdb_stub] |
3a3dad98 | 18 | || ![istarget *-linux*] || [skip_shlib_tests]} { |
b8040f19 JK |
19 | continue |
20 | } | |
21 | ||
5e3b36f8 JK |
22 | load_lib prelink-support.exp |
23 | ||
b8040f19 | 24 | set test "break-interp" |
a64d2530 | 25 | set binprefix [standard_output_file ${test}] |
b8040f19 JK |
26 | # Only to get the $interp_system name. |
27 | set srcfile_test "start.c" | |
28 | set binfile_test ${test}-test | |
a64d2530 | 29 | set binfile_lib ${binprefix}.so |
06a6f270 JK |
30 | set srcfile "${test}-main.c" |
31 | set srcfile_lib "${test}-lib.c" | |
32 | ||
4c93b1db | 33 | if [get_compiler_info] { |
06a6f270 JK |
34 | return -1 |
35 | } | |
36 | ||
5e3b36f8 | 37 | # Use -soname so that the new library gets copied by build_executable_own_libs. |
06a6f270 | 38 | |
d8b34041 | 39 | if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug ldflags=-Wl,-soname,${test}.so]] != ""} { |
06a6f270 JK |
40 | return -1 |
41 | } | |
42 | ||
b8040f19 JK |
43 | if {[build_executable ${test}.exp $binfile_test ${srcfile_test} {}] == -1} { |
44 | return -1 | |
45 | } | |
46 | ||
b8040f19 JK |
47 | # Note: The separate debug info file content build-id/crc32 are not verified |
48 | # contrary to the GDB search algorithm skipping non-matching ones. | |
49 | proc system_debug_get {exec} { | |
50 | global debug_root | |
51 | ||
52 | set exec_build_id_debug [build_id_debug_filename_get $exec] | |
53 | set debug_base "[file tail $exec].debug" | |
54 | set exec_dir [file dirname $exec] | |
55 | ||
56 | # isfile returns 1 even for symlinks to files. | |
57 | set retval $debug_root/$exec_build_id_debug | |
58 | if [file isfile $retval] { | |
59 | return $retval | |
60 | } | |
61 | set retval $exec_dir/$debug_base | |
62 | if [file isfile $retval] { | |
63 | return $retval | |
64 | } | |
65 | set retval $exec_dir/.debug/$debug_base | |
66 | if [file isfile $retval] { | |
67 | return $retval | |
68 | } | |
69 | set retval $debug_root/$exec_dir/$debug_base | |
70 | if [file isfile $retval] { | |
71 | return $retval | |
72 | } | |
73 | return "" | |
74 | } | |
75 | ||
76 | gdb_exit | |
77 | gdb_start | |
78 | set debug_root "" | |
79 | set test "show debug-file-directory" | |
80 | gdb_test_multiple $test $test { | |
81 | -re "The directory where separate debug symbols are searched for is \"(.*)\".\r\n$gdb_prompt $" { | |
82 | set debug_root $expect_out(1,string) | |
83 | } | |
84 | } | |
85 | ||
a64d2530 | 86 | set interp_system [section_get [standard_output_file $binfile_test] .interp] |
b8040f19 JK |
87 | set interp_system_debug [system_debug_get $interp_system] |
88 | verbose -log "$interp_system has debug $interp_system_debug" | |
89 | ||
5e3b36f8 JK |
90 | proc prelinkNO {arg {name ""}} { |
91 | return [prelink_no $arg $name] | |
b8040f19 JK |
92 | } |
93 | ||
94 | proc prelinkYES {arg {name ""}} { | |
5e3b36f8 | 95 | return [prelink_yes $arg $name] |
b8040f19 JK |
96 | } |
97 | ||
98 | proc strip_debug {dest} { | |
99 | set test "strip [file tail $dest]" | |
100 | set strip_program [transform strip] | |
101 | set command "exec $strip_program --strip-debug $dest" | |
102 | verbose -log "command is $command" | |
103 | if [catch $command] { | |
104 | fail $test | |
105 | return 0 | |
106 | } else { | |
107 | pass $test | |
108 | return 1 | |
109 | } | |
110 | } | |
111 | ||
a29a3fb7 GB |
112 | # The marker function for the standard runtime linker interface is |
113 | # _dl_debug_state. The probes-based interface has no specific marker | |
114 | # function; the probe we will stop on (init_start) is in dl_main so we | |
115 | # check for that. | |
116 | ||
117 | set solib_bp {(_dl_debug_state|dl_main)} | |
118 | ||
d3d7896d JK |
119 | # Implementation of reach. |
120 | ||
121 | proc reach_1 {func command displacement} { | |
a29a3fb7 | 122 | global gdb_prompt expect_out solib_bp |
ccf26247 | 123 | |
a29a3fb7 | 124 | if {$func == $solib_bp} { |
d3d7896d JK |
125 | # Breakpoint on _dl_debug_state can have problems due to its overlap |
126 | # with the existing internal breakpoint from GDB. | |
127 | gdb_test_no_output "set stop-on-solib-events 1" | |
128 | } elseif {! [gdb_breakpoint $func allow-pending]} { | |
129 | return | |
130 | } | |
b8040f19 | 131 | |
d3d7896d JK |
132 | set test "reach" |
133 | set test_displacement "seen displacement message as $displacement" | |
134 | set debug_state_count 0 | |
135 | gdb_test_multiple $command $test { | |
136 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
137 | # Missing "$gdb_prompt $" is intentional. | |
138 | if {$expect_out(1,string) == "0x0"} { | |
139 | set case "ZERO" | |
140 | } else { | |
141 | set case "NONZERO" | |
ccf26247 | 142 | } |
d3d7896d JK |
143 | if {$displacement == $case || $displacement == "PRESENT"} { |
144 | pass $test_displacement | |
145 | set displacement "FOUND-$displacement" | |
146 | } else { | |
147 | fail $test_displacement | |
148 | } | |
149 | exp_continue | |
150 | } | |
900e11f9 | 151 | -re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" { |
a29a3fb7 | 152 | if {$func == $solib_bp} { |
d3d7896d JK |
153 | fail $test |
154 | } else { | |
b8040f19 JK |
155 | pass $test |
156 | } | |
d3d7896d | 157 | } |
900e11f9 | 158 | -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" { |
a29a3fb7 | 159 | if {$func == $solib_bp} { |
d3d7896d JK |
160 | fail $test |
161 | } else { | |
b8040f19 JK |
162 | pass $test |
163 | } | |
164 | } | |
edcc5120 | 165 | -re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" { |
a29a3fb7 | 166 | if {$func == $solib_bp} { |
d3d7896d JK |
167 | if {$debug_state_count == 0} { |
168 | # First stop does not yet relocate the _start function | |
169 | # descriptor on ppc64. | |
170 | set debug_state_count 1 | |
171 | send_gdb "continue\n" | |
172 | exp_continue | |
173 | } else { | |
174 | pass $test | |
175 | } | |
176 | } else { | |
177 | fail $test | |
178 | } | |
ccf26247 | 179 | } |
b8040f19 | 180 | } |
d3d7896d JK |
181 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
182 | fail $test_displacement | |
183 | } | |
184 | ||
a29a3fb7 | 185 | if {$func == $solib_bp} { |
d3d7896d JK |
186 | gdb_test_no_output "set stop-on-solib-events 0" |
187 | } | |
188 | } | |
189 | ||
190 | # `runto' does not check we stopped really at the function we specified. | |
191 | # DISPLACEMENT can be "NONE" for no message to be present, "ZERO" for | |
192 | # displacement of 0 bytes to be present, "NONZERO" for displacement of non-0 | |
193 | # bytes to be present and "PRESENT" if both "ZERO" and "NONZERO" are valid. | |
2b74ba5a AB |
194 | # |
195 | # The optional ITERATION parameter is used in order to make unique | |
196 | # test prefixes, when calling this proc with the same FUNC name | |
197 | # provide a unique ITERATION value for each call. | |
198 | proc reach {func command displacement {iteration 1}} { | |
199 | set prefix "reach-$func" | |
200 | if { $iteration > 1 } { | |
201 | set prefix "$prefix-$iteration" | |
202 | } | |
203 | with_test_prefix $prefix { | |
6a5870ce PA |
204 | reach_1 $func $command $displacement |
205 | } | |
b8040f19 JK |
206 | } |
207 | ||
0a251e08 YQ |
208 | proc test_core {file displacement} { |
209 | with_test_prefix "core" { | |
210 | global srcdir subdir gdb_prompt expect_out | |
61f0d762 | 211 | |
0a251e08 YQ |
212 | set corefile [core_find $file {} "segv"] |
213 | if {$corefile == ""} { | |
214 | return | |
215 | } | |
ccf26247 | 216 | |
0a251e08 YQ |
217 | gdb_exit |
218 | gdb_start | |
219 | # Clear it to never find any separate debug infos in $debug_root. | |
220 | gdb_test_no_output "set debug-file-directory" \ | |
221 | "set debug-file-directory for core" | |
222 | gdb_reinitialize_dir $srcdir/$subdir | |
223 | gdb_load $file | |
224 | ||
225 | # Print the "PIE (Position Independent Executable) displacement" message. | |
226 | gdb_test_no_output "set verbose on" | |
227 | ||
228 | set test "core loaded" | |
229 | set test_displacement "seen displacement message as $displacement" | |
230 | gdb_test_multiple "core-file $corefile" $test { | |
231 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
232 | # Missing "$gdb_prompt $" is intentional. | |
233 | if {$expect_out(1,string) == "0x0"} { | |
234 | set case "ZERO" | |
235 | } else { | |
236 | set case "NONZERO" | |
237 | } | |
238 | if {$displacement == $case || $displacement == "PRESENT"} { | |
239 | pass $test_displacement | |
240 | set displacement "FOUND-$displacement" | |
241 | } else { | |
242 | fail $test_displacement | |
243 | } | |
244 | exp_continue | |
ccf26247 | 245 | } |
0a251e08 YQ |
246 | -re "Core was generated by .*\r\n#0 .*$gdb_prompt $" { |
247 | # Do not check the binary filename as it may be truncated. | |
248 | pass $test | |
ccf26247 | 249 | } |
ccf26247 | 250 | } |
0a251e08 YQ |
251 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
252 | fail $test_displacement | |
ccf26247 | 253 | } |
0a251e08 YQ |
254 | |
255 | gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt" | |
ccf26247 | 256 | } |
0a251e08 | 257 | } |
61f0d762 | 258 | |
0a251e08 YQ |
259 | proc test_attach_gdb {file pid displacement prefix} { |
260 | with_test_prefix "$prefix" { | |
261 | global gdb_prompt expect_out | |
ccf26247 | 262 | |
0a251e08 YQ |
263 | gdb_exit |
264 | gdb_start | |
bbfba9ed | 265 | |
0a251e08 YQ |
266 | # Print the "PIE (Position Independent Executable) displacement" message. |
267 | gdb_test_no_output "set verbose on" | |
ccf26247 | 268 | |
3453e7e4 | 269 | gdb_test "file $file" "Reading symbols from .*" "file" |
ccf26247 | 270 | |
0a251e08 YQ |
271 | set test "attach" |
272 | gdb_test_multiple "attach $pid" $test { | |
273 | -re "Attaching to (program: .*, )?process $pid\r\n" { | |
274 | # Missing "$gdb_prompt $" is intentional. | |
275 | pass $test | |
276 | } | |
ccf26247 | 277 | } |
ccf26247 | 278 | |
0a251e08 YQ |
279 | set test "attach final prompt" |
280 | set test_displacement "seen displacement message as $displacement" | |
281 | gdb_test_multiple "" $test { | |
282 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
283 | # Missing "$gdb_prompt $" is intentional. | |
284 | if {$expect_out(1,string) == "0x0"} { | |
285 | set case "ZERO" | |
286 | } else { | |
287 | set case "NONZERO" | |
288 | } | |
289 | if {$displacement == $case || $displacement == "PRESENT"} { | |
290 | pass $test_displacement | |
291 | set displacement "FOUND-$displacement" | |
292 | } else { | |
293 | fail $test_displacement | |
294 | } | |
295 | exp_continue | |
ccf26247 | 296 | } |
0a251e08 YQ |
297 | -re "$gdb_prompt $" { |
298 | pass $test | |
ccf26247 | 299 | } |
ccf26247 | 300 | } |
0a251e08 YQ |
301 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
302 | fail $test_displacement | |
ccf26247 | 303 | } |
ccf26247 | 304 | |
0a251e08 YQ |
305 | gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "attach main bt" |
306 | gdb_exit | |
307 | } | |
308 | } | |
bbfba9ed | 309 | |
0a1e94c7 JK |
310 | proc test_attach {file displacement {relink_args ""}} { |
311 | global board_info | |
4a2d9c08 | 312 | global exec |
0a1e94c7 JK |
313 | |
314 | gdb_exit | |
315 | ||
316 | set test "sleep function started" | |
317 | ||
318 | set command "${file} sleep" | |
2c8c5d37 PA |
319 | set test_spawn_id [remote_spawn host $command] |
320 | if { $test_spawn_id < 0 || $test_spawn_id == "" } { | |
0a1e94c7 JK |
321 | perror "Spawning $command failed." |
322 | fail $test | |
323 | return | |
324 | } | |
2c8c5d37 | 325 | set pid [spawn_id_get_pid $test_spawn_id] |
0a1e94c7 JK |
326 | gdb_expect { |
327 | -re "sleeping\r\n" { | |
328 | pass $test | |
329 | } | |
330 | eof { | |
331 | fail "$test (eof)" | |
2c8c5d37 | 332 | wait -i $test_spawn_id |
0a1e94c7 JK |
333 | return |
334 | } | |
335 | timeout { | |
336 | fail "$test (timeout)" | |
2c8c5d37 | 337 | kill_wait_spawned_process $test_spawn_id |
0a1e94c7 JK |
338 | return |
339 | } | |
340 | } | |
341 | ||
342 | if {$relink_args == ""} { | |
4a2d9c08 | 343 | test_attach_gdb $exec $pid $displacement "attach" |
0a1e94c7 JK |
344 | } else { |
345 | # These could be rather passed as arguments. | |
4a2d9c08 | 346 | global interp_saved interp |
0a1e94c7 JK |
347 | |
348 | foreach relink {YES NO} { | |
3cd07d20 JK |
349 | # Formerly this test was testing only prelinking of $EXEC. As the |
350 | # prelink command automatically prelinks all of $EXEC's libraries, | |
351 | # even $INTERP got prelinked. Therefore, we formerly had to | |
5e3b36f8 JK |
352 | # `[file_copy $interp_saved $interp]' to make $INTERP not affected |
353 | # by this prelinking of $EXEC. | |
3cd07d20 JK |
354 | # |
355 | # But now we need to test even prelinking of $INTERP. We could | |
356 | # create a separate test to test just the $INTERP prelinking. For | |
357 | # test simplicity, we merged this test and the test above by not | |
358 | # restoring $INTERP after $EXEC prelink. $INTERP gets restored | |
359 | # later below. | |
02835898 JK |
360 | # |
361 | # `(wrong library or version mismatch?)' messages are printed for | |
362 | # $binfile_lib on platforms converting REL->RELA relocations by | |
363 | # prelink (such as on i386). There is no reliable way to verify | |
364 | # the library file matches the running library in such case but | |
365 | # GDB at least attempts to set the right displacement. We test | |
366 | # `libfunc' is present in the backtrace and therefore the | |
367 | # displacement has been guessed right. | |
3cd07d20 JK |
368 | |
369 | if [prelink$relink $relink_args [file tail $exec]] { | |
0a1e94c7 JK |
370 | # /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)". |
371 | test_attach_gdb $exec $pid $displacement "attach-relink$relink" | |
372 | } | |
373 | } | |
5e3b36f8 | 374 | file_copy $interp_saved $interp |
0a1e94c7 JK |
375 | } |
376 | ||
2c8c5d37 | 377 | kill_wait_spawned_process $test_spawn_id |
0a1e94c7 JK |
378 | } |
379 | ||
ccf26247 | 380 | proc test_ld {file ifmain trynosym displacement} { |
a29a3fb7 | 381 | global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp |
b8040f19 JK |
382 | |
383 | # First test normal `file'-command loaded $FILE with symbols. | |
384 | ||
385 | gdb_exit | |
386 | gdb_start | |
387 | # Clear it to never find any separate debug infos in $debug_root. | |
27d3a1a2 | 388 | gdb_test_no_output "set debug-file-directory" |
b8040f19 JK |
389 | gdb_reinitialize_dir $srcdir/$subdir |
390 | gdb_load $file | |
391 | ||
ccf26247 | 392 | # Print the "PIE (Position Independent Executable) displacement" message. |
27d3a1a2 | 393 | gdb_test_no_output "set verbose on" |
ccf26247 | 394 | |
4e5799b6 JK |
395 | # We want to test the re-run of a PIE in the case where the executable |
396 | # is loaded with a different displacement, but disable-randomization | |
397 | # prevents that from happening. So turn it off. | |
398 | gdb_test "set disable-randomization off" | |
399 | ||
d3d7896d JK |
400 | if $ifmain { |
401 | gdb_test_no_output "set args segv" | |
402 | } else { | |
a64d2530 | 403 | global binfile_test |
d3d7896d JK |
404 | |
405 | # ld.so needs some executable to run to reach _dl_debug_state. | |
a64d2530 TT |
406 | gdb_test_no_output "set args [standard_output_file $binfile_test]" \ |
407 | "set args OBJDIR/${subdir}/$binfile_test" | |
d3d7896d JK |
408 | } |
409 | ||
2b74ba5a | 410 | reach $solib_bp "run" $displacement 1 |
06a6f270 | 411 | |
a29a3fb7 | 412 | gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" "dl bt" |
06a6f270 | 413 | |
b8040f19 | 414 | if $ifmain { |
86e4bafc | 415 | reach "main" continue "NONE" |
06a6f270 | 416 | |
ccf26247 | 417 | reach "libfunc" continue "NONE" |
06a6f270 JK |
418 | |
419 | gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt" | |
4e5799b6 | 420 | } |
61f0d762 | 421 | |
4e5799b6 JK |
422 | # Try re-run if the new PIE displacement takes effect. |
423 | gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y" | |
2b74ba5a | 424 | reach $solib_bp "run" $displacement 2 |
4e5799b6 JK |
425 | |
426 | if $ifmain { | |
ccf26247 | 427 | test_core $file $displacement |
bbfba9ed | 428 | |
ccf26247 | 429 | test_attach $file $displacement |
b8040f19 | 430 | } |
51bee8e9 JK |
431 | |
432 | if !$trynosym { | |
433 | return | |
434 | } | |
435 | ||
11337c2f PA |
436 | with_test_prefix "symbol-less" { |
437 | # Test also `exec-file'-command loaded $FILE - therefore | |
438 | # without symbols. SYMBOL_OBJFILE is not available and only | |
439 | # EXEC_BFD must be used. | |
440 | ||
441 | gdb_exit | |
442 | gdb_start | |
443 | # Clear it to never find any separate debug infos in $debug_root. | |
444 | gdb_test_no_output "set debug-file-directory" | |
445 | gdb_reinitialize_dir $srcdir/$subdir | |
446 | ||
447 | # Print the "PIE (Position Independent Executable) | |
448 | # displacement" message. | |
449 | gdb_test_no_output "set verbose on" | |
450 | ||
451 | # Test no (error) message has been printed by `exec-file'. | |
452 | set escapedfile [string_to_regexp $file] | |
453 | gdb_test "exec-file $file" "exec-file $escapedfile" "load" | |
454 | ||
455 | if $ifmain { | |
2b74ba5a | 456 | reach $solib_bp run $displacement 3 |
11337c2f PA |
457 | |
458 | # Use two separate gdb_test_multiple statements to avoid timeouts due | |
459 | # to slow processing of wildcard capturing long output | |
460 | set test "info files" | |
461 | set entrynohex "" | |
117eb594 TV |
462 | set info_line [join [list \ |
463 | "\r\n" "\[\t\]" "0x\[0-9af\]+" " - " \ | |
464 | "0x\[0-9af\]+" " @ " "0x\[0-9af\]+" \ | |
465 | " is " "\[^\r\n\]+"] ""] | |
11337c2f PA |
466 | gdb_test_multiple $test $test { |
467 | -re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n" { | |
468 | set entrynohex $expect_out(1,string) | |
469 | gdb_test_multiple "" $test { | |
470 | -re "\r\n$gdb_prompt $" { | |
471 | pass $test | |
472 | } | |
117eb594 TV |
473 | -re $info_line { |
474 | # Avoid timeout with check-read1 | |
475 | exp_continue | |
476 | } | |
93c17e06 | 477 | } |
e0cc584e | 478 | } |
51bee8e9 | 479 | } |
e0cc584e | 480 | |
11337c2f PA |
481 | # `info sym' cannot be tested for .opd as the binary may not have |
482 | # symbols. | |
483 | if {[istarget powerpc64-*] && [is_lp64_target]} { | |
484 | set test "convert entry point" | |
485 | gdb_test_multiple "p *(void(*)(void) *) 0x$entrynohex" $test { | |
486 | -re " =( \\(\[^0-9\]*\\))? 0x(\[0-9a-f\]+)( < \[^\r\n\]*)?\r\n$gdb_prompt $" { | |
487 | set entrynohex $expect_out(2,string) | |
488 | pass $test | |
489 | } | |
4569eed2 JK |
490 | } |
491 | } | |
11337c2f PA |
492 | if {$entrynohex != ""} { |
493 | gdb_test "break *0x$entrynohex" "" "break at entry point" | |
494 | gdb_test "continue" "\r\nBreakpoint \[0-9\]+, 0x0*$entrynohex in .*" "entry point reached" | |
495 | } | |
496 | } else { | |
497 | # There is no symbol to break at ld.so. Moreover it can | |
498 | # exit with an error code. | |
499 | ||
500 | set test "ld.so exit" | |
501 | set test_displacement "seen displacement message as $displacement" | |
502 | gdb_test_multiple "run" $test { | |
503 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
504 | # Missing "$gdb_prompt $" is intentional. | |
505 | if {$expect_out(1,string) == "0x0"} { | |
506 | set case "ZERO" | |
507 | } else { | |
508 | set case "NONZERO" | |
509 | } | |
510 | if {$displacement == $case || $displacement == "PRESENT"} { | |
511 | pass $test_displacement | |
512 | set displacement "FOUND-$displacement" | |
513 | } else { | |
514 | fail $test_displacement | |
515 | } | |
516 | exp_continue | |
ccf26247 | 517 | } |
11337c2f PA |
518 | -re "$inferior_exited_re (normally|with code \[0-9\]+).\r\n$gdb_prompt $" { |
519 | # Do not check the binary filename as it may be truncated. | |
520 | pass $test | |
ccf26247 | 521 | } |
ccf26247 | 522 | } |
11337c2f PA |
523 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
524 | fail $test_displacement | |
ccf26247 JK |
525 | } |
526 | } | |
51bee8e9 | 527 | } |
b8040f19 JK |
528 | } |
529 | ||
530 | # Create separate binaries for each testcase - to make the possible reported | |
531 | # problem reproducible after the whole test run finishes. | |
532 | ||
b8040f19 JK |
533 | foreach ldprelink {NO YES} { |
534 | foreach ldsepdebug {NO IN SEP} { | |
535 | # Skip running the ldsepdebug test if we do not have system separate | |
536 | # debug info available. | |
537 | if {$interp_system_debug == "" && $ldsepdebug == "SEP"} { | |
538 | continue | |
539 | } | |
540 | ||
541 | set ldname "LDprelink${ldprelink}debug${ldsepdebug}" | |
542 | set interp $binprefix-$ldname | |
543 | ||
544 | # prelink needs to always prelink all the dependencies to do any file | |
545 | # modifications of its files. ld.so also needs all the dependencies to | |
546 | # be prelinked to omit the relocation process. In-memory file offsets | |
547 | # are not dependent whether ld.so went the prelink way or through the | |
548 | # relocation process. | |
549 | # | |
550 | # For GDB we are not interested whether prelink succeeds as it is | |
551 | # transparent to GDB. GDB is being tested for differences of file | |
552 | # offsets vs. in-memory offsets. So we have to prelink even ld.so for | |
553 | # the BIN modification to happen but we need to restore the original | |
554 | # possibly unprelinked ld.so to test all the combinations for GDB. | |
555 | set interp_saved ${interp}-saved | |
556 | ||
11337c2f PA |
557 | with_test_prefix "$ldname" { |
558 | if {$ldsepdebug == "NO"} { | |
559 | file_copy $interp_system $interp | |
560 | # Never call strip-debug before unprelink: | |
561 | # prelink: ...: Section .note.gnu.build-id created after prelinking | |
562 | if ![prelinkNO $interp] { | |
563 | continue | |
564 | } | |
565 | strip_debug $interp | |
566 | } elseif {$ldsepdebug == "IN" && $interp_system_debug == ""} { | |
567 | file_copy $interp_system $interp | |
568 | } elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} { | |
0295a32e | 569 | file_copy $interp_system $interp |
11337c2f PA |
570 | file_copy $interp_system_debug "${interp}.debug" |
571 | # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u | |
572 | if {![prelinkNO $interp] || ![prelinkNO "${interp}.debug"]} { | |
573 | continue | |
574 | } | |
575 | set test "eu-unstrip unprelinked:[file tail $interp_system] + [file tail $interp_system_debug] to [file tail $interp]" | |
576 | set command "exec eu-unstrip -o $interp $interp ${interp}.debug" | |
577 | verbose -log "command is $command" | |
578 | if [catch $command] { | |
579 | setup_xfail *-*-* | |
580 | fail $test | |
581 | continue | |
582 | } else { | |
583 | pass $test | |
584 | } | |
585 | } elseif {$ldsepdebug == "SEP" && $interp_system_debug == ""} { | |
586 | file_copy $interp_system $interp | |
587 | # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u | |
588 | if ![prelinkNO $interp] { | |
589 | continue | |
590 | } | |
591 | gdb_gnu_strip_debug $interp | |
592 | } elseif {$ldsepdebug == "SEP" && $interp_system_debug != ""} { | |
593 | file_copy $interp_system $interp | |
594 | file_copy $interp_system_debug "${interp}.debug" | |
b8040f19 | 595 | } |
11337c2f PA |
596 | |
597 | if {$ldsepdebug == "SEP"} { | |
598 | if ![prelinkNO "${interp}.debug"] { | |
599 | continue | |
600 | } | |
b8040f19 | 601 | } else { |
11337c2f | 602 | file delete "${interp}.debug" |
b8040f19 | 603 | } |
11337c2f | 604 | |
2b74ba5a | 605 | if ![prelink$ldprelink $interp "$interp, second time"] { |
b8040f19 JK |
606 | continue |
607 | } | |
2b74ba5a | 608 | |
11337c2f PA |
609 | if {$ldprelink == "NO"} { |
610 | set displacement "NONZERO" | |
611 | } else { | |
612 | # x86* kernel loads prelinked PIE binary at its | |
613 | # prelinked address but ppc* kernel loads it at a | |
614 | # random address. prelink normally skips PIE binaries | |
615 | # during the system scan. | |
616 | set displacement "PRESENT" | |
617 | } | |
618 | test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement | |
b8040f19 | 619 | |
11337c2f | 620 | if ![file_copy $interp $interp_saved] { |
b8040f19 JK |
621 | continue |
622 | } | |
b8040f19 | 623 | |
11337c2f PA |
624 | foreach binprelink {NO YES} { |
625 | foreach binsepdebug {NO IN SEP} { | |
626 | # "ATTACH" is like "YES" but it is modified during | |
627 | # run. It cannot be used for problem | |
628 | # reproducibility after the testcase ends. | |
629 | foreach binpie {NO YES ATTACH} { | |
630 | # This combination is not possible, non-PIE (fixed address) | |
631 | # binary cannot be prelinked to any (other) address. | |
632 | if {$binprelink == "YES" && $binpie == "NO"} { | |
633 | continue | |
634 | } | |
b8040f19 | 635 | |
11337c2f PA |
636 | set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}" |
637 | set exec $binprefix-$binname | |
b8040f19 | 638 | |
11337c2f PA |
639 | with_test_prefix "$binname" { |
640 | set opts "ldflags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]" | |
641 | if {$binsepdebug != "NO"} { | |
642 | lappend opts {debug} | |
643 | } | |
644 | if {$binpie != "NO"} { | |
968aa7ae AH |
645 | lappend opts {pie} |
646 | } else { | |
647 | # Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled. | |
648 | lappend opts {nopie} | |
11337c2f | 649 | } |
5e3b36f8 | 650 | |
11337c2f PA |
651 | set dir ${exec}.d |
652 | set relink_args [build_executable_own_libs ${test}.exp [file tail $exec] $srcfile $opts $interp $dir] | |
653 | if {$relink_args == ""} { | |
4ec70201 | 654 | continue |
11337c2f | 655 | } |
5e3b36f8 | 656 | |
11337c2f PA |
657 | if {$binsepdebug == "SEP"} { |
658 | gdb_gnu_strip_debug $exec | |
659 | } | |
b8040f19 | 660 | |
11337c2f PA |
661 | if {$binpie == "NO"} { |
662 | set displacement "NONE" | |
663 | } elseif {$binprelink == "NO"} { | |
664 | set displacement "NONZERO" | |
665 | } else { | |
666 | # x86* kernel loads prelinked PIE binary at its prelinked | |
667 | # address but ppc* kernel loads it at a random address. | |
668 | # prelink normally skips PIE binaries during the system scan. | |
669 | set displacement "PRESENT" | |
670 | } | |
0a1e94c7 | 671 | |
11337c2f PA |
672 | if {[prelink$binprelink $relink_args [file tail $exec]] |
673 | && [file_copy $interp_saved $interp]} { | |
2b74ba5a AB |
674 | # In order to make test names unique wrap the core of this if block |
675 | # with a test prefix. Some of the tests performed in the if | |
676 | # condition are repeated within this body. | |
677 | with_test_prefix "INNER" { | |
678 | if {$binpie != "ATTACH"} { | |
679 | test_ld $exec 1 [expr {$binsepdebug == "NO"}] $displacement | |
680 | } else { | |
681 | # If the file has been randomly prelinked it must be | |
682 | # "NONZERO". We could see "ZERO" only if it was unprelinked | |
683 | # and it is now running at the same address - which is 0 but | |
684 | # executable can never run at address 0. | |
685 | ||
686 | set displacement "NONZERO" | |
687 | test_attach $exec $displacement $relink_args | |
688 | ||
689 | # ATTACH means that executables and libraries have been | |
690 | # modified after they have been run. They cannot be reused | |
691 | # for problem reproducibility after the testcase ends in | |
692 | # the ATTACH case. Therefore they are rather deleted not | |
693 | # to confuse after the run finishes. | |
694 | set exec_debug [system_debug_get $exec] | |
695 | if {$exec_debug != ""} { | |
696 | # `file delete [glob "${exec_debug}*"]' does not work. | |
697 | foreach f [glob "${exec_debug}*"] { | |
698 | file delete $f | |
699 | } | |
700 | } | |
701 | file delete -force $dir | |
702 | # `file delete [glob "${exec}*"]' does not work. | |
703 | foreach f [glob "${exec}*"] { | |
11337c2f PA |
704 | file delete $f |
705 | } | |
706 | } | |
0a1e94c7 JK |
707 | } |
708 | } | |
ccf26247 | 709 | } |
b8040f19 JK |
710 | } |
711 | } | |
712 | } | |
b8040f19 | 713 | |
11337c2f PA |
714 | file delete $interp_saved |
715 | } | |
b8040f19 JK |
716 | } |
717 | } |