aboutsummaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/break-interp.exp
blob: fd2b166de5dc7c0504df0e1bce0013223fad17e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# Copyright 2010-2021 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# This test only works on GNU/Linux.
if { ![isnative] || [is_remote host] || [use_gdb_stub]
     || ![istarget *-linux*] || [skip_shlib_tests]} {
    continue
}

load_lib prelink-support.exp

set test "break-interp"
set binprefix [standard_output_file ${test}]
# Only to get the $interp_system name.
set srcfile_test "start.c"
set binfile_test ${test}-test
set binfile_lib ${binprefix}.so
set srcfile "${test}-main.c"
set srcfile_lib "${test}-lib.c"

if [get_compiler_info] {
    return -1
}

# Use -soname so that the new library gets copied by build_executable_own_libs.

if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug ldflags=-Wl,-soname,${test}.so]] != ""} {
    return -1
}

if {[build_executable ${test}.exp $binfile_test ${srcfile_test} {}] == -1} {
    return -1
}

# Note: The separate debug info file content build-id/crc32 are not verified
# contrary to the GDB search algorithm skipping non-matching ones.
proc system_debug_get {exec} {
    global debug_root

    set exec_build_id_debug [build_id_debug_filename_get $exec]
    set debug_base "[file tail $exec].debug"
    set exec_dir [file dirname $exec]

    # isfile returns 1 even for symlinks to files.
    set retval $debug_root/$exec_build_id_debug
    if [file isfile $retval] {
	return $retval
    }
    set retval $exec_dir/$debug_base
    if [file isfile $retval] {
	return $retval
    }
    set retval $exec_dir/.debug/$debug_base
    if [file isfile $retval] {
	return $retval
    }
    set retval $debug_root/$exec_dir/$debug_base
    if [file isfile $retval] {
	return $retval
    }
    return ""
}

gdb_exit
gdb_start
set debug_root ""
set test "show debug-file-directory"
gdb_test_multiple $test $test {
    -re "The directory where separate debug symbols are searched for is \"(.*)\".\r\n$gdb_prompt $" {
	set debug_root $expect_out(1,string)
    }
}

set interp_system [section_get [standard_output_file $binfile_test] .interp]
clean_restart $interp_system
set dl_main_found 0
gdb_test_multiple "info addr dl_main" "" {
    -re -wrap "Symbol \"dl_main\" is a function at address $hex\\." {
	set dl_main_found 1
    }
    -re -wrap "No symbol \"dl_main\" in current context\\." {
    }
}

set interp_system_debug [system_debug_get $interp_system]
verbose -log "$interp_system has debug $interp_system_debug"

proc prelinkNO {arg {name ""}} {
    return [prelink_no $arg $name]
}

proc prelinkYES {arg {name ""}} {
    return [prelink_yes $arg $name]
}

proc strip_debug {dest} {
    set test "strip [file tail $dest]"
    set strip_program [transform strip]
    set command "exec $strip_program --strip-debug $dest"
    verbose -log "command is $command"
    if [catch $command] {
	fail $test
	return 0
    } else {
    	pass $test
	return 1
    }
}

# The marker function for the standard runtime linker interface is
# _dl_debug_state.  The probes-based interface has no specific marker
# function; the probe we will stop on (init_start) is in dl_main so we
# check for that.

set solib_bp {(_dl_debug_state|dl_main)}

# Implementation of reach.

