llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libunwind

Author: Minsoo Choo (mchoo7)

<details>
<summary>Changes</summary>

fd4113508a64 (#<!-- -->229176) was merged without receiving review for 
non-FreeBSD platforms. Thus, revert it and ) (#<!-- -->235756) which is an 
Android build fix for fd4113508a64 (#<!-- -->229176).

Closes: #<!-- -->235599

---

Patch is 36.13 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/237222.diff


13 Files Affected:

- (modified) libunwind/include/__libunwind_config.h (+1-1) 
- (modified) libunwind/include/libunwind.h (-9) 
- (modified) libunwind/src/AddressSpace.hpp (+2-2) 
- (modified) libunwind/src/Registers.hpp (+7-92) 
- (modified) libunwind/src/UnwindCursor.hpp (-27) 
- (modified) libunwind/src/UnwindRegistersRestore.S (+7-62) 
- (modified) libunwind/src/UnwindRegistersSave.S (+5-57) 
- (modified) libunwind/src/assembly.h (-22) 
- (modified) libunwind/src/libunwind.cpp (-52) 
- (removed) libunwind/test/x86_64_dwarf_registers.pass.cpp (-59) 
- (removed) libunwind/test/x86_64_extended_registers.pass.cpp (-163) 
- (removed) libunwind/test/x86_64_getcontext_preserves_rbx.pass.cpp (-80) 
- (removed) libunwind/test/x86_64_resume_extended_registers.pass.cpp (-150) 


``````````diff
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 30a6e891bac5c1..60ab1bdc2cf757 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -17,7 +17,7 @@
 #endif
 
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86       8
-#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86_64    59
+#define _LIBUNWIND_HIGHEST_DWARF_REGISTER_X86_64    32
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC       112
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER_PPC64     116
 #define _LIBUNWIND_HIGHEST_DWARF_REGISTER_ARM64     95
diff --git a/libunwind/include/libunwind.h b/libunwind/include/libunwind.h
index 7c2f611e208923..6c2dfe58e53bf1 100644
--- a/libunwind/include/libunwind.h
+++ b/libunwind/include/libunwind.h
@@ -295,15 +295,6 @@ enum {
   UNW_X86_64_XMM13 = 30,
   UNW_X86_64_XMM14 = 31,
   UNW_X86_64_XMM15 = 32,
-  UNW_X86_64_RFLAGS = 49,
-  UNW_X86_64_ES = 50,
-  UNW_X86_64_CS = 51,
-  UNW_X86_64_SS = 52,
-  UNW_X86_64_DS = 53,
-  UNW_X86_64_FS = 54,
-  UNW_X86_64_GS = 55,
-  UNW_X86_64_FS_BASE = 58,
-  UNW_X86_64_GS_BASE = 59,
 };
 
 
diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index d446f6abd9578f..3711189f57b1d1 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -453,8 +453,8 @@ static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, 
size_t image_base,
 #endif
 }
 
-static inline int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo,
-                                           size_t pinfo_size, void *data) {
+static int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo,
+                                    size_t pinfo_size, void *data) {
   auto cbdata = static_cast<dl_iterate_cb_data *>(data);
   if (pinfo->dlpi_phnum == 0 || cbdata->targetAddr < pinfo->dlpi_addr)
     return 0;
diff --git a/libunwind/src/Registers.hpp b/libunwind/src/Registers.hpp
index 7b76708510beba..4870e315962e09 100644
--- a/libunwind/src/Registers.hpp
+++ b/libunwind/src/Registers.hpp
@@ -347,26 +347,14 @@ class _LIBUNWIND_HIDDEN Registers_x86_64 {
     uint64_t __r14;
     uint64_t __r15;
     uint64_t __rip;
-    // RFLAGS bits 32-63 are reserved. Pack the selectors with the low flags
-    // word so the complete segment state fits the existing context ABI.
-    uint32_t __rflags;
-    uint16_t __cs;
-    uint16_t __ss;
-    uint16_t __ds;
-    uint16_t __es;
-    uint16_t __fs;
-    uint16_t __gs;
-    uint64_t __fs_base;
-    uint64_t __gs_base;
+    uint64_t __rflags;
+    uint64_t __cs;
+    uint64_t __fs;
+    uint64_t __gs;
 #if defined(_WIN64)
     uint64_t __padding; // 16-byte align
 #endif
   };
-  static_assert(offsetof(GPRs, __rflags) == 136 &&
-                    offsetof(GPRs, __cs) == 140 &&
-                    offsetof(GPRs, __fs_base) == 152 &&
-                    offsetof(GPRs, __gs_base) == 160,
-                "x86_64 segment state must match the assembly offsets");
   GPRs _registers;
 #if defined(_WIN64)
   v128 _xmm[16];
@@ -390,19 +378,9 @@ inline bool Registers_x86_64::validRegister(int regNum) 
const {
     return true;
   if (regNum < 0)
     return false;
-  if (regNum <= UNW_X86_64_RIP)
-    return true;
-  if (regNum >= UNW_X86_64_RFLAGS && regNum <= UNW_X86_64_GS)
-    return true;
-  // Native base capture and restore need an OS interface. Cross unwinding
-  // can still represent bases recovered from DWARF on any host.
-#if (!defined(_LIBUNWIND_IS_BAREMETAL) &&                                      
\
-     (defined(__linux__) || defined(__FreeBSD__))) ||                          
\
-    !defined(_LIBUNWIND_IS_NATIVE_ONLY)
-  if (regNum == UNW_X86_64_FS_BASE || regNum == UNW_X86_64_GS_BASE)
-    return true;
-#endif
-  return false;
+  if (regNum > 16)
+    return false;
+  return true;
 }
 
 inline uint64_t Registers_x86_64::getRegister(int regNum) const {
@@ -444,24 +422,6 @@ inline uint64_t Registers_x86_64::getRegister(int regNum) 
const {
     return _registers.__r14;
   case UNW_X86_64_R15:
     return _registers.__r15;
-  case UNW_X86_64_RFLAGS:
-    return _registers.__rflags;
-  case UNW_X86_64_ES:
-    return _registers.__es;
-  case UNW_X86_64_CS:
-    return _registers.__cs;
-  case UNW_X86_64_SS:
-    return _registers.__ss;
-  case UNW_X86_64_DS:
-    return _registers.__ds;
-  case UNW_X86_64_FS:
-    return _registers.__fs;
-  case UNW_X86_64_GS:
-    return _registers.__gs;
-  case UNW_X86_64_FS_BASE:
-    return _registers.__fs_base;
-  case UNW_X86_64_GS_BASE:
-    return _registers.__gs_base;
   }
   _LIBUNWIND_ABORT("unsupported x86_64 register");
 }
