Commit | Line | Data |
---|---|---|
28e7fd62 | 1 | # Copyright 2010-2013 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. | |
3a3dad98 JK |
17 | if { ![isnative] || [is_remote host] || [target_info exists use_gdb_stub] |
18 | || ![istarget *-linux*] || [skip_shlib_tests]} { | |
b8040f19 JK |
19 | continue |
20 | } | |
21 | ||
5e3b36f8 JK |
22 | load_lib prelink-support.exp |
23 | ||
b8040f19 JK |
24 | set test "break-interp" |
25 | set binprefix ${objdir}/${subdir}/${test} | |
26 | # Only to get the $interp_system name. | |
27 | set srcfile_test "start.c" | |
28 | set binfile_test ${test}-test | |
06a6f270 JK |
29 | set binfile_lib ${objdir}/${subdir}/${test}.so |
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 | ||
86 | set interp_system [section_get ${objdir}/${subdir}/$binfile_test .interp] | |
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 | ||
d3d7896d JK |
112 | # Implementation of reach. |
113 | ||
114 | proc reach_1 {func command displacement} { | |
ccf26247 JK |
115 | global gdb_prompt expect_out |
116 | ||
d3d7896d JK |
117 | if {$func == "_dl_debug_state"} { |
118 | # Breakpoint on _dl_debug_state can have problems due to its overlap | |
119 | # with the existing internal breakpoint from GDB. | |
120 | gdb_test_no_output "set stop-on-solib-events 1" | |
121 | } elseif {! [gdb_breakpoint $func allow-pending]} { | |
122 | return | |
123 | } | |
b8040f19 | 124 | |
d3d7896d JK |
125 | set test "reach" |
126 | set test_displacement "seen displacement message as $displacement" | |
127 | set debug_state_count 0 | |
128 | gdb_test_multiple $command $test { | |
129 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
130 | # Missing "$gdb_prompt $" is intentional. | |
131 | if {$expect_out(1,string) == "0x0"} { | |
132 | set case "ZERO" | |
133 | } else { | |
134 | set case "NONZERO" | |
ccf26247 | 135 | } |
d3d7896d JK |
136 | if {$displacement == $case || $displacement == "PRESENT"} { |
137 | pass $test_displacement | |
138 | set displacement "FOUND-$displacement" | |
139 | } else { | |
140 | fail $test_displacement | |
141 | } | |
142 | exp_continue | |
143 | } | |
900e11f9 | 144 | -re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" { |
d3d7896d JK |
145 | if {$func == "_dl_debug_state"} { |
146 | fail $test | |
147 | } else { | |
b8040f19 JK |
148 | pass $test |
149 | } | |
d3d7896d | 150 | } |
900e11f9 | 151 | -re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" { |
d3d7896d JK |
152 | if {$func == "_dl_debug_state"} { |
153 | fail $test | |
154 | } else { | |
b8040f19 JK |
155 | pass $test |
156 | } | |
157 | } | |
edcc5120 | 158 | -re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" { |
d3d7896d JK |
159 | if {$func == "_dl_debug_state"} { |
160 | if {$debug_state_count == 0} { | |
161 | # First stop does not yet relocate the _start function | |
162 | # descriptor on ppc64. | |
163 | set debug_state_count 1 | |
164 | send_gdb "continue\n" | |
165 | exp_continue | |
166 | } else { | |
167 | pass $test | |
168 | } | |
169 | } else { | |
170 | fail $test | |
171 | } | |
ccf26247 | 172 | } |
b8040f19 | 173 | } |
d3d7896d JK |
174 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
175 | fail $test_displacement | |
176 | } | |
177 | ||
178 | if {$func == "_dl_debug_state"} { | |
179 | gdb_test_no_output "set stop-on-solib-events 0" | |
180 | } | |
181 | } | |
182 | ||
183 | # `runto' does not check we stopped really at the function we specified. | |
184 | # DISPLACEMENT can be "NONE" for no message to be present, "ZERO" for | |
185 | # displacement of 0 bytes to be present, "NONZERO" for displacement of non-0 | |
186 | # bytes to be present and "PRESENT" if both "ZERO" and "NONZERO" are valid. | |
187 | proc reach {func command displacement} { | |
0f4d39d5 | 188 | with_test_prefix "reach-$func" { |
6a5870ce PA |
189 | reach_1 $func $command $displacement |
190 | } | |
b8040f19 JK |
191 | } |
192 | ||
0a251e08 YQ |
193 | proc test_core {file displacement} { |
194 | with_test_prefix "core" { | |
195 | global srcdir subdir gdb_prompt expect_out | |
61f0d762 | 196 | |
0a251e08 YQ |
197 | set corefile [core_find $file {} "segv"] |
198 | if {$corefile == ""} { | |
199 | return | |
200 | } | |
ccf26247 | 201 | |
0a251e08 YQ |
202 | gdb_exit |
203 | gdb_start | |
204 | # Clear it to never find any separate debug infos in $debug_root. | |
205 | gdb_test_no_output "set debug-file-directory" \ | |
206 | "set debug-file-directory for core" | |
207 | gdb_reinitialize_dir $srcdir/$subdir | |
208 | gdb_load $file | |
209 | ||
210 | # Print the "PIE (Position Independent Executable) displacement" message. | |
211 | gdb_test_no_output "set verbose on" | |
212 | ||
213 | set test "core loaded" | |
214 | set test_displacement "seen displacement message as $displacement" | |
215 | gdb_test_multiple "core-file $corefile" $test { | |
216 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
217 | # Missing "$gdb_prompt $" is intentional. | |
218 | if {$expect_out(1,string) == "0x0"} { | |
219 | set case "ZERO" | |
220 | } else { | |
221 | set case "NONZERO" | |
222 | } | |
223 | if {$displacement == $case || $displacement == "PRESENT"} { | |
224 | pass $test_displacement | |
225 | set displacement "FOUND-$displacement" | |
226 | } else { | |
227 | fail $test_displacement | |
228 | } | |
229 | exp_continue | |
ccf26247 | 230 | } |
0a251e08 YQ |
231 | -re "Core was generated by .*\r\n#0 .*$gdb_prompt $" { |
232 | # Do not check the binary filename as it may be truncated. | |
233 | pass $test | |
ccf26247 | 234 | } |
ccf26247 | 235 | } |
0a251e08 YQ |
236 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
237 | fail $test_displacement | |
ccf26247 | 238 | } |
0a251e08 YQ |
239 | |
240 | gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt" | |
ccf26247 | 241 | } |
0a251e08 | 242 | } |
61f0d762 | 243 | |
0a251e08 YQ |
244 | proc test_attach_gdb {file pid displacement prefix} { |
245 | with_test_prefix "$prefix" { | |
246 | global gdb_prompt expect_out | |
ccf26247 | 247 | |
0a251e08 YQ |
248 | gdb_exit |
249 | gdb_start | |
bbfba9ed | 250 | |
0a251e08 YQ |
251 | # Print the "PIE (Position Independent Executable) displacement" message. |
252 | gdb_test_no_output "set verbose on" | |
ccf26247 | 253 | |
0a251e08 | 254 | gdb_test "file $file" "Reading symbols from .*done\\." "file" |
ccf26247 | 255 | |
0a251e08 YQ |
256 | set test "attach" |
257 | gdb_test_multiple "attach $pid" $test { | |
258 | -re "Attaching to (program: .*, )?process $pid\r\n" { | |
259 | # Missing "$gdb_prompt $" is intentional. | |
260 | pass $test | |
261 | } | |
ccf26247 | 262 | } |
ccf26247 | 263 | |
0a251e08 YQ |
264 | set test "attach final prompt" |
265 | set test_displacement "seen displacement message as $displacement" | |
266 | gdb_test_multiple "" $test { | |
267 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
268 | # Missing "$gdb_prompt $" is intentional. | |
269 | if {$expect_out(1,string) == "0x0"} { | |
270 | set case "ZERO" | |
271 | } else { | |
272 | set case "NONZERO" | |
273 | } | |
274 | if {$displacement == $case || $displacement == "PRESENT"} { | |
275 | pass $test_displacement | |
276 | set displacement "FOUND-$displacement" | |
277 | } else { | |
278 | fail $test_displacement | |
279 | } | |
280 | exp_continue | |
ccf26247 | 281 | } |
0a251e08 YQ |
282 | -re "$gdb_prompt $" { |
283 | pass $test | |
ccf26247 | 284 | } |
ccf26247 | 285 | } |
0a251e08 YQ |
286 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
287 | fail $test_displacement | |
ccf26247 | 288 | } |
ccf26247 | 289 | |
0a251e08 YQ |
290 | gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "attach main bt" |
291 | gdb_exit | |
292 | } | |
293 | } | |
bbfba9ed | 294 | |
0a1e94c7 JK |
295 | proc test_attach {file displacement {relink_args ""}} { |
296 | global board_info | |
4a2d9c08 | 297 | global exec |
0a1e94c7 JK |
298 | |
299 | gdb_exit | |
300 | ||
301 | set test "sleep function started" | |
302 | ||
303 | set command "${file} sleep" | |
304 | set res [remote_spawn host $command]; | |
305 | if { $res < 0 || $res == "" } { | |
306 | perror "Spawning $command failed." | |
307 | fail $test | |
308 | return | |
309 | } | |
310 | set pid [exp_pid -i $res] | |
311 | gdb_expect { | |
312 | -re "sleeping\r\n" { | |
313 | pass $test | |
314 | } | |
315 | eof { | |
316 | fail "$test (eof)" | |
317 | return | |
318 | } | |
319 | timeout { | |
320 | fail "$test (timeout)" | |
321 | return | |
322 | } | |
323 | } | |
324 | ||
325 | if {$relink_args == ""} { | |
4a2d9c08 | 326 | test_attach_gdb $exec $pid $displacement "attach" |
0a1e94c7 JK |
327 | } else { |
328 | # These could be rather passed as arguments. | |
4a2d9c08 | 329 | global interp_saved interp |
0a1e94c7 JK |
330 | |
331 | foreach relink {YES NO} { | |
3cd07d20 JK |
332 | # Formerly this test was testing only prelinking of $EXEC. As the |
333 | # prelink command automatically prelinks all of $EXEC's libraries, | |
334 | # even $INTERP got prelinked. Therefore, we formerly had to | |
5e3b36f8 JK |
335 | # `[file_copy $interp_saved $interp]' to make $INTERP not affected |
336 | # by this prelinking of $EXEC. | |
3cd07d20 JK |
337 | # |
338 | # But now we need to test even prelinking of $INTERP. We could | |
339 | # create a separate test to test just the $INTERP prelinking. For | |
340 | # test simplicity, we merged this test and the test above by not | |
341 | # restoring $INTERP after $EXEC prelink. $INTERP gets restored | |
342 | # later below. | |
02835898 JK |
343 | # |
344 | # `(wrong library or version mismatch?)' messages are printed for | |
345 | # $binfile_lib on platforms converting REL->RELA relocations by | |
346 | # prelink (such as on i386). There is no reliable way to verify | |
347 | # the library file matches the running library in such case but | |
348 | # GDB at least attempts to set the right displacement. We test | |
349 | # `libfunc' is present in the backtrace and therefore the | |
350 | # displacement has been guessed right. | |
3cd07d20 JK |
351 | |
352 | if [prelink$relink $relink_args [file tail $exec]] { | |
0a1e94c7 JK |
353 | # /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)". |
354 | test_attach_gdb $exec $pid $displacement "attach-relink$relink" | |
355 | } | |
356 | } | |
5e3b36f8 | 357 | file_copy $interp_saved $interp |
0a1e94c7 JK |
358 | } |
359 | ||
360 | remote_exec host "kill -9 $pid" | |
361 | } | |
362 | ||
ccf26247 | 363 | proc test_ld {file ifmain trynosym displacement} { |
fda326dd | 364 | global srcdir subdir gdb_prompt expect_out inferior_exited_re |
b8040f19 JK |
365 | |
366 | # First test normal `file'-command loaded $FILE with symbols. | |
367 | ||
368 | gdb_exit | |
369 | gdb_start | |
370 | # Clear it to never find any separate debug infos in $debug_root. | |
27d3a1a2 | 371 | gdb_test_no_output "set debug-file-directory" |
b8040f19 JK |
372 | gdb_reinitialize_dir $srcdir/$subdir |
373 | gdb_load $file | |
374 | ||
ccf26247 | 375 | # Print the "PIE (Position Independent Executable) displacement" message. |
27d3a1a2 | 376 | gdb_test_no_output "set verbose on" |
ccf26247 | 377 | |
4e5799b6 JK |
378 | # We want to test the re-run of a PIE in the case where the executable |
379 | # is loaded with a different displacement, but disable-randomization | |
380 | # prevents that from happening. So turn it off. | |
381 | gdb_test "set disable-randomization off" | |
382 | ||
d3d7896d JK |
383 | if $ifmain { |
384 | gdb_test_no_output "set args segv" | |
385 | } else { | |
386 | global objdir binfile_test | |
387 | ||
388 | # ld.so needs some executable to run to reach _dl_debug_state. | |
a449c2d8 | 389 | gdb_test_no_output "set args ${objdir}/${subdir}/$binfile_test" "set args OBJDIR/${subdir}/$binfile_test" |
d3d7896d JK |
390 | } |
391 | ||
392 | reach "_dl_debug_state" "run" $displacement | |
06a6f270 | 393 | |
900e11f9 | 394 | gdb_test "bt" "#0 +\[^\r\n\]*\\m(__GI_)?_dl_debug_state\\M.*" "dl bt" |
06a6f270 | 395 | |
b8040f19 | 396 | if $ifmain { |
86e4bafc | 397 | reach "main" continue "NONE" |
06a6f270 | 398 | |
ccf26247 | 399 | reach "libfunc" continue "NONE" |
06a6f270 JK |
400 | |
401 | gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt" | |
4e5799b6 | 402 | } |
61f0d762 | 403 | |
4e5799b6 JK |
404 | # Try re-run if the new PIE displacement takes effect. |
405 | gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y" | |
d3d7896d | 406 | reach "_dl_debug_state" "run" $displacement |
4e5799b6 JK |
407 | |
408 | if $ifmain { | |
ccf26247 | 409 | test_core $file $displacement |
bbfba9ed | 410 | |
ccf26247 | 411 | test_attach $file $displacement |
b8040f19 | 412 | } |
51bee8e9 JK |
413 | |
414 | if !$trynosym { | |
415 | return | |
416 | } | |
417 | ||
11337c2f PA |
418 | with_test_prefix "symbol-less" { |
419 | # Test also `exec-file'-command loaded $FILE - therefore | |
420 | # without symbols. SYMBOL_OBJFILE is not available and only | |
421 | # EXEC_BFD must be used. | |
422 | ||
423 | gdb_exit | |
424 | gdb_start | |
425 | # Clear it to never find any separate debug infos in $debug_root. | |
426 | gdb_test_no_output "set debug-file-directory" | |
427 | gdb_reinitialize_dir $srcdir/$subdir | |
428 | ||
429 | # Print the "PIE (Position Independent Executable) | |
430 | # displacement" message. | |
431 | gdb_test_no_output "set verbose on" | |
432 | ||
433 | # Test no (error) message has been printed by `exec-file'. | |
434 | set escapedfile [string_to_regexp $file] | |
435 | gdb_test "exec-file $file" "exec-file $escapedfile" "load" | |
436 | ||
437 | if $ifmain { | |
438 | reach "_dl_debug_state" run $displacement | |
439 | ||
440 | # Use two separate gdb_test_multiple statements to avoid timeouts due | |
441 | # to slow processing of wildcard capturing long output | |
442 | set test "info files" | |
443 | set entrynohex "" | |
444 | gdb_test_multiple $test $test { | |
445 | -re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n" { | |
446 | set entrynohex $expect_out(1,string) | |
447 | gdb_test_multiple "" $test { | |
448 | -re "\r\n$gdb_prompt $" { | |
449 | pass $test | |
450 | } | |
93c17e06 | 451 | } |
e0cc584e | 452 | } |
51bee8e9 | 453 | } |
e0cc584e | 454 | |
11337c2f PA |
455 | # `info sym' cannot be tested for .opd as the binary may not have |
456 | # symbols. | |
457 | if {[istarget powerpc64-*] && [is_lp64_target]} { | |
458 | set test "convert entry point" | |
459 | gdb_test_multiple "p *(void(*)(void) *) 0x$entrynohex" $test { | |
460 | -re " =( \\(\[^0-9\]*\\))? 0x(\[0-9a-f\]+)( < \[^\r\n\]*)?\r\n$gdb_prompt $" { | |
461 | set entrynohex $expect_out(2,string) | |
462 | pass $test | |
463 | } | |
4569eed2 JK |
464 | } |
465 | } | |
11337c2f PA |
466 | if {$entrynohex != ""} { |
467 | gdb_test "break *0x$entrynohex" "" "break at entry point" | |
468 | gdb_test "continue" "\r\nBreakpoint \[0-9\]+, 0x0*$entrynohex in .*" "entry point reached" | |
469 | } | |
470 | } else { | |
471 | # There is no symbol to break at ld.so. Moreover it can | |
472 | # exit with an error code. | |
473 | ||
474 | set test "ld.so exit" | |
475 | set test_displacement "seen displacement message as $displacement" | |
476 | gdb_test_multiple "run" $test { | |
477 | -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " { | |
478 | # Missing "$gdb_prompt $" is intentional. | |
479 | if {$expect_out(1,string) == "0x0"} { | |
480 | set case "ZERO" | |
481 | } else { | |
482 | set case "NONZERO" | |
483 | } | |
484 | if {$displacement == $case || $displacement == "PRESENT"} { | |
485 | pass $test_displacement | |
486 | set displacement "FOUND-$displacement" | |
487 | } else { | |
488 | fail $test_displacement | |
489 | } | |
490 | exp_continue | |
ccf26247 | 491 | } |
11337c2f PA |
492 | -re "$inferior_exited_re (normally|with code \[0-9\]+).\r\n$gdb_prompt $" { |
493 | # Do not check the binary filename as it may be truncated. | |
494 | pass $test | |
ccf26247 | 495 | } |
ccf26247 | 496 | } |
11337c2f PA |
497 | if ![regexp {^(NONE|FOUND-.*)$} $displacement] { |
498 | fail $test_displacement | |
ccf26247 JK |
499 | } |
500 | } | |
51bee8e9 | 501 | } |
b8040f19 JK |
502 | } |
503 | ||
504 | # Create separate binaries for each testcase - to make the possible reported | |
505 | # problem reproducible after the whole test run finishes. | |
506 | ||
b8040f19 JK |
507 | foreach ldprelink {NO YES} { |
508 | foreach ldsepdebug {NO IN SEP} { | |
509 | # Skip running the ldsepdebug test if we do not have system separate | |
510 | # debug info available. | |
511 | if {$interp_system_debug == "" && $ldsepdebug == "SEP"} { | |
512 | continue | |
513 | } | |
514 | ||
515 | set ldname "LDprelink${ldprelink}debug${ldsepdebug}" | |
516 | set interp $binprefix-$ldname | |
517 | ||
518 | # prelink needs to always prelink all the dependencies to do any file | |
519 | # modifications of its files. ld.so also needs all the dependencies to | |
520 | # be prelinked to omit the relocation process. In-memory file offsets | |
521 | # are not dependent whether ld.so went the prelink way or through the | |
522 | # relocation process. | |
523 | # | |
524 | # For GDB we are not interested whether prelink succeeds as it is | |
525 | # transparent to GDB. GDB is being tested for differences of file | |
526 | # offsets vs. in-memory offsets. So we have to prelink even ld.so for | |
527 | # the BIN modification to happen but we need to restore the original | |
528 | # possibly unprelinked ld.so to test all the combinations for GDB. | |
529 | set interp_saved ${interp}-saved | |
530 | ||
11337c2f PA |
531 | with_test_prefix "$ldname" { |
532 | if {$ldsepdebug == "NO"} { | |
533 | file_copy $interp_system $interp | |
534 | # Never call strip-debug before unprelink: | |
535 | # prelink: ...: Section .note.gnu.build-id created after prelinking | |
536 | if ![prelinkNO $interp] { | |
537 | continue | |
538 | } | |
539 | strip_debug $interp | |
540 | } elseif {$ldsepdebug == "IN" && $interp_system_debug == ""} { | |
541 | file_copy $interp_system $interp | |
542 | } elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} { | |
5e3b36f8 | 543 | file_copy $interp_system $interp |
11337c2f PA |
544 | file_copy $interp_system_debug "${interp}.debug" |
545 | # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u | |
546 | if {![prelinkNO $interp] || ![prelinkNO "${interp}.debug"]} { | |
547 | continue | |
548 | } | |
549 | set test "eu-unstrip unprelinked:[file tail $interp_system] + [file tail $interp_system_debug] to [file tail $interp]" | |
550 | set command "exec eu-unstrip -o $interp $interp ${interp}.debug" | |
551 | verbose -log "command is $command" | |
552 | if [catch $command] { | |
553 | setup_xfail *-*-* | |
554 | fail $test | |
555 | continue | |
556 | } else { | |
557 | pass $test | |
558 | } | |
559 | } elseif {$ldsepdebug == "SEP" && $interp_system_debug == ""} { | |
560 | file_copy $interp_system $interp | |
561 | # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u | |
562 | if ![prelinkNO $interp] { | |
563 | continue | |
564 | } | |
565 | gdb_gnu_strip_debug $interp | |
566 | } elseif {$ldsepdebug == "SEP" && $interp_system_debug != ""} { | |
567 | file_copy $interp_system $interp | |
568 | file_copy $interp_system_debug "${interp}.debug" | |
b8040f19 | 569 | } |
11337c2f PA |
570 | |
571 | if {$ldsepdebug == "SEP"} { | |
572 | if ![prelinkNO "${interp}.debug"] { | |
573 | continue | |
574 | } | |
b8040f19 | 575 | } else { |
11337c2f | 576 | file delete "${interp}.debug" |
b8040f19 | 577 | } |
11337c2f PA |
578 | |
579 | if ![prelink$ldprelink $interp] { | |
b8040f19 JK |
580 | continue |
581 | } | |
11337c2f PA |
582 | if {$ldprelink == "NO"} { |
583 | set displacement "NONZERO" | |
584 | } else { | |
585 | # x86* kernel loads prelinked PIE binary at its | |
586 | # prelinked address but ppc* kernel loads it at a | |
587 | # random address. prelink normally skips PIE binaries | |
588 | # during the system scan. | |
589 | set displacement "PRESENT" | |
590 | } | |
591 | test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement | |
b8040f19 | 592 | |
11337c2f | 593 | if ![file_copy $interp $interp_saved] { |
b8040f19 JK |
594 | continue |
595 | } | |
b8040f19 | 596 | |
11337c2f PA |
597 | foreach binprelink {NO YES} { |
598 | foreach binsepdebug {NO IN SEP} { | |
599 | # "ATTACH" is like "YES" but it is modified during | |
600 | # run. It cannot be used for problem | |
601 | # reproducibility after the testcase ends. | |
602 | foreach binpie {NO YES ATTACH} { | |
603 | # This combination is not possible, non-PIE (fixed address) | |
604 | # binary cannot be prelinked to any (other) address. | |
605 | if {$binprelink == "YES" && $binpie == "NO"} { | |
606 | continue | |
607 | } | |
b8040f19 | 608 | |
11337c2f PA |
609 | set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}" |
610 | set exec $binprefix-$binname | |
b8040f19 | 611 | |
11337c2f PA |
612 | with_test_prefix "$binname" { |
613 | set opts "ldflags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]" | |
614 | if {$binsepdebug != "NO"} { | |
615 | lappend opts {debug} | |
616 | } | |
617 | if {$binpie != "NO"} { | |
618 | lappend opts {additional_flags=-fPIE -pie} | |
619 | } | |
5e3b36f8 | 620 | |
11337c2f PA |
621 | set dir ${exec}.d |
622 | set relink_args [build_executable_own_libs ${test}.exp [file tail $exec] $srcfile $opts $interp $dir] | |
623 | if {$relink_args == ""} { | |
624 | continue; | |
625 | } | |
5e3b36f8 | 626 | |
11337c2f PA |
627 | if {$binsepdebug == "SEP"} { |
628 | gdb_gnu_strip_debug $exec | |
629 | } | |
b8040f19 | 630 | |
11337c2f PA |
631 | if {$binpie == "NO"} { |
632 | set displacement "NONE" | |
633 | } elseif {$binprelink == "NO"} { | |
634 | set displacement "NONZERO" | |
635 | } else { | |
636 | # x86* kernel loads prelinked PIE binary at its prelinked | |
637 | # address but ppc* kernel loads it at a random address. | |
638 | # prelink normally skips PIE binaries during the system scan. | |
639 | set displacement "PRESENT" | |
640 | } | |
0a1e94c7 | 641 | |
11337c2f PA |
642 | if {[prelink$binprelink $relink_args [file tail $exec]] |
643 | && [file_copy $interp_saved $interp]} { | |
644 | if {$binpie != "ATTACH"} { | |
645 | test_ld $exec 1 [expr {$binsepdebug == "NO"}] $displacement | |
646 | } else { | |
647 | # If the file has been randomly prelinked it must be | |
648 | # "NONZERO". We could see "ZERO" only if it was unprelinked | |
649 | # and it is now running at the same address - which is 0 but | |
650 | # executable can never run at address 0. | |
651 | ||
652 | set displacement "NONZERO" | |
653 | test_attach $exec $displacement $relink_args | |
654 | ||
655 | # ATTACH means that executables and libraries have been | |
656 | # modified after they have been run. They cannot be reused | |
657 | # for problem reproducibility after the testcase ends in | |
658 | # the ATTACH case. Therefore they are rather deleted not | |
659 | # to confuse after the run finishes. | |
660 | set exec_debug [system_debug_get $exec] | |
661 | if {$exec_debug != ""} { | |
662 | # `file delete [glob "${exec_debug}*"]' does not work. | |
663 | foreach f [glob "${exec_debug}*"] { | |
664 | file delete $f | |
665 | } | |
666 | } | |
667 | file delete -force $dir | |
668 | # `file delete [glob "${exec}*"]' does not work. | |
669 | foreach f [glob "${exec}*"] { | |
670 | file delete $f | |
671 | } | |
0a1e94c7 JK |
672 | } |
673 | } | |
ccf26247 | 674 | } |
b8040f19 JK |
675 | } |
676 | } | |
677 | } | |
b8040f19 | 678 | |
11337c2f PA |
679 | file delete $interp_saved |
680 | } | |
b8040f19 JK |
681 | } |
682 | } |