proc reach_1 {func command displacement} {
    global gdb_prompt expect_out solib_bp

    if {$func == $solib_bp} {
	# Breakpoint on _dl_debug_state can have problems due to its overlap
	# with the existing internal breakpoint from GDB.
	gdb_test_no_output "set stop-on-solib-events 1"
    } elseif {! [gdb_breakpoint $func allow-pending]} {
	return
    }

    set test "reach"
    set test_displacement "seen displacement message as $displacement"
    set debug_state_count 0
    gdb_test_multiple $command $test {
	-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
	    # Missing "$gdb_prompt $" is intentional.
	    if {$expect_out(1,string) == "0x0"} {
		set case "ZERO"
	    } else {
		set case "NONZERO"
	    }
	    if {$displacement == $case || $displacement == "PRESENT"} {
		pass $test_displacement
		set displacement "FOUND-$displacement"
	    } else {
		fail $test_displacement
	    }
	    exp_continue
	}
	-re "Breakpoint \[0-9\]+, \\.?(__GI_)?$func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
	    if {$func == $solib_bp} {
		fail $test
	    } else {
		pass $test
	    }
	}
	-re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in \\.?(__GI_)?$func \\(\\).*\r\n$gdb_prompt $" {
	    if {$func == $solib_bp} {
		fail $test
	    } else {
		pass $test
	    }
	}
	-re "Stopped due to (spurious )?shared library event.*\r\n$gdb_prompt $" {
	    if {$func == $solib_bp} {
		if {$debug_state_count == 0} {
		    # First stop does not yet relocate the _start function
		    # descriptor on ppc64.
		    set debug_state_count 1
		    send_gdb "continue\n"
		    exp_continue
		} else {
		    pass $test
		}
	    } else {
		fail $test
	    }
	}
    }
    if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
	fail $test_displacement
    }

    if {$func == $solib_bp} {
	gdb_test_no_output "set stop-on-solib-events 0"
    }
}

# `runto' does not check we stopped really at the function we specified.
# DISPLACEMENT can be "NONE" for no message to be present, "ZERO" for
# displacement of 0 bytes to be present, "NONZERO" for displacement of non-0
# bytes to be present and "PRESENT" if both "ZERO" and "NONZERO" are valid.
#
# The optional ITERATION parameter is used in order to make unique
# test prefixes, when calling this proc with the same FUNC name
# provide a unique ITERATION value for each call.
proc reach {func command displacement {iteration 1}} {
    set prefix "reach-$func"
    if { $iteration > 1 } {
	set prefix "$prefix-$iteration"
    }
    with_test_prefix $prefix {
	reach_1 $func $command $displacement
    }
}

proc test_core {file displacement} {
    with_test_prefix "core" {
	global srcdir subdir gdb_prompt expect_out

	set corefile [core_find $file {} "segv"]
	if {$corefile == ""} {
	    return
	}

	gdb_exit
	gdb_start
	# Clear it to never find any separate debug infos in $debug_root.
	gdb_test_no_output "set debug-file-directory" \
	    "set debug-file-directory for core"
	gdb_reinitialize_dir $srcdir/$subdir
	gdb_load $file

	# Print the "PIE (Position Independent Executable) displacement" message.
	gdb_test_no_output "set verbose on"

	set test "core loaded"
	set test_displacement "seen displacement message as $displacement"
	gdb_test_multiple "core-file $corefile" $test {
	    -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
		# Missing "$gdb_prompt $" is intentional.
		if {$expect_out(1,string) == "0x0"} {
		    set case "ZERO"
		} else {
		    set case "NONZERO"
		}
		if {$displacement == $case || $displacement == "PRESENT"} {
		    pass $test_displacement
		    set displacement "FOUND-$displacement"
		} else {
		    fail $test_displacement
		}
		exp_continue
	    }
	    -re "Core was generated by .*\r\n#0 .*$gdb_prompt $" {
		# Do not check the binary filename as it may be truncated.
		pass $test
	    }
	}
	if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
	    fail $test_displacement
	}
	gdb_test_no_output "set verbose off"

	gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt"
    }
}

