From: Yonghong Song <yonghong.song@linux.dev>
To: Alan Maguire <alan.maguire@oracle.com>,
Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
dwarves@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, kernel-team@fb.com
Subject: [PATCH 2/3] dwarf_loader: Do not align the argument register index for FP arguments
Date: Thu, 17 Sep 2026 09:40:48 -0700 [thread overview]
Message-ID: <20260917164048.1578102-1-yonghong.song@linux.dev> (raw)
In-Reply-To: <20260917164038.1576763-1-yonghong.song@linux.dev>
The arm64 ABI aligns a general purpose argument that occupies two registers
to an even register number, leaving a hole when the next free register is an
odd one. parameter__abi_reg_align() applies that rule to every argument
wider than a pointer, but floating point and vector arguments are allocated
from a register bank of their own -- v0-v7 on arm64, xmm0-xmm7 on x86-64 --
so a wide one never takes a general purpose register pair and must not
trigger the rule:
u64 f_fp(u64 a, long double v, u64 b);
Recognize floating point and vector arguments and leave the general purpose
register index alone for them.
This does not change the BTF that is emitted today: such an argument still
advances the general purpose register index by its own size, so the
alignment is not the only thing standing between the model and the ABI. It
does keep parameter__abi_reg_align() honest about which bank the rule
applies to.
Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
---
dwarf_loader.c | 21 ++++++++++++++++++++-
dwarves.h | 10 ++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/dwarf_loader.c b/dwarf_loader.c
index 81c2076..1e5363a 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -3651,6 +3651,25 @@ static int parameter__abi_slots(const struct parameter *parm, const struct cu *c
return slots > 0 ? slots : 1;
}
+/*
+ * Floating point and vector arguments are allocated from a register bank of
+ * their own -- v0-v7 on arm64, xmm0-xmm7 on x86-64 -- so a wide one does not
+ * take a general purpose register pair and must not trigger the even-register
+ * alignment rule, which applies to the general purpose bank only.
+ */
+static bool tag__uses_gpr_bank(const struct tag *type, const struct cu *cu)
+{
+ /* Scalars represented by FP/SIMD registers have their own allocation bank. */
+ if (tag__is_base_type(type, cu) && base_type__is_float(tag__base_type(type)))
+ return false;
+
+ /* Also exclude vector/SIMD types if dwarves represents them distinctly. */
+ if (tag__is_vector(type))
+ return false;
+
+ return true;
+}
+
static int parameter__abi_reg_align(const struct parameter *parm, const struct cu *cu)
{
struct tag *type;
@@ -3659,7 +3678,7 @@ static int parameter__abi_reg_align(const struct parameter *parm, const struct c
return 1;
type = tag__strip_typedefs_and_modifiers(&parm->tag, cu);
- if (type == NULL)
+ if (type == NULL || !tag__uses_gpr_bank(type, cu))
return 1;
return tag__natural_alignment(type, cu) > cu->addr_size ? 2 : 1;
diff --git a/dwarves.h b/dwarves.h
index 70adbbf..f3453ed 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -1607,6 +1607,11 @@ static inline uint16_t base_type__size(const struct tag *tag)
return tag__base_type(tag)->bit_size / 8;
}
+static inline bool base_type__is_float(const struct base_type *bt)
+{
+ return bt->float_type != 0;
+}
+
const char *__base_type__name(const struct base_type *bt);
const char *base_type__name(const struct base_type *btype, char *bf, size_t len);
@@ -1625,6 +1630,11 @@ static inline struct array_type *tag__array_type(const struct tag *tag)
return (struct array_type *)tag;
}
+static inline bool tag__is_vector(const struct tag *tag)
+{
+ return tag->tag == DW_TAG_array_type && tag__array_type(tag)->is_vector;
+}
+
struct string_type {
struct tag tag;
uint32_t nr_entries;
--
2.53.0-Meta
next prev parent reply other threads:[~2026-09-17 16:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 16:40 [PATCH dwarves v2 0/3] pahole: Fix arm64 argument register allocation Yonghong Song
2026-09-17 16:40 ` [PATCH 1/3] dwarf_loader: Skip the argument register the arm64 ABI leaves as a hole Yonghong Song
2026-09-17 16:40 ` Yonghong Song [this message]
2026-09-17 16:40 ` [PATCH 3/3] tests: tests: Add test for 16-byte aligned arguments on arm64 Yonghong Song
2026-09-24 16:15 ` [PATCH dwarves v2 0/3] pahole: Fix arm64 argument register allocation Alan Maguire
2026-09-24 16:20 ` Alexei Starovoitov
2026-09-25 6:59 ` Alan Maguire
2026-09-25 7:03 ` Alan Maguire
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260917164048.1578102-1-yonghong.song@linux.dev \
--to=yonghong.song@linux.dev \
--cc=alan.maguire@oracle.com \
--cc=andrii@kernel.org \
--cc=arnaldo.melo@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox