tyfkda / xcc

Standalone C compiler/assembler/linker/libc for x86-64/aarch64/riscv64/wasm
https://tyfkda.github.io/xcc/
MIT License
197 stars 14 forks source link

Use x8 register for result struct address on aarch64 #124

Open tyfkda opened 1 year ago

tyfkda commented 1 year ago

Unlike x64, aarch64 uses %x8 to pass the function result struct address:

typedef struct {
    long long x, y, z;
} FooStruct;

FooStruct return_struct(long long x, long long y, long long z) {
    FooStruct s = {.x = x, .y = y, .z = z};
    return s;
}
$ gcc -S -O2 -fno-asynchronous-unwind-tables ,foo/foo.c
    .section    __TEXT,__text,regular,pure_instructions
    .build_version macos, 13, 0 sdk_version 13, 3
    .globl  _return_struct                  ; -- Begin function return_struct
    .p2align    2
_return_struct:                         ; @return_struct
    .cfi_startproc
; %bb.0:
    stp x0, x1, [x8]
    str x2, [x8, #16]
    ret
    .cfi_endproc
                                        ; -- End function
.subsections_via_symbols