proc test_attach_gdb {file pid displacement prefix} {
    with_test_prefix "$prefix" {
	global gdb_prompt expect_out

	gdb_exit
	gdb_start

	# Print the "PIE (Position Independent Executable) displacement" message.
	gdb_test_no_output "set verbose on"

	gdb_test "file $file" "Reading symbols from .*" "file"

	set test "attach"
	gdb_test_multiple "attach $pid" $test {
	    -re "Attaching to (program: .*, )?process $pid\r\n" {
		# Missing "$gdb_prompt $" is intentional.
		pass $test
	    }
	}

	set test "attach final prompt"
	set test_displacement "seen displacement message as $displacement"
	gdb_test_multiple "" $test {
	    -re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
		# Missing "$gdb_prompt $" is intentional.
		if {$expect_out(1,string) == "0x0"} {
		    set case "ZERO"
		} else {
		    set case "NONZERO"
		}
		if {$displacement == $case || $displacement == "PRESENT"} {
		    pass $test_displacement
		    set displacement "FOUND-$displacement"
		} else {
		    fail $test_displacement
		}
		exp_continue
	    }
	    -re "$gdb_prompt $" {
		pass $test
	    }
	}
	if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
	    fail $test_displacement
	}
	gdb_test_no_output "set verbose off"

	gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "attach main bt"
	gdb_exit
    }
}

proc test_attach {file displacement {relink_args ""}} {
    global board_info
    global exec

    gdb_exit

    set test "sleep function started"

    set command "${file} sleep"
    set test_spawn_id [remote_spawn host $command]
    if { $test_spawn_id < 0 || $test_spawn_id == "" } {
	perror "Spawning $command failed."
	fail $test
	return
    }
    set pid [spawn_id_get_pid $test_spawn_id]
    gdb_expect {
	-re "sleeping\r\n" {
	    pass $test
	}
	eof {
	    fail "$test (eof)"
	    wait -i $test_spawn_id
	    return
	}
	timeout {
	    fail "$test (timeout)"
	    kill_wait_spawned_process $test_spawn_id
	    return
	}
    }

    if {$relink_args == ""} {
	test_attach_gdb $exec $pid $displacement "attach"
    } else {
	# These could be rather passed as arguments.
	global interp_saved interp

	foreach relink {YES NO} {
	    # Formerly this test was testing only prelinking of $EXEC.  As the
	    # prelink command automatically prelinks all of $EXEC's libraries,
	    # even $INTERP got prelinked.  Therefore, we formerly had to
	    # `[file_copy $interp_saved $interp]' to make $INTERP not affected
	    # by this prelinking of $EXEC.
	    #
	    # But now we need to test even prelinking of $INTERP.  We could
	    # create a separate test to test just the $INTERP prelinking.  For
	    # test simplicity, we merged this test and the test above by not
	    # restoring $INTERP after $EXEC prelink.  $INTERP gets restored
	    # later below.
	    #
	    # `(wrong library or version mismatch?)' messages are printed for
	    # $binfile_lib on platforms converting REL->RELA relocations by
	    # prelink (such as on i386).  There is no reliable way to verify
	    # the library file matches the running library in such case but
	    # GDB at least attempts to set the right displacement.  We test
	    # `libfunc' is present in the backtrace and therefore the
	    # displacement has been guessed right.

	    if [prelink$relink $relink_args [file tail $exec]] {
		# /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)".
		test_attach_gdb $exec $pid $displacement "attach-relink$relink"
	    }
	}
	file_copy $interp_saved $interp
    }

    kill_wait_spawned_process $test_spawn_id
}

