Skip to content

Commit

Permalink
aarch64, Darwin, libgcc: Add support for aarch64 darwin.
Browse files Browse the repository at this point in the history
1. libgcc, aarch64, Darwin: Initial libgcc boiler-plate changes.

Initial changes to build libgcc for aarch64 Darwin (declare the port,
handle Mach-O assembler syntax and arrange for building the main extra
pieces).

2. libgcc, aarch64, Darwin: Do not build legacy EH shim.

Darwin aarch64 does not exist for macOS 10.6, so there is no need to
build a shim to target it.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

libgcc/

	* config.host: Omit the Darwin10 unwinder shim for aarch64 Darwin.

3. libgcc, aarch64, Darwin: Darwin should use an OS call to clear caches.

The sys_icache_invalidate() function is the right one to use.

The fixes issue #17

4. libgcc, aarch64, Darwin: Enable heap trampolines.
  • Loading branch information
iains committed Dec 3, 2022
1 parent f7ef1c2 commit 4c0176f
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gcc/config/aarch64/aarch64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28575,7 +28575,7 @@ aarch64_libgcc_floating_mode_supported_p

/* The architecture reserves bits 0 and 1 so use bit 2 for descriptors. */
#undef TARGET_CUSTOM_FUNCTION_DESCRIPTORS
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS 4
#define TARGET_CUSTOM_FUNCTION_DESCRIPTORS AARCH64_CUSTOM_FUNCTION_TEST

#undef TARGET_HARD_REGNO_NREGS
#define TARGET_HARD_REGNO_NREGS aarch64_hard_regno_nregs
Expand Down
6 changes: 6 additions & 0 deletions gcc/config/aarch64/aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
/* Heap alignment (same as BIGGEST_ALIGNMENT and STACK_BOUNDARY). */
#define MALLOC_ABI_ALIGNMENT 128

/* We will and with this value to test if a custom function descriptor needs
a static chain. The function boundary must the adjusted so that the bit
this represents is no longer part of the address. 0 Disables the custom
function descriptors. */
#define AARCH64_CUSTOM_FUNCTION_TEST 4

/* Defined by the ABI */
#define WCHAR_TYPE "unsigned int"
#define WCHAR_TYPE_SIZE 32
Expand Down
9 changes: 9 additions & 0 deletions gcc/config/aarch64/darwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ along with GCC; see the file COPYING3. If not see
#undef LONG_DOUBLE_TYPE_SIZE
#define LONG_DOUBLE_TYPE_SIZE 64

/* Disable custom function descriptors on Darwin, it breaks ABI. */
#undef AARCH64_CUSTOM_FUNCTION_TEST
#define AARCH64_CUSTOM_FUNCTION_TEST 0

/* Non-PIE executables are forbidden by the aarch64-darwin security model;
remove the option from link-lines since they just produce a warning from
ld64 and are then ignored anyway. */
Expand Down Expand Up @@ -268,3 +272,8 @@ along with GCC; see the file COPYING3. If not see
#define SYMBOL_FLAG_SUBT_DEP (SYMBOL_FLAG_MACH_DEP)

#undef ASM_OUTPUT_DEF_FROM_DECLS

