forked from Imagelibrary/binutils-gdb
On SLE-11, with glibc 2.11.3, I run into:
...
(gdb) PASS: gdb.arch/amd64-disp-step-avx.exp: vex3: \
var128 has expected value after
continue^M
Continuing.^M
^M
Program received signal SIGSEGV, Segmentation fault.^M
0x0000000000400283 in _exit (status=0) at \
../sysdeps/unix/sysv/linux/_exit.c:33^M
33 ../sysdeps/unix/sysv/linux/_exit.c: No such file or directory.^M
(gdb) FAIL: gdb.arch/amd64-disp-step-avx.exp: \
continue until exit at amd64-disp-step-avx
...
This is not related to gdb, we get the same result by just running the exec.
The problem is that the test-case:
- calls glibc's _exit, and
- uses -nostartfiles -static, putting the burden for any necessary
initialization for calling glibc's _exit on the test-case itself.
So, when we get to the second insn in _exit:
...
000000000040acb0 <_exit>:
40acb0: 48 63 d7 movslq %edi,%rdx
40acb3: 64 4c 8b 14 25 00 00 mov %fs:0x0,%r10
...
no glibc-related initialization is done, and we run into the segfault.
Adding this (borrowed from __libc_start_main) in _start in the .S file is
sufficient to fix it:
...
.rept 200
nop
+ call __pthread_initialize_minimal
.endr
...
But that already doesn't compile with say glibc 2.31, and regardless I think
this sort of fix is too fragile.
We could of course fix this by simply not running to exit. But ideally we'd
have an exec that doesn't segfault when you just run it.
Alternatively, we could hand-code an _exit syscall and bypass glibc
all together. But I'd rather fix this in a way that simplifies the test-case.
Taking a step back, the -nostartfiles -static was added to address that the
xmm registers were not zero at main (which AFAICT is a valid thing to happen).
[ The change itself silently broke the test-case, needing further fixing by
commit 40310f30a5 ("gdb: make gdb.arch/amd64-disp-step-avx.exp actually test
displaced stepping"). ]
Instead, simplify things by reverting to the original situation:
- no -nostartfiles -static compilation flags,
- no _start in the .S file,
- use exit instead of _exit in the .S file,
and fix the original problem by setting the xmm registers to zero rather than
checking that they're zero.
Now that we're no longer forcing -static, add nopie to the flags to prevent
compilation failure with target board unix/-fPIE/-pie.
Tested on x86_64-linux.
PR testsuite/30132
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30132
145 lines
4.2 KiB
Plaintext
145 lines
4.2 KiB
Plaintext
# Copyright 2009-2023 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 file is part of the gdb testsuite.
|
|
|
|
# Test displaced stepping over VEX-encoded RIP-relative AVX
|
|
# instructions.
|
|
|
|
require is_x86_64_m64_target have_avx
|
|
|
|
standard_testfile .S
|
|
|
|
set options [list debug nopie]
|
|
if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} $options] } {
|
|
return -1
|
|
}
|
|
|
|
# Get things started.
|
|
|
|
gdb_test "set displaced-stepping on" ""
|
|
gdb_test "show displaced-stepping" ".* displaced stepping .* is on.*"
|
|
|
|
if {![runto_main]} {
|
|
return 0
|
|
}
|
|
|
|
# GDB picks a spare register from this list to hold the RIP-relative
|
|
# address.
|
|
set rip_regs { "rax" "rbx" "rcx" "rdx" "rbp" "rsi" "rdi" }
|
|
|
|
# Assign VAL to all the RIP_REGS.
|
|
|
|
proc set_regs { val } {
|
|
global gdb_prompt
|
|
global rip_regs
|
|
|
|
foreach reg ${rip_regs} {
|
|
gdb_test_no_output "set \$${reg} = ${val}"
|
|
}
|
|
}
|
|
|
|
# Verify all RIP_REGS print as HEX_VAL_RE in hex.
|
|
|
|
proc verify_regs { hex_val_re } {
|
|
global rip_regs
|
|
|
|
foreach reg ${rip_regs} {
|
|
gdb_test "p /x \$${reg}" " = ${hex_val_re}" "${reg} expected value"
|
|
}
|
|
}
|
|
|
|
# Set a break at FUNC, which starts with a RIP-relative instruction
|
|
# that we want to displaced-step over, and then continue over the
|
|
# breakpoint, forcing a displaced-stepping sequence.
|
|
|
|
proc disp_step_func { func } {
|
|
global srcfile
|
|
|
|
set test_start_label "${func}"
|
|
set test_end_label "${func}_end"
|
|
|
|
gdb_test "break ${test_start_label}" \
|
|
"Breakpoint.*at.* file .*$srcfile, line.*"
|
|
gdb_test "break ${test_end_label}" \
|
|
"Breakpoint.*at.* file .*$srcfile, line.*"
|
|
|
|
gdb_test "continue" \
|
|
"Continuing.*Breakpoint.*, ${test_start_label} ().*" \
|
|
"continue to ${test_start_label}"
|
|
|
|
# GDB picks a spare register to hold the RIP-relative address.
|
|
# Ensure the spare register value is restored properly (rax-rdi,
|
|
# sans rsp).
|
|
set value "0xdeadbeefd3adb33f"
|
|
set_regs $value
|
|
|
|
# Turn "debug displaced" on to make sure a displaced step is actually
|
|
# executed, not an inline step.
|
|
gdb_test_no_output "set debug displaced on"
|
|
|
|
gdb_test "continue" \
|
|
"Continuing.*prepared successfully .*Breakpoint.*, ${test_end_label} ().*" \
|
|
"continue to ${test_end_label}"
|
|
|
|
gdb_test_no_output "set debug displaced off"
|
|
|
|
verify_regs $value
|
|
}
|
|
|
|
# Test a VEX2-encoded RIP-relative instruction.
|
|
with_test_prefix "vex2" {
|
|
# Initialize all XMM registers to 0.
|
|
for {set i 0 } { $i < 16 } { incr i } {
|
|
gdb_test_no_output "set \$xmm${i}.uint128 = 0" \
|
|
"xmm${i} set to zero"
|
|
}
|
|
|
|
disp_step_func "test_rip_vex2"
|
|
|
|
# Confirm the instruction's expected side effects. It should have
|
|
# modified xmm0.
|
|
gdb_test "p /x \$xmm0.uint128" " = 0x1122334455667788" \
|
|
"xmm0 has expected value after"
|
|
|
|
# And all of the other XMM register should still be 0.
|
|
for {set i 1 } { $i < 16 } { incr i } {
|
|
gdb_test "p /x \$xmm${i}.uint128" " = 0x0" \
|
|
"xmm${i} has expected value after"
|
|
}
|
|
}
|
|
|
|
# Test a VEX3-encoded RIP-relative instruction.
|
|
with_test_prefix "vex3" {
|
|
# This case writes to the 'var128' variable. Confirm the
|
|
# variable's value is what we believe it is before the AVX
|
|
# instruction runs.
|
|
gdb_test "p /x (unsigned long long \[2\]) var128" \
|
|
" = \\{0xaa55aa55aa55aa55, 0x55aa55aa55aa55aa\\}" \
|
|
"var128 has expected value before"
|
|
|
|
# Run the AVX instruction.
|
|
disp_step_func "test_rip_vex3"
|
|
|
|
# Confirm the instruction's expected side effects. It should have
|
|
# modifed the 'var128' variable.
|
|
gdb_test "p /x (unsigned long long \[2\]) var128" \
|
|
" = \\{0x1122334455667788, 0x0\\}" \
|
|
"var128 has expected value after"
|
|
}
|
|
|
|
# Done, run program to exit.
|
|
gdb_continue_to_end "amd64-disp-step-avx"
|