proc test_ld {file ifmain trynosym displacement} {
    global srcdir subdir gdb_prompt expect_out inferior_exited_re solib_bp
    global hex dl_main_found

    # First test normal `file'-command loaded $FILE with symbols.

    gdb_exit
    gdb_start
    # Clear it to never find any separate debug infos in $debug_root.
    gdb_test_no_output "set debug-file-directory"
    gdb_reinitialize_dir $srcdir/$subdir
    gdb_load $file

    # Print the "PIE (Position Independent Executable) displacement" message.
    gdb_test_no_output "set verbose on"

    # We want to test the re-run of a PIE in the case where the executable
    # is loaded with a different displacement, but disable-randomization
    # prevents that from happening.  So turn it off.
    gdb_test "set disable-randomization off"

    if $ifmain {
	gdb_test_no_output "set args segv"
    } else {
	global binfile_test

	# ld.so needs some executable to run to reach _dl_debug_state.
	gdb_test_no_output "set args [standard_output_file $binfile_test]" \
	    "set args OBJDIR/${subdir}/$binfile_test"
    }

    reach $solib_bp "run" $displacement 1

    with_test_prefix "first backtrace" {
	gdb_test_no_output "set verbose off"
	gdb_test_multiple "bt" "dl bt" {
	    -re -wrap "#0 +\[^\r\n\]*\\m(__GI_)?$solib_bp\\M.*" {
		pass $gdb_test_name
	    }
	    -re -wrap "#0  ($hex) .*" {
		if { $dl_main_found } {
		    fail $gdb_test_name
		} else {
		    set pc $expect_out(1,string)
		    regsub "0x0*" $pc "" pc
		    gdb_test "p /x 0x$pc" ".*"
		    gdb_test_multiple "info probes stap rtld" $gdb_test_name {
			-re -wrap "(?:init_start|init_complete) +0x0*$pc .*" {
			    pass $gdb_test_name
			}
			-re -wrap "" {
			    fail $gdb_test_name
			}
		    }
		}
	    }
	}
	gdb_test_no_output "set verbose on"
    }

    if $ifmain {
	reach "main" continue "NONE"

	reach "libfunc" continue "NONE"

	with_test_prefix "second backtrace" {
	    gdb_test_no_output "set verbose off"
	    gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt"
	    gdb_test_no_output "set verbose on"
	}
    }

    # Try re-run if the new PIE displacement takes effect.
    gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
    reach $solib_bp "run" $displacement 2
    gdb_test_no_output "set verbose off"

    if $ifmain {
	test_core $file $displacement

	test_attach $file $displacement
    }

    if !$trynosym {
	return
    }

    with_test_prefix "symbol-less" {
	# Test also `exec-file'-command loaded $FILE - therefore
	# without symbols.  SYMBOL_OBJFILE is not available and only
	# EXEC_BFD must be used.

	gdb_exit
	gdb_start
	# Clear it to never find any separate debug infos in $debug_root.
	gdb_test_no_output "set debug-file-directory"
	gdb_reinitialize_dir $srcdir/$subdir

	# Print the "PIE (Position Independent Executable)
	# displacement" message.
	gdb_test_no_output "set verbose on"

	# Test no (error) message has been printed by `exec-file'.
	set escapedfile [string_to_regexp $file]
	gdb_test "exec-file $file" "exec-file $escapedfile" "load"

	if $ifmain {
	    reach $solib_bp run $displacement 3

	    # Use two separate gdb_test_multiple statements to avoid timeouts due
	    # to slow processing of wildcard capturing long output
	    set test "info files"
	    set entrynohex ""
	    set info_line [join [list \
				     "\r\n" "\[\t\]" "0x\[0-9af\]+" " - " \
				     "0x\[0-9af\]+" " @ " "0x\[0-9af\]+"  \
				     " is " "\[^\r\n\]+"] ""]
	    gdb_test_multiple $test $test {
		-re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n" {
		    set entrynohex $expect_out(1,string)
		    gdb_test_multiple "" $test {
			-re "\r\n$gdb_prompt $" {
			    pass $test
			}
			-re $info_line {
			    # Avoid timeout with check-read1
			    exp_continue
			}
		    }
		}
	    }

	    # `info sym' cannot be tested for .opd as the binary may not have
	    # symbols.
	    if {[istarget powerpc64-*] && [is_lp64_target]} {
		set test "convert entry point"
		gdb_test_multiple "p *(void(*)(void) *) 0x$entrynohex" $test {
		    -re " =( \\(\[^0-9\]*\\))? 0x(\[0-9a-f\]+)( < \[^\r\n\]*)?\r\n$gdb_prompt $" {
			set entrynohex $expect_out(2,string)
			pass $test
		    }
		}
	    }
	    if {$entrynohex != ""} {
		gdb_test "break *0x$entrynohex" "" "break at entry point"
		gdb_test "continue" "\r\nBreakpoint \[0-9\]+, 0x0*$entrynohex in .*" "entry point reached"
	    }
	} else {
	    # There is no symbol to break at ld.so.  Moreover it can
	    # exit with an error code.

	    set test "ld.so exit"
	    set test_displacement "seen displacement message as $displacement"
	    gdb_test_multiple "run" $test {
		-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
		    # Missing "$gdb_prompt $" is intentional.
		    if {$expect_out(1,string) == "0x0"} {
			set case "ZERO"
		    } else {
			set case "NONZERO"
		    }
		    if {$displacement == $case || $displacement == "PRESENT"} {
			pass $test_displacement
			set displacement "FOUND-$displacement"
		    } else {
			fail $test_displacement
		    }
		    exp_continue
		}
		-re "$inferior_exited_re (normally|with code \[0-9\]+).\r\n$gdb_prompt $" {
		    # Do not check the binary filename as it may be truncated.
		    pass $test
		}
	    }
	    if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
		fail $test_displacement
	    }
	}
	gdb_test_no_output "set verbose off"
    }
}

