From 3e707e8f20d151d8e92bdf29d7e8e08d657fcb87 Mon Sep 17 00:00:00 2001
From: Fabian Groffen <grobian@gentoo.org>
Date: Wed, 8 Jun 2022 20:35:59 +0200
Subject: [PATCH] [ld64] fix compilation on arm64

Signed-off-by: Fabian Groffen <grobian@gentoo.org>
---
 ld64/src/ld/InputFiles.cpp                  |  2 +
 ld64/src/ld/parsers/libunwind/Registers.hpp | 49 +++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git ld64/src/ld/InputFiles.cpp ld64/src/ld/InputFiles.cpp
index 617d9d4..957a676 100644
--- ld64/src/ld/InputFiles.cpp
+++ ld64/src/ld/InputFiles.cpp
@@ -907,6 +907,8 @@ void InputFiles::inferArchitecture(Options& opts, const char** archName)
 	opts.setArchitecture(CPU_TYPE_X86_64, CPU_SUBTYPE_X86_64_ALL, Options::kPlatformOSX);
 #elif __arm__
 	opts.setArchitecture(CPU_TYPE_ARM, CPU_SUBTYPE_ARM_V6, Options::kPlatformOSX);
+#elif __arm64__
+	opts.setArchitecture(CPU_TYPE_ARM64, CPU_SUBTYPE_ARM64_ALL, Options::kPlatformOSX);
 #else
 	#error unknown default architecture
 #endif
diff --git ld64/src/ld/parsers/libunwind/Registers.hpp ld64/src/ld/parsers/libunwind/Registers.hpp
index ceacc28..c111947 100644
--- ld64/src/ld/parsers/libunwind/Registers.hpp
+++ ld64/src/ld/parsers/libunwind/Registers.hpp
@@ -43,6 +43,55 @@
 namespace libunwind {
 
 
+#ifndef i386_thread_state_t
+struct _i386_thread_state_t
+{
+    unsigned int	__eax;
+    unsigned int	__ebx;
+    unsigned int	__ecx;
+    unsigned int	__edx;
+    unsigned int	__edi;
+    unsigned int	__esi;
+    unsigned int	__ebp;
+    unsigned int	__esp;
+    unsigned int	__ss;
+    unsigned int	__eflags;
+    unsigned int	__eip;
+    unsigned int	__cs;
+    unsigned int	__ds;
+    unsigned int	__es;
+    unsigned int	__fs;
+    unsigned int	__gs;
+};
+#define i386_thread_state_t _i386_thread_state_t
+#endif
+#ifndef x86_thread_state64_t
+struct _x86_thread_state64_t
+{
+	__uint64_t	__rax;
+	__uint64_t	__rbx;
+	__uint64_t	__rcx;
+	__uint64_t	__rdx;
+	__uint64_t	__rdi;
+	__uint64_t	__rsi;
+	__uint64_t	__rbp;
+	__uint64_t	__rsp;
+	__uint64_t	__r8;
+	__uint64_t	__r9;
+	__uint64_t	__r10;
+	__uint64_t	__r11;
+	__uint64_t	__r12;
+	__uint64_t	__r13;
+	__uint64_t	__r14;
+	__uint64_t	__r15;
+	__uint64_t	__rip;
+	__uint64_t	__rflags;
+	__uint64_t	__cs;
+	__uint64_t	__fs;
+	__uint64_t	__gs;
+};
+#define x86_thread_state64_t _x86_thread_state64_t
+#endif
 ///
 /// Registers_x86 holds the register state of a thread in a 32-bit intel process.  
 ///
-- 
2.38.1

