Skip to contentSkip to conversation

btf: Add --btf_prefix flag

PATCH In review 程书意 5 participants 17 messages May 17, 2021 – May 27, 2021 1 message not in the archive

lore
Share & tools
lore

程书意

author
#0 lore raw

PATCH 1/1 btf: Add --btf_prefix flag

To solve problems similar to _RH_KABI_REPLACE, _RH_KABI_REPLACE makes many structures have different names, resulting in a particularly large vmlinux btf. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --btf_prefix flag, the running time is:
                real 8m28.912s
                user 8m27.271s
                sys 0m1.471s
And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --btf_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running time of the command is:
                real 0m19.634s
                user 0m18.457s
                sys 0m1.169s
The size of the generated btf segment is 3117719 bytes.

Thanks.

---
 pahole.c         | 10 ++++++++++
 pahole_strings.h |  2 ++
 strings.c        |  9 +++++++--

 3 files changed, 19 insertions(+), 2 deletions(-)
pahole.c +0 -0
index dc40ccf..0b4f4ca 100644
@@ -24,6 +24,7 @@

 #include "btf_encoder.h"
 #include "libbtf.h"
 #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"

 static bool btf_encode;
 static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version; #define ARGP_btf_gen_floats       322
 #define ARGP_btf_gen_all       323
 #define ARGP_with_flexible_array   324