@@ -523,33 +483,6 @@ inline void Registers_x86_64::setRegister(int regNum, 
uint64_t value) {
   case UNW_X86_64_R15:
     _registers.__r15 = value;
     return;
-  case UNW_X86_64_RFLAGS:
-    _registers.__rflags = static_cast<uint32_t>(value);
-    return;
-  case UNW_X86_64_ES:
-    _registers.__es = static_cast<uint16_t>(value);
-    return;
-  case UNW_X86_64_CS:
-    _registers.__cs = static_cast<uint16_t>(value);
-    return;
-  case UNW_X86_64_SS:
-    _registers.__ss = static_cast<uint16_t>(value);
-    return;
-  case UNW_X86_64_DS:
-    _registers.__ds = static_cast<uint16_t>(value);
-    return;
-  case UNW_X86_64_FS:
-    _registers.__fs = static_cast<uint16_t>(value);
-    return;
-  case UNW_X86_64_GS:
-    _registers.__gs = static_cast<uint16_t>(value);
-    return;
-  case UNW_X86_64_FS_BASE:
-    _registers.__fs_base = value;
-    return;
-  case UNW_X86_64_GS_BASE:
-    _registers.__gs_base = value;
-    return;
   }
   _LIBUNWIND_ABORT("unsupported x86_64 register");
 }
