Skip to content

Commit

Permalink
Fix arm64 assembly for macOS (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubo committed Apr 6, 2024
1 parent b8812f5 commit a9fc560
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/prehook-arm64-gas.S
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#if defined __APPLE__
#define funchook_hook_caller_asm _funchook_hook_caller_asm
#define funchook_hook_caller _funchook_hook_caller
#endif
.arch armv8-a
.text
.globl funchook_hook_caller_asm
#if defined __linux__
.type funchook_hook_caller_asm, %function
#endif
funchook_hook_caller_asm:
.cfi_startproc
// save frame pointer (x29) and link register (x30).
Expand Down
52 changes: 52 additions & 0 deletions test/libfunchook_test_aarch64_gas.S
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
#ifdef __APPLE__
#define call_get_val_in_dll _call_get_val_in_dll
#define get_val_in_dll _get_val_in_dll
#define jump_get_val_in_dll _jump_get_val_in_dll
#define arm64_test_adr _arm64_test_adr
#define arm64_test_beq _arm64_test_beq
#define arm64_test_bne _arm64_test_bne
#define arm64_test_cbnz _arm64_test_cbnz
#define arm64_test_cbz _arm64_test_cbz
#define arm64_test_ldr_w _arm64_test_ldr_w
#define arm64_test_ldr_x _arm64_test_ldr_x
#define arm64_test_ldr_s _arm64_test_ldr_s
#define arm64_test_ldr_d _arm64_test_ldr_d
#define arm64_test_ldr_q _arm64_test_ldr_q
#define arm64_test_prfm _arm64_test_prfm
#define arm64_test_ldrsw _arm64_test_ldrsw
#define arm64_test_tbnz _arm64_test_tbnz
#define arm64_test_tbz _arm64_test_tbz
#define test_data _test_data
#endif
.arch armv8-a
.file "libfunchook_test_aarch64_gas.S"
.text
Expand All @@ -9,28 +29,36 @@ test_data:

call_get_val_in_dll:
.global call_get_val_in_dll
#ifdef __linux__
.type call_get_val_in_dll, %function
#endif
stp x29, x30, [sp, -16]!
bl get_val_in_dll
ldp x29, x30, [sp], 16
ret

jump_get_val_in_dll:
.global jump_get_val_in_dll
#ifdef __linux__
.type jump_get_val_in_dll, %function
#endif
b get_val_in_dll

arm64_test_adr:
.global arm64_test_adr
#ifdef __linux__
.type arm64_test_adr, %function
#endif
adr x9, test_data
ldr x9, [x9]
add x0, x0, x9
ret

arm64_test_beq:
.global arm64_test_beq
#ifdef __linux__
.type arm64_test_beq, %function
#endif
adds x0, x0, 1
beq 1f
sub x0, x0, 2
Expand All @@ -39,7 +67,9 @@ arm64_test_beq:

arm64_test_bne:
.global arm64_test_bne
#ifdef __linux__
.type arm64_test_bne, %function
#endif
adds x0, x0, 1
bne 1f
sub x0, x0, 2
Expand All @@ -49,7 +79,9 @@ arm64_test_bne:

arm64_test_cbnz:
.global arm64_test_cbnz
#ifdef __linux__
.type arm64_test_cbnz, %function
#endif
cbnz x0, 1f
add x0, x0, 2
1:
Expand All @@ -58,7 +90,9 @@ arm64_test_cbnz:

arm64_test_cbz:
.global arm64_test_cbz
#ifdef __linux__
.type arm64_test_cbz, %function
#endif
cbz x0, 1f
add x0, x0, 2
1:
Expand All @@ -67,37 +101,47 @@ arm64_test_cbz:

arm64_test_ldr_w:
.global arm64_test_ldr_w
#ifdef __linux__
.type arm64_test_ldr_w, %function
#endif
ldr w9, test_data
add x0, x0, x9
ret

arm64_test_ldr_x:
.global arm64_test_ldr_x
#ifdef __linux__
.type arm64_test_ldr_x, %function
#endif
ldr x9, test_data
add x0, x0, x9
ret

arm64_test_ldr_s:
.global arm64_test_ldr_s
#ifdef __linux__
.type arm64_test_ldr_s, %function
#endif
ldr s16, test_data
mov w9, v16.s[0]
add x0, x0, x9
ret

arm64_test_ldr_d:
.global arm64_test_ldr_d
#ifdef __linux__
.type arm64_test_ldr_d, %function
#endif
ldr d16, test_data
mov x9, v16.d[0]
add x0, x0, x9
ret

arm64_test_ldr_q:
.global arm64_test_ldr_q
#ifdef __linux__
.type arm64_test_ldr_q, %function
#endif
ldr q16, test_data
mov x9, v16.d[0]
add x0, x0, x9
Expand All @@ -107,22 +151,28 @@ arm64_test_ldr_q:

arm64_test_prfm:
.global arm64_test_prfm
#ifdef __linux__
.type arm64_test_prfm, %function
#endif
prfm pldl1keep, test_data
ldr x9, test_data
add x0, x0, x9
ret

arm64_test_ldrsw:
.global arm64_test_ldrsw
#ifdef __linux__
.type arm64_test_ldrsw, %function
#endif
ldrsw x9, 1f
add x0, x0, x9
ret

arm64_test_tbnz:
.global arm64_test_tbnz
#ifdef __linux__
.type arm64_test_tbnz, %function
#endif
tbnz x0, 32, 1f
add x0, x0, 2
1:
Expand All @@ -131,7 +181,9 @@ arm64_test_tbnz:

arm64_test_tbz:
.global arm64_test_tbz
#ifdef __linux__
.type arm64_test_tbz, %function
#endif
tbz x0, 32, 1f
add x0, x0, 2
1:
Expand Down

0 comments on commit a9fc560

Please sign in to comment.