# Create separate binaries for each testcase - to make the possible reported
# problem reproducible after the whole test run finishes.

foreach_with_prefix ldprelink {NO YES} {
    foreach_with_prefix ldsepdebug {NO IN SEP} {
	# Skip running the ldsepdebug test if we do not have system separate
	# debug info available.
	if {$interp_system_debug == "" && $ldsepdebug == "SEP"} {
	    continue
	}

	set ldname "LDprelink${ldprelink}debug${ldsepdebug}"
	set interp $binprefix-$ldname

	# prelink needs to always prelink all the dependencies to do any file
	# modifications of its files.  ld.so also needs all the dependencies to
	# be prelinked to omit the relocation process.  In-memory file offsets
	# are not dependent whether ld.so went the prelink way or through the
	# relocation process.
	#
	# For GDB we are not interested whether prelink succeeds as it is
	# transparent to GDB.  GDB is being tested for differences of file
	# offsets vs. in-memory offsets.  So we have to prelink even ld.so for
	# the BIN modification to happen but we need to restore the original
	# possibly unprelinked ld.so to test all the combinations for GDB.
	set interp_saved ${interp}-saved

	if {$ldsepdebug == "NO"} {
	    file_copy $interp_system $interp
	    # Never call strip-debug before unprelink:
	    # prelink: ...: Section .note.gnu.build-id created after prelinking
	    if ![prelinkNO $interp] {
		continue
	    }
	    strip_debug $interp
	} elseif {$ldsepdebug == "IN" && $interp_system_debug == ""} {
	    file_copy $interp_system $interp
	} elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} {
	    file_copy $interp_system $interp
	    file_copy $interp_system_debug "${interp}.debug"
	    # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u
	    if {![prelinkNO $interp] || ![prelinkNO "${interp}.debug"]} {
		continue
	    }
	    set test "eu-unstrip unprelinked:[file tail $interp_system] + [file tail $interp_system_debug] to [file tail $interp]"
	    set command "exec eu-unstrip -o $interp $interp ${interp}.debug"
	    verbose -log "command is $command"
	    if [catch $command] {
		setup_xfail *-*-*
		fail $test
		continue
	    } else {
		pass $test
	    }
	} elseif {$ldsepdebug == "SEP" && $interp_system_debug == ""} {
	    file_copy $interp_system $interp
	    # eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u
	    if ![prelinkNO $interp] {
		continue
	    }
	    gdb_gnu_strip_debug $interp
	} elseif {$ldsepdebug == "SEP" && $interp_system_debug != ""} {
	    file_copy $interp_system $interp
	    file_copy $interp_system_debug "${interp}.debug"
	}

	if {$ldsepdebug == "SEP"} {
	    if ![prelinkNO "${interp}.debug"] {
		continue
	    }
	} else {
	    file delete "${interp}.debug"
	}

	if ![prelink$ldprelink $interp "[file tail $interp], second time"] {
	    continue
	}

	if {$ldprelink == "NO"} {
	    set displacement "NONZERO"
	} else {
	    # x86* kernel loads prelinked PIE binary at its
	    # prelinked address but ppc* kernel loads it at a
	    # random address.  prelink normally skips PIE binaries
	    # during the system scan.
	    set displacement "PRESENT"
	}
	test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement

	if ![file_copy $interp $interp_saved] {
	    continue
	}

	foreach_with_prefix binprelink {NO YES} {
	    foreach_with_prefix binsepdebug {NO IN SEP} {
		# "ATTACH" is like "YES" but it is modified during
		# run.  It cannot be used for problem
		# reproducibility after the testcase ends.
		foreach_with_prefix binpie {NO YES ATTACH} {
		    # This combination is not possible, non-PIE (fixed address)
		    # binary cannot be prelinked to any (other) address.
		    if {$binprelink == "YES" && $binpie == "NO"} {
			continue
		    }

		    set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}"
		    set exec $binprefix-$binname

		    set opts "ldflags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]"
		    if {$binsepdebug != "NO"} {
			lappend opts {debug}
		    }
		    if {$binpie != "NO"} {
			lappend opts {pie}
		    } else {
			# Debian9/Ubuntu16.10 onwards default to PIE enabled. Ensure it is disabled.
			lappend opts {nopie}
		    }

		    set dir ${exec}.d
		    set relink_args [build_executable_own_libs ${test}.exp [file tail $exec] $srcfile $opts $interp $dir]
		    if {$relink_args == ""} {
			continue
		    }

		    if {$binsepdebug == "SEP"} {
			gdb_gnu_strip_debug $exec
		    }

		    if {$binpie == "NO"} {
			set displacement "NONE"
		    } elseif {$binprelink == "NO"} {
			set displacement "NONZERO"
		    } else {
			# x86* kernel loads prelinked PIE binary at its prelinked
			# address but ppc* kernel loads it at a random address.
			# prelink normally skips PIE binaries during the system scan.
			set displacement "PRESENT"
		    }

		    if {[prelink$binprelink $relink_args [file tail $exec]]
			&& [file_copy $interp_saved $interp]} {
			# In order to make test names unique wrap the core of this if block
			# with a test prefix.  Some of the tests performed in the if
			# condition are repeated within this body.
			with_test_prefix "INNER" {
			    if {$binpie != "ATTACH"} {
				test_ld $exec 1 [expr {$binsepdebug == "NO"}] $displacement
			    } else {
				# If the file has been randomly prelinked it must be
				# "NONZERO".  We could see "ZERO" only if it was unprelinked
				# and it is now running at the same address - which is 0 but
				# executable can never run at address 0.

				set displacement "NONZERO"
				test_attach $exec $displacement $relink_args

				# ATTACH means that executables and libraries have been
				# modified after they have been run.  They cannot be reused
				# for problem reproducibility after the testcase ends in
				# the ATTACH case.  Therefore they are rather deleted not
				# to confuse after the run finishes.
				set exec_debug [system_debug_get $exec]
				if {$exec_debug != ""} {
				    # `file delete [glob "${exec_debug}*"]' does not work.
				    foreach f [glob "${exec_debug}*"] {
					file delete $f
				    }
				}
				file delete -force $dir
				# `file delete [glob "${exec}*"]' does not work.
				foreach f [glob "${exec}*"] {
				    file delete $f
				}
			    }
			}
		    }
		}
	    }
	}

	file delete $interp_saved
    }
}