summaryrefslogtreecommitdiff
path: root/gdb/amd64-linux-nat.c
diff options
context:
space:
mode:
authorTom de Vries <tdevries@suse.de>2019-09-24 23:38:49 +0200
committerTom de Vries <tdevries@suse.de>2019-09-24 23:38:49 +0200
commit3d4352200e3e98a6d8855e6f3a39b6d33d84e36b (patch)
treeb125a52bc79b11576a7a16a5232536e804504f91 /gdb/amd64-linux-nat.c
parente8f8842d90abe5eafa8c32f08fbc3a747a45747c (diff)
downloadbinutils-gdb-3d4352200e3e98a6d8855e6f3a39b6d33d84e36b.tar.gz
[gdb/tdep] Handle mxcsr kernel bug on Intel Skylake CPUs
On my openSUSE Leap 15.1 x86_64 Skylake system with the default (4.12) kernel, I run into: ... FAIL: gdb.base/gcore.exp: corefile restored all registers ... The problem is that there's a difference in the mxcsr register value before and after the gcore command: ... - mxcsr 0x0 [ ] + mxcsr 0x400440 [ DAZ OM ] ... This can be traced back to amd64_linux_nat_target::fetch_registers, where xstateregs is partially initialized by the ptrace call: ... char xstateregs[X86_XSTATE_MAX_SIZE]; struct iovec iov; amd64_collect_xsave (regcache, -1, xstateregs, 0); iov.iov_base = xstateregs; iov.iov_len = sizeof (xstateregs); if (ptrace (PTRACE_GETREGSET, tid, (unsigned int) NT_X86_XSTATE, (long) &iov) < 0) perror_with_name (_("Couldn't get extended state status")); amd64_supply_xsave (regcache, -1, xstateregs); ... after which amd64_supply_xsave is called. The amd64_supply_xsave call is supposed to only use initialized parts of xstateregs, but due to a kernel bug on intel skylake (fixed from 4.14 onwards by commit 0852b374173b "x86/fpu: Add FPU state copying quirk to handle XRSTOR failure on Intel Skylake CPUs") it can happen that the mxcsr part of xstateregs is not initialized, while amd64_supply_xsave expects it to be initialized, which explains the FAIL mentioned above. Fix the undetermined behaviour by initializing xstateregs before calling ptrace, which makes sure we get a 0x0 for mxcsr when this kernel bug occurs, and which also happens to fix the FAIL. Furthermore, add an xfail for this FAIL which triggers the same kernel bug: ... FAIL: gdb.arch/amd64-init-x87-values.exp: check_setting_mxcsr_before_enable: \ check new value of MXCSR is still in place ... Both FAILs pass when using a 5.3 kernel instead on the system mentioned above. Tested on x86_64-linux. gdb/ChangeLog: 2019-09-24 Tom de Vries <tdevries@suse.de> PR gdb/23815 * amd64-linux-nat.c (amd64_linux_nat_target::fetch_registers): Initialize xstateregs before ptrace PTRACE_GETREGSET call. gdb/testsuite/ChangeLog: 2019-09-24 Tom de Vries <tdevries@suse.de> PR gdb/24598 * gdb.arch/amd64-init-x87-values.exp: Add xfail.
Diffstat (limited to 'gdb/amd64-linux-nat.c')
-rw-r--r--gdb/amd64-linux-nat.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c
index 4f1c98a0d1e..d0328b677d5 100644
--- a/gdb/amd64-linux-nat.c
+++ b/gdb/amd64-linux-nat.c
@@ -238,6 +238,12 @@ amd64_linux_nat_target::fetch_registers (struct regcache *regcache, int regnum)
char xstateregs[X86_XSTATE_MAX_SIZE];
struct iovec iov;
+ /* Pre-4.14 kernels have a bug (fixed by commit 0852b374173b
+ "x86/fpu: Add FPU state copying quirk to handle XRSTOR failure on
+ Intel Skylake CPUs") that sometimes causes the mxcsr location in
+ xstateregs not to be copied by PTRACE_GETREGSET. Make sure that
+ the location is at least initialized with a defined value. */
+ memset (xstateregs, 0, sizeof (xstateregs));
iov.iov_base = xstateregs;
iov.iov_len = sizeof (xstateregs);
if (ptrace (PTRACE_GETREGSET, tid,