@@ -593,24 +526,6 @@ inline const char *Registers_x86_64::getRegisterName(int 
regNum) {
     return "r14";
   case UNW_X86_64_R15:
     return "r15";
-  case UNW_X86_64_RFLAGS:
-    return "rflags";
-  case UNW_X86_64_ES:
-    return "es";
-  case UNW_X86_64_CS:
-    return "cs";
-  case UNW_X86_64_SS:
-    return "ss";
-  case UNW_X86_64_DS:
-    return "ds";
-  case UNW_X86_64_FS:
-    return "fs";
-  case UNW_X86_64_GS:
-    return "gs";
-  case UNW_X86_64_FS_BASE:
-    return "fs.base";
-  case UNW_X86_64_GS_BASE:
-    return "gs.base";
   case UNW_X86_64_XMM0:
     return "xmm0";
   case UNW_X86_64_XMM1:
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 362738d8274491..dfd5b2b19e1b48 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -632,7 +632,6 @@ UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A 
&as)
   RtlCaptureContext(&_msContext);
   _msContext.ContextFlags = 
CONTEXT_CONTROL|CONTEXT_INTEGER|CONTEXT_FLOATING_POINT;
 #if defined(_LIBUNWIND_TARGET_X86_64)
-  _msContext.ContextFlags |= CONTEXT_SEGMENTS;
   _msContext.Rax = r.getRegister(UNW_X86_64_RAX);
   _msContext.Rcx = r.getRegister(UNW_X86_64_RCX);
   _msContext.Rdx = r.getRegister(UNW_X86_64_RDX);
@@ -650,17 +649,6 @@ UnwindCursor<A, R>::UnwindCursor(unw_context_t *context, A 
&as)
   _msContext.R14 = r.getRegister(UNW_X86_64_R14);
   _msContext.R15 = r.getRegister(UNW_X86_64_R15);
   _msContext.Rip = r.getRegister(UNW_REG_IP);
-  // ARM64EC getcontext leaves these fields zero. Keep the values supplied by
-  // RtlCaptureContext instead of replacing them with uncaptured x86 state.
-#if !defined(__arm64ec__)
-  _msContext.EFlags = static_cast<DWORD>(r.getRegister(UNW_X86_64_RFLAGS));
-  _msContext.SegEs = static_cast<WORD>(r.getRegister(UNW_X86_64_ES));
-  _msContext.SegCs = static_cast<WORD>(r.getRegister(UNW_X86_64_CS));
-  _msContext.SegSs = static_cast<WORD>(r.getRegister(UNW_X86_64_SS));
-  _msContext.SegDs = static_cast<WORD>(r.getRegister(UNW_X86_64_DS));
-  _msContext.SegFs = static_cast<WORD>(r.getRegister(UNW_X86_64_FS));
-  _msContext.SegGs = static_cast<WORD>(r.getRegister(UNW_X86_64_GS));
-#endif
   union {
     v128 v;
     M128A m;
@@ -751,7 +739,6 @@ bool UnwindCursor<A, R>::validReg(int regNum) {
   if (regNum == UNW_REG_IP || regNum == UNW_REG_SP) return true;
 #if defined(_LIBUNWIND_TARGET_X86_64)
   if (regNum >= UNW_X86_64_RAX && regNum <= UNW_X86_64_RIP) return true;
-  if (regNum >= UNW_X86_64_RFLAGS && regNum <= UNW_X86_64_GS) return true;
 #elif defined(_LIBUNWIND_TARGET_ARM)
   if ((regNum >= UNW_ARM_R0 && regNum <= UNW_ARM_R15) ||
       regNum == UNW_ARM_RA_AUTH_CODE)
@@ -785,13 +772,6 @@ unw_word_t UnwindCursor<A, R>::getReg(int regNum) {
   case UNW_X86_64_R13: return _msContext.R13;
   case UNW_X86_64_R14: return _msContext.R14;
   case UNW_X86_64_R15: return _msContext.R15;
-  case UNW_X86_64_RFLAGS: return _msContext.EFlags;
-  case UNW_X86_64_ES: return _msContext.SegEs;
-  case UNW_X86_64_CS: return _msContext.SegCs;
-  case UNW_X86_64_SS: return _msContext.SegSs;
-  case UNW_X86_64_DS: return _msContext.SegDs;
-  case UNW_X86_64_FS: return _msContext.SegFs;
-  case UNW_X86_64_GS: return _msContext.SegGs;
 #elif defined(_LIBUNWIND_TARGET_ARM)
   case UNW_ARM_R0: return _msContext.R0;
   case UNW_ARM_R1: return _msContext.R1;
@@ -843,13 +823,6 @@ void UnwindCursor<A, R>::setReg(int regNum, unw_word_t 
value) {
   case UNW_X86_64_R13: _msContext.R13 = value; break;
   case UNW_X86_64_R14: _msContext.R14 = value; break;
   case UNW_X86_64_R15: _msContext.R15 = value; break;
-  case UNW_X86_64_RFLAGS: _msContext.EFlags = static_cast<DWORD>(value); break;
-  case UNW_X86_64_ES: _msContext.SegEs = static_cast<WORD>(value); break;
-  case UNW_X86_64_CS: _msContext.SegCs = static_cast<WORD>(value); break;
-  case UNW_X86_64_SS: _msContext.SegSs = static_cast<WORD>(value); break;
-  case UNW_X86_64_DS: _msContext.SegDs = static_cast<WORD>(value); break;
-  case UNW_X86_64_FS: _msContext.SegFs = static_cast<WORD>(value); break;
-  case UNW_X86_64_GS: _msContext.SegGs = static_cast<WORD>(value); break;
 #elif defined(_LIBUNWIND_TARGET_ARM)
   case UNW_ARM_R0: _msContext.R0 = value; break;
   case UNW_ARM_R1: _msContext.R1 = value; break;
diff --git a/libunwind/src/UnwindRegistersRestore.S 
b/libunwind/src/UnwindRegistersRestore.S
index 5a99bfa5aec431..6c9dcc48c309ad 100644
--- a/libunwind/src/UnwindRegistersRestore.S
+++ b/libunwind/src/UnwindRegistersRestore.S
@@ -72,10 +72,7 @@ DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
   # skip fs
   # skip gs
 
-// Native FreeBSD restores selectors and bases together through sigreturn in
-// libunwind.cpp; its sysarch base setters also replace the segment selectors.
-#elif defined(__x86_64__) && !defined(__arm64ec__) && \
-    (!defined(__FreeBSD__) || defined(_LIBUNWIND_IS_BAREMETAL))
+#elif defined(__x86_64__) && !defined(__arm64ec__)
 .att_syntax
 
 DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
@@ -101,57 +98,6 @@ 
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
   movq  %rbx, 0(%rax)
   movq  128(%rdi), %rbx # store new rip on new stack
   movq  %rbx, 8(%rax)
-  # Segment selectors are 16 bits. In particular, do not reload unchanged
-  # FS/GS selectors: doing so can clear their hidden base addresses.
-  movw  %fs,%ax
-  cmpw  148(%rdi),%ax
-  je    1f
-  movw  148(%rdi),%fs
-1:
-  movw  %gs,%ax
-  cmpw  150(%rdi),%ax
-  je    2f
-  movw  150(%rdi),%gs
-2:
-  movw  146(%rdi),%es
-  movw  142(%rdi),%ss
-  movw  144(%rdi),%ds
-  movw  %cs,%ax
-  cmpw  140(%rdi),%ax
-  je    3f
-  # An indirect far jump changes CS without consuming a shadow-stack entry.
-  movzwq 140(%rdi),%rax
-  pushq %rax
-  leaq  3f(%rip),%rax
-  pushq %rax
-  rex64 ljmp *(%rsp)
-3:
-  _LIBUNWIND_CET_ENDBR
-  # The far-jump path used a temporary 16-byte far pointer on the old stack.
-  # The old stack is discarded below.
-
-#if defined(X86_64_BASE_SYSCALL)
-  movq  %rdi,%r8
-  movq  $X86_64_BASE_SYSCALL,%rax
-  movq  $X86_64_SET_FSBASE,%rdi
-  movq  152(%r8),%rsi
-  syscall
-  testq %rax,%rax
-  js    9f
-  movq  $X86_64_BASE_SYSCALL,%rax
-  movq  $X86_64_SET_GSBASE,%rdi
-  movq  160(%r8),%rsi
-  syscall
-  testq %rax,%rax
-  js    9f
-  movq  %r8,%rdi
-#endif
-
-  # Restore flags after all arithmetic, comparisons, and syscalls. The upper
-  # half of the packed flags word contains selectors, so zero-extend it first.
-  movl  136(%rdi),%eax
-  pushq %rax
-  popfq
   # restore all registers
   movq    0(%rdi), %rax
   movq    8(%rdi), %rbx
@@ -172,6 +118,10 @@ 
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
   movq  112(%rdi), %r14
   movq  120(%rdi), %r15
 #endif
+  # skip rflags
+  # skip cs
+  # skip fs
+  # skip gs
 
 #if defined(_WIN64)
   movdqu 176(%rdi),%xmm0
@@ -193,13 +143,8 @@ 
DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
 #endif
   movq  56(%rdi), %rsp  # cut back rsp to new location
   pop    %rdi      # rdi was saved here earlier
-  leaq   8(%rsp),%rsp
-  jmpq   *-8(%rsp)
-#if defined(X86_64_BASE_SYSCALL)
-9:
-  # A failed base restore cannot safely resume with a different TLS base.
-  ud2
-#endif
+  pop    %rcx
+  jmpq   *%rcx
 
 
 #elif defined(__powerpc64__)
diff --git a/libunwind/src/UnwindRegistersSave.S 
b/libunwind/src/UnwindRegistersSave.S
index faea60ad55e051..81d32009952895 100644
--- a/libunwind/src/UnwindRegistersSave.S
+++ b/libunwind/src/UnwindRegistersSave.S
@@ -91,8 +91,6 @@ DEFINE_LIBUNWIND_FUNCTION("#__unw_getcontext")
   stp    x19,x20, [x0, #0x060]  // r12, r13
   stp    x21,x22, [x0, #0x070]  // r14, r15
   str    x30,     [x0, #0x080]  // store return address as pc
-  stp    xzr,xzr, [x0, #0x088]  // flags and segment selectors
-  stp    xzr,xzr, [x0, #0x098]  // fs.base, gs.base
   stp    q0, q1,  [x0, #0x0b0]  // xmm0, xmm1
   stp    q2, q3,  [x0, #0x0d0]  // xmm2, xmm3
   stp    q4, q5,  [x0, #0x0f0]  // xmm4, xmm5
@@ -126,11 +124,9 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
 #if defined(_WIN64)
 #define PTR %rcx
 #define TMP %rdx
-#define TMP32 %edx
 #else
 #define PTR %rdi
 #define TMP %rsi
-#define TMP32 %esi
 #endif
 
   _LIBUNWIND_CET_ENDBR
@@ -142,6 +138,7 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
   movq  %rsi, 40(PTR)
   movq  %rbp, 48(PTR)
   movq  %rsp, 56(PTR)
+  addq  $8,   56(PTR)
   movq  %r8,  64(PTR)
   movq  %r9,  72(PTR)
   movq  %r10, 80(PTR)
@@ -155,53 +152,10 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
 #endif
   movq  (%rsp),TMP
   movq  TMP,128(PTR) # store return address as rip
-  # Capture flags before any instruction that changes them.
-  pushfq
-  popq  TMP
-  movl  TMP32,136(PTR)
-  leaq  8(%rsp),TMP
-  movq  TMP,56(PTR) # store what sp was at call site as rsp
-  movw  %cs,140(PTR)
-  movw  %fs,148(PTR)
-  movw  %gs,150(PTR)
-  movw  %es,146(PTR)
-  movw  %ss,142(PTR)
-  movw  %ds,144(PTR)
-  movq  $0,152(PTR)
-  movq  $0,160(PTR)
-
-#if defined(X86_64_BASE_SYSCALL)
-  # Use syscalls rather than FSGSBASE instructions, which require both CPU
-  # support and OS enablement. All syscall-clobbered registers are saved above.
-  # FreeBSD may clear r8-r10 on syscall return. Keep the context pointer in
-  # the callee-saved rbx, preserving its value for our caller as well.
-  pushq %rbx
-  movq  PTR,%rbx
-  movq  $X86_64_BASE_SYSCALL,%rax
-  movq  $X86_64_GET_FSBASE,%rdi
-  leaq  152(%rbx),%rsi
-  syscall
-  # FreeBSD reports errors in CF with a positive errno in rax; Linux returns
-  # a negative errno in rax. Check the appropriate convention after each call.
-#if defined(__FreeBSD__)
-  jc    9f
-#else
-  testq %rax,%rax
-  js    9f
-#endif
-  movq  $X86_64_BASE_SYSCALL,%rax
-  movq  $X86_64_GET_GSBASE,%rdi
-  leaq  160(%rbx),%rsi
-  syscall
-#if defined(__FreeBSD__)
-  jc    9f
-#else
-  testq %rax,%rax
-  js    9f
-#endif
-  movq  %rbx,PTR
-  popq  %rbx
-#endif
+  # skip rflags
+  # skip cs
+  # skip fs
+  # skip gs
 
 #if defined(_WIN64)
   movdqu %xmm0,176(PTR)
@@ -223,12 +177,6 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
 #endif
   xorl  %eax, %eax    # return UNW_ESUCCESS
   ret
-#if defined(X86_64_BASE_SYSCALL)
-9:
-  popq %rbx
-  movl $-6540,%eax # UNW_EUNSPEC: segment base capture failed
-  ret
-#endif
 
 #elif defined(__mips__) && defined(_ABIO32) && _MIPS_SIM == _ABIO32
 
diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h
index cb6a06c53ac19f..84c9d526f1d759 100644
--- a/libunwind/src/assembly.h
+++ b/libunwind/src/assembly.h
@@ -15,28 +15,6 @@
 #ifndef UNWIND_ASSEMBLY_H
 #define UNWIND_ASSEMBLY_H
 
-#if defined(__x86_64__) && !defined(_LIBUNWIND_IS_BAREMETAL) &&                
\
-    (defined(__linux__) || defined(__FreeBSD__))
-#if defined(__linux__)
-// Use the kernel UAPI headers, which are safe to include from assembly. The
-// libc <sys/syscall.h> is not: on Android it pulls in <sys/cdefs.h> and
-// <android/api-level.h>, which contain C declarations.
-#include <asm/prctl.h>
-#include <asm/unistd.h>
-#define X86_64_GET_FSBASE ARCH_GET_FS
-#define X86_64_GET_GSBASE ARCH_GET_GS
-#define X86_64_SET_FSBASE ARCH_SET_FS
-#define X86_64_SET_GSBASE ARCH_SET_GS
-#define X86_64_BASE_SYSCALL __NR_arch_prctl
-#else
-#include <sys/syscall.h>
-// <machine/sysarch.h> contains C declarations and cannot be included here.
-#define X86_64_GET_FSBASE 128 // AMD64_GET_FSBASE
-#define X86_64_GET_GSBASE 130 // AMD64_GET_GSBASE
-#define X86_64_BASE_SYSCALL SYS_sysarch
-#endif
-#endif
-
 #if defined(__CET__)
 #include <cet.h>
 #define _LIBUNWIND_CET_ENDBR _CET_ENDBR
diff --git a/libunwind/src/libunwind.cpp b/libunwind/src/libunwind.cpp
index 29364a0fe2818f..0b9d56ec805bca 100644
--- a/libunwind/src/libunwind.cpp
+++ b/libunwind/src/libunwind.cpp
@@ -16,12 +16,6 @@
 
 #include <stdlib.h>
 
-#if defined(__FreeBSD__) && defined(__x86_64__) &&                             
\
-    !defined(_LIBUNWIND_IS_BAREMETAL)
-#include <signal.h>
-#include <ucontext.h>
-#endif
-
 // Define the __has_feature extension for compilers that do not support it so
 // that we can later check for the presence of ASan in a compiler-neutral way.
 #if !defined(__has_feature)
@@ -38,52 +32,6 @@
 
 using namespace libunwind;
 
-#if defined(__FreeBSD__) && defined(__x86_64__) &&                             
\
-    !defined(_LIBUNWIND_IS_BAREMETAL)
-// Changing FS/GS selectors can clear their bases, while sysarch base setters
-// replace the selectors. Let sigreturn restore the complete state atomically.
-// use sigreturn() over setcontext() as setcontext() intentionally leaves CS
-// unchanged.
-extern "C" _LIBUNWIND_HIDDEN void
-__libunwind_Registers_x86_64_jumpto(Registers_x86_64 *registers) {
-  ucontext_t context;
-  if (getcontext(&context) != 0)
-    _LIBUNWIND_ABORT("getcontext failed");
-  mcontext_t &mc = context.uc_mcontext;
-#define RESTORE(reg, field) mc.field = registers->getRegister(UNW_X86_64_##reg)
-  RESTORE(RAX, mc_rax);
-  RESTORE(RBX, mc_rbx);
-  RESTORE(RCX, mc_rcx);
-  RESTORE(RDX, mc_rdx);
-  RESTORE(RDI, mc_rdi);
-  RESTORE(RSI, mc_rsi);
-  RESTORE(RBP, mc_rbp);
-  RESTORE(RSP, mc_rsp);
-  RESTORE(R8, mc_r8);
-  RESTORE(R9, mc_r9);
-  RESTORE(R10, mc_r10);
-  RESTORE(R11, mc_r11);
-  RESTORE(R12, mc_r12);
-  RESTORE(R13, mc_r13);
-  RESTORE(R14, mc_r14);
-  RESTORE(R15, mc_r15);
-  RESTORE(RIP, mc_rip);
-  RESTORE(RFLAGS, mc_rflags);
-  RESTORE(CS, mc_cs);
-  RESTORE(SS, mc_ss);
-  RESTORE(DS, mc_ds);
-  RESTORE(ES, mc_es);
-  RESTORE(FS, mc_fs);
-  RESTORE(GS, mc_gs);
-  RESTORE(FS_BASE, mc_fsbase);
-  RESTORE(GS_BASE, mc_gsbase);
-#undef RESTORE
-  mc.mc_flags |= _MC_HASSEGS | _MC_HASBASES;
-  sigreturn(&context);
-  _LIBUNWIND_ABORT("sigreturn failed");
-}
-#endif
-
 /// internal object to represent this process's address space
 LocalAddressSpace LocalAddressSpace::sThisAddressSpace;
 
diff --git a/libunwind/test/x86_64_dwarf_registers.pass.cpp 
b/libunwind/test/x86_64_dwarf_registers.pass.cpp
deleted file mode 100644
index 23ad6aad2d5721..00000000000000
--- a/libunwind/test/x86_64_dwarf_registers.pass.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// REQUIRES: target={{x86_64-.+}}
-// UNSUPPORTED: target={{.*-windows.*}}
-// ADDITIONAL_COMPILE_FLAGS: -D_LIBUNWIND_IS_NATIVE_ONLY
-
-// Disable internal tracing, which depends on private library symbols.
-#ifndef NDEBUG
-#define NDEBUG
-#endif
-#include "../src/AddressSpace.hpp"
-#include "../src/DwarfParser.hpp"
-#undef NDEBUG
-#include <assert.h>
-
-using namespace libunwind;
-
-int main(int, char **) {
-  using Parser = CFI_Parser<LocalAddressSpace>;
-  Lo...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/237222
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to