diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp --- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp @@ -224,9 +224,13 @@ # if SANITIZER_LINUX && SANITIZER_X64 // See kernel arch/x86/kernel/fpu/signal.c for details. const auto *fpregs = static_cast(ctx)->uc_mcontext.fpregs; - if (fpregs->__glibc_reserved1[12] == FP_XSTATE_MAGIC1) - return reinterpret_cast(fpregs) + - fpregs->__glibc_reserved1[13] - static_cast(ctx); + // The member names differ across header versions, but the actual layout + // is always the same. So avoid using members, just use arithmetic. + const uint32_t *after_xmm = + reinterpret_cast(fpregs + 1) - 24; + if (after_xmm[12] == FP_XSTATE_MAGIC1) + return reinterpret_cast(fpregs) + after_xmm[13] - + static_cast(ctx); # endif return sizeof(ucontext_t); } diff --git a/compiler-rt/test/msan/Linux/signal_mcontext.cpp b/compiler-rt/test/msan/Linux/signal_mcontext.cpp --- a/compiler-rt/test/msan/Linux/signal_mcontext.cpp +++ b/compiler-rt/test/msan/Linux/signal_mcontext.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -12,7 +13,11 @@ #if defined(__x86_64__) auto *mctx = &static_cast(uctx)->uc_mcontext; if (auto *fpregs = mctx->fpregs) { - if (fpregs->__glibc_reserved1[12] == FP_XSTATE_MAGIC1) { + // The member names differ across header versions, but the actual layout + // is always the same. So avoid using members, just use arithmetic. + const uint32_t *after_xmm = + reinterpret_cast(fpregs + 1) - 24; + if (after_xmm[12] == FP_XSTATE_MAGIC1) { auto *xstate = reinterpret_cast<_xstate *>(mctx->fpregs); __msan_check_mem_is_initialized(xstate, sizeof(*xstate)); } diff --git a/compiler-rt/test/msan/Linux/signal_mcontext2.cpp b/compiler-rt/test/msan/Linux/signal_mcontext2.cpp --- a/compiler-rt/test/msan/Linux/signal_mcontext2.cpp +++ b/compiler-rt/test/msan/Linux/signal_mcontext2.cpp @@ -4,13 +4,18 @@ #include #include +#include #include void handler(int sig, siginfo_t *info, void *uctx) { volatile int uninit; auto *mctx = &static_cast(uctx)->uc_mcontext; auto *fpregs = mctx->fpregs; - if (fpregs && fpregs->__glibc_reserved1[12] == FP_XSTATE_MAGIC1) + // The member names differ across header versions, but the actual layout + // is always the same. So avoid using members, just use arithmetic. + const uint32_t *after_xmm = + reinterpret_cast(fpregs + 1) - 24; + if (after_xmm[12] == FP_XSTATE_MAGIC1) reinterpret_cast<_xstate *>(mctx->fpregs)->ymmh.ymmh_space[0] = uninit; else mctx->gregs[REG_RAX] = uninit;