#undef CLEAR_INSN_CACHE
#define CLEAR_INSN_CACHE(beg, end) \
extern void sys_icache_invalidate(void *start, size_t len); \
sys_icache_invalidate ((beg), (size_t)((end)-(beg)))
18 changes: 16 additions & 2 deletions libgcc/config.host
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ m32c*-*-*)
cpu_type=m32c
tmake_file=t-fdpbit
;;
aarch64*-*-*)
aarch64*-*-* | arm64*-*-*)
cpu_type=aarch64
;;
alpha*-*-*)
Expand Down Expand Up @@ -272,7 +272,7 @@ case ${host} in
echo "Warning: libgcc configured to support macOS 10.5" 1>&2
;;
esac
extra_parts="crt3.o libd10-uwfef.a crttms.o crttme.o libemutls_w.a"
extra_parts="crt3.o crttms.o crttme.o libemutls_w.a"
;;
*-*-dragonfly*)
tmake_file="$tmake_file t-crtstuff-pic t-libgcc-pic t-eh-dw2-dip"
Expand Down Expand Up @@ -416,6 +416,16 @@ aarch64*-*-elf | aarch64*-*-rtems*)
tmake_file="${tmake_file} t-dfprules"
md_unwind_header=aarch64/aarch64-unwind.h
;;
aarch64*-*-darwin*)
extra_parts="$extra_parts crtfastmath.o"
tmake_file="${tmake_file} ${cpu_type}/t-lse "
tmake_file="${tmake_file} t-crtfm"
# No soft float for now because our long double is DF not TF.
md_unwind_header=aarch64/aarch64-unwind.h
if test x$off_stack_trampolines = xyes; then
tmake_file="${tmake_file} ${cpu_type}/t-heap-trampoline"
fi
;;
aarch64*-*-freebsd*)
extra_parts="$extra_parts crtfastmath.o"
tmake_file="${tmake_file} ${cpu_type}/t-aarch64"
Expand Down Expand Up @@ -715,11 +725,13 @@ hppa*-*-netbsd*)
i[34567]86-*-darwin*)
tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi"
tm_file="$tm_file i386/darwin-lib.h"
extra_parts="$extra_parts libd10-uwfef.a "
extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
;;
x86_64-*-darwin*)
tmake_file="$tmake_file i386/t-crtpc t-crtfm i386/t-msabi"
tm_file="$tm_file i386/darwin-lib.h"
extra_parts="$extra_parts libd10-uwfef.a "
extra_parts="$extra_parts crtprec32.o crtprec64.o crtprec80.o crtfastmath.o"
if test x$off_stack_trampolines = xyes; then
tmake_file="${tmake_file} i386/t-heap-trampoline"
Expand Down Expand Up @@ -1195,12 +1207,14 @@ powerpc-*-darwin*)
# We build the darwin10 EH shim for Rosetta (running on x86 machines).
tm_file="$tm_file i386/darwin-lib.h"
tmake_file="$tmake_file rs6000/t-ppc64-fp rs6000/t-ibm-ldouble"
extra_parts="$extra_parts libd10-uwfef.a "
extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o"
;;
powerpc64-*-darwin*)
# We build the darwin10 EH shim for Rosetta (running on x86 machines).
tm_file="$tm_file i386/darwin-lib.h"
tmake_file="$tmake_file rs6000/t-darwin64 rs6000/t-ibm-ldouble"
extra_parts="$extra_parts libd10-uwfef.a "
extra_parts="$extra_parts crt2.o crt3_2.o libef_ppc.a dw_ppc.o"
;;
powerpc*-*-freebsd*)
Expand Down
28 changes: 28 additions & 0 deletions libgcc/config/aarch64/lse.S
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#endif

/* Declare the symbol gating the LSE implementations. */
#if __ELF__
.hidden __aarch64_have_lse_atomics
#else
.private_extern __aarch64_have_lse_atomics
#endif

/* Turn size and memory model defines into mnemonic fragments. */
#if SIZE == 1
Expand Down Expand Up @@ -164,6 +168,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#define BTI_C hint 34

/* Start and end a function. */
#if __ELF__
.macro STARTFN name
.text
.balign 16
Expand All @@ -187,6 +192,29 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
cbz w(tmp0), \label
.endm

#else
.macro STARTFN name
.text
.balign 16
.private_extern _\name
.cfi_startproc
_\name:
BTI_C
.endm

.macro ENDFN name
.cfi_endproc
.endm

/* Branch to LABEL if LSE is disabled. */
.macro JUMP_IF_NOT_LSE label
adrp x(tmp0), ___aarch64_have_lse_atomics@PAGE
ldrb w(tmp0), [x(tmp0), ___aarch64_have_lse_atomics@PAGEOFF]
cbz w(tmp0), \label
.endm

#endif

#ifdef L_cas

STARTFN NAME(cas)
Expand Down
7 changes: 7 additions & 0 deletions libgcc/config/aarch64/t-darwin
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# FIXME: decide what we need here, or delete this file.

HOST_LIBGCC2_CFLAGS += -mmacosx-version-min=11.0

LIB2_SIDITI_CONV_FUNCS = yes

BUILD_LIBGCCS1 =

0 comments on commit 4c0176f

Please sign in to comment.