Skip to content

Commit bbe18e1

Browse files
committed
[cli/trampolines]: Fix aarch64-apple-darwin trampoline ASM syntax
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. (cherry picked from commit cdb0833)
1 parent a9c0859 commit bbe18e1

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

cli/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ $(BUILDDIR)/loader_exe.o : $(SRCDIR)/loader_exe.c $(HEADERS) $(JULIAHOME)/VERSIO
5454
$(BUILDDIR)/loader_exe.dbg.obj : $(SRCDIR)/loader_exe.c $(HEADERS) $(JULIAHOME)/VERSION
5555
@$(call PRINT_CC, $(CC) $(DEBUGFLAGS) $(LOADER_CFLAGS) -c $< -o $@)
5656
$(BUILDDIR)/loader_trampolines.o : $(SRCDIR)/trampolines/trampolines_$(ARCH).S
57-
@$(call PRINT_CC, $(CC) $(DEBUGFLAGS) $(LOADER_CFLAGS) $< -c -o $@)
57+
@$(call PRINT_CC, $(CC) $(SHIPFLAGS) $(LOADER_CFLAGS) $< -c -o $@)
58+
59+
# Debugging target to help us see what kind of code is being generated for our trampolines
60+
dump-trampolines: $(SRCDIR)/trampolines/trampolines_$(ARCH).S
61+
$(CC) $(SHIPFLAGS) $(LOADER_CFLAGS) $< -S | sed -E 's/ ((%%)|;) /\n/g' | sed -E 's/.global/\n.global/g'
5862

5963
DIRS = $(build_bindir) $(build_libdir)
6064
$(DIRS):

cli/trampolines/trampolines_aarch64.S

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
#include "../../src/jl_exported_funcs.inc"
22

3+
// On macOS, we need to prepend underscores on symbols
4+
#if defined(__APPLE__) && defined(__MACH__)
5+
#define CNAME(x) _##x
6+
#define PAGE(x) x##@PAGE
7+
#define PAGEOFF(x) x##@PAGEOFF
8+
#define SEP %%
9+
#else
10+
#define CNAME(x) x
11+
#define PAGE(x) x
12+
#define PAGEOFF(x) #:lo12:##x
13+
#define SEP ;
14+
#endif
15+
316
#define XX(name) \
4-
.global name; \
5-
.cfi_startproc; \
6-
name##:; \
7-
adrp x0, name##_addr; \
8-
ldr x0, [x0, #:lo12:name##_addr]; \
9-
br x0; \
10-
.cfi_endproc; \
17+
.global CNAME(name) SEP \
18+
.cfi_startproc SEP \
19+
.p2align 2 SEP \
20+
CNAME(name)##: SEP \
21+
adrp x0, PAGE(CNAME(name##_addr)) SEP \
22+
ldr x0, [x0, PAGEOFF(CNAME(name##_addr))] SEP \
23+
br x0 SEP \
24+
.cfi_endproc SEP \
25+
1126
JL_EXPORTED_FUNCS(XX)
1227
#undef XX

0 commit comments

Comments
 (0)