Skip to contentSkip to conversation

pahole: Apply CU-level filters early in loading

PATCH In review Matthew Maurer 3 participants 4 messages Aug 1, 2024 – Aug 9, 2024 Rust

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 pahole: Apply CU-level filters early in loading

Without this, even with --lang_exclude=rust set, running on vmlinux with CONFIG_RUST enabled will lead to errors like:
die__process_function: tag not supported 0x2f (template_type_parameter)! because the filtering doesn't happen until finalization, but unsupported tags are reported during loading.

As an added bonus, this should speed up processing of large objects with filtered CUs, as their details will no longer be walked.

---
 dwarf_loader.c | 10 ++++++++++
 dwarves.h      |  1 +
 pahole.c       |  4 ++++
 3 files changed, 15 insertions(+)
dwarf_loader.c +10 -0
index b832c93..02a17f4 100644
@@ -2854,6 +2854,16 @@ static int die__process(Dwarf_Die *die, struct cu *cu, struct conf_load *conf)
 
 	cu->language = attr_numeric(die, DW_AT_language);
 
+	if (conf->early_cu_filter)
+		cu = conf->early_cu_filter(cu);
+
+	/*
+	 * If we filtered this CU out, we still want to keep iterating, but
+	 * there's no need to walk the rest of the CU info.
+	 */
+	if (cu == NULL)
+		return DWARF_CB_OK;
+
 	if (dwarf_child(die, &child) == 0) {
 		int err = die__process_unit(&child, cu, conf);
 		if (err)
dwarves.h +1 -0
index f5ae79f..92d102b 100644
@@ -72,6 +72,7 @@ struct conf_load {
 	enum load_steal_kind	(*steal)(struct cu *cu,
 					 struct conf_load *conf,
 					 void *thr_data);
+	struct cu *		(*early_cu_filter)(struct cu *cu);
 	int			(*thread_exit)(struct conf_load *conf, void *thr_data);
 	void			*cookie;
 	char			*format_path;
pahole.c +4 -0
index 954498d..42a9c16 100644
@@ -3765,6 +3765,10 @@ int main(int argc, char *argv[])
 	memset(tab, ' ', sizeof(tab) - 1);
 
 	conf_load.steal = pahole_stealer;
+
+	if (languages.exclude)
+		conf_load.early_cu_filter = cu__filter;
+
 	conf_load.thread_exit = pahole_thread_exit;
 
 	if (conf_load.reproducible_build) {
Signature · 1 line
2.46.0.rc2.264.g509ed76dc8-goog
Reviewed-by Tested-by on v2 1/1
#1 lore raw
Quoted 10 lines · Matthew Maurer

Without this, even with --lang_exclude=rust set, running on vmlinux with CONFIG_RUST enabled will lead to errors like:
die__process_function: tag not supported 0x2f (template_type_parameter)! because the filtering doesn't happen until finalization, but unsupported tags are reported during loading.

As an added bonus, this should speed up processing of large objects with filtered CUs, as their details will no longer be walked.

LGTM, thanks!

Quoted 54 lines
---
 dwarf_loader.c | 10 ++++++++++
 dwarves.h      |  1 +
 pahole.c       |  4 ++++
 3 files changed, 15 insertions(+)
dwarf_loader.c +10 -0
index b832c93..02a17f4 100644
@@ -2854,6 +2854,16 @@ static int die__process(Dwarf_Die *die, struct cu *cu, struct conf_load *conf)
 
 	cu->language = attr_numeric(die, DW_AT_language);
 
+	if (conf->early_cu_filter)
+		cu = conf->early_cu_filter(cu);
+
+	/*
+	 * If we filtered this CU out, we still want to keep iterating, but
+	 * there's no need to walk the rest of the CU info.
+	 */
+	if (cu == NULL)
+		return DWARF_CB_OK;
+
 	if (dwarf_child(die, &child) == 0) {
 		int err = die__process_unit(&child, cu, conf);
 		if (err)
dwarves.h +1 -0
index f5ae79f..92d102b 100644
@@ -72,6 +72,7 @@ struct conf_load {
 	enum load_steal_kind	(*steal)(struct cu *cu,
 					 struct conf_load *conf,
 					 void *thr_data);
+	struct cu *		(*early_cu_filter)(struct cu *cu);
 	int			(*thread_exit)(struct conf_load *conf, void *thr_data);
 	void			*cookie;
 	char			*format_path;
pahole.c +4 -0
index 954498d..42a9c16 100644
@@ -3765,6 +3765,10 @@ int main(int argc, char *argv[])
 	memset(tab, ' ', sizeof(tab) - 1);
 
 	conf_load.steal = pahole_stealer;
+
+	if (languages.exclude)
+		conf_load.early_cu_filter = cu__filter;
+
 	conf_load.thread_exit = pahole_thread_exit;
 
 	if (conf_load.reproducible_build) {
Reviewed-by Alan Maguire Tested-by Alan Maguire
#2 lore raw
Quoted 10 lines · Alan Maguire
Quoted 9 lines · Matthew Maurer

Without this, even with --lang_exclude=rust set, running on vmlinux with CONFIG_RUST enabled will lead to errors like:
die__process_function: tag not supported 0x2f (template_type_parameter)! because the filtering doesn't happen until finalization, but unsupported tags are reported during loading.

As an added bonus, this should speed up processing of large objects with filtered CUs, as their details will no longer be walked.

Quoted 6 lines
Quoted 1 line

LGTM, thanks!

Thanks, I just split it into two patches, one adding the new early filtering facility and with the second making then use of this new facility in pahole:

⬢[acme@toolbox pahole]$ git log --oneline -5
fbcca0f6c2fbeb52 (HEAD -> master) pahole: Do --languages_exclude CU filtering earlier
1f8d83d16d6d6dfa dwarf_loader: Allow filtering CUs early in loading
14be4e3d3fe56ce9 pahole: Only warn about multithreading not being available with older versions of elfutils in verbose mode ee933f35484ac934 dwarf_loader: Simplify the tag__alloc() routine
cbecc3785266f0c5 (x1/master) dwarf_loader: Do just one alloc for 'struct dwarf_tag + struct tag' ⬢[acme@toolbox pahole]$ git show
commit fbcca0f6c2fbeb52349e28f03093a7efafb040ea (HEAD -> master)

Author: Matthew Maurer <[email protected]>
Date:   Thu Aug 1 18:50:54 2024 +0000

pahole: Do --languages_exclude CU filtering earlier

With this, we can avoid warnings for unsupported DWARF tags like:

die__process_function: tag not supported 0x2f (template_type_parameter)!

when processing object files generated from languages such as Rust, for instance when building the Linux kernel with CONFIG_RUST, after appltying the next patch in this series.

As an added bonus, this should speed up processing of large objects with filtered CUs, as their details will no longer be walked.

pahole.c +4 -0
index 4db51071b97d5f09..42ef6c262384a8e0 100644
@@ -3766,6 +3766,10 @@ int main(int argc, char *argv[])
        memset(tab, ' ', sizeof(tab) - 1);
 
        conf_load.steal = pahole_stealer;
+
+       if (languages.exclude)
+               conf_load.early_cu_filter = cu__filter;
+
        conf_load.thread_exit = pahole_thread_exit;
 
        if (conf_load.reproducible_build) {

⬢[acme@toolbox pahole]$

#3 lore raw
Quoted 18 lines · Arnaldo Carvalho de Melo
Quoted 10 lines · Alan Maguire
Quoted 9 lines · Matthew Maurer

Without this, even with --lang_exclude=rust set, running on vmlinux with CONFIG_RUST enabled will lead to errors like:
die__process_function: tag not supported 0x2f (template_type_parameter)! because the filtering doesn't happen until finalization, but unsupported tags are reported during loading.

As an added bonus, this should speed up processing of large objects with filtered CUs, as their details will no longer be walked.

Quoted 6 lines
Quoted 1 line

LGTM, thanks!

Quoted 7 lines

Thanks, I just split it into two patches, one adding the new early filtering facility and with the second making then use of this new facility in pahole:

⬢[acme@toolbox pahole]$ git log --oneline -5
fbcca0f6c2fbeb52 (HEAD -> master) pahole: Do --languages_exclude CU filtering earlier 1f8d83d16d6d6dfa dwarf_loader: Allow filtering CUs early in loading

Tested building a kernel with CONFIG_RUST, no warnings (that template_type_param wouldn't appear anyway as I added initial support for it, at least for creating some structs out of its DWARF info, so no more warnings), but:

⬢[acme@toolbox linux]$ pahole -C '<kernel::str::RawFormatter as core::fmt::Write>::{vtable_type}' ../build/rust-kernel/rust/kernel.o
die__process_class: tag not supported 0x33 (variant_part) at <14f43>!

struct <kernel::str::RawFormatter as core::fmt::Write>::{vtable_type} {
	() *                       drop_in_place __attribute__((__aligned__(8))); /*     0     8 */
	usize                      size __attribute__((__aligned__(8))); /*     8     8 */
	usize                      align __attribute__((__aligned__(8))); /*    16     8 */
	() *                       __method3 __attribute__((__aligned__(8))); /*    24     8 */
	() *                       __method4 __attribute__((__aligned__(8))); /*    32     8 */
	() *                       __method5 __attribute__((__aligned__(8))); /*    40     8 */

	/* size: 48, cachelines: 1, members: 6 */
	/* forced alignments: 6 */
	/* last cacheline: 48 bytes */
} __attribute__((__aligned__(8)));

⬢[acme@toolbox linux]$

That DW_TAG_variant_part warning would show up without this series, so seems to be working as expected :-)

- Arnaldo