From: Alan Maguire <alan.maguire@oracle.com>
To: acme@kernel.org, yhs@fb.com, ast@kernel.org, olsajiri@gmail.com,
timo@incline.eu
Cc: daniel@iogearbox.net, andrii@kernel.org, songliubraving@fb.com,
john.fastabend@gmail.com, kpsingh@chromium.org, sdf@google.com,
haoluo@google.com, martin.lau@kernel.org, bpf@vger.kernel.org,
Alan Maguire <alan.maguire@oracle.com>
Subject: [PATCH dwarves 1/5] dwarves: help dwarf loader spot functions with optimized-out parameters
Date: Tue, 24 Jan 2023 13:45:27 +0000 [thread overview]
Message-ID: <1674567931-26458-2-git-send-email-alan.maguire@oracle.com> (raw)
In-Reply-To: <1674567931-26458-1-git-send-email-alan.maguire@oracle.com>
Compilation generates DWARF at several stages, and often the
later DWARF representations more accurately represent optimizations
that have occurred during compilation.
In particular, parameter representations can be spotted by their
abstract origin references to the original parameter, but they
often have more accurate location information. In most cases,
the parameter locations will match calling conventions, and be
registers for the first 6 parameters on x86_64, first 8 on ARM64
etc. If the parameter is not a register when it should be however,
it is likely passed via the stack or the compiler has used a
constant representation instead.
This change adds a field to parameters and their associated
ftype to note if a parameter has been optimized out. Having
this information allows us to skip such functions, as their
presence in CUs makes BTF encoding impossible.
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
---
dwarf_loader.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
dwarves.h | 4 +++-
2 files changed, 77 insertions(+), 3 deletions(-)
diff --git a/dwarf_loader.c b/dwarf_loader.c
index 5a74035..0220f1d 100644
--- a/dwarf_loader.c
+++ b/dwarf_loader.c
@@ -992,13 +992,67 @@ static struct class_member *class_member__new(Dwarf_Die *die, struct cu *cu,
return member;
}
-static struct parameter *parameter__new(Dwarf_Die *die, struct cu *cu, struct conf_load *conf)
+/* How many function parameters are passed via registers? Used below in
+ * determining if an argument has been optimized out or if it is simply
+ * an argument > NR_REGISTER_PARAMS. Setting NR_REGISTER_PARAMS to 0
+ * allows unsupported architectures to skip tagging optimized-out
+ * values.
+ */
+#if defined(__x86_64__)
+#define NR_REGISTER_PARAMS 6
+#elif defined(__s390__)
+#define NR_REGISTER_PARAMS 5
+#elif defined(__aarch64__)
+#define NR_REGISTER_PARAMS 8
+#elif defined(__mips__)
+#define NR_REGISTER_PARAMS 8
+#elif defined(__powerpc__)
+#define NR_REGISTER_PARAMS 8
+#elif defined(__sparc__)
+#define NR_REGISTER_PARAMS 6
+#elif defined(__riscv) && __riscv_xlen == 64
+#define NR_REGISTER_PARAMS 8
+#elif defined(__arc__)
+#define NR_REGISTER_PARAMS 8
+#else
+#define NR_REGISTER_PARAMS 0
+#endif
+
+static struct parameter *parameter__new(Dwarf_Die *die, struct cu *cu,
+ struct conf_load *conf, int param_idx)
{
struct parameter *parm = tag__alloc(cu, sizeof(*parm));
if (parm != NULL) {
+ struct location loc;
+
tag__init(&parm->tag, cu, die);
parm->name = attr_string(die, DW_AT_name, conf);
+
+ /* Parameters which use DW_AT_abstract_origin to point at
+ * the original parameter definition (with no name in the DIE)
+ * are the result of later DWARF generation during compilation
+ * so often better take into account if arguments were
+ * optimized out.
+ *
+ * By checking that locations for parameters that are expected
+ * to be passed as registers are actually passed as registers,
+ * we can spot optimized-out parameters.
+ */
+ if (param_idx < NR_REGISTER_PARAMS && !parm->name &&
+ attr_location(die, &loc.expr, &loc.exprlen) == 0 &&
+ loc.exprlen != 0) {
+ Dwarf_Op *expr = loc.expr;
+
+ switch (expr->atom) {
+ case DW_OP_reg1 ... DW_OP_reg31:
+ case DW_OP_breg0 ... DW_OP_breg31:
+ break;
+ default:
+ parm->optimized = true;
+ break;
+ }
+ }
}
return parm;
@@ -1450,7 +1504,7 @@ static struct tag *die__create_new_parameter(Dwarf_Die *die,
struct cu *cu, struct conf_load *conf,
int param_idx)
{
- struct parameter *parm = parameter__new(die, cu, conf);
+ struct parameter *parm = parameter__new(die, cu, conf, param_idx);
if (parm == NULL)
return NULL;
@@ -2209,6 +2263,10 @@ static void ftype__recode_dwarf_types(struct tag *tag, struct cu *cu)
}
pos->name = tag__parameter(dtype->tag)->name;
pos->tag.type = dtype->tag->type;
+ if (pos->optimized) {
+ tag__parameter(dtype->tag)->optimized = pos->optimized;
+ type->optimized_parms = 1;
+ }
continue;
}
@@ -2219,6 +2277,20 @@ static void ftype__recode_dwarf_types(struct tag *tag, struct cu *cu)
}
pos->tag.type = dtype->small_id;
}
+ /* if parameters were optimized out, set flag for the ftype this
+ * function tag referred to via abstract origin.
+ */
+ if (type->optimized_parms) {
+ struct dwarf_tag *dtype = type->tag.priv;
+ struct dwarf_tag *dftype;
+
+ dftype = dwarf_cu__find_tag_by_ref(dcu, &dtype->abstract_origin);
+ if (dftype && dftype->tag) {
+ struct ftype *ftype = tag__ftype(dftype->tag);
+
+ ftype->optimized_parms = 1;
+ }
+ }
}
static void lexblock__recode_dwarf_types(struct lexblock *tag, struct cu *cu)
diff --git a/dwarves.h b/dwarves.h
index 589588e..1ad1b3b 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -808,6 +808,7 @@ size_t lexblock__fprintf(const struct lexblock *lexblock, const struct cu *cu,
struct parameter {
struct tag tag;
const char *name;
+ bool optimized;
};
static inline struct parameter *tag__parameter(const struct tag *tag)
@@ -827,7 +828,8 @@ struct ftype {
struct tag tag;
struct list_head parms;
uint16_t nr_parms;
- uint8_t unspec_parms; /* just one bit is needed */
+ uint8_t unspec_parms:1; /* just one bit is needed */
+ uint8_t optimized_parms:1;
};
static inline struct ftype *tag__ftype(const struct tag *tag)
--
1.8.3.1
next prev parent reply other threads:[~2023-01-24 13:49 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-24 13:45 [PATCH dwarves 0/5] dwarves: support encoding of optimized-out parameters, removal of inconsistent static functions Alan Maguire
2023-01-24 13:45 ` Alan Maguire [this message]
2023-01-25 16:53 ` [PATCH dwarves 1/5] dwarves: help dwarf loader spot functions with optimized-out parameters Jiri Olsa
2023-01-25 17:47 ` Eduard Zingerman
2023-01-25 18:28 ` Alan Maguire
2023-01-25 21:34 ` Eduard Zingerman
2023-01-25 22:52 ` Alan Maguire
2023-01-25 23:42 ` Eduard Zingerman
2023-01-26 0:20 ` Eduard Zingerman
2023-01-26 14:02 ` Alan Maguire
2023-01-26 15:02 ` Eduard Zingerman
2023-01-24 13:45 ` [PATCH dwarves 2/5] btf_encoder: refactor function addition into dedicated btf_encoder__add_func Alan Maguire
2023-01-24 13:45 ` [PATCH dwarves 3/5] btf_encoder: child encoders should have a reference to parent encoder Alan Maguire
2023-01-24 13:45 ` [PATCH dwarves 4/5] btf_encoder: represent "."-suffixed optimized functions (".isra.0") in BTF Alan Maguire
2023-01-25 17:54 ` Kui-Feng Lee
2023-01-25 18:56 ` Arnaldo Carvalho de Melo
2023-01-26 18:37 ` Kui-Feng Lee
2023-01-25 18:59 ` Alan Maguire
2023-01-26 17:43 ` Kui-Feng Lee
2023-01-24 13:45 ` [PATCH dwarves 5/5] btf_encoder: skip BTF encoding of static functions with inconsistent prototypes Alan Maguire
2023-01-25 13:39 ` Jiri Olsa
2023-01-25 14:18 ` Alan Maguire
2023-01-25 16:53 ` Jiri Olsa
2023-01-26 14:12 ` Alan Maguire
2023-01-24 15:14 ` [PATCH dwarves 0/5] dwarves: support encoding of optimized-out parameters, removal of inconsistent static functions Jiri Olsa
2023-01-24 16:11 ` Alan Maguire
2023-01-25 13:59 ` Jiri Olsa
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=1674567931-26458-2-git-send-email-alan.maguire@oracle.com \
--to=alan.maguire@oracle.com \
--cc=acme@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=kpsingh@chromium.org \
--cc=martin.lau@kernel.org \
--cc=olsajiri@gmail.com \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=timo@incline.eu \
--cc=yhs@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