Created
July 2, 2017 02:16
-
-
Save mikeash/ce38d3a77b88734a9e0e9dc3f352fbc7 to your computer and use it in GitHub Desktop.
ARM64 normal and variadic calling conventions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// xcrun -sdk iphoneos clang -O3 -arch arm64 -S test.c | |
#import <stdarg.h> | |
#import <stdio.h> | |
void normal(int a, int b, int c, int d, int e, int f, int g, int h) { | |
printf("%d %d %d %d %d %d %d %d", a, b, c, d, e, f, g, h); | |
} | |
void normal_target(int a, int b, int c, int d, int e, int f, int g, int h); | |
void call_normal() { | |
normal_target(1, 2, 3, 4, 5, 6, 7, 8); | |
} | |
void vararg(int a, ...) { | |
va_list args; | |
va_start(args, a); | |
int b = va_arg(args, int); | |
int c = va_arg(args, int); | |
int d = va_arg(args, int); | |
int e = va_arg(args, int); | |
int f = va_arg(args, int); | |
int g = va_arg(args, int); | |
int h = va_arg(args, int); | |
printf("%d %d %d %d %d %d %d %d", a, b, c, d, e, f, g, h); | |
} | |
void vararg_target(int a, ...); | |
void call_vararg() { | |
vararg_target(1, 2, 3, 4, 5, 6, 7, 8); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.section __TEXT,__text,regular,pure_instructions | |
.ios_version_min 10, 3 | |
.globl _normal | |
.p2align 2 | |
_normal: ; @normal | |
; BB#0: | |
sub sp, sp, #80 ; =80 | |
stp x29, x30, [sp, #64] ; 8-byte Folded Spill | |
add x29, sp, #64 ; =64 | |
; kill: %W7<def> %W7<kill> %X7<def> | |
; kill: %W6<def> %W6<kill> %X6<def> | |
; kill: %W5<def> %W5<kill> %X5<def> | |
; kill: %W4<def> %W4<kill> %X4<def> | |
; kill: %W3<def> %W3<kill> %X3<def> | |
; kill: %W2<def> %W2<kill> %X2<def> | |
; kill: %W1<def> %W1<kill> %X1<def> | |
; kill: %W0<def> %W0<kill> %X0<def> | |
stp x6, x7, [sp, #48] | |
stp x4, x5, [sp, #32] | |
stp x2, x3, [sp, #16] | |
Lloh0: | |
adrp x8, L_.str@PAGE | |
Lloh1: | |
add x8, x8, L_.str@PAGEOFF | |
stp x0, x1, [sp] | |
mov x0, x8 | |
bl _printf | |
ldp x29, x30, [sp, #64] ; 8-byte Folded Reload | |
add sp, sp, #80 ; =80 | |
ret | |
.loh AdrpAdd Lloh0, Lloh1 | |
.globl _call_normal | |
.p2align 2 | |
_call_normal: ; @call_normal | |
; BB#0: | |
orr w0, wzr, #0x1 | |
orr w1, wzr, #0x2 | |
orr w2, wzr, #0x3 | |
orr w3, wzr, #0x4 | |
mov w4, #5 | |
orr w5, wzr, #0x6 | |
orr w6, wzr, #0x7 | |
orr w7, wzr, #0x8 | |
b _normal_target | |
.globl _vararg | |
.p2align 2 | |
_vararg: ; @vararg | |
; BB#0: | |
sub sp, sp, #96 ; =96 | |
stp x29, x30, [sp, #80] ; 8-byte Folded Spill | |
add x29, sp, #80 ; =80 | |
; kill: %W0<def> %W0<kill> %X0<def> | |
add x8, x29, #16 ; =16 | |
stur x8, [x29, #-8] | |
orr x8, x8, #0x8 | |
stur x8, [x29, #-8] | |
ldr w9, [x29, #16] | |
add x10, x8, #8 ; =8 | |
stur x10, [x29, #-8] | |
ldr w8, [x8] | |
add x11, x10, #8 ; =8 | |
stur x11, [x29, #-8] | |
ldr w10, [x10] | |
add x12, x11, #8 ; =8 | |
stur x12, [x29, #-8] | |
ldr w11, [x11] | |
add x13, x12, #8 ; =8 | |
stur x13, [x29, #-8] | |
ldr w12, [x12] | |
add x14, x13, #8 ; =8 | |
stur x14, [x29, #-8] | |
ldr w13, [x13] | |
add x15, x14, #8 ; =8 | |
stur x15, [x29, #-8] | |
ldr w14, [x14] | |
stp x13, x14, [sp, #48] | |
stp x11, x12, [sp, #32] | |
stp x8, x10, [sp, #16] | |
Lloh2: | |
adrp x8, L_.str@PAGE | |
Lloh3: | |
add x8, x8, L_.str@PAGEOFF | |
stp x0, x9, [sp] | |
mov x0, x8 | |
bl _printf | |
ldp x29, x30, [sp, #80] ; 8-byte Folded Reload | |
add sp, sp, #96 ; =96 | |
ret | |
.loh AdrpAdd Lloh2, Lloh3 | |
.globl _call_vararg | |
.p2align 2 | |
_call_vararg: ; @call_vararg | |
; BB#0: | |
sub sp, sp, #80 ; =80 | |
stp x29, x30, [sp, #64] ; 8-byte Folded Spill | |
add x29, sp, #64 ; =64 | |
orr w8, wzr, #0x8 | |
str x8, [sp, #48] | |
orr w8, wzr, #0x7 | |
orr w9, wzr, #0x6 | |
stp x9, x8, [sp, #32] | |
mov w8, #5 | |
orr w9, wzr, #0x4 | |
stp x9, x8, [sp, #16] | |
orr w8, wzr, #0x3 | |
orr w9, wzr, #0x2 | |
stp x9, x8, [sp] | |
orr w0, wzr, #0x1 | |
bl _vararg_target | |
ldp x29, x30, [sp, #64] ; 8-byte Folded Reload | |
add sp, sp, #80 ; =80 | |
ret | |
.section __TEXT,__cstring,cstring_literals | |
L_.str: ; @.str | |
.asciz "%d %d %d %d %d %d %d %d" | |
.subsections_via_symbols |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment