All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pahole: Implement cu_exclude_lang flag
@ 2022-04-21 14:47 Martin Reboredo
  2022-05-03 14:58 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Reboredo @ 2022-04-21 14:47 UTC (permalink / raw)
  To: arnaldo.melo, dwarves; +Cc: ast, andrii, daniel

Exclude compilation units that have the language id equal to the one
from the --cu_exclude_lang=LANG flag.

Required by Rust Linux builds due to failing BTF checks product of
things like rustc's struct reordering.

Signed-off-by: Martin Reboredo <yakoyoku@gmail.com>
Tested-by: Martin Reboredo <yakoyoku@gmail.com>
---
 dwarves.h | 18 ++++++++++++++++++
 pahole.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/dwarves.h b/dwarves.h
index 456b037..9d57a4f 100644
--- a/dwarves.h
+++ b/dwarves.h
@@ -204,6 +204,24 @@ enum dwarf_languages {
     LANG_ObjC_plus_plus	= 0x11,	/* Objective-C++ */
     LANG_UPC		= 0x12,	/* Unified Parallel C */
     LANG_D		= 0x13,	/* D */
+    LANG_Python	= 0x14,	/* Python */
+    LANG_OpenCL	= 0x15,	/* OpenCL */
+    LANG_Go	= 0x16,	/* Go */
+    LANG_Modula3	= 0x17,	/* Modula-3 */
+    LANG_Haskell	= 0x18,	/* Haskell */
+    LANG_C_plus_plus_03	= 0x19, /* ISO C++:2003 */
+    LANG_C_plus_plus_11	= 0x1a, /* ISO C++:2011 */
+    LANG_OCaml	= 0x1b,	/* OCaml */
+    LANG_Rust	= 0x1c,	/* Rust */
+    LANG_C11	= 0x1d,	/* ISO C:2011 */
+    LANG_Swift	= 0x1e,	/* Swift */
+    LANG_Julia	= 0x1f,	/* Julia */
+    LANG_Dylan	= 0x20,	/* Dylan */
+    LANG_C_plus_plus_14	= 0x21, /* ISO C++:2014 */
+    LANG_Fortran03	= 0x22,	/* ISO/IEC 1539-1:2004 */
+    LANG_Fortran08	= 0x23,	/* ISO/IEC 1539-1:2010 */
+    LANG_RenderScript	= 0x24, /* RenderScript Kernal Language */
+    LANG_BLISS	= 0x25,	/* BLISS */
 };
 
 /** struct debug_fmt_ops - specific to the underlying debug file format
diff --git a/pahole.c b/pahole.c
index a909b22..1c961fb 100644
--- a/pahole.c
+++ b/pahole.c
@@ -57,6 +57,8 @@ static size_t class__include_prefix_len;
 static char *cu__exclude_prefix;
 static size_t cu__exclude_prefix_len;
 
+static uint32_t cu__exclude_lang;
+
 static char *decl_exclude_prefix;
 static size_t decl_exclude_prefix_len;
 
@@ -615,6 +617,10 @@ static struct cu *cu__filter(struct cu *cu)
 		     cu__exclude_prefix_len) == 0))
 		return NULL;
 
+  if (cu__exclude_lang != 0 &&
+	    cu__exclude_lang == cu->language)
+		return NULL;
+
 	return cu;
 }
 
@@ -988,6 +994,39 @@ static void cu__account_nr_methods(struct cu *cu)
 	}
 }
 
+static const struct {
+  const char *name;
+  uint32_t id;
+} language_table[] = {
+	{ "C", LANG_C },
+	{ "C89", LANG_C89 },
+	{ "C99", LANG_C99 },
+	{ "C11", LANG_C11 },
+	{ "C++", LANG_C_plus_plus },
+	{ "C++03", LANG_C_plus_plus_03 },
+	{ "C++11", LANG_C_plus_plus_11 },
+	{ "C++14", LANG_C_plus_plus_14 },
+	{ "Fortran77", LANG_Fortran77 },
+	{ "Fortran90", LANG_Fortran90 },
+	{ "Fortran95", LANG_Fortran95 },
+	{ "Fortran03", LANG_Fortran03 },
+	{ "Fortran08", LANG_Fortran08 },
+	{ "Go", LANG_Go },
+	{ "Haskell", LANG_Haskell },
+	{ "Rust", LANG_Rust },
+	{ NULL, 0 },
+};
+
+static uint32_t language_id(const char *lang) {
+	for (int l = 0; language_table[l].name; l++) {
+		if (strcmp(lang, language_table[l].name) == 0) {
+			return language_table[l].id;
+		}
+	}
+
+	return 0;
+}
+
 static char tab[128];
 
 static void print_structs_with_pointer_to(struct cu *cu, uint32_t type)
@@ -1137,6 +1176,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_skip_missing          332
 #define ARGP_skip_encoding_btf_type_tag 333
 #define ARGP_compile		   334
+#define ARGP_exclude_lang	   335
 
 static const struct argp_option pahole__options[] = {
 	{
@@ -1512,6 +1552,12 @@ static const struct argp_option pahole__options[] = {
 		.key  = ARGP_devel_stats,
 		.doc  = "Print internal data structures stats",
 	},
+	{
+		.name = "cu_exclude_lang",
+		.key  = ARGP_exclude_lang,
+		.arg  = "LANG",
+		.doc  = "exclude LANGuage compilation units",
+	},
 	{
 		.name = "skip_encoding_btf_decl_tag",
 		.key  = ARGP_skip_encoding_btf_decl_tag,
@@ -1681,6 +1727,8 @@ static error_t pahole__options_parser(int key, char *arg,
 		conf_load.hashtable_bits = atoi(arg);	break;
 	case ARGP_devel_stats:
 		conf_load.ptr_table_stats = true;	break;
+	case ARGP_exclude_lang:
+		cu__exclude_lang = language_id(arg);	break;
 	case ARGP_skip_encoding_btf_decl_tag:
 		conf_load.skip_encoding_btf_decl_tag = true;	break;
 	case ARGP_skip_missing:
-- 
2.36.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pahole: Implement cu_exclude_lang flag
  2022-04-21 14:47 [PATCH] pahole: Implement cu_exclude_lang flag Martin Reboredo
@ 2022-05-03 14:58 ` Arnaldo Carvalho de Melo
  2022-05-04 19:42   ` Martin Reboredo
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2022-05-03 14:58 UTC (permalink / raw)
  To: Martin Reboredo; +Cc: arnaldo.melo, dwarves, ast, andrii, daniel

Em Thu, Apr 21, 2022 at 11:47:15AM -0300, Martin Reboredo escreveu:
> Exclude compilation units that have the language id equal to the one
> from the --cu_exclude_lang=LANG flag.
> 
> Required by Rust Linux builds due to failing BTF checks product of
> things like rustc's struct reordering.

Sorry, when I saw this patch I already had committed a similar one, can
you please take a look?

Its in the "next" branch at:

https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=next

- Arnaldo
 
> Signed-off-by: Martin Reboredo <yakoyoku@gmail.com>
> Tested-by: Martin Reboredo <yakoyoku@gmail.com>
> ---
>  dwarves.h | 18 ++++++++++++++++++
>  pahole.c  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 66 insertions(+)
> 
> diff --git a/dwarves.h b/dwarves.h
> index 456b037..9d57a4f 100644
> --- a/dwarves.h
> +++ b/dwarves.h
> @@ -204,6 +204,24 @@ enum dwarf_languages {
>      LANG_ObjC_plus_plus	= 0x11,	/* Objective-C++ */
>      LANG_UPC		= 0x12,	/* Unified Parallel C */
>      LANG_D		= 0x13,	/* D */
> +    LANG_Python	= 0x14,	/* Python */
> +    LANG_OpenCL	= 0x15,	/* OpenCL */
> +    LANG_Go	= 0x16,	/* Go */
> +    LANG_Modula3	= 0x17,	/* Modula-3 */
> +    LANG_Haskell	= 0x18,	/* Haskell */
> +    LANG_C_plus_plus_03	= 0x19, /* ISO C++:2003 */
> +    LANG_C_plus_plus_11	= 0x1a, /* ISO C++:2011 */
> +    LANG_OCaml	= 0x1b,	/* OCaml */
> +    LANG_Rust	= 0x1c,	/* Rust */
> +    LANG_C11	= 0x1d,	/* ISO C:2011 */
> +    LANG_Swift	= 0x1e,	/* Swift */
> +    LANG_Julia	= 0x1f,	/* Julia */
> +    LANG_Dylan	= 0x20,	/* Dylan */
> +    LANG_C_plus_plus_14	= 0x21, /* ISO C++:2014 */
> +    LANG_Fortran03	= 0x22,	/* ISO/IEC 1539-1:2004 */
> +    LANG_Fortran08	= 0x23,	/* ISO/IEC 1539-1:2010 */
> +    LANG_RenderScript	= 0x24, /* RenderScript Kernal Language */
> +    LANG_BLISS	= 0x25,	/* BLISS */
>  };
>  
>  /** struct debug_fmt_ops - specific to the underlying debug file format
> diff --git a/pahole.c b/pahole.c
> index a909b22..1c961fb 100644
> --- a/pahole.c
> +++ b/pahole.c
> @@ -57,6 +57,8 @@ static size_t class__include_prefix_len;
>  static char *cu__exclude_prefix;
>  static size_t cu__exclude_prefix_len;
>  
> +static uint32_t cu__exclude_lang;
> +
>  static char *decl_exclude_prefix;
>  static size_t decl_exclude_prefix_len;
>  
> @@ -615,6 +617,10 @@ static struct cu *cu__filter(struct cu *cu)
>  		     cu__exclude_prefix_len) == 0))
>  		return NULL;
>  
> +  if (cu__exclude_lang != 0 &&
> +	    cu__exclude_lang == cu->language)
> +		return NULL;
> +
>  	return cu;
>  }
>  
> @@ -988,6 +994,39 @@ static void cu__account_nr_methods(struct cu *cu)
>  	}
>  }
>  
> +static const struct {
> +  const char *name;
> +  uint32_t id;
> +} language_table[] = {
> +	{ "C", LANG_C },
> +	{ "C89", LANG_C89 },
> +	{ "C99", LANG_C99 },
> +	{ "C11", LANG_C11 },
> +	{ "C++", LANG_C_plus_plus },
> +	{ "C++03", LANG_C_plus_plus_03 },
> +	{ "C++11", LANG_C_plus_plus_11 },
> +	{ "C++14", LANG_C_plus_plus_14 },
> +	{ "Fortran77", LANG_Fortran77 },
> +	{ "Fortran90", LANG_Fortran90 },
> +	{ "Fortran95", LANG_Fortran95 },
> +	{ "Fortran03", LANG_Fortran03 },
> +	{ "Fortran08", LANG_Fortran08 },
> +	{ "Go", LANG_Go },
> +	{ "Haskell", LANG_Haskell },
> +	{ "Rust", LANG_Rust },
> +	{ NULL, 0 },
> +};
> +
> +static uint32_t language_id(const char *lang) {
> +	for (int l = 0; language_table[l].name; l++) {
> +		if (strcmp(lang, language_table[l].name) == 0) {
> +			return language_table[l].id;
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>  static char tab[128];
>  
>  static void print_structs_with_pointer_to(struct cu *cu, uint32_t type)
> @@ -1137,6 +1176,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
>  #define ARGP_skip_missing          332
>  #define ARGP_skip_encoding_btf_type_tag 333
>  #define ARGP_compile		   334
> +#define ARGP_exclude_lang	   335
>  
>  static const struct argp_option pahole__options[] = {
>  	{
> @@ -1512,6 +1552,12 @@ static const struct argp_option pahole__options[] = {
>  		.key  = ARGP_devel_stats,
>  		.doc  = "Print internal data structures stats",
>  	},
> +	{
> +		.name = "cu_exclude_lang",
> +		.key  = ARGP_exclude_lang,
> +		.arg  = "LANG",
> +		.doc  = "exclude LANGuage compilation units",
> +	},
>  	{
>  		.name = "skip_encoding_btf_decl_tag",
>  		.key  = ARGP_skip_encoding_btf_decl_tag,
> @@ -1681,6 +1727,8 @@ static error_t pahole__options_parser(int key, char *arg,
>  		conf_load.hashtable_bits = atoi(arg);	break;
>  	case ARGP_devel_stats:
>  		conf_load.ptr_table_stats = true;	break;
> +	case ARGP_exclude_lang:
> +		cu__exclude_lang = language_id(arg);	break;
>  	case ARGP_skip_encoding_btf_decl_tag:
>  		conf_load.skip_encoding_btf_decl_tag = true;	break;
>  	case ARGP_skip_missing:
> -- 
> 2.36.0

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pahole: Implement cu_exclude_lang flag
  2022-05-03 14:58 ` Arnaldo Carvalho de Melo
@ 2022-05-04 19:42   ` Martin Reboredo
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Reboredo @ 2022-05-04 19:42 UTC (permalink / raw)
  To: arnaldo.melo, dwarves; +Cc: ast, andrii, daniel

>Em Thu, Apr 21, 2022 at 11:47:15AM -0300, Martin Reboredo escreveu:
>> Exclude compilation units that have the language id equal to the one
>> from the --cu_exclude_lang=LANG flag.
>> 
>> Required by Rust Linux builds due to failing BTF checks product of
>> things like rustc's struct reordering.
>
>Sorry, when I saw this patch I already had committed a similar one, can
>you please take a look?
>
>Its in the "next" branch at:
>
>https://git.kernel.org/pub/scm/devel/pahole/pahole.git/commit/?h=next

I've saw said patches and performed local testing with a Rust-for-Linux
kernel, both in Qemu and bare metal, the kernel and it was working as
expected, bpftool could eject a proper header

$ bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h

and I could do BTF test from a guide by Aniket Bhattacharyea in
containiq.com (https://www.containiq.com/post/btf-bpf-type-format).

So yeah, I can say that this patch was effectively superseeded by the
patch series at next. Thanks for your attention though.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-04 19:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-21 14:47 [PATCH] pahole: Implement cu_exclude_lang flag Martin Reboredo
2022-05-03 14:58 ` Arnaldo Carvalho de Melo
2022-05-04 19:42   ` Martin Reboredo

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.