From 6ab01716cebda2a9017c32dd2eb1c592b182993c Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Mon, 8 Jan 2024 13:26:28 -0800 Subject: [PATCH] Fix aarch64 setjmp abi We now store values in jmp_buf where the compiler wants them to be. This fixes code that calls __builtin_setjmp() and __builtin_longjmp() such as libunwind. All libcxxabi tests are now passing on ARM64. See #1076 --- build/htags | 2 +- build/run | 9 ++++----- libc/nexgen32e/longjmp.S | 8 ++++---- libc/nexgen32e/setjmp.S | 10 +++++----- third_party/libcxxabi/test/BUILD.mk | 5 +---- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/build/htags b/build/htags index 2af1013c9..698a4de2e 100755 --- a/build/htags +++ b/build/htags @@ -66,7 +66,7 @@ set -- --regex-c='/^extern [^(]*(\*const \([^)]*\))(/\1/b' "$@" # struct WorstSoftwareEver; set -- --regex-c='/^struct.*;$/uehocruehcroue/b' "$@" -exec $TAGS \ +build/run $TAGS \ -e \ --langmap=c:.c.h \ --exclude=libc/nt/struct/imagefileheader.internal.h \ diff --git a/build/run b/build/run index d1ada17a1..c7fc0c292 100755 --- a/build/run +++ b/build/run @@ -1,9 +1,8 @@ #!/bin/sh -if printf '%s\n' "$*" | grep aarch64 >/dev/null 2>&1; then - if [ ! -f o/third_party/qemu/qemu-aarch64 ]; then - make -j8 o/third_party/qemu/qemu-aarch64 - fi - exec o/third_party/qemu/qemu-aarch64 "$@" +UNAMEM=$(uname -m) +UNAMES=$(uname -s) +if [ x"$UNAMES" = x"Darwin" ] && [ x"$UNAMEM" = x"arm64" ]; then + exec ape "$@" else exec "$@" fi diff --git a/libc/nexgen32e/longjmp.S b/libc/nexgen32e/longjmp.S index 307d699da..985a2d657 100644 --- a/libc/nexgen32e/longjmp.S +++ b/libc/nexgen32e/longjmp.S @@ -43,13 +43,13 @@ _longjmp: mov 48(%rdi),%r15 jmp *56(%rdi) #elif defined(__aarch64__) - ldp x19,x20,[x0,#0] - ldp x21,x22,[x0,#16] + ldp x29,x30,[x0,#0] + ldp x2,x22,[x0,#16] ldp x23,x24,[x0,#32] ldp x25,x26,[x0,#48] ldp x27,x28,[x0,#64] - ldp x29,x30,[x0,#80] - ldr x2,[x0,#104] + ldp x19,x20,[x0,#80] + ldr x21,[x0,#104] mov sp,x2 ldp d8 ,d9,[x0,#112] ldp d10,d11,[x0,#128] diff --git a/libc/nexgen32e/setjmp.S b/libc/nexgen32e/setjmp.S index 1a4498f5f..0dfac7df9 100644 --- a/libc/nexgen32e/setjmp.S +++ b/libc/nexgen32e/setjmp.S @@ -44,14 +44,14 @@ _setjmp: xor %eax,%eax ret #elif defined(__aarch64__) - stp x19,x20,[x0,#0] - stp x21,x22,[x0,#16] + mov x2,sp + stp x29,x30,[x0,#0] + stp x2,x22,[x0,#16] stp x23,x24,[x0,#32] stp x25,x26,[x0,#48] stp x27,x28,[x0,#64] - stp x29,x30,[x0,#80] - mov x2,sp - str x2,[x0,#104] + stp x19,x20,[x0,#80] + str x21,[x0,#104] stp d8,d9,[x0,#112] stp d10,d11,[x0,#128] stp d12,d13,[x0,#144] diff --git a/third_party/libcxxabi/test/BUILD.mk b/third_party/libcxxabi/test/BUILD.mk index dee728a7f..1fd97b1a1 100644 --- a/third_party/libcxxabi/test/BUILD.mk +++ b/third_party/libcxxabi/test/BUILD.mk @@ -1,8 +1,6 @@ #-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐ #── vi: set noet ft=make ts=8 sw=8 fenc=utf-8 :vi ────────────────────┘ -ifeq ($(MODE), ) - PKGS += THIRD_PARTY_LIBCXXABI_TEST THIRD_PARTY_LIBCXXABI_TEST_A = o/$(MODE)/third_party/libcxxabi/test/test.a @@ -109,6 +107,7 @@ THIRD_PARTY_LIBCXXABI_TEST_CHECKS = \ THIRD_PARTY_LIBCXXABI_TEST_DIRECTDEPS = \ LIBC_NEXGEN32E \ + LIBC_LOG \ THIRD_PARTY_LIBCXX \ THIRD_PARTY_LIBCXXABI @@ -168,8 +167,6 @@ o/$(MODE)/third_party/libcxxabi/test/incomplete_type.sh.com.dbg: \ $(APE_NO_MODIFY_SELF) @$(APELINK) -endif - o/$(MODE)/third_party/libcxxabi/test/catch_multi_level_pointer.pass.o: private COPTS += -O0 o/$(MODE)/third_party/libcxxabi/test/catch_multi_level_pointer.pass.o: private QUOTA += -C30 -M4000m