1 |
330 |
jeremybenn |
# Copyright 2010 Free Software Foundation, Inc.
|
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 .
|
15 |
|
|
|
16 |
|
|
# This test only works on GNU/Linux.
|
17 |
|
|
if { ![isnative] || [is_remote host] || ![istarget *-linux*] || [skip_shlib_tests]} {
|
18 |
|
|
continue
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
load_lib prelink-support.exp
|
22 |
|
|
|
23 |
|
|
set test "break-interp"
|
24 |
|
|
set binprefix ${objdir}/${subdir}/${test}
|
25 |
|
|
# Only to get the $interp_system name.
|
26 |
|
|
set srcfile_test "start.c"
|
27 |
|
|
set binfile_test ${test}-test
|
28 |
|
|
set binfile_lib ${objdir}/${subdir}/${test}.so
|
29 |
|
|
set srcfile "${test}-main.c"
|
30 |
|
|
set srcfile_lib "${test}-lib.c"
|
31 |
|
|
|
32 |
|
|
if [get_compiler_info ${binfile_lib}] {
|
33 |
|
|
return -1
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
# Use -soname so that the new library gets copied by build_executable_own_libs.
|
37 |
|
|
|
38 |
|
|
if {[gdb_compile_shlib ${srcdir}/${subdir}/${srcfile_lib} ${binfile_lib} [list debug additional_flags=-Wl,-soname,${test}.so]] != ""} {
|
39 |
|
|
return -1
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
if {[build_executable ${test}.exp $binfile_test ${srcfile_test} {}] == -1} {
|
43 |
|
|
return -1
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
# Note: The separate debug info file content build-id/crc32 are not verified
|
47 |
|
|
# contrary to the GDB search algorithm skipping non-matching ones.
|
48 |
|
|
proc system_debug_get {exec} {
|
49 |
|
|
global debug_root
|
50 |
|
|
|
51 |
|
|
set exec_build_id_debug [build_id_debug_filename_get $exec]
|
52 |
|
|
set debug_base "[file tail $exec].debug"
|
53 |
|
|
set exec_dir [file dirname $exec]
|
54 |
|
|
|
55 |
|
|
# isfile returns 1 even for symlinks to files.
|
56 |
|
|
set retval $debug_root/$exec_build_id_debug
|
57 |
|
|
if [file isfile $retval] {
|
58 |
|
|
return $retval
|
59 |
|
|
}
|
60 |
|
|
set retval $exec_dir/$debug_base
|
61 |
|
|
if [file isfile $retval] {
|
62 |
|
|
return $retval
|
63 |
|
|
}
|
64 |
|
|
set retval $exec_dir/.debug/$debug_base
|
65 |
|
|
if [file isfile $retval] {
|
66 |
|
|
return $retval
|
67 |
|
|
}
|
68 |
|
|
set retval $debug_root/$exec_dir/$debug_base
|
69 |
|
|
if [file isfile $retval] {
|
70 |
|
|
return $retval
|
71 |
|
|
}
|
72 |
|
|
return ""
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
gdb_exit
|
76 |
|
|
gdb_start
|
77 |
|
|
set debug_root ""
|
78 |
|
|
set test "show debug-file-directory"
|
79 |
|
|
gdb_test_multiple $test $test {
|
80 |
|
|
-re "The directory where separate debug symbols are searched for is \"(.*)\".\r\n$gdb_prompt $" {
|
81 |
|
|
set debug_root $expect_out(1,string)
|
82 |
|
|
}
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
set interp_system [section_get ${objdir}/${subdir}/$binfile_test .interp]
|
86 |
|
|
set interp_system_debug [system_debug_get $interp_system]
|
87 |
|
|
verbose -log "$interp_system has debug $interp_system_debug"
|
88 |
|
|
|
89 |
|
|
proc prelinkNO {arg {name ""}} {
|
90 |
|
|
return [prelink_no $arg $name]
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
proc prelinkYES {arg {name ""}} {
|
94 |
|
|
return [prelink_yes $arg $name]
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
proc strip_debug {dest} {
|
98 |
|
|
set test "strip [file tail $dest]"
|
99 |
|
|
set strip_program [transform strip]
|
100 |
|
|
set command "exec $strip_program --strip-debug $dest"
|
101 |
|
|
verbose -log "command is $command"
|
102 |
|
|
if [catch $command] {
|
103 |
|
|
fail $test
|
104 |
|
|
return 0
|
105 |
|
|
} else {
|
106 |
|
|
pass $test
|
107 |
|
|
return 1
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
# `runto' does not check we stopped really at the function we specified.
|
112 |
|
|
# DISPLACEMENT can be "NONE", "ZERO" or "NONZERO"
|
113 |
|
|
proc reach {func command displacement} {
|
114 |
|
|
global gdb_prompt expect_out
|
115 |
|
|
|
116 |
|
|
global pf_prefix
|
117 |
|
|
set old_ldprefix $pf_prefix
|
118 |
|
|
lappend pf_prefix "reach-$func:"
|
119 |
|
|
|
120 |
|
|
if [gdb_breakpoint $func allow-pending] {
|
121 |
|
|
set test "reach"
|
122 |
|
|
set test_displacement "seen displacement message as $displacement"
|
123 |
|
|
gdb_test_multiple $command $test {
|
124 |
|
|
-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
|
125 |
|
|
# Missing "$gdb_prompt $" is intentional.
|
126 |
|
|
if {$expect_out(1,string) == "0x0"} {
|
127 |
|
|
set case "ZERO"
|
128 |
|
|
} else {
|
129 |
|
|
set case "NONZERO"
|
130 |
|
|
}
|
131 |
|
|
if {$displacement == $case} {
|
132 |
|
|
pass $test_displacement
|
133 |
|
|
set displacement "FOUND-$displacement"
|
134 |
|
|
} else {
|
135 |
|
|
fail $test_displacement
|
136 |
|
|
}
|
137 |
|
|
exp_continue
|
138 |
|
|
}
|
139 |
|
|
-re "Breakpoint \[0-9\]+, $func \\(.*\\) at .*:\[0-9\]+\r\n.*$gdb_prompt $" {
|
140 |
|
|
pass $test
|
141 |
|
|
}
|
142 |
|
|
-re "Breakpoint \[0-9\]+, \[0-9xa-f\]+ in $func \\(\\).*\r\n$gdb_prompt $" {
|
143 |
|
|
pass $test
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
|
147 |
|
|
fail $test_displacement
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
set pf_prefix $old_ldprefix
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
proc test_core {file displacement} {
|
155 |
|
|
global srcdir subdir gdb_prompt expect_out
|
156 |
|
|
|
157 |
|
|
set corefile [core_find $file {} "segv"]
|
158 |
|
|
if {$corefile == ""} {
|
159 |
|
|
return
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
global pf_prefix
|
163 |
|
|
set old_ldprefix $pf_prefix
|
164 |
|
|
lappend pf_prefix "core:"
|
165 |
|
|
|
166 |
|
|
gdb_exit
|
167 |
|
|
gdb_start
|
168 |
|
|
# Clear it to never find any separate debug infos in $debug_root.
|
169 |
|
|
gdb_test_no_output "set debug-file-directory" \
|
170 |
|
|
"set debug-file-directory for core"
|
171 |
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
172 |
|
|
gdb_load $file
|
173 |
|
|
|
174 |
|
|
# Print the "PIE (Position Independent Executable) displacement" message.
|
175 |
|
|
gdb_test_no_output "set verbose on"
|
176 |
|
|
|
177 |
|
|
set test "core loaded"
|
178 |
|
|
set test_displacement "seen displacement message as $displacement"
|
179 |
|
|
gdb_test_multiple "core-file $corefile" $test {
|
180 |
|
|
-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
|
181 |
|
|
# Missing "$gdb_prompt $" is intentional.
|
182 |
|
|
if {$expect_out(1,string) == "0x0"} {
|
183 |
|
|
set case "ZERO"
|
184 |
|
|
} else {
|
185 |
|
|
set case "NONZERO"
|
186 |
|
|
}
|
187 |
|
|
if {$displacement == $case} {
|
188 |
|
|
pass $test_displacement
|
189 |
|
|
set displacement "FOUND-$displacement"
|
190 |
|
|
} else {
|
191 |
|
|
fail $test_displacement
|
192 |
|
|
}
|
193 |
|
|
exp_continue
|
194 |
|
|
}
|
195 |
|
|
-re "Core was generated by .*\r\n#0 .*$gdb_prompt $" {
|
196 |
|
|
# Do not check the binary filename as it may be truncated.
|
197 |
|
|
pass $test
|
198 |
|
|
}
|
199 |
|
|
}
|
200 |
|
|
if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
|
201 |
|
|
fail $test_displacement
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "core main bt"
|
205 |
|
|
|
206 |
|
|
set pf_prefix $old_ldprefix
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
proc test_attach_gdb {file pid displacement prefix} {
|
210 |
|
|
global gdb_prompt expect_out
|
211 |
|
|
|
212 |
|
|
global pf_prefix
|
213 |
|
|
set old_ldprefix $pf_prefix
|
214 |
|
|
lappend pf_prefix "$prefix:"
|
215 |
|
|
|
216 |
|
|
gdb_exit
|
217 |
|
|
gdb_start
|
218 |
|
|
|
219 |
|
|
# Print the "PIE (Position Independent Executable) displacement" message.
|
220 |
|
|
gdb_test_no_output "set verbose on"
|
221 |
|
|
|
222 |
|
|
if {$file != ""} {
|
223 |
|
|
gdb_test "file $file" "Reading symbols from .*done\\." "file"
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
set test "attach"
|
227 |
|
|
gdb_test_multiple "attach $pid" $test {
|
228 |
|
|
-re "Attaching to (program: .*, )?process $pid\r\n" {
|
229 |
|
|
# Missing "$gdb_prompt $" is intentional.
|
230 |
|
|
pass $test
|
231 |
|
|
}
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
set test "attach final prompt"
|
235 |
|
|
set test_displacement "seen displacement message as $displacement"
|
236 |
|
|
gdb_test_multiple "" $test {
|
237 |
|
|
-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
|
238 |
|
|
# Missing "$gdb_prompt $" is intentional.
|
239 |
|
|
if {$expect_out(1,string) == "0x0"} {
|
240 |
|
|
set case "ZERO"
|
241 |
|
|
} else {
|
242 |
|
|
set case "NONZERO"
|
243 |
|
|
}
|
244 |
|
|
if {$displacement == $case} {
|
245 |
|
|
pass $test_displacement
|
246 |
|
|
set displacement "FOUND-$displacement"
|
247 |
|
|
} else {
|
248 |
|
|
fail $test_displacement
|
249 |
|
|
}
|
250 |
|
|
exp_continue
|
251 |
|
|
}
|
252 |
|
|
-re "$gdb_prompt $" {
|
253 |
|
|
pass $test
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
|
257 |
|
|
fail $test_displacement
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
gdb_test "bt" "#\[0-9\]+ +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#\[0-9\]+ +\[^\r\n\]*\\mmain\\M.*" "attach main bt"
|
261 |
|
|
gdb_exit
|
262 |
|
|
|
263 |
|
|
set pf_prefix $old_ldprefix
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
proc test_attach {file displacement {relink_args ""}} {
|
267 |
|
|
global board_info
|
268 |
|
|
|
269 |
|
|
gdb_exit
|
270 |
|
|
|
271 |
|
|
set test "sleep function started"
|
272 |
|
|
|
273 |
|
|
set command "${file} sleep"
|
274 |
|
|
set res [remote_spawn host $command];
|
275 |
|
|
if { $res < 0 || $res == "" } {
|
276 |
|
|
perror "Spawning $command failed."
|
277 |
|
|
fail $test
|
278 |
|
|
return
|
279 |
|
|
}
|
280 |
|
|
set pid [exp_pid -i $res]
|
281 |
|
|
gdb_expect {
|
282 |
|
|
-re "sleeping\r\n" {
|
283 |
|
|
pass $test
|
284 |
|
|
}
|
285 |
|
|
eof {
|
286 |
|
|
fail "$test (eof)"
|
287 |
|
|
return
|
288 |
|
|
}
|
289 |
|
|
timeout {
|
290 |
|
|
fail "$test (timeout)"
|
291 |
|
|
return
|
292 |
|
|
}
|
293 |
|
|
}
|
294 |
|
|
|
295 |
|
|
if {$relink_args == ""} {
|
296 |
|
|
test_attach_gdb "" $pid $displacement "attach"
|
297 |
|
|
} else {
|
298 |
|
|
# These could be rather passed as arguments.
|
299 |
|
|
global exec interp_saved interp
|
300 |
|
|
|
301 |
|
|
foreach relink {YES NO} {
|
302 |
|
|
# Formerly this test was testing only prelinking of $EXEC. As the
|
303 |
|
|
# prelink command automatically prelinks all of $EXEC's libraries,
|
304 |
|
|
# even $INTERP got prelinked. Therefore, we formerly had to
|
305 |
|
|
# `[file_copy $interp_saved $interp]' to make $INTERP not affected
|
306 |
|
|
# by this prelinking of $EXEC.
|
307 |
|
|
#
|
308 |
|
|
# But now we need to test even prelinking of $INTERP. We could
|
309 |
|
|
# create a separate test to test just the $INTERP prelinking. For
|
310 |
|
|
# test simplicity, we merged this test and the test above by not
|
311 |
|
|
# restoring $INTERP after $EXEC prelink. $INTERP gets restored
|
312 |
|
|
# later below.
|
313 |
|
|
|
314 |
|
|
if [prelink$relink $relink_args [file tail $exec]] {
|
315 |
|
|
# /proc/PID/exe cannot be loaded as it is "EXECNAME (deleted)".
|
316 |
|
|
test_attach_gdb $exec $pid $displacement "attach-relink$relink"
|
317 |
|
|
}
|
318 |
|
|
}
|
319 |
|
|
file_copy $interp_saved $interp
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
remote_exec host "kill -9 $pid"
|
323 |
|
|
}
|
324 |
|
|
|
325 |
|
|
proc test_ld {file ifmain trynosym displacement} {
|
326 |
|
|
global srcdir subdir gdb_prompt expect_out
|
327 |
|
|
|
328 |
|
|
# First test normal `file'-command loaded $FILE with symbols.
|
329 |
|
|
|
330 |
|
|
gdb_exit
|
331 |
|
|
gdb_start
|
332 |
|
|
# Clear it to never find any separate debug infos in $debug_root.
|
333 |
|
|
gdb_test_no_output "set debug-file-directory"
|
334 |
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
335 |
|
|
gdb_load $file
|
336 |
|
|
|
337 |
|
|
# Print the "PIE (Position Independent Executable) displacement" message.
|
338 |
|
|
gdb_test_no_output "set verbose on"
|
339 |
|
|
|
340 |
|
|
# We want to test the re-run of a PIE in the case where the executable
|
341 |
|
|
# is loaded with a different displacement, but disable-randomization
|
342 |
|
|
# prevents that from happening. So turn it off.
|
343 |
|
|
gdb_test "set disable-randomization off"
|
344 |
|
|
|
345 |
|
|
reach "dl_main" "run segv" $displacement
|
346 |
|
|
|
347 |
|
|
gdb_test "bt" "#0 +\[^\r\n\]*\\mdl_main\\M.*" "dl bt"
|
348 |
|
|
|
349 |
|
|
if $ifmain {
|
350 |
|
|
reach "main" continue "NONE"
|
351 |
|
|
|
352 |
|
|
reach "libfunc" continue "NONE"
|
353 |
|
|
|
354 |
|
|
gdb_test "bt" "#0 +\[^\r\n\]*\\mlibfunc\\M\[^\r\n\]*\r\n#1 +\[^\r\n\]*\\mmain\\M.*" "main bt"
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
# Try re-run if the new PIE displacement takes effect.
|
358 |
|
|
gdb_test "kill" "" "kill" {Kill the program being debugged\? \(y or n\) } "y"
|
359 |
|
|
reach "dl_main" "run segv" $displacement
|
360 |
|
|
|
361 |
|
|
if $ifmain {
|
362 |
|
|
test_core $file $displacement
|
363 |
|
|
|
364 |
|
|
test_attach $file $displacement
|
365 |
|
|
}
|
366 |
|
|
|
367 |
|
|
if !$trynosym {
|
368 |
|
|
return
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
global pf_prefix
|
372 |
|
|
set old_ldprefix $pf_prefix
|
373 |
|
|
lappend pf_prefix "symbol-less:"
|
374 |
|
|
|
375 |
|
|
# Test also `exec-file'-command loaded $FILE - therefore without symbols.
|
376 |
|
|
# SYMBOL_OBJFILE is not available and only EXEC_BFD must be used.
|
377 |
|
|
|
378 |
|
|
gdb_exit
|
379 |
|
|
gdb_start
|
380 |
|
|
# Clear it to never find any separate debug infos in $debug_root.
|
381 |
|
|
gdb_test_no_output "set debug-file-directory"
|
382 |
|
|
gdb_reinitialize_dir $srcdir/$subdir
|
383 |
|
|
|
384 |
|
|
# Print the "PIE (Position Independent Executable) displacement" message.
|
385 |
|
|
gdb_test_no_output "set verbose on"
|
386 |
|
|
|
387 |
|
|
# Test no (error) message has been printed by `exec-file'.
|
388 |
|
|
set escapedfile [string_to_regexp $file]
|
389 |
|
|
gdb_test "exec-file $file" "exec-file $escapedfile" "load"
|
390 |
|
|
|
391 |
|
|
if $ifmain {
|
392 |
|
|
reach "dl_main" run $displacement
|
393 |
|
|
|
394 |
|
|
set test "info files"
|
395 |
|
|
set entrynohex ""
|
396 |
|
|
gdb_test_multiple $test $test {
|
397 |
|
|
-re "\r\n\[\t \]*Entry point:\[\t \]*0x(\[0-9a-f\]+)\r\n.*$gdb_prompt $" {
|
398 |
|
|
set entrynohex $expect_out(1,string)
|
399 |
|
|
pass $test
|
400 |
|
|
}
|
401 |
|
|
}
|
402 |
|
|
if {$entrynohex != ""} {
|
403 |
|
|
gdb_test "break *0x$entrynohex" "" "break at entry point"
|
404 |
|
|
gdb_test "continue" "\r\nBreakpoint \[0-9\]+, 0x0*$entrynohex in .*" "entry point reached"
|
405 |
|
|
}
|
406 |
|
|
} else {
|
407 |
|
|
# There is no symbol to break at ld.so. Moreover it can exit with an
|
408 |
|
|
# error code.
|
409 |
|
|
|
410 |
|
|
set test "ld.so exit"
|
411 |
|
|
set test_displacement "seen displacement message as $displacement"
|
412 |
|
|
gdb_test_multiple "run" $test {
|
413 |
|
|
-re "Using PIE \\(Position Independent Executable\\) displacement (0x\[0-9a-f\]+) " {
|
414 |
|
|
# Missing "$gdb_prompt $" is intentional.
|
415 |
|
|
if {$expect_out(1,string) == "0x0"} {
|
416 |
|
|
set case "ZERO"
|
417 |
|
|
} else {
|
418 |
|
|
set case "NONZERO"
|
419 |
|
|
}
|
420 |
|
|
if {$displacement == $case} {
|
421 |
|
|
pass $test_displacement
|
422 |
|
|
set displacement "FOUND-$displacement"
|
423 |
|
|
} else {
|
424 |
|
|
fail $test_displacement
|
425 |
|
|
}
|
426 |
|
|
exp_continue
|
427 |
|
|
}
|
428 |
|
|
-re "Program exited (normally|with code \[0-9\]+)\\.\r\n$gdb_prompt $" {
|
429 |
|
|
# Do not check the binary filename as it may be truncated.
|
430 |
|
|
pass $test
|
431 |
|
|
}
|
432 |
|
|
}
|
433 |
|
|
if ![regexp {^(NONE|FOUND-.*)$} $displacement] {
|
434 |
|
|
fail $test_displacement
|
435 |
|
|
}
|
436 |
|
|
}
|
437 |
|
|
|
438 |
|
|
set pf_prefix $old_ldprefix
|
439 |
|
|
}
|
440 |
|
|
|
441 |
|
|
# Create separate binaries for each testcase - to make the possible reported
|
442 |
|
|
# problem reproducible after the whole test run finishes.
|
443 |
|
|
|
444 |
|
|
set old_ldprefix $pf_prefix
|
445 |
|
|
foreach ldprelink {NO YES} {
|
446 |
|
|
foreach ldsepdebug {NO IN SEP} {
|
447 |
|
|
# Skip running the ldsepdebug test if we do not have system separate
|
448 |
|
|
# debug info available.
|
449 |
|
|
if {$interp_system_debug == "" && $ldsepdebug == "SEP"} {
|
450 |
|
|
continue
|
451 |
|
|
}
|
452 |
|
|
|
453 |
|
|
set ldname "LDprelink${ldprelink}debug${ldsepdebug}"
|
454 |
|
|
set interp $binprefix-$ldname
|
455 |
|
|
|
456 |
|
|
# prelink needs to always prelink all the dependencies to do any file
|
457 |
|
|
# modifications of its files. ld.so also needs all the dependencies to
|
458 |
|
|
# be prelinked to omit the relocation process. In-memory file offsets
|
459 |
|
|
# are not dependent whether ld.so went the prelink way or through the
|
460 |
|
|
# relocation process.
|
461 |
|
|
#
|
462 |
|
|
# For GDB we are not interested whether prelink succeeds as it is
|
463 |
|
|
# transparent to GDB. GDB is being tested for differences of file
|
464 |
|
|
# offsets vs. in-memory offsets. So we have to prelink even ld.so for
|
465 |
|
|
# the BIN modification to happen but we need to restore the original
|
466 |
|
|
# possibly unprelinked ld.so to test all the combinations for GDB.
|
467 |
|
|
set interp_saved ${interp}-saved
|
468 |
|
|
|
469 |
|
|
set pf_prefix $old_ldprefix
|
470 |
|
|
lappend pf_prefix "$ldname:"
|
471 |
|
|
|
472 |
|
|
if {$ldsepdebug == "NO"} {
|
473 |
|
|
file_copy $interp_system $interp
|
474 |
|
|
# Never call strip-debug before unprelink:
|
475 |
|
|
# prelink: ...: Section .note.gnu.build-id created after prelinking
|
476 |
|
|
if ![prelinkNO $interp] {
|
477 |
|
|
continue
|
478 |
|
|
}
|
479 |
|
|
strip_debug $interp
|
480 |
|
|
} elseif {$ldsepdebug == "IN" && $interp_system_debug == ""} {
|
481 |
|
|
file_copy $interp_system $interp
|
482 |
|
|
} elseif {$ldsepdebug == "IN" && $interp_system_debug != ""} {
|
483 |
|
|
file_copy $interp_system $interp
|
484 |
|
|
file_copy $interp_system_debug "${interp}.debug"
|
485 |
|
|
# eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u
|
486 |
|
|
if {![prelinkNO $interp] || ![prelinkNO "${interp}.debug"]} {
|
487 |
|
|
continue
|
488 |
|
|
}
|
489 |
|
|
set test "eu-unstrip unprelinked:[file tail $interp_system] + [file tail $interp_system_debug] to [file tail $interp]"
|
490 |
|
|
set command "exec eu-unstrip -o $interp $interp ${interp}.debug"
|
491 |
|
|
verbose -log "command is $command"
|
492 |
|
|
if [catch $command] {
|
493 |
|
|
setup_xfail *-*-*
|
494 |
|
|
fail $test
|
495 |
|
|
continue
|
496 |
|
|
} else {
|
497 |
|
|
pass $test
|
498 |
|
|
}
|
499 |
|
|
} elseif {$ldsepdebug == "SEP" && $interp_system_debug == ""} {
|
500 |
|
|
file_copy $interp_system $interp
|
501 |
|
|
# eu-unstrip: DWARF data in '...' not adjusted for prelinking bias; consider prelink -u
|
502 |
|
|
if ![prelinkNO $interp] {
|
503 |
|
|
continue
|
504 |
|
|
}
|
505 |
|
|
gdb_gnu_strip_debug $interp
|
506 |
|
|
} elseif {$ldsepdebug == "SEP" && $interp_system_debug != ""} {
|
507 |
|
|
file_copy $interp_system $interp
|
508 |
|
|
file_copy $interp_system_debug "${interp}.debug"
|
509 |
|
|
}
|
510 |
|
|
|
511 |
|
|
if {$ldsepdebug == "SEP"} {
|
512 |
|
|
if ![prelinkNO "${interp}.debug"] {
|
513 |
|
|
continue
|
514 |
|
|
}
|
515 |
|
|
} else {
|
516 |
|
|
file delete "${interp}.debug"
|
517 |
|
|
}
|
518 |
|
|
|
519 |
|
|
if ![prelink$ldprelink $interp] {
|
520 |
|
|
continue
|
521 |
|
|
}
|
522 |
|
|
if {$ldprelink == "NO"} {
|
523 |
|
|
set displacement "NONZERO"
|
524 |
|
|
} else {
|
525 |
|
|
set displacement "ZERO"
|
526 |
|
|
}
|
527 |
|
|
test_ld $interp 0 [expr {$ldsepdebug == "NO"}] $displacement
|
528 |
|
|
|
529 |
|
|
if ![file_copy $interp $interp_saved] {
|
530 |
|
|
continue
|
531 |
|
|
}
|
532 |
|
|
set old_binprefix $pf_prefix
|
533 |
|
|
foreach binprelink {NO YES} {
|
534 |
|
|
foreach binsepdebug {NO IN SEP} {
|
535 |
|
|
# "ATTACH" is like "YES" but it is modified during run.
|
536 |
|
|
# It cannot be used for problem reproducibility after the
|
537 |
|
|
# testcase ends.
|
538 |
|
|
foreach binpie {NO YES ATTACH} {
|
539 |
|
|
# This combination is not possible, non-PIE (fixed address)
|
540 |
|
|
# binary cannot be prelinked to any (other) address.
|
541 |
|
|
if {$binprelink == "YES" && $binpie == "NO"} {
|
542 |
|
|
continue
|
543 |
|
|
}
|
544 |
|
|
|
545 |
|
|
set binname "BINprelink${binprelink}debug${binsepdebug}pie${binpie}"
|
546 |
|
|
set exec $binprefix-$binname
|
547 |
|
|
|
548 |
|
|
set pf_prefix $old_binprefix
|
549 |
|
|
lappend pf_prefix "$binname:"
|
550 |
|
|
|
551 |
|
|
set opts "additional_flags=-Wl,$binfile_lib,-rpath,[file dirname $binfile_lib]"
|
552 |
|
|
if {$binsepdebug != "NO"} {
|
553 |
|
|
lappend opts {debug}
|
554 |
|
|
}
|
555 |
|
|
if {$binpie != "NO"} {
|
556 |
|
|
lappend opts {additional_flags=-fPIE -pie}
|
557 |
|
|
}
|
558 |
|
|
|
559 |
|
|
set dir ${exec}.d
|
560 |
|
|
set relink_args [build_executable_own_libs ${test}.exp [file tail $exec] $srcfile $opts $interp $dir]
|
561 |
|
|
if {$relink_args == ""} {
|
562 |
|
|
continue;
|
563 |
|
|
}
|
564 |
|
|
|
565 |
|
|
if {$binsepdebug == "SEP"} {
|
566 |
|
|
gdb_gnu_strip_debug $exec
|
567 |
|
|
}
|
568 |
|
|
|
569 |
|
|
if {$binpie == "NO"} {
|
570 |
|
|
set displacement "NONE"
|
571 |
|
|
} elseif {$binprelink == "NO"} {
|
572 |
|
|
set displacement "NONZERO"
|
573 |
|
|
} else {
|
574 |
|
|
set displacement "ZERO"
|
575 |
|
|
}
|
576 |
|
|
|
577 |
|
|
if {[prelink$binprelink $relink_args [file tail $exec]]
|
578 |
|
|
&& [file_copy $interp_saved $interp]} {
|
579 |
|
|
if {$binpie != "ATTACH"} {
|
580 |
|
|
test_ld $exec 1 [expr {$binsepdebug == "NO"}] $displacement
|
581 |
|
|
} else {
|
582 |
|
|
# If the file has been randomly prelinked it must
|
583 |
|
|
# be "NONZERO". We could see "ZERO" only if it was
|
584 |
|
|
# unprelinked and it is now running at the same
|
585 |
|
|
# address - which is 0 but executable can never run
|
586 |
|
|
# at address 0.
|
587 |
|
|
|
588 |
|
|
set displacement "NONZERO"
|
589 |
|
|
test_attach $exec $displacement $relink_args
|
590 |
|
|
|
591 |
|
|
# ATTACH means that executables and libraries have
|
592 |
|
|
# been modified after they have been run. They
|
593 |
|
|
# cannot be reused for problem reproducibility after
|
594 |
|
|
# the testcase ends in the ATTACH case. Therefore
|
595 |
|
|
# they are rather deleted not to confuse after the
|
596 |
|
|
# run finishes.
|
597 |
|
|
set exec_debug [system_debug_get $exec]
|
598 |
|
|
if {$exec_debug != ""} {
|
599 |
|
|
# `file delete [glob "${exec_debug}*"]' does not work.
|
600 |
|
|
foreach f [glob "${exec_debug}*"] {
|
601 |
|
|
file delete $f
|
602 |
|
|
}
|
603 |
|
|
}
|
604 |
|
|
file delete -force $dir
|
605 |
|
|
# `file delete [glob "${exec}*"]' does not work.
|
606 |
|
|
foreach f [glob "${exec}*"] {
|
607 |
|
|
file delete $f
|
608 |
|
|
}
|
609 |
|
|
}
|
610 |
|
|
}
|
611 |
|
|
}
|
612 |
|
|
}
|
613 |
|
|
}
|
614 |
|
|
|
615 |
|
|
file delete $interp_saved
|
616 |
|
|
}
|
617 |
|
|
}
|
618 |
|
|
set pf_prefix $old_ldprefix
|