[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Ed Maste via cfe-commits

https://github.com/emaste created 
https://github.com/llvm/llvm-project/pull/86658

As discussed in #86320; opening this PR for CI.

It looks like (prior to this change) there are no C++26 jobs right now.

>From 6cf1345feee41ec3bad51ba853091e35723c85ab Mon Sep 17 00:00:00 2001
From: Dmitry Chagin 
Date: Thu, 12 Oct 2023 16:02:06 +0300
Subject: [PATCH 1/2] [libunwind] Unwind through aarch64/FreeBSD sigreturn
 frame

Similar to D90898 (Linux Aarch64).

Differential Revision: https://reviews.llvm.org/D155066
---
 libunwind/include/__libunwind_config.h |  5 ++
 libunwind/src/UnwindCursor.hpp | 85 --
 2 files changed, 84 insertions(+), 6 deletions(-)

diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..783a488d7de0fd 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -39,6 +39,9 @@
 # if defined(__HAIKU__)
 #  define _LIBUNWIND_TARGET_HAIKU 1
 # endif
+#if defined(__FreeBSD__)
+#define _LIBUNWIND_TARGET_FREEBSD 1
+#endif
 # if defined(__i386__)
 #  define _LIBUNWIND_TARGET_I386
 #  define _LIBUNWIND_CONTEXT_SIZE 8
@@ -73,6 +76,8 @@
 #  define _LIBUNWIND_CONTEXT_SIZE 66
 #  if defined(__SEH__)
 #define _LIBUNWIND_CURSOR_SIZE 164
+#elif defined(_LIBUNWIND_TARGET_FREEBSD)
+#define _LIBUNWIND_CURSOR_SIZE 80
 #  else
 #define _LIBUNWIND_CURSOR_SIZE 78
 #  endif
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 7753936a5894a3..96d82d6aac7c93 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -39,6 +39,17 @@
 #include 
 #include 
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
+#define _LIBUNWIND_CHECK_SIGRETURN 1
+#endif
+
+#if defined(_LIBUNWIND_TARGET_FREEBSD) && defined(_LIBUNWIND_TARGET_AARCH64)
+#include 
+#include 
+#include 
+#include 
+#include 
+#define _LIBUNWIND_CHECK_FREEBSD_SIGRETURN 1
+#define _LIBUNWIND_CHECK_SIGRETURN 1
 #endif
 
 #include "AddressSpace.hpp"
@@ -983,7 +994,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   }
 #endif
 
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   bool setInfoForSigReturn() {
 R dummy;
 return setInfoForSigReturn(dummy);
@@ -1011,7 +1022,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   template  int stepThroughSigReturn(Registers &) {
 return UNW_STEP_END;
   }
-#endif
+#endif // defined(_LIBUNWIND_CHECK_SIGRETURN)
 
 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
   bool getInfoFromFdeCie(const typename CFI_Parser::FDE_Info &fdeInfo,
@@ -1314,9 +1325,14 @@ class UnwindCursor : public AbstractUnwindCursor{
   unw_proc_info_t  _info;
   bool _unwindInfoMissing;
   bool _isSignalFrame;
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   bool _isSigReturn = false;
+#if defined(_LIBUNWIND_CHECK_FREEBSD_SIGRETURN)
+  bool _isSigTrampDetermined = false;
+  pint_t _sigTrampStart;
+  pint_t _sigTrampEnd;
 #endif
+#endif // defined(_LIBUNWIND_CHECK_SIGRETURN)
 };
 
 
@@ -2558,7 +2574,7 @@ int UnwindCursor::stepWithTBTable(pint_t pc, 
tbtable *TBTable,
 
 template 
 void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) {
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   _isSigReturn = false;
 #endif
 
@@ -2673,7 +2689,7 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool 
isReturnAddress) {
   }
 #endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   if (setInfoForSigReturn())
 return;
 #endif
@@ -2909,6 +2925,63 @@ int UnwindCursor::stepThroughSigReturn(Registers_s390x &) {
 #endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&
// defined(_LIBUNWIND_TARGET_S390X)
 
+#if defined(_LIBUNWIND_CHECK_FREEBSD_SIGRETURN) && 
\
+defined(_LIBUNWIND_TARGET_AARCH64)
+template 
+bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) {
+  // Look for the sigreturn trampoline.
+  //
+  // https://cgit.freebsd.org/src/tree/sys/arm64/arm64/sigtramp.S
+  const pint_t pc = static_cast(this->getReg(UNW_REG_IP));
+
+  if (_isSigTrampDetermined == false) {
+struct kinfo_sigtramp kst = {0};
+size_t len = sizeof(kst);
+int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_SIGTRAMP, getpid()};
+if (sysctl(mib, 4, &kst, &len, NULL, 0) == 0) {
+  _isSigTrampDetermined = true;
+  _sigTrampStart = reinterpret_cast(kst.ksigtramp_start);
+  _sigTrampEnd = reinterpret_cast(kst.ksigtramp_end);
+}
+  }
+
+  if (_isSigTrampDetermined == false ||
+  (pc < _sigTrampStart || pc >= _sigTrampEnd))
+return false;
+
+  _info = {};
+  _info.start_ip = _sigTrampStart;
+  _info.end_ip = _sigTrampEnd;
+  _isSigReturn = true;
+  return true;
+}
+
+template 
+int UnwindCursor::stepThroughSigReturn(Registers_arm64 &) {
+  // In the signal trampoline 

[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: Ed Maste (emaste)


Changes

As discussed in #86320; opening this PR for CI.

It looks like (prior to this change) there are no C++26 jobs right now.

---
Full diff: https://github.com/llvm/llvm-project/pull/86658.diff


3 Files Affected:

- (modified) libcxx/utils/ci/buildkite-pipeline.yml (+1-1) 
- (modified) libunwind/include/__libunwind_config.h (+5) 
- (modified) libunwind/src/UnwindCursor.hpp (+79-6) 


``diff
diff --git a/libcxx/utils/ci/buildkite-pipeline.yml 
b/libcxx/utils/ci/buildkite-pipeline.yml
index 31e794e67d330d..c43e414418729a 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -207,7 +207,7 @@ steps:
 - group: ':freebsd: FreeBSD'
   steps:
   - label: FreeBSD 13 amd64
-command: libcxx/utils/ci/run-buildbot generic-cxx23
+command: libcxx/utils/ci/run-buildbot generic-cxx26
 env:
   CC: clang17
   CXX: clang++17
diff --git a/libunwind/include/__libunwind_config.h 
b/libunwind/include/__libunwind_config.h
index 8db336b2d727ce..783a488d7de0fd 100644
--- a/libunwind/include/__libunwind_config.h
+++ b/libunwind/include/__libunwind_config.h
@@ -39,6 +39,9 @@
 # if defined(__HAIKU__)
 #  define _LIBUNWIND_TARGET_HAIKU 1
 # endif
+#if defined(__FreeBSD__)
+#define _LIBUNWIND_TARGET_FREEBSD 1
+#endif
 # if defined(__i386__)
 #  define _LIBUNWIND_TARGET_I386
 #  define _LIBUNWIND_CONTEXT_SIZE 8
@@ -73,6 +76,8 @@
 #  define _LIBUNWIND_CONTEXT_SIZE 66
 #  if defined(__SEH__)
 #define _LIBUNWIND_CURSOR_SIZE 164
+#elif defined(_LIBUNWIND_TARGET_FREEBSD)
+#define _LIBUNWIND_CURSOR_SIZE 80
 #  else
 #define _LIBUNWIND_CURSOR_SIZE 78
 #  endif
diff --git a/libunwind/src/UnwindCursor.hpp b/libunwind/src/UnwindCursor.hpp
index 7753936a5894a3..96d82d6aac7c93 100644
--- a/libunwind/src/UnwindCursor.hpp
+++ b/libunwind/src/UnwindCursor.hpp
@@ -39,6 +39,17 @@
 #include 
 #include 
 #define _LIBUNWIND_CHECK_LINUX_SIGRETURN 1
+#define _LIBUNWIND_CHECK_SIGRETURN 1
+#endif
+
+#if defined(_LIBUNWIND_TARGET_FREEBSD) && defined(_LIBUNWIND_TARGET_AARCH64)
+#include 
+#include 
+#include 
+#include 
+#include 
+#define _LIBUNWIND_CHECK_FREEBSD_SIGRETURN 1
+#define _LIBUNWIND_CHECK_SIGRETURN 1
 #endif
 
 #include "AddressSpace.hpp"
@@ -983,7 +994,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   }
 #endif
 
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   bool setInfoForSigReturn() {
 R dummy;
 return setInfoForSigReturn(dummy);
@@ -1011,7 +1022,7 @@ class UnwindCursor : public AbstractUnwindCursor{
   template  int stepThroughSigReturn(Registers &) {
 return UNW_STEP_END;
   }
-#endif
+#endif // defined(_LIBUNWIND_CHECK_SIGRETURN)
 
 #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
   bool getInfoFromFdeCie(const typename CFI_Parser::FDE_Info &fdeInfo,
@@ -1314,9 +1325,14 @@ class UnwindCursor : public AbstractUnwindCursor{
   unw_proc_info_t  _info;
   bool _unwindInfoMissing;
   bool _isSignalFrame;
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   bool _isSigReturn = false;
+#if defined(_LIBUNWIND_CHECK_FREEBSD_SIGRETURN)
+  bool _isSigTrampDetermined = false;
+  pint_t _sigTrampStart;
+  pint_t _sigTrampEnd;
 #endif
+#endif // defined(_LIBUNWIND_CHECK_SIGRETURN)
 };
 
 
@@ -2558,7 +2574,7 @@ int UnwindCursor::stepWithTBTable(pint_t pc, 
tbtable *TBTable,
 
 template 
 void UnwindCursor::setInfoBasedOnIPRegister(bool isReturnAddress) {
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   _isSigReturn = false;
 #endif
 
@@ -2673,7 +2689,7 @@ void UnwindCursor::setInfoBasedOnIPRegister(bool 
isReturnAddress) {
   }
 #endif // #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
 
-#if defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN)
+#if defined(_LIBUNWIND_CHECK_SIGRETURN)
   if (setInfoForSigReturn())
 return;
 #endif
@@ -2909,6 +2925,63 @@ int UnwindCursor::stepThroughSigReturn(Registers_s390x &) {
 #endif // defined(_LIBUNWIND_CHECK_LINUX_SIGRETURN) &&
// defined(_LIBUNWIND_TARGET_S390X)
 
+#if defined(_LIBUNWIND_CHECK_FREEBSD_SIGRETURN) && 
\
+defined(_LIBUNWIND_TARGET_AARCH64)
+template 
+bool UnwindCursor::setInfoForSigReturn(Registers_arm64 &) {
+  // Look for the sigreturn trampoline.
+  //
+  // https://cgit.freebsd.org/src/tree/sys/arm64/arm64/sigtramp.S
+  const pint_t pc = static_cast(this->getReg(UNW_REG_IP));
+
+  if (_isSigTrampDetermined == false) {
+struct kinfo_sigtramp kst = {0};
+size_t len = sizeof(kst);
+int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_SIGTRAMP, getpid()};
+if (sysctl(mib, 4, &kst, &len, NULL, 0) == 0) {
+  _isSigTrampDetermined = true;
+  _sigTrampStart = reinterpret_cast(kst.ksigtramp_start);
+  _sigTrampEnd = reinterpret_cast(kst.ksigtramp_end);
+}
+  }
+
+  if (_isSigTrampDetermined == false ||
+  (pc < _s

[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

The C++26 job is part of the first jobs that get run. Did you just miss it, or 
do you mean something else?

https://github.com/llvm/llvm-project/pull/86658
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Nikolas Klauser via cfe-commits


@@ -39,6 +39,9 @@
 # if defined(__HAIKU__)
 #  define _LIBUNWIND_TARGET_HAIKU 1
 # endif
+#if defined(__FreeBSD__)

philnik777 wrote:

Are these changes related?

https://github.com/llvm/llvm-project/pull/86658
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Ed Maste via cfe-commits


@@ -39,6 +39,9 @@
 # if defined(__HAIKU__)
 #  define _LIBUNWIND_TARGET_HAIKU 1
 # endif
+#if defined(__FreeBSD__)

emaste wrote:

Yes, libunwind change was included by accident - I just let the CI jobs finish 
rather than restarting; I will update the pull req to fix.


https://github.com/llvm/llvm-project/pull/86658
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Ed Maste via cfe-commits

emaste wrote:

> The C++26 job is part of the first jobs that get run'
Oops, I did miss that. I think this would be the only buildkite job using 
`generic-cxx26`

https://github.com/llvm/llvm-project/pull/86658
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

Yes, it would be the only buildkite one (AFAIK). I don't think that would make 
much of a difference though.


https://github.com/llvm/llvm-project/pull/86658
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [libunwind] [DRAFT][libc++] Switch FreeBSD to C++26 (PR #86658)

2024-03-26 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 approved this pull request.

LGTM with the libunwind changes removed.

https://github.com/llvm/llvm-project/pull/86658
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits