Skip to content

Commit

Permalink
[cli/trampolines]: Fix aarch64-apple-darwin trampoline ASM syntax
Browse files Browse the repository at this point in the history
It turns out that aarch64 assembly syntax uses `;` as the comment
character, not as the statement separator.  So we need to polyfill
that.  We also set an alignment of 4 bytes (`2^2`) which is required on
Apple targets, but is also a good idea on most other aarch64 machines.
  • Loading branch information
staticfloat committed Dec 19, 2020
1 parent ea39b70 commit cdb0833
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
6 changes: 5 additions & 1 deletion cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ $(BUILDDIR)/loader_exe.o : $(SRCDIR)/loader_exe.c $(HEADERS)
$(BUILDDIR)/loader_exe.dbg.obj : $(SRCDIR)/loader_exe.c $(HEADERS)
@$(call PRINT_CC, $(CC) $(DEBUGFLAGS) $(LOADER_CFLAGS) -c $< -o $@)
$(BUILDDIR)/loader_trampolines.o : $(SRCDIR)/trampolines/trampolines_$(ARCH).S
@$(call PRINT_CC, $(CC) $(DEBUGFLAGS) $(LOADER_CFLAGS) $< -c -o $@)
@$(call PRINT_CC, $(CC) $(SHIPFLAGS) $(LOADER_CFLAGS) $< -c -o $@)

# Debugging target to help us see what kind of code is being generated for our trampolines
dump-trampolines: $(SRCDIR)/trampolines/trampolines_$(ARCH).S
$(CC) $(SHIPFLAGS) $(LOADER_CFLAGS) $< -S | sed -E 's/ ((%%)|;) /\n/g' | sed -E 's/.global/\n.global/g'

DIRS = $(build_bindir) $(build_libdir)
$(DIRS):
Expand Down
29 changes: 22 additions & 7 deletions cli/trampolines/trampolines_aarch64.S
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
#include "../../src/jl_exported_funcs.inc"

// On macOS, we need to prepend underscores on symbols
#if defined(__APPLE__) && defined(__MACH__)
#define CNAME(x) _##x
#define PAGE(x) x##@PAGE
#define PAGEOFF(x) x##@PAGEOFF
#define SEP %%
#else
#define CNAME(x) x
#define PAGE(x) x
#define PAGEOFF(x) #:lo12:##x
#define SEP ;
#endif

#define XX(name) \
.global name; \
.cfi_startproc; \
name##:; \
adrp x0, name##_addr; \
ldr x0, [x0, #:lo12:name##_addr]; \
br x0; \
.cfi_endproc; \
.global CNAME(name) SEP \
.cfi_startproc SEP \
.p2align 2 SEP \
CNAME(name)##: SEP \
adrp x0, PAGE(CNAME(name##_addr)) SEP \
ldr x0, [x0, PAGEOFF(CNAME(name##_addr))] SEP \
br x0 SEP \
.cfi_endproc SEP \

JL_EXPORTED_FUNCS(XX)
#undef XX

0 comments on commit cdb0833

Please sign in to comment.