mirror of
git://repo.or.cz/tinycc.git
synced 2026-06-17 15:44:18 +08:00
arm64-gen: fix 16-byte alignment for variadic arguments on stack
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
Some checks failed
build and test / test-x86_64-linux (push) Has been cancelled
build and test / test-x86_64-osx (push) Has been cancelled
build and test / test-aarch64-osx (push) Has been cancelled
build and test / test-x86_64-win32 (push) Has been cancelled
build and test / test-i386-win32 (push) Has been cancelled
build and test / test-armv7-linux (push) Has been cancelled
build and test / test-aarch64-linux (push) Has been cancelled
build and test / test-riscv64-linux (push) Has been cancelled
According to AAPCS64, when an argument requires 16-byte alignment and is passed on the stack, the stack address must be rounded up to the next 16-byte boundary. TCC previously failed to perform this alignment check in gen_va_arg, leading to data corruption when a 16-byte aligned argument followed an 8-byte argument on the stack. Note: This issue is most prominent on Mach-O/Apple Silicon where variadic arguments are passed entirely on the stack. Testing shows this fix resolves the failure on macOS while remaining compatible with Linux/ARM64 (e.g., Raspberry Pi). Modified gen_va_arg to perform a round-up (addr + 15) & ~15 when align == 16.
This commit is contained in:
parent
b8513fe895
commit
5ce2c4b454
@ -1355,6 +1355,10 @@ ST_FUNC void gen_va_arg(CType *t)
|
||||
o(0x540000ad); // b.le .+20
|
||||
#endif
|
||||
o(0xf9400000 | r1 | r0 << 5); // ldr x(r1),[x(r0)] // __stack
|
||||
if (align == 16) {
|
||||
o(0x91003c00 | r1 | r1 << 5); // add x(r1),x(r1),#15
|
||||
o(0x927cec00 | r1 | r1 << 5); // and x(r1),x(r1),#-16
|
||||
}
|
||||
o(0x9100001e | r1 << 5 | n << 10); // add x30,x(r1),#(n)
|
||||
o(0xf900001e | r0 << 5); // str x30,[x(r0)] // __stack
|
||||
#if !defined(TCC_TARGET_MACHO)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user