From 2be0218be4461f9e453cbdcb98f81f41a5ae8bed Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Thu, 30 Jul 2026 22:53:29 +0900 Subject: [PATCH] arm64: fix symbol addends on LLP64 hosts The host-sized symbol addend parameter was introduced by commit b14ef0e2 and truncates 64-bit addends on LLP64 hosts. Use addr_t and cover the negative-addend case. --- arm64-gen.c | 2 +- tests/tests2/152_arm64_addend.c | 17 +++++++++++++++++ tests/tests2/152_arm64_addend.expect | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/tests2/152_arm64_addend.c create mode 100644 tests/tests2/152_arm64_addend.expect diff --git a/arm64-gen.c b/arm64-gen.c index 268319af..85aa7c0e 100644 --- a/arm64-gen.c +++ b/arm64-gen.c @@ -463,7 +463,7 @@ static void arm64_strv(int sz_, int dst, int bas, uint64_t off) } } -static void arm64_sym(int r, Sym *sym, unsigned long addend) +static void arm64_sym(int r, Sym *sym, addr_t addend) { if (sym->type.t & VT_TLS) { #if TCC_TARGET_PE diff --git a/tests/tests2/152_arm64_addend.c b/tests/tests2/152_arm64_addend.c new file mode 100644 index 00000000..c2f126ba --- /dev/null +++ b/tests/tests2/152_arm64_addend.c @@ -0,0 +1,17 @@ +#include +#include + +static unsigned short data[844]; + +static uint64_t address_for_index(int index) +{ + return (uint64_t)(uintptr_t)data - 845186ULL + + (uint64_t)index * 2; +} + +int main(void) +{ + printf("%d\n", address_for_index(422593) + == (uint64_t)(uintptr_t)data); + return 0; +} diff --git a/tests/tests2/152_arm64_addend.expect b/tests/tests2/152_arm64_addend.expect new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/tests/tests2/152_arm64_addend.expect @@ -0,0 +1 @@ +1