Skip to content

Commit 7a5d4c9

Browse files
aykevldeadprogram
authored andcommitted
darwin: add support for arm64 GOARCH (aka Apple Silicon)
This patch adds support for generating GOOS=darwin GOARCH=arm64 binaries. This means that it will become possible to run `go test` on recent Macs, for example.
1 parent af6bbaf commit 7a5d4c9

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ endif
635635
GOOS=linux GOARCH=arm $(TINYGO) build -size short -o test.elf ./testdata/cgo
636636
GOOS=windows GOARCH=amd64 $(TINYGO) build -size short -o test.exe ./testdata/cgo
637637
GOOS=darwin GOARCH=amd64 $(TINYGO) build -o test ./testdata/cgo
638+
GOOS=darwin GOARCH=arm64 $(TINYGO) build -o test ./testdata/cgo
638639
ifneq ($(OS),Windows_NT)
639640
# TODO: this does not yet work on Windows. Somehow, unused functions are
640641
# not garbage collected.

src/internal/task/task_stack_arm64.S

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
#ifdef __MACH__
2+
.global _tinygo_startTask
3+
_tinygo_startTask:
4+
#else
15
.section .text.tinygo_startTask
26
.global tinygo_startTask
37
.type tinygo_startTask, %function
48
tinygo_startTask:
9+
#endif
510
.cfi_startproc
611
// Small assembly stub for starting a goroutine. This is already run on the
712
// new stack, with the callee-saved registers already loaded.
@@ -23,13 +28,25 @@ tinygo_startTask:
2328
blr x19
2429

2530
// After return, exit this goroutine. This is a tail call.
31+
#ifdef __MACH__
32+
b _tinygo_pause
33+
#else
2634
b tinygo_pause
35+
#endif
2736
.cfi_endproc
37+
#ifndef __MACH__
2838
.size tinygo_startTask, .-tinygo_startTask
39+
#endif
2940

41+
42+
#ifdef __MACH__
43+
.global _tinygo_swapTask
44+
_tinygo_swapTask:
45+
#else
3046
.global tinygo_swapTask
3147
.type tinygo_swapTask, %function
3248
tinygo_swapTask:
49+
#endif
3350
// This function gets the following parameters:
3451
// x0 = newStack uintptr
3552
// x1 = oldStack *uintptr

src/runtime/gc_arm64.S

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
#ifdef __MACH__
2+
.global _tinygo_scanCurrentStack
3+
_tinygo_scanCurrentStack:
4+
#else
15
.section .text.tinygo_scanCurrentStack
26
.global tinygo_scanCurrentStack
37
.type tinygo_scanCurrentStack, %function
48
tinygo_scanCurrentStack:
9+
#endif
510
// Sources:
611
// * https://developer.arm.com/architectures/learn-the-architecture/armv8-a-instruction-set-architecture/procedure-call-standard
712
// * https://godbolt.org/z/qrvrEh
@@ -16,7 +21,11 @@ tinygo_scanCurrentStack:
1621

1722
// Scan the stack.
1823
mov x0, sp
24+
#ifdef __MACH__
25+
bl _tinygo_scanstack
26+
#else
1927
bl tinygo_scanstack
28+
#endif
2029

2130
// Restore stack state and return.
2231
ldp x29, x30, [sp], #96

0 commit comments

Comments
 (0)