[libunwind] [libunwind] Add support for the AArch64 "Vector Granule" (VG) register (PR #153565)

Benjamin Maxwell via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 14 03:32:34 PDT 2025


================
@@ -1895,11 +1907,27 @@ inline bool Registers_arm64::validRegister(int regNum) const {
     return false;
   if (regNum == UNW_AARCH64_RA_SIGN_STATE)
     return true;
+  if (regNum == UNW_AARCH64_VG)
+    return true;
   if ((regNum > 32) && (regNum < 64))
     return false;
   return true;
 }
 
+inline uint64_t Registers_arm64::lazyGetVG() const {
+  if (!_misc_registers.__vg) {
+#if defined(__aarch64__)
+    register uint64_t vg asm("x0");
+    asm(".inst 0x04e0e3e0" // CNTD x0
+        : "=r"(vg));
+    _misc_registers.__vg = vg;
----------------
MacDue wrote:

Not sure if there's a nicer way to do this, LLVM's compiler-rt provides `__arm_get_current_vg` (which would be a safer alternative), but depending on how libunwind is built, it's not necessarily going to be available. 

https://github.com/llvm/llvm-project/pull/153565


More information about the cfe-commits mailing list