From: Maxim Khmelevskii <max@linux.ibm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: dwarves@vger.kernel.org, linux-debuggers@vger.kernel.org,
Alan Maguire <alan.maguire@oracle.com>,
Ilya Leoshkevich <iii@linux.ibm.com>
Subject: [PATCH dwarves v1 1/2] dwarf_loader: Support in-memory return values for s390
Date: Sun, 22 Nov 2026 22:06:19 +0100 [thread overview]
Message-ID: <20261122210636.2896891-5-max@linux.ibm.com> (raw)
In-Reply-To: <20261122210636.2896891-4-max@linux.ibm.com>
The s390 ABI returns any aggregate and scalars larger than 8 bytes, such
as __int128, in a return value buffer allocated by the caller.
This buffer's address is treated like a "hidden argument" and passed
by the caller in %r2. The function's first parameter is passed in %r3.
Without this change pahole skips such functions and with "--verbose"
prints a message like this:
<function> : skipping BTF encoding of function due to unexpected register usage for parameter
Set the first parameter register index (reg_idx) to the proper value.
Move function's return type resolution before parameters
are analyzed, because the analysis depends on the return type.
Although param_loc_supported is not set for s390, calculate
the reg_idx in function__match_clang_parameter_locations in case
the flag is enabled in the future.
The change affects only s390.
Signed-off-by: Maxim Khmelevskii <max@linux.ibm.com>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
dwarf_loader.c | 84 +++++++++++++++++++++++++++++++++++++++-----------
dwarves.h | 1 +
2 files changed, 67 insertions(+), 18 deletions(-)
diff --git a/dwarf_loader.c b/dwarf_loader.c
index 01049e9..e6cc4e3 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -4044,6 +4044,51 @@ static bool parameter__apply_true_sig_member(struct parameter *parm, struct cu *
return true;
}
+static bool tag__is_aggregate(const struct tag *type)
+{
+ switch (type->tag) {
+ case DW_TAG_structure_type:
+ case DW_TAG_class_type:
+ case DW_TAG_union_type:
+ case DW_TAG_array_type:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static bool s390x__ret_in_memory(const struct tag *type, const struct cu *cu)
+{
+ if (tag__is_aggregate(type))
+ return true;
+
+ return tag__size(type, cu) > 8;
+}
+
+static bool ftype__ret_in_memory(const struct ftype *ftype, const struct cu *cu)
+{
+ switch (cu->e_machine) {
+ case EM_S390: {
+ struct tag *type;
+
+ if (ftype->tag.type == 0)
+ return false;
+
+ type = tag__strip_typedefs_and_modifiers(&ftype->tag, cu);
+ if (type == NULL)
+ return false;
+ return s390x__ret_in_memory(type, cu);
+ } break;
+ default:
+ return false;
+ }
+}
+
+static int ftype__first_param_reg_idx(const struct ftype *ftype, const struct cu *cu)
+{
+ return ftype__ret_in_memory(ftype, cu) ? 1 : 0;
+}
+
static bool parameter__reg_in_expected_window(const struct parameter *parm, int reg_idx,
int slots, const struct cu *cu)
{
@@ -4060,8 +4105,8 @@ static bool parameter__reg_in_expected_window(const struct parameter *parm, int
static void function__match_clang_parameter_locations(struct ftype *ftype, struct cu *cu)
{
+ int reg_idx = ftype__first_param_reg_idx(ftype, cu);
struct parameter *pos;
- int reg_idx = 0;
ftype__for_each_parameter(ftype, pos) {
int slots = parameter__abi_slots(pos, cu);
@@ -4089,7 +4134,7 @@ static void function__analyze_parameter_locations(struct function *fn, struct cu
bool true_sig_enabled = cu->param_loc_supported && conf->true_signature &&
ftype->signature_changed;
bool check_locations = !cu->producer_clang || ftype->signature_changed;
- int reg_idx = 0;
+ int reg_idx = ftype__first_param_reg_idx(ftype, cu);
if (!check_locations) {
/* Producer is clang and the signature was not changed: match
@@ -4448,6 +4493,24 @@ static int cu__resolve_func_ret_types_optimized(struct cu *cu, struct conf_load
continue;
fn = tag__function(tag);
+
+ /* Set the function return type, it affects the register index associated
+ * with the first parameter of the function. If the return value is passed
+ * in memory the index is shifted.
+ */
+ if (tag->type == 0 && fn->abstract_origin) {
+ struct dwarf_tag *dtag = tag__dwarf(tag);
+ struct dwarf_tag *dfunc;
+
+ dfunc = dwarf_cu__find_tag_by_ref(cu->priv, dtag, abstract_origin);
+ if (dfunc == NULL) {
+ tag__print_abstract_origin_not_found(tag);
+ return -1;
+ }
+
+ tag->type = dtag__tag(dfunc)->type;
+ }
+
/* Abstract inline subprograms describe source signatures; their
* concrete locations belong to DW_TAG_inlined_subroutine children.
*/
@@ -4475,22 +4538,6 @@ static int cu__resolve_func_ret_types_optimized(struct cu *cu, struct conf_load
fn->proto.unexpected_reg = 1;
}
}
-
- if (tag == NULL || tag->type != 0)
- continue;
-
- if (!fn->abstract_origin)
- continue;
-
- struct dwarf_tag *dtag = tag__dwarf(tag);
- struct dwarf_tag *dfunc;
- dfunc = dwarf_cu__find_tag_by_ref(cu->priv, dtag, abstract_origin);
- if (dfunc == NULL) {
- tag__print_abstract_origin_not_found(tag);
- return -1;
- }
-
- tag->type = dtag__tag(dfunc)->type;
}
return 0;
}
@@ -4805,6 +4852,7 @@ static int cu__set_common(struct cu *cu, struct conf_load *conf,
cu->agg_use_two_regs = arch__agg_use_two_regs(&ehdr);
cu->arg_align_two_regs = arch__arg_align_two_regs(&ehdr);
cu->param_loc_supported = arch__param_loc_supported(&ehdr);
+ cu->e_machine = ehdr.e_machine;
arch__set_register_params(&ehdr, cu);
return 0;
}
diff --git a/dwarves.h b/dwarves.h
index 07d85e6..c7b254d 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -333,6 +333,7 @@ struct cu {
uint8_t arg_align_two_regs:1; /* An over-aligned arg starts on an even register */
uint8_t param_loc_supported:1; /* Parameter location analysis is validated for this arch */
uint8_t nr_register_params;
+ uint16_t e_machine;
int register_params[ARCH_MAX_REGISTER_PARAMS];
int functions_saved;
uint16_t language;
--
2.56.0
next prev parent reply other threads:[~2026-11-22 21:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 21:06 [PATCH dwarves v1 0/2] Support in-memory return values for s390 Maxim Khmelevskii
2026-11-22 21:06 ` Maxim Khmelevskii [this message]
2026-11-22 21:06 ` [PATCH dwarves v1 2/2] tests: Add test for in-memory return values Maxim Khmelevskii
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=20261122210636.2896891-5-max@linux.ibm.com \
--to=max@linux.ibm.com \
--cc=acme@kernel.org \
--cc=alan.maguire@oracle.com \
--cc=dwarves@vger.kernel.org \
--cc=iii@linux.ibm.com \
--cc=linux-debuggers@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.