+#define ARGP_btf_prefix   325

 static const struct argp_option pahole__options[] = {
     {
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = { .doc  = "Path to the base BTF file",
     },
     {
+        .name = "btf_prefix",
+        .key = ARGP_btf_prefix,
+        .arg = "STRING",
+        .doc = "Strings with the same prefix are considered the same.", +    },
+    {
         .name = "btf_encode",
         .key  = 'J',
         .doc  = "Encode as BTF",
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char *arg, btf_encode_force = true;        break;
     case ARGP_btf_base:
         base_btf_file = arg;            break;
+    case ARGP_btf_prefix:
+        btf_prefix = arg;        break;
     case ARGP_numeric_version:
         print_numeric_version = true;        break;
     case ARGP_btf_gen_floats:

pahole_strings.h +0 -0
index 522fbf2..bf3dc7c 100644
@@ -14,6 +14,8 @@ struct strings {

     struct btf *btf;
 };

+extern const char *btf_prefix;
+
 struct strings *strings__new(void);

 void strings__delete(struct strings *strings);

strings.c +0 -0
index d37f49d..911ce25 100644
@@ -16,6 +16,9 @@
 

 #include "dutil.h"
 #include "lib/bpf/src/libbpf.h"
+#include "libbtf.h"
+
+const char *btf_prefix;

 struct strings *strings__new(void)
 {
@@ -47,8 +50,10 @@ strings_t strings__add(struct strings *strs, const char *str)

     if (str == NULL)
         return 0;
-
-    index = btf__add_str(strs->btf, str);
+    if(btf_prefix && strncmp(str,btf_prefix,strlen(btf_prefix))==0) +        index = btf__add_str(strs->btf, btf_prefix);
+    else
+        index = btf__add_str(strs->btf, str);
     if (index < 0)
         return 0;

Signature · 1 line
1.8.3.1
#1 lore raw

Em Mon, May 17, 2021 at 08:06:30PM +0800, 程书意 escreveu:

Quoted 1 line

To solve problems similar to _RH_KABI_REPLACE, _RH_KABI_REPLACE makes many

Can you explain what is _RH_KABI_REPLACE, why it is needed so that people unfamiliar with it can make sense of your patch?

Also why "btf_prefix" when this is related to this other feature? Can you find a better name?

You also forgot to update the man page at man-pages/pahole.1.

- Arnaldo

Quoted 88 lines

structures have different names, resulting in a particularly large vmlinux btf. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --btf_prefix flag, the running time is:
                real 8m28.912s
                user 8m27.271s
                sys 0m1.471s
And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --btf_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running
time of the command is:
                real 0m19.634s
                user 0m18.457s
                sys 0m1.169s
The size of the generated btf segment is 3117719 bytes.

Thanks.

---
 pahole.c         | 10 ++++++++++
 pahole_strings.h |  2 ++
 strings.c        |  9 +++++++--

 3 files changed, 19 insertions(+), 2 deletions(-)
pahole.c +8 -0
index dc40ccf..0b4f4ca 100644
@@ -24,6 +24,7 @@
  #include "btf_encoder.h"
  #include "libbtf.h"
  #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
  static bool btf_encode;
  static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
  #define ARGP_btf_gen_floats       322
  #define ARGP_btf_gen_all       323
  #define ARGP_with_flexible_array   324
+#define ARGP_btf_prefix   325
 
  static const struct argp_option pahole__options[] = {
      {
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
          .doc  = "Path to the base BTF file",
      },
      {
+        .name = "btf_prefix",
+        .key = ARGP_btf_prefix,
+        .arg = "STRING",
+        .doc = "Strings with the same prefix are considered the same.",
+    },
+    {
          .name = "btf_encode",
          .key  = 'J',
          .doc  = "Encode as BTF",
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char
 *arg,
          btf_encode_force = true;        break;

     case ARGP_btf_base:
         base_btf_file = arg;            break; +    case ARGP_btf_prefix:
+        btf_prefix = arg;        break; case ARGP_numeric_version:
         print_numeric_version = true;        break; case ARGP_btf_gen_floats:

pahole_strings.h +2 -0
index 522fbf2..bf3dc7c 100644
@@ -14,6 +14,8 @@ struct strings {
      struct btf *btf;
  };
 
+extern const char *btf_prefix;
+
  struct strings *strings__new(void);
 
  void strings__delete(struct strings *strings);
strings.c +0 -0
index d37f49d..911ce25 100644

strings.c line 19

Quoted 4 lines
strings.c +1 -0
@@ -16,6 +16,9 @@
 
  #include "dutil.h"
  #include "lib/bpf/src/libbpf.h"
+#include "libbtf.h"

Why do you need to add this new include? I guess you meant including pahole_strings.h to get the forward declaration for 'btf_prefix'?

strings.c strings_t strings__add(struct strings *strs, const char · line 54

Quoted 13 lines
strings.c +3 -2
+
+const char *btf_prefix;
 
  struct strings *strings__new(void)
  {
@@ -47,8 +50,10 @@ strings_t strings__add(struct strings *strs, const char
 *str)
 
      if (str == NULL)
          return 0;
-
-    index = btf__add_str(strs->btf, str);
+    if(btf_prefix && strncmp(str,btf_prefix,strlen(btf_prefix))==0)

Please also follow the existing coding style, i.e. use a space after 'if' and also after the commas.

- Arnaldo

Quoted 10 lines
strings.c +3 -0
+        index = btf__add_str(strs->btf, btf_prefix);
+    else
+        index = btf__add_str(strs->btf, str);
      if (index < 0)
          return 0;
Signature · 2 lines
-- 
1.8.3.1
Signature · 1 line
- Arnaldo
author
#2 lore raw
Quoted 4 lines · Arnaldo Carvalho de Melo

Em Mon, May 17, 2021 at 08:06:30PM +0800, 程书意 escreveu:

Quoted 1 line

To solve problems similar to _RH_KABI_REPLACE, _RH_KABI_REPLACE makes many

Can you explain what is _RH_KABI_REPLACE, why it is needed so that people unfamiliar with it can make sense of your patch?

The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

# define _RH_KABI_REPLACE(_orig, _new)         \
     union {                        \
         _new;                    \
         struct {                \
             _orig;                \
         } __UNIQUE_ID(rh_kabi_hide);        \
         __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
     }

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide29;
        union {        };
    };
};
struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide31;
        union {        };
    };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming.

Quoted 3 lines

Also why "btf_prefix" when this is related to this other feature? Can you find a better name?

"btf_prefix" means that if two strings have the same prefix, treat them as the same string.From the above example,if btf_prefix is __UNIQUE_ID_rh_kabi_hide, then __UNIQUE_ID_rh_kabi_hide29 and __UNIQUE_ID_rh_kabi_hide31 are equal.Maybe "btf_kabi_prefix_string" is better

Quoted 3 lines

You also forgot to update the man page at man-pages/pahole.1.

- Arnaldo

Yes i forgot.

Quoted 61 lines
Quoted 61 lines

structures have different names, resulting in a particularly large vmlinux btf. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --btf_prefix flag, the running time is:
                real 8m28.912s
                user 8m27.271s
                sys 0m1.471s
And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --btf_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running
time of the command is:
                real 0m19.634s
                user 0m18.457s
                sys 0m1.169s
The size of the generated btf segment is 3117719 bytes.

Thanks.

---
  pahole.c         | 10 ++++++++++
  pahole_strings.h |  2 ++
  strings.c        |  9 +++++++--
  3 files changed, 19 insertions(+), 2 deletions(-)
pahole.c +8 -0
index dc40ccf..0b4f4ca 100644
@@ -24,6 +24,7 @@
  #include "btf_encoder.h"
  #include "libbtf.h"
  #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
  static bool btf_encode;
  static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
  #define ARGP_btf_gen_floats       322
  #define ARGP_btf_gen_all       323
  #define ARGP_with_flexible_array   324
+#define ARGP_btf_prefix   325
 
  static const struct argp_option pahole__options[] = {
      {
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
          .doc  = "Path to the base BTF file",
      },
      {
+        .name = "btf_prefix",
+        .key = ARGP_btf_prefix,
+        .arg = "STRING",
+        .doc = "Strings with the same prefix are considered the same.",
+    },
+    {
          .name = "btf_encode",
          .key  = 'J',
          .doc  = "Encode as BTF", @@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int 

key, char *arg,          btf_encode_force = true;        break; case ARGP_btf_base:          base_btf_file = arg;            break;

Quoted 8 lines
Quoted 6 lines

+    case ARGP_btf_prefix: +        btf_prefix = arg;        break;
     case ARGP_numeric_version:          print_numeric_version = true;        break;      case ARGP_btf_gen_floats: diff --git a/pahole_strings.h b/pahole_strings.h index 522fbf2..bf3dc7c 100644
--- a/pahole_strings.h +++ b/pahole_strings.h @@ -14,6 +14,8 @@
struct strings {      struct btf *btf;  }; +extern const char *btf_prefix; +  struct strings *strings__new(void);  void strings__delete(struct strings *strings); diff --git a/strings.c b/strings.c index d37f49d..911ce25 100644 --- a/strings.c +++ b/strings.c @@ -16,6 +16,9 @@  #include "dutil.h"
 #include "lib/bpf/src/libbpf.h"
+#include "libbtf.h"

Why do you need to add this new include? I guess you meant including pahole_strings.h to get the forward declaration for 'btf_prefix'?

It is of no use, I forgot to delete it.

Quoted 16 lines

pahole.c strings_t strings__add(struct strings *strs, const char · line 54

Quoted 13 lines
pahole.c +3 -2
+
+const char *btf_prefix;
 
  struct strings *strings__new(void)
  {
@@ -47,8 +50,10 @@ strings_t strings__add(struct strings *strs, const char
 *str)
 
      if (str == NULL)
          return 0;
-
-    index = btf__add_str(strs->btf, str);
+    if(btf_prefix && strncmp(str,btf_prefix,strlen(btf_prefix))==0)

Please also follow the existing coding style, i.e. use a space after 'if' and also after the commas.

Quoted 2 lines

- Arnaldo

Okay, I know. If you want to receive this patch, I will send a complete patch later.

Quoted 10 lines
Quoted 10 lines
pahole.c +3 -0
+        index = btf__add_str(strs->btf, btf_prefix);
+    else
+        index = btf__add_str(strs->btf, str);
      if (index < 0)
          return 0;
Signature · 2 lines
-- 
1.8.3.1
#3 lore raw

Em Tue, May 18, 2021 at 05:02:26PM +0800, chengshuyi escreveu:

Quoted 44 lines · Arnaldo Carvalho de Melo
Quoted 4 lines

Em Mon, May 17, 2021 at 08:06:30PM +0800, 程书意 escreveu:

Quoted 1 line

To solve problems similar to _RH_KABI_REPLACE, _RH_KABI_REPLACE makes many

Can you explain what is _RH_KABI_REPLACE, why it is needed so that people unfamiliar with it can make sense of your patch?

The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

# define _RH_KABI_REPLACE(_orig, _new)         \
     union {                        \
         _new;                    \
         struct {                \
             _orig;                \
         } __UNIQUE_ID(rh_kabi_hide);        \
         __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
     }

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide29;
        union {        };
    };
};
struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide31;
        union {        };
    };
};

Quoted 8 lines

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming.

Quoted 3 lines

Also why "btf_prefix" when this is related to this other feature? Can you find a better name?

"btf_prefix" means that if two strings have the same prefix, treat them as

I understood what is its purpose, but pahole is not just about DWARF and BTF, it has an admittedly unmaintained CTF encoder that predates BTF and was even used as an starting point for the BTF encoder, so using BTF isn't appropriate, perhaps --common_prefix? Or even --kabi_prefix to make it even more explicit?

- Arnaldo

Quoted 123 lines

the same string.From the above example,if btf_prefix is __UNIQUE_ID_rh_kabi_hide, then __UNIQUE_ID_rh_kabi_hide29 and __UNIQUE_ID_rh_kabi_hide31 are equal.Maybe "btf_kabi_prefix_string" is better

Quoted 3 lines

You also forgot to update the man page at man-pages/pahole.1.

- Arnaldo

Yes i forgot.

Quoted 69 lines
Quoted 69 lines

structures have different names, resulting in a particularly large vmlinux btf. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --btf_prefix flag, the running time is:
                real 8m28.912s
                user 8m27.271s
                sys 0m1.471s
And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --btf_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running
time of the command is:
                real 0m19.634s
                user 0m18.457s
                sys 0m1.169s
The size of the generated btf segment is 3117719 bytes.

Thanks.

---
  pahole.c         | 10 ++++++++++
  pahole_strings.h |  2 ++
  strings.c        |  9 +++++++--
  3 files changed, 19 insertions(+), 2 deletions(-)
pahole.c +8 -0
index dc40ccf..0b4f4ca 100644
@@ -24,6 +24,7 @@
  #include "btf_encoder.h"
  #include "libbtf.h"
  #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
  static bool btf_encode;
  static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
  #define ARGP_btf_gen_floats       322
  #define ARGP_btf_gen_all       323
  #define ARGP_with_flexible_array   324
+#define ARGP_btf_prefix   325
 
  static const struct argp_option pahole__options[] = {
      {
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
          .doc  = "Path to the base BTF file",
      },
      {
+        .name = "btf_prefix",
+        .key = ARGP_btf_prefix,
+        .arg = "STRING",
+        .doc = "Strings with the same prefix are considered the same.",
+    },
+    {
          .name = "btf_encode",
          .key  = 'J',
          .doc  = "Encode as BTF", @@ -1297,6 +1305,8 @@ static

error_t pahole__options_parser(int key, char *arg,
btf_encode_force = true;        break; case ARGP_btf_base:
    base_btf_file = arg;            break; +    case
ARGP_btf_prefix: +        btf_prefix = arg;        break;      case
ARGP_numeric_version:          print_numeric_version = true; break;      case ARGP_btf_gen_floats: diff --git a/pahole_strings.h b/pahole_strings.h index 522fbf2..bf3dc7c 100644 --- a/pahole_strings.h +++ b/pahole_strings.h @@ -14,6 +14,8 @@ struct strings {      struct btf *btf;  }; +extern const char *btf_prefix;

Quoted 8 lines
Quoted 6 lines

+  struct strings *strings__new(void);  void strings__delete(struct strings *strings); diff --git a/strings.c b/strings.c index d37f49d..911ce25 100644 --- a/strings.c +++ b/strings.c @@ -16,6 +16,9 @@  #include "dutil.h"
 #include "lib/bpf/src/libbpf.h"
+#include "libbtf.h"

Why do you need to add this new include? I guess you meant including pahole_strings.h to get the forward declaration for 'btf_prefix'?

It is of no use, I forgot to delete it.

Quoted 16 lines

pahole.c strings_t strings__add(struct strings *strs, const char · line 54

Quoted 13 lines
pahole.c +3 -2
+
+const char *btf_prefix;
 
  struct strings *strings__new(void)
  {
@@ -47,8 +50,10 @@ strings_t strings__add(struct strings *strs, const char
 *str)
 
      if (str == NULL)
          return 0;
-
-    index = btf__add_str(strs->btf, str);
+    if(btf_prefix && strncmp(str,btf_prefix,strlen(btf_prefix))==0)

Please also follow the existing coding style, i.e. use a space after 'if' and also after the commas.

Quoted 2 lines

- Arnaldo

Okay, I know. If you want to receive this patch, I will send a complete patch later.

Quoted 10 lines
Quoted 10 lines
pahole.c +3 -0
+        index = btf__add_str(strs->btf, btf_prefix);
+    else
+        index = btf__add_str(strs->btf, str);
      if (index < 0)
          return 0;
Signature · 2 lines
-- 
1.8.3.1
Signature · 1 line
- Arnaldo
#4 lore raw
Quoted 53 lines · Arnaldo Carvalho de Melo

Em Tue, May 18, 2021 at 05:02:26PM +0800, chengshuyi escreveu:

Quoted 51 lines · Arnaldo Carvalho de Melo
Quoted 4 lines

Em Mon, May 17, 2021 at 08:06:30PM +0800, 程书意 escreveu:

Quoted 1 line

To solve problems similar to _RH_KABI_REPLACE, _RH_KABI_REPLACE makes many

Can you explain what is _RH_KABI_REPLACE, why it is needed so that people unfamiliar with it can make sense of your patch?

The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

# define _RH_KABI_REPLACE(_orig, _new)         \
     union {                        \
         _new;                    \
         struct {                \
             _orig;                \
         } __UNIQUE_ID(rh_kabi_hide);        \
         __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
     }

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
     union {
         struct acpi_device *companion;
         struct {
             void *handle;
         } __UNIQUE_ID_rh_kabi_hide29;
         union {        };
     };
};
struct acpi_dev_node {
     union {
         struct acpi_device *companion;
         struct {
             void *handle;
         } __UNIQUE_ID_rh_kabi_hide31;
         union {        };
     };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming.

Quoted 3 lines

Also why "btf_prefix" when this is related to this other feature? Can you find a better name?

Quoted 8 lines
Quoted 1 line

"btf_prefix" means that if two strings have the same prefix, treat them as

I understood what is its purpose, but pahole is not just about DWARF and BTF, it has an admittedly unmaintained CTF encoder that predates BTF and was even used as an starting point for the BTF encoder, so using BTF isn't appropriate, perhaps --common_prefix? Or even --kabi_prefix to make it even more explicit?

+1 for --kabi_prefix

Quoted 129 lines

- Arnaldo

Quoted 107 lines

the same string.From the above example,if btf_prefix is __UNIQUE_ID_rh_kabi_hide, then __UNIQUE_ID_rh_kabi_hide29 and __UNIQUE_ID_rh_kabi_hide31 are equal.Maybe "btf_kabi_prefix_string" is better

Quoted 3 lines

You also forgot to update the man page at man-pages/pahole.1.

- Arnaldo

Yes i forgot.

Quoted 69 lines
Quoted 69 lines

structures have different names, resulting in a particularly large vmlinux btf. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --btf_prefix flag, the running time is:

                 real 8m28.912s
                 user 8m27.271s
                 sys 0m1.471s

And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --btf_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running
time of the command is:

                 real 0m19.634s
                 user 0m18.457s
                 sys 0m1.169s

The size of the generated btf segment is 3117719 bytes.

Thanks.

---
  pahole.c         | 10 ++++++++++
  pahole_strings.h |  2 ++
  strings.c        |  9 +++++++--
  3 files changed, 19 insertions(+), 2 deletions(-)
pahole.c +8 -0
index dc40ccf..0b4f4ca 100644
@@ -24,6 +24,7 @@
  #include "btf_encoder.h"
  #include "libbtf.h"
  #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
  static bool btf_encode;
  static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
  #define ARGP_btf_gen_floats       322
  #define ARGP_btf_gen_all       323
  #define ARGP_with_flexible_array   324
+#define ARGP_btf_prefix   325
 
  static const struct argp_option pahole__options[] = {
      {
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
          .doc  = "Path to the base BTF file",
      },
      {
+        .name = "btf_prefix",
+        .key = ARGP_btf_prefix,
+        .arg = "STRING",
+        .doc = "Strings with the same prefix are considered the same.",
+    },
+    {
          .name = "btf_encode",
          .key  = 'J',
          .doc  = "Encode as BTF", @@ -1297,6 +1305,8 @@ static

error_t pahole__options_parser(int key, char *arg,
btf_encode_force = true; break; case ARGP_btf_base:
base_btf_file = arg; break; + case
ARGP_btf_prefix: + btf_prefix = arg; break; case
ARGP_numeric_version: print_numeric_version = true;
break; case ARGP_btf_gen_floats: diff --git a/pahole_strings.h
b/pahole_strings.h index 522fbf2..bf3dc7c 100644 --- a/pahole_strings.h +++ b/pahole_strings.h @@ -14,6 +14,8 @@ struct
strings { struct btf *btf; }; +extern const char *btf_prefix;

Quoted 8 lines
Quoted 6 lines

+ struct strings *strings__new(void); void strings__delete(struct strings *strings); diff --git a/strings.c b/strings.c index d37f49d..911ce25 100644 --- a/strings.c +++ b/strings.c @@ -16,6 +16,9 @@ #include "dutil.h"
#include "lib/bpf/src/libbpf.h"
+#include "libbtf.h"

Why do you need to add this new include? I guess you meant including pahole_strings.h to get the forward declaration for 'btf_prefix'?

It is of no use, I forgot to delete it.

Quoted 16 lines

pahole.c strings_t strings__add(struct strings *strs, const char · line 54

Quoted 13 lines
pahole.c +3 -2
+
+const char *btf_prefix;
 
  struct strings *strings__new(void)
  {
@@ -47,8 +50,10 @@ strings_t strings__add(struct strings *strs, const char
 *str)
 
      if (str == NULL)
          return 0;
-
-    index = btf__add_str(strs->btf, str);
+    if(btf_prefix && strncmp(str,btf_prefix,strlen(btf_prefix))==0)

Please also follow the existing coding style, i.e. use a space after 'if' and also after the commas.

Quoted 16 lines
Quoted 2 lines

- Arnaldo

Okay, I know. If you want to receive this patch, I will send a complete patch later.

Quoted 10 lines
Quoted 10 lines
pahole.c +3 -1
+        index = btf__add_str(strs->btf, btf_prefix);
+    else
+        index = btf__add_str(strs->btf, str);
      if (index < 0)
          return 0;
 
--

1.8.3.1

--

- Arnaldo

#5 lore raw

PATCH v2 1/1 pahole: Add --kabi_prefix flag

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

# define _RH_KABI_REPLACE(_orig, _new)            \
    union {                        \
        _new;                    \
        struct {                \
            _orig;                \
        } __UNIQUE_ID(rh_kabi_hide);        \
        __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
    }

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide29;
        union {        };
    };
};
struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide31;
        union {        };
    };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --kabi_prefix flag, the running time is:

                real 8m28.912s
                user 8m27.271s
                sys 0m1.471s

And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --kabi_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running time of the command is:

                real 0m19.634s
                user 0m18.457s
                sys 0m1.169s

And the size of the generated btf segment is 3117719 bytes.

---

v1:https://lore.kernel.org/dwarves/CAEf4Bzazh4RNCY3rGRRXfO2wJ7DSiMx8w+61B_hjhu9FrOffpQ@mail.gmail.com v1->v2:
--Change btf_prefix to --kabi_prefix.
--Add man page.
--Add space after if and comma.

 man-pages/pahole.1 |  4 ++++
 pahole.c           | 10 ++++++++++
 pahole_strings.h   |  2 ++
 strings.c          |  9 ++++++++-
 4 files changed, 24 insertions(+), 1 deletion(-)
man-pages/pahole.1 +0 -0
index a10738f..2659fe6 100644
@@ -340,6 +340,10 @@ Show a traditional string version, i.e.: "v1.18".
 Show a numeric only version, suitable for use in Makefiles and scripts 

where
one wants to know what if the installed version has some feature,
i.e.: 118 instead of "v1.18".

+.TP
+.B \-\-kabi_prefix=STRING
+When the prefix of the string is STRING, treat the string as STRING. +
.SH NOTES

To enable the generation of debugging information in the Linux kernel
build

pahole.c +10 -0
index dc40ccf..6a700d9 100644
@@ -24,6 +24,7 @@
 #include "btf_encoder.h"
 #include "libbtf.h"
 #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
 static bool btf_encode;
 static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_btf_gen_floats	   322
 #define ARGP_btf_gen_all	   323
 #define ARGP_with_flexible_array   324
+#define ARGP_kabi_prefix   325
 
 static const struct argp_option pahole__options[] = {
 	{
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
 		.doc  = "Path to the base BTF file",
 	},
 	{
+		.name = "kabi_prefix",
+		.key = ARGP_kabi_prefix,
+		.arg = "STRING",
+		.doc = "When the prefix of the string is STRING, treat the string as STRING.",
+	},
+	{
 		.name = "btf_encode",
 		.key  = 'J',
 		.doc  = "Encode as BTF",
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char *arg,
 		btf_encode_force = true;		break;
 	case ARGP_btf_base:
 		base_btf_file = arg;			break;
+	case ARGP_kabi_prefix:
+		kabi_prefix = arg;		break;
 	case ARGP_numeric_version:
 		print_numeric_version = true;		break;
 	case ARGP_btf_gen_floats:
pahole_strings.h +2 -0
index 522fbf2..a836ba8 100644
@@ -14,6 +14,8 @@ struct strings {
 	struct btf *btf;
 };
 
+extern const char *kabi_prefix;
+
 struct strings *strings__new(void);
 
 void strings__delete(struct strings *strings);
strings.c +8 -1
index d37f49d..d1a54ec 100644
@@ -17,6 +17,8 @@
 #include "dutil.h"
 #include "lib/bpf/src/libbpf.h"
 
+const char *kabi_prefix;
+
 struct strings *strings__new(void)
 {
 	struct strings *strs = malloc(sizeof(*strs));
@@ -48,7 +50,12 @@ strings_t strings__add(struct strings *strs, const char *str)
 	if (str == NULL)
 		return 0;
 
-	index = btf__add_str(strs->btf, str);
+	if (kabi_prefix &&
+		strncmp(str, kabi_prefix, strlen(kabi_prefix)) == 0)
+		index = btf__add_str(strs->btf, kabi_prefix);
+	else
+		index = btf__add_str(strs->btf, str);
+		
 	if (index < 0)
 		return 0;
 
Signature · 1 line
1.8.3.1
#6 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

Quoted 4 lines · Shuyi Cheng

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

Quoted 8 lines
# define _RH_KABI_REPLACE(_orig, _new)            \
    union {                        \
        _new;                    \
        struct {                \
            _orig;                \
        } __UNIQUE_ID(rh_kabi_hide);        \
        __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
    }

hi,
that macro sounds familiar ;-) I think this should be already solved directly in the header file by this one:

https://gitlab.com/cki-project/kernel-ark/-/commit/331be9c5a436057ee852075c102d9d90a9046a30

jirka

Quoted 162 lines

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide29;
        union {        };
    };
};
struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide31;
        union {        };
    };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --kabi_prefix flag, the running time is:

                real 8m28.912s
                user 8m27.271s
                sys 0m1.471s

And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --kabi_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running time of the command is:

                real 0m19.634s
                user 0m18.457s
                sys 0m1.169s

And the size of the generated btf segment is 3117719 bytes.

---

v1:https://lore.kernel.org/dwarves/CAEf4Bzazh4RNCY3rGRRXfO2wJ7DSiMx8w+61B_hjhu9FrOffpQ@mail.gmail.com v1->v2:
--Change btf_prefix to --kabi_prefix.
--Add man page.
--Add space after if and comma.

 man-pages/pahole.1 |  4 ++++
 pahole.c           | 10 ++++++++++
 pahole_strings.h   |  2 ++
 strings.c          |  9 ++++++++-
 4 files changed, 24 insertions(+), 1 deletion(-)
man-pages/pahole.1 +0 -0
index a10738f..2659fe6 100644
@@ -340,6 +340,10 @@ Show a traditional string version, i.e.: "v1.18".
 Show a numeric only version, suitable for use in Makefiles and scripts

where
one wants to know what if the installed version has some feature, i.e.: 118
instead of "v1.18".

+.TP
+.B \-\-kabi_prefix=STRING

man-pages/pahole.1 +2 -0
+When the prefix of the string is STRING, treat the string as STRING.
+
 .SH NOTES
 
 To enable the generation of debugging information in the Linux kernel build
pahole.c +8 -0
index dc40ccf..6a700d9 100644
@@ -24,6 +24,7 @@
 #include "btf_encoder.h"
 #include "libbtf.h"
 #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
 static bool btf_encode;
 static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_btf_gen_floats	   322
 #define ARGP_btf_gen_all	   323
 #define ARGP_with_flexible_array   324
+#define ARGP_kabi_prefix   325
 
 static const struct argp_option pahole__options[] = {
 	{
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
 		.doc  = "Path to the base BTF file",
 	},
 	{
+		.name = "kabi_prefix",
+		.key = ARGP_kabi_prefix,
+		.arg = "STRING",
+		.doc = "When the prefix of the string is STRING, treat the string as
 STRING.",
+	},
+	{
 		.name = "btf_encode",
 		.key  = 'J',
pahole.c +2 -0
 		.doc  = "Encode as BTF",
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char
 *arg,
 		btf_encode_force = true;		break;
 	case ARGP_btf_base:
 		base_btf_file = arg;			break;
+	case ARGP_kabi_prefix:
+		kabi_prefix = arg;		break;
 	case ARGP_numeric_version:
 		print_numeric_version = true;		break;
pahole.c +0 -0
 	case ARGP_btf_gen_floats:
pahole_strings.h +2 -0
index 522fbf2..a836ba8 100644
@@ -14,6 +14,8 @@ struct strings {
 	struct btf *btf;
 };
 
+extern const char *kabi_prefix;
+
 struct strings *strings__new(void);
 
 void strings__delete(struct strings *strings);
strings.c +8 -1
index d37f49d..d1a54ec 100644
@@ -17,6 +17,8 @@
 #include "dutil.h"
 #include "lib/bpf/src/libbpf.h"
 
+const char *kabi_prefix;
+
 struct strings *strings__new(void)
 {
 	struct strings *strs = malloc(sizeof(*strs));
@@ -48,7 +50,12 @@ strings_t strings__add(struct strings *strs, const char
 *str)
 	if (str == NULL)
 		return 0;
 
-	index = btf__add_str(strs->btf, str);
+	if (kabi_prefix &&
+		strncmp(str, kabi_prefix, strlen(kabi_prefix)) == 0)
+		index = btf__add_str(strs->btf, kabi_prefix);
+	else
+		index = btf__add_str(strs->btf, str);
+		
 	if (index < 0)
 		return 0;
Signature · 2 lines
-- 
1.8.3.1

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

Quoted 19 lines · Arnaldo
Quoted 16 lines · Jiri Olsa
Quoted 1 line · Shuyi Cheng

To solve problems similar to _RH_KABI_REPLACE. The

_RH_KABI_REPLACE(_orig,

Quoted 1 line

_new) macros perserve size alignment and kabi agreement between _orig

and

Quoted 10 lines

_new.Below is the definition of this macro:

# define _RH_KABI_REPLACE(_orig, _new)            \
    union {                        \
        _new;                    \
        struct {                \
            _orig;                \
        } __UNIQUE_ID(rh_kabi_hide);        \
        __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
    }
Quoted 8 lines
Quoted 6 lines

hi,
that macro sounds familiar ;-) I think this should be already solved directly in the header file by this one:

https://gitlab.com/cki-project/kernel-ark/-/commit/331be9c5a436057ee852075c102d9d90a9046a30

But this means newer kernels will not have that issue, so perhaps we should just document this?

I don't think there's released kernel with this issue

Quoted 2 lines

Or would it be worth the effort of having a --ignore_prefix option for the people using all the kernels where this is applicable to and leave the option lingering there just in case?

this is specific to rh kernels and fixed by that patch above, I wouldn't expect seeing it again

jirka

#9 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

Quoted 36 lines · Jiri Olsa
Quoted 3 lines · Arnaldo

On May 19, 2021 5:07:03 PM GMT-03:00, Jiri Olsa <[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines · Shuyi Cheng
Quoted 1 line

To solve problems similar to _RH_KABI_REPLACE. The

_RH_KABI_REPLACE(_orig,

Quoted 1 line

_new) macros perserve size alignment and kabi agreement between

_orig

Quoted 17 lines
Quoted 12 lines

and

Quoted 10 lines

_new.Below is the definition of this macro:

# define _RH_KABI_REPLACE(_orig, _new)            \
    union {                        \
        _new;                    \
        struct {                \
            _orig;                \
        } __UNIQUE_ID(rh_kabi_hide);        \
        __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
    }
Quoted 4 lines

hi,
that macro sounds familiar ;-) I think this should be already solved directly in the header file by this one:

Quoted 4 lines

https://gitlab.com/cki-project/kernel-ark/-/commit/331be9c5a436057ee852075c102d9d90a9046a30

Quoted 1 line

But this means newer kernels will not have that issue, so perhaps we

should just document this?

I don't think there's released kernel with this issue

Quoted 1 line
Quoted 6 lines
Quoted 1 line

Or would it be worth the effort of having a --ignore_prefix option

for the people using all the kernels where this is applicable to and leave the option lingering there just in case?

this is specific to rh kernels and fixed by that patch above, I wouldn't expect seeing it again

Cool, case closed then :-)

Quoted 2 lines

jirka

Signature · 1 line
Sent from my Android device with K-9 Mail. Please excuse my brevity.
#10 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

In reply to Jiri Olsa
Quoted 14 lines · Jiri Olsa
Quoted 4 lines · Shuyi Cheng

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

Quoted 8 lines
# define _RH_KABI_REPLACE(_orig, _new)            \
     union {                        \
         _new;                    \
         struct {                \
             _orig;                \
         } __UNIQUE_ID(rh_kabi_hide);        \
         __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
     }
Quoted 8 lines

hi,
that macro sounds familiar ;-) I think this should be already solved directly in the header file by this one:

   https://gitlab.com/cki-project/kernel-ark/-/commit/331be9c5a436057ee852075c102d9d90a9046a30

jirka

Well, this patch solves this problem very well from the kernel level. But there are many mirrors [here](http://debuginfo.centos.org/7/x86_64/) that still have this problem. And these mirrors support ebpf, so it is very important to effectively extract the btf segment from these mirrors. :-)

Quoted 162 lines
Quoted 162 lines

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
     union {
         struct acpi_device *companion;
         struct {
             void *handle;
         } __UNIQUE_ID_rh_kabi_hide29;
         union {        };
     };
};
struct acpi_dev_node {
     union {
         struct acpi_device *companion;
         struct {
             void *handle;
         } __UNIQUE_ID_rh_kabi_hide31;
         union {        };
     };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --kabi_prefix flag, the running time is:

                 real 8m28.912s
                 user 8m27.271s
                 sys 0m1.471s

And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --kabi_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running time of the command is:

                 real 0m19.634s
                 user 0m18.457s
                 sys 0m1.169s

And the size of the generated btf segment is 3117719 bytes.

---

v1:https://lore.kernel.org/dwarves/CAEf4Bzazh4RNCY3rGRRXfO2wJ7DSiMx8w+61B_hjhu9FrOffpQ@mail.gmail.com v1->v2:
--Change btf_prefix to --kabi_prefix.
--Add man page.
--Add space after if and comma.

  man-pages/pahole.1 |  4 ++++
  pahole.c           | 10 ++++++++++
  pahole_strings.h   |  2 ++
  strings.c          |  9 ++++++++-
  4 files changed, 24 insertions(+), 1 deletion(-)
man-pages/pahole.1 +0 -0
index a10738f..2659fe6 100644
@@ -340,6 +340,10 @@ Show a traditional string version, i.e.: "v1.18".
  Show a numeric only version, suitable for use in Makefiles and scripts

where
one wants to know what if the installed version has some feature, i.e.: 118
instead of "v1.18".

+.TP
+.B \-\-kabi_prefix=STRING

man-pages/pahole.1 +2 -0
+When the prefix of the string is STRING, treat the string as STRING.
+
  .SH NOTES
 
  To enable the generation of debugging information in the Linux kernel build
pahole.c +8 -0
index dc40ccf..6a700d9 100644
@@ -24,6 +24,7 @@
  #include "btf_encoder.h"
  #include "libbtf.h"
  #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
  static bool btf_encode;
  static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
  #define ARGP_btf_gen_floats	   322
  #define ARGP_btf_gen_all	   323
  #define ARGP_with_flexible_array   324
+#define ARGP_kabi_prefix   325
 
  static const struct argp_option pahole__options[] = {
  	{
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
  		.doc  = "Path to the base BTF file",
  	},
  	{
+		.name = "kabi_prefix",
+		.key = ARGP_kabi_prefix,
+		.arg = "STRING",
+		.doc = "When the prefix of the string is STRING, treat the string as
 STRING.",
+	},
+	{
  		.name = "btf_encode",
  		.key  = 'J',

.doc = "Encode as BTF",

pahole.c +2 -0
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char
 *arg,
  		btf_encode_force = true;		break;
  	case ARGP_btf_base:
  		base_btf_file = arg;			break;
+	case ARGP_kabi_prefix:
+		kabi_prefix = arg;		break;
  	case ARGP_numeric_version:
  		print_numeric_version = true;		break;

case ARGP_btf_gen_floats:

pahole_strings.h +2 -0
index 522fbf2..a836ba8 100644
@@ -14,6 +14,8 @@ struct strings {
  	struct btf *btf;
  };
 
+extern const char *kabi_prefix;
+
  struct strings *strings__new(void);
 
  void strings__delete(struct strings *strings);
strings.c +8 -1
index d37f49d..d1a54ec 100644
@@ -17,6 +17,8 @@
  #include "dutil.h"
  #include "lib/bpf/src/libbpf.h"
 
+const char *kabi_prefix;
+
  struct strings *strings__new(void)
  {
  	struct strings *strs = malloc(sizeof(*strs));
@@ -48,7 +50,12 @@ strings_t strings__add(struct strings *strs, const char
 *str)
  	if (str == NULL)
  		return 0;
 
-	index = btf__add_str(strs->btf, str);
+	if (kabi_prefix &&
+		strncmp(str, kabi_prefix, strlen(kabi_prefix)) == 0)
+		index = btf__add_str(strs->btf, kabi_prefix);
+	else
+		index = btf__add_str(strs->btf, str);
+		
  	if (index < 0)
  		return 0;
Signature · 2 lines
-- 
1.8.3.1
#11 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

Quoted 23 lines · Shuyi Cheng
Quoted 20 lines · Jiri Olsa
Quoted 4 lines · Shuyi Cheng

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

Quoted 8 lines
# define _RH_KABI_REPLACE(_orig, _new)            \
     union {                        \
         _new;                    \
         struct {                \
             _orig;                \
         } __UNIQUE_ID(rh_kabi_hide);        \
         __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
     }

hi,
that macro sounds familiar ;-) I think this should be already solved directly in the header file by this one:

   https://gitlab.com/cki-project/kernel-ark/-/commit/331be9c5a436057ee852075c102d9d90a9046a30
Quoted 7 lines
Quoted 2 lines

jirka

Well, this patch solves this problem very well from the kernel level. But there are many mirrors [here](http://debuginfo.centos.org/7/x86_64/) that still have this problem. And these mirrors support ebpf, so it is very important to effectively extract the btf segment from these mirrors. :-)

hum, the link shows 3.10.* centos kernel, right?
AFAIK there's no BTF support in those kernels..

but maybe I'm missing some backporting channel,
could you please point me to related sources?

jirka

Quoted 164 lines
Quoted 163 lines
Quoted 163 lines

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
     union {
         struct acpi_device *companion;
         struct {
             void *handle;
         } __UNIQUE_ID_rh_kabi_hide29;
         union {        };
     };
};
struct acpi_dev_node {
     union {
         struct acpi_device *companion;
         struct {
             void *handle;
         } __UNIQUE_ID_rh_kabi_hide31;
         union {        };
     };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --kabi_prefix flag, the running time is:

                 real 8m28.912s
                 user 8m27.271s
                 sys 0m1.471s

And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --kabi_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running time of the command is:

                 real 0m19.634s
                 user 0m18.457s
                 sys 0m1.169s

And the size of the generated btf segment is 3117719 bytes.

---

v1:https://lore.kernel.org/dwarves/CAEf4Bzazh4RNCY3rGRRXfO2wJ7DSiMx8w+61B_hjhu9FrOffpQ@mail.gmail.com v1->v2:
--Change btf_prefix to --kabi_prefix.
--Add man page.
--Add space after if and comma.

  man-pages/pahole.1 |  4 ++++
  pahole.c           | 10 ++++++++++
  pahole_strings.h   |  2 ++
  strings.c          |  9 ++++++++-
  4 files changed, 24 insertions(+), 1 deletion(-)
man-pages/pahole.1 +0 -0
index a10738f..2659fe6 100644
@@ -340,6 +340,10 @@ Show a traditional string version, i.e.: "v1.18".
  Show a numeric only version, suitable for use in Makefiles and scripts

where
one wants to know what if the installed version has some feature, i.e.: 118
instead of "v1.18".

+.TP
+.B \-\-kabi_prefix=STRING

man-pages/pahole.1 +2 -0
+When the prefix of the string is STRING, treat the string as STRING.
+
  .SH NOTES
 
  To enable the generation of debugging information in the Linux kernel build
pahole.c +8 -0
index dc40ccf..6a700d9 100644
@@ -24,6 +24,7 @@
  #include "btf_encoder.h"
  #include "libbtf.h"
  #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
  static bool btf_encode;
  static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
  #define ARGP_btf_gen_floats	   322
  #define ARGP_btf_gen_all	   323
  #define ARGP_with_flexible_array   324
+#define ARGP_kabi_prefix   325
 
  static const struct argp_option pahole__options[] = {
  	{
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
  		.doc  = "Path to the base BTF file",
  	},
  	{
+		.name = "kabi_prefix",
+		.key = ARGP_kabi_prefix,
+		.arg = "STRING",
+		.doc = "When the prefix of the string is STRING, treat the string as
 STRING.",
+	},
+	{
  		.name = "btf_encode",
  		.key  = 'J',

.doc = "Encode as BTF",

pahole.c +2 -0
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char
 *arg,
  		btf_encode_force = true;		break;
  	case ARGP_btf_base:
  		base_btf_file = arg;			break;
+	case ARGP_kabi_prefix:
+		kabi_prefix = arg;		break;
  	case ARGP_numeric_version:
  		print_numeric_version = true;		break;

case ARGP_btf_gen_floats:

pahole_strings.h +2 -0
index 522fbf2..a836ba8 100644
@@ -14,6 +14,8 @@ struct strings {
  	struct btf *btf;
  };
 
+extern const char *kabi_prefix;
+
  struct strings *strings__new(void);
 
  void strings__delete(struct strings *strings);
strings.c +8 -1
index d37f49d..d1a54ec 100644
@@ -17,6 +17,8 @@
  #include "dutil.h"
  #include "lib/bpf/src/libbpf.h"
 
+const char *kabi_prefix;
+
  struct strings *strings__new(void)
  {
  	struct strings *strs = malloc(sizeof(*strs));
@@ -48,7 +50,12 @@ strings_t strings__add(struct strings *strs, const char
 *str)
  	if (str == NULL)
  		return 0;
 
-	index = btf__add_str(strs->btf, str);
+	if (kabi_prefix &&
+		strncmp(str, kabi_prefix, strlen(kabi_prefix)) == 0)
+		index = btf__add_str(strs->btf, kabi_prefix);
+	else
+		index = btf__add_str(strs->btf, str);
+		
  	if (index < 0)
  		return 0;
Signature · 2 lines
-- 
1.8.3.1
#12 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

Quoted 32 lines · Jiri Olsa
Quoted 23 lines · Shuyi Cheng
Quoted 20 lines · Jiri Olsa
Quoted 4 lines · Shuyi Cheng

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

Quoted 8 lines
# define _RH_KABI_REPLACE(_orig, _new)            \
      union {                        \
          _new;                    \
          struct {                \
              _orig;                \
          } __UNIQUE_ID(rh_kabi_hide);        \
          __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
      }

hi,
that macro sounds familiar ;-) I think this should be already solved directly in the header file by this one:

    https://gitlab.com/cki-project/kernel-ark/-/commit/331be9c5a436057ee852075c102d9d90a9046a30
Quoted 7 lines
Quoted 2 lines

jirka

Well, this patch solves this problem very well from the kernel level. But there are many mirrors [here](http://debuginfo.centos.org/7/x86_64/) that still have this problem. And these mirrors support ebpf, so it is very important to effectively extract the btf segment from these mirrors. :-)

Quoted 8 lines

hum, the link shows 3.10.* centos kernel, right?
AFAIK there's no BTF support in those kernels..

but maybe I'm missing some backporting channel,
could you please point me to related sources?

jirka

Yes, it is the centos kernel of version 3.10. This version of the centos kernel supports ebpf. As far as I think, BTF features don't depend on the kernel much. Only when using the STRUCT OPS feature does the kernel support BTF, see [here](https://github.com/libbpf/libbpf/blob/57375504c6c9766d23f178c40f71bf5e8df9363d/src/libbpf.c#L2549) and [here](https://www.spinics.net/lists/netdev/msg637060.html). Therefore, in the 3.10 version of the Centos kernel, with the help of the vmlinux btf segment, libbpf CO-RE can be easily supported.

Quoted 164 lines
Quoted 164 lines
Quoted 163 lines
Quoted 163 lines

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
      union {
          struct acpi_device *companion;
          struct {
              void *handle;
          } __UNIQUE_ID_rh_kabi_hide29;
          union {        };
      };
};
struct acpi_dev_node {
      union {
          struct acpi_device *companion;
          struct {
              void *handle;
          } __UNIQUE_ID_rh_kabi_hide31;
          union {        };
      };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --kabi_prefix flag, the running time is:

                  real 8m28.912s
                  user 8m27.271s
                  sys 0m1.471s

And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --kabi_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running time of the command is:

                  real 0m19.634s
                  user 0m18.457s
                  sys 0m1.169s

And the size of the generated btf segment is 3117719 bytes.

---

v1:https://lore.kernel.org/dwarves/CAEf4Bzazh4RNCY3rGRRXfO2wJ7DSiMx8w+61B_hjhu9FrOffpQ@mail.gmail.com v1->v2:
--Change btf_prefix to --kabi_prefix.
--Add man page.
--Add space after if and comma.

   man-pages/pahole.1 |  4 ++++
   pahole.c           | 10 ++++++++++
   pahole_strings.h   |  2 ++
   strings.c          |  9 ++++++++-
   4 files changed, 24 insertions(+), 1 deletion(-)
man-pages/pahole.1 +0 -0
index a10738f..2659fe6 100644
@@ -340,6 +340,10 @@ Show a traditional string version, i.e.: "v1.18".
   Show a numeric only version, suitable for use in Makefiles and scripts

where
one wants to know what if the installed version has some feature, i.e.: 118
instead of "v1.18".

+.TP
+.B \-\-kabi_prefix=STRING

man-pages/pahole.1 +2 -0
+When the prefix of the string is STRING, treat the string as STRING.
+
   .SH NOTES
 
   To enable the generation of debugging information in the Linux kernel build
pahole.c +8 -0
index dc40ccf..6a700d9 100644
@@ -24,6 +24,7 @@
   #include "btf_encoder.h"
   #include "libbtf.h"
   #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
   static bool btf_encode;
   static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
   #define ARGP_btf_gen_floats	   322
   #define ARGP_btf_gen_all	   323
   #define ARGP_with_flexible_array   324
+#define ARGP_kabi_prefix   325
 
   static const struct argp_option pahole__options[] = {
   	{
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
   		.doc  = "Path to the base BTF file",
   	},
   	{
+		.name = "kabi_prefix",
+		.key = ARGP_kabi_prefix,
+		.arg = "STRING",
+		.doc = "When the prefix of the string is STRING, treat the string as
 STRING.",
+	},
+	{
   		.name = "btf_encode",
   		.key  = 'J',

.doc = "Encode as BTF",

pahole.c +2 -0
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char
 *arg,
   		btf_encode_force = true;		break;
   	case ARGP_btf_base:
   		base_btf_file = arg;			break;
+	case ARGP_kabi_prefix:
+		kabi_prefix = arg;		break;
   	case ARGP_numeric_version:
   		print_numeric_version = true;		break;

case ARGP_btf_gen_floats:

pahole_strings.h +2 -0
index 522fbf2..a836ba8 100644
@@ -14,6 +14,8 @@ struct strings {
   	struct btf *btf;
   };
 
+extern const char *kabi_prefix;
+
   struct strings *strings__new(void);
 
   void strings__delete(struct strings *strings);
strings.c +8 -1
index d37f49d..d1a54ec 100644
@@ -17,6 +17,8 @@
   #include "dutil.h"
   #include "lib/bpf/src/libbpf.h"
 
+const char *kabi_prefix;
+
   struct strings *strings__new(void)
   {
   	struct strings *strs = malloc(sizeof(*strs));
@@ -48,7 +50,12 @@ strings_t strings__add(struct strings *strs, const char
 *str)
   	if (str == NULL)
   		return 0;
 
-	index = btf__add_str(strs->btf, str);
+	if (kabi_prefix &&
+		strncmp(str, kabi_prefix, strlen(kabi_prefix)) == 0)
+		index = btf__add_str(strs->btf, kabi_prefix);
+	else
+		index = btf__add_str(strs->btf, str);
+		
   	if (index < 0)
   		return 0;
Signature · 2 lines
-- 
1.8.3.1
#13 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

Quoted 44 lines · Shuyi Cheng
Quoted 32 lines · Jiri Olsa
Quoted 23 lines · Shuyi Cheng
Quoted 20 lines · Jiri Olsa
Quoted 4 lines · Shuyi Cheng

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

Quoted 8 lines
# define _RH_KABI_REPLACE(_orig, _new)            \
      union {                        \
          _new;                    \
          struct {                \
              _orig;                \
          } __UNIQUE_ID(rh_kabi_hide);        \
          __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
      }

hi,
that macro sounds familiar ;-) I think this should be already solved directly in the header file by this one:

    https://gitlab.com/cki-project/kernel-ark/-/commit/331be9c5a436057ee852075c102d9d90a9046a30
Quoted 7 lines
Quoted 2 lines

jirka

Well, this patch solves this problem very well from the kernel level. But there are many mirrors [here](http://debuginfo.centos.org/7/x86_64/) that still have this problem. And these mirrors support ebpf, so it is very important to effectively extract the btf segment from these mirrors. :-)

Quoted 8 lines

hum, the link shows 3.10.* centos kernel, right?
AFAIK there's no BTF support in those kernels..

but maybe I'm missing some backporting channel,
could you please point me to related sources?

jirka

Quoted 7 lines

Yes, it is the centos kernel of version 3.10. This version of the centos
kernel supports ebpf. As far as I think, BTF features don't depend on the
kernel much. Only when using the STRUCT OPS feature does the kernel support
BTF, see [here](https://github.com/libbpf/libbpf/blob/57375504c6c9766d23f178c40f71bf5e8df9363d/src/libbpf.c#L2549) and [here](https://www.spinics.net/lists/netdev/msg637060.html). Therefore,
in the 3.10 version of the Centos kernel, with the help of the vmlinux btf
segment, libbpf CO-RE can be easily supported.

ok, so you're generating BTF for centos 3.10 kernel?

I think that fix would be easy kernel backport, but I guess we can go with pahole option just as well, if backport is not an option for you

jirka

#14 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

Quoted 53 lines · Jiri Olsa
Quoted 44 lines · Shuyi Cheng
Quoted 32 lines · Jiri Olsa
Quoted 23 lines · Shuyi Cheng
Quoted 20 lines · Jiri Olsa
Quoted 4 lines · Shuyi Cheng

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

Quoted 8 lines
# define _RH_KABI_REPLACE(_orig, _new)            \
       union {                        \
           _new;                    \
           struct {                \
               _orig;                \
           } __UNIQUE_ID(rh_kabi_hide);        \
           __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
       }

hi,
that macro sounds familiar ;-) I think this should be already solved directly in the header file by this one:

     https://gitlab.com/cki-project/kernel-ark/-/commit/331be9c5a436057ee852075c102d9d90a9046a30
Quoted 7 lines
Quoted 2 lines

jirka

Well, this patch solves this problem very well from the kernel level. But there are many mirrors [here](http://debuginfo.centos.org/7/x86_64/) that still have this problem. And these mirrors support ebpf, so it is very important to effectively extract the btf segment from these mirrors. :-)

Quoted 8 lines

hum, the link shows 3.10.* centos kernel, right?
AFAIK there's no BTF support in those kernels..

but maybe I'm missing some backporting channel,
could you please point me to related sources?

jirka

Quoted 7 lines

Yes, it is the centos kernel of version 3.10. This version of the centos
kernel supports ebpf. As far as I think, BTF features don't depend on the
kernel much. Only when using the STRUCT OPS feature does the kernel support
BTF, see [here](https://github.com/libbpf/libbpf/blob/57375504c6c9766d23f178c40f71bf5e8df9363d/src/libbpf.c#L2549) and [here](https://www.spinics.net/lists/netdev/msg637060.html). Therefore,
in the 3.10 version of the Centos kernel, with the help of the vmlinux btf
segment, libbpf CO-RE can be easily supported.

Quoted 8 lines

ok, so you're generating BTF for centos 3.10 kernel?

I think that fix would be easy kernel backport, but I guess we can go with pahole option just as well, if backport is not an option for you

jirka

Yes, I am generating btf segment for centos 3.10 kernel. There are two main reasons for adding this patch:
1. There are too many kernel versions in centos 3.10, and a certain technical foundation is required to compile the kernel.
2. In my opinion, many people are using pahole to generate vmlinux btf segment, and there are still a large number of users on centos.

Acked-by on v2 1/1
#15 lore raw

Re: [PATCH v2] pahole: Add --kabi_prefix flag

In reply to Shuyi Cheng

On Wed, May 19, 2021 at 10:44:44AM +0800, Shuyi Cheng wrote:

SNIP

Quoted 32 lines

where
one wants to know what if the installed version has some feature, i.e.: 118
instead of "v1.18".

+.TP
+.B \-\-kabi_prefix=STRING

(quoted diff) +2 -0
+When the prefix of the string is STRING, treat the string as STRING.
+
 .SH NOTES
 
 To enable the generation of debugging information in the Linux kernel build
pahole.c +2 -0
index dc40ccf..6a700d9 100644
@@ -24,6 +24,7 @@
 #include "btf_encoder.h"
 #include "libbtf.h"
 #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
 static bool btf_encode;
 static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_btf_gen_floats	   322
 #define ARGP_btf_gen_all	   323
 #define ARGP_with_flexible_array   324
+#define ARGP_kabi_prefix   325
 
 static const struct argp_option pahole__options[] = {
 	{

pahole.c static const struct argp_option pahole__options[] = { · line 1149

Quoted 8 lines
pahole.c +4 -0
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
 		.doc  = "Path to the base BTF file",
 	},
 	{
+		.name = "kabi_prefix",
+		.key = ARGP_kabi_prefix,
+		.arg = "STRING",
+		.doc = "When the prefix of the string is STRING, treat the string as
 STRING.",

please keep the '=' indentation

Quoted 43 lines
pahole.c +2 -0
+	},
+	{
 		.name = "btf_encode",
 		.key  = 'J',
pahole.c +2 -0
 		.doc  = "Encode as BTF",
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char
 *arg,
 		btf_encode_force = true;		break;
 	case ARGP_btf_base:
 		base_btf_file = arg;			break;
+	case ARGP_kabi_prefix:
+		kabi_prefix = arg;		break;
 	case ARGP_numeric_version:
 		print_numeric_version = true;		break;
pahole.c +0 -0
 	case ARGP_btf_gen_floats:
pahole_strings.h +2 -0
index 522fbf2..a836ba8 100644
@@ -14,6 +14,8 @@ struct strings {
 	struct btf *btf;
 };
 
+extern const char *kabi_prefix;
+
 struct strings *strings__new(void);
 
 void strings__delete(struct strings *strings);
strings.c +2 -0
index d37f49d..d1a54ec 100644
@@ -17,6 +17,8 @@
 #include "dutil.h"
 #include "lib/bpf/src/libbpf.h"
 
+const char *kabi_prefix;
+
 struct strings *strings__new(void)
 {
 	struct strings *strs = malloc(sizeof(*strs));
@@ -48,7 +50,12 @@ strings_t strings__add(struct strings *strs, const char
 *str)

strings.c strings_t strings__add(struct strings *strs, const char · line 59

Quoted 10 lines
strings.c +6 -1
 	if (str == NULL)
 		return 0;
 
-	index = btf__add_str(strs->btf, str);
+	if (kabi_prefix &&
+		strncmp(str, kabi_prefix, strlen(kabi_prefix)) == 0)
+		index = btf__add_str(strs->btf, kabi_prefix);
+	else
+		index = btf__add_str(strs->btf, str);
+		

^^^ extra whitespace, other than that looks ok

jirka

Quoted 6 lines
strings.c +0 -0
 	if (index < 0)
 		return 0;
Signature · 2 lines
-- 
1.8.3.1
#16 lore raw

PATCH v3 1/1 pahole: Add --kabi_prefix flag

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

# define _RH_KABI_REPLACE(_orig, _new)            \
    union {                        \
        _new;                    \
        struct {                \
            _orig;                \
        } __UNIQUE_ID(rh_kabi_hide);        \
        __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
    }

__UNIQUE_ID uses the __COUNTER__ macro, and the __COUNTER__ macro is automatically incremented by 1 every time it is precompiled. Therefore, in different compilation units, the same structure has different names.Here is a concrete example:

struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide29;
        union {        };
    };
};
struct acpi_dev_node {
    union {
        struct acpi_device *companion;
        struct {
            void *handle;
        } __UNIQUE_ID_rh_kabi_hide31;
        union {        };
    };
};

Finally, it will cause the btf algorithm to de-duplication efficiency is not high, and time-consuming. For example, running ./pahole -J vmlinux-3.10.0-1160.el7.x86_64 without --kabi_prefix flag, the running time is:

                real 8m28.912s
                user 8m27.271s
                sys 0m1.471s

And the size of the generated btf segment is 30678240 bytes.

After adding the patch, running ./pahole --kabi_prefix=__UNIQUE_ID_rh_kabi_hide -J vmlinux-3.10.0-1160.el7.x86_64. The running time of the command is:

                real 0m19.634s
                user 0m18.457s
                sys 0m1.169s

And the size of the generated btf segment is 3117719 bytes.

Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Andrii Nakryiko <[email protected]>
Cc Wenan Mao <[email protected]>

---

v1: https://lore.kernel.org/dwarves/[email protected]/
v1->v2:
-- Change btf_prefix to --kabi_prefix.
-- Add man page.
-- Add space after if and comma.

v2: https://lore.kernel.org/dwarves/[email protected]/
v2->v3:
-- Keep the '=' indentation.
-- Remove extra whitespace.

 man-pages/pahole.1 |  4 ++++
 pahole.c           | 10 ++++++++++
 pahole_strings.h   |  2 ++
 strings.c          |  9 ++++++++-
 4 files changed, 24 insertions(+), 1 deletion(-)
man-pages/pahole.1 +0 -0
index a10738f..2659fe6 100644
@@ -340,6 +340,10 @@ Show a traditional string version, i.e.: "v1.18".
 Show a numeric only version, suitable for use in Makefiles and scripts 

where
one wants to know what if the installed version has some feature,
i.e.: 118 instead of "v1.18".

+.TP
+.B \-\-kabi_prefix=STRING
+When the prefix of the string is STRING, treat the string as STRING. +
.SH NOTES

To enable the generation of debugging information in the Linux kernel
build

pahole.c +10 -0
index dc40ccf..f2406e4 100644
@@ -24,6 +24,7 @@
 #include "btf_encoder.h"
 #include "libbtf.h"
 #include "lib/bpf/src/libbpf.h"
+#include "pahole_strings.h"
 
 static bool btf_encode;
 static bool ctf_encode;
@@ -855,6 +856,7 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = dwarves_print_version;
 #define ARGP_btf_gen_floats	   322
 #define ARGP_btf_gen_all	   323
 #define ARGP_with_flexible_array   324
+#define ARGP_kabi_prefix   325
 
 static const struct argp_option pahole__options[] = {
 	{
@@ -1140,6 +1142,12 @@ static const struct argp_option pahole__options[] = {
 		.doc  = "Path to the base BTF file",
 	},
 	{
+		.name = "kabi_prefix",
+		.key  = ARGP_kabi_prefix,
+		.arg  = "STRING",
+		.doc  = "When the prefix of the string is STRING, treat the string as STRING.",
+	},
+	{
 		.name = "btf_encode",
 		.key  = 'J',
 		.doc  = "Encode as BTF",
@@ -1297,6 +1305,8 @@ static error_t pahole__options_parser(int key, char *arg,
 		btf_encode_force = true;		break;
 	case ARGP_btf_base:
 		base_btf_file = arg;			break;
+	case ARGP_kabi_prefix:
+		kabi_prefix = arg;		break;
 	case ARGP_numeric_version:
 		print_numeric_version = true;		break;
 	case ARGP_btf_gen_floats:
pahole_strings.h +2 -0
index 522fbf2..a836ba8 100644
@@ -14,6 +14,8 @@ struct strings {
 	struct btf *btf;
 };
 
+extern const char *kabi_prefix;
+
 struct strings *strings__new(void);
 
 void strings__delete(struct strings *strings);
strings.c +8 -1
index d37f49d..d5eb3a1 100644
@@ -17,6 +17,8 @@
 #include "dutil.h"
 #include "lib/bpf/src/libbpf.h"
 
+const char *kabi_prefix;
+
 struct strings *strings__new(void)
 {
 	struct strings *strs = malloc(sizeof(*strs));
@@ -48,7 +50,12 @@ strings_t strings__add(struct strings *strs, const char *str)
 	if (str == NULL)
 		return 0;
 
-	index = btf__add_str(strs->btf, str);
+	if (kabi_prefix &&
+		strncmp(str, kabi_prefix, strlen(kabi_prefix)) == 0)
+		index = btf__add_str(strs->btf, kabi_prefix);
+	else
+		index = btf__add_str(strs->btf, str);
+
 	if (index < 0)
 		return 0;
 
Signature · 1 line
1.8.3.1
#17 lore raw

Re: [PATCH v3] pahole: Add --kabi_prefix flag

Em Fri, May 21, 2021 at 09:44:20AM +0800, Shuyi Cheng escreveu:

Quoted 4 lines

To solve problems similar to _RH_KABI_REPLACE. The _RH_KABI_REPLACE(_orig, _new) macros perserve size alignment and kabi agreement between _orig and _new.Below is the definition of this macro:

Quoted 8 lines
# define _RH_KABI_REPLACE(_orig, _new)            \
    union {                        \
        _new;                    \
        struct {                \
            _orig;                \
        } __UNIQUE_ID(rh_kabi_hide);        \
        __RH_KABI_CHECK_SIZE_ALIGN(_orig, _new);    \
    }

Thanks, applied.

- Arnaldo