Skip to contentSkip to conversation

Add support for BTF deduplication

PATCH In review Andrii Nakryiko 4 participants 9 messages Feb 17, 2019 – Feb 19, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Add support for BTF deduplication

This patchset adds btf_dedup() support during DWARF to BTF conversion.

Andrii Nakryiko (2):
libbpf: pull latest libbpf and build libbpf as shared lib
btf_encoder: run BTF deduplication before writing out to ELF

 CMakeLists.txt | 13 +++++++++----
 lib/bpf        |  2 +-
 libbtf.c       | 44 ++++++++++++++++++++++++++++++++++----------
 3 files changed, 44 insertions(+), 15 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 libbpf: pull latest libbpf and build libbpf as shared lib

Bring in latest changes from libbpf which allow to use btf__dedup() for big binaries (e.g., linux kernel image).

This patch also changes CMakeLists.txt to build libbpf as shared library to satisfy libdwarves shared library compilation.

---
 CMakeLists.txt | 13 +++++++++----
 lib/bpf        |  2 +-
 2 files changed, 10 insertions(+), 5 deletions(-)
CMakeLists.txt +9 -4
index 0cc383a..d6929b4 100644
@@ -72,9 +72,14 @@ if (NOT HAVE_REALLOCARRAY_SUPPORT)
 endif()
 
 file(GLOB libbpf_sources "lib/bpf/src/*.c")
-add_library(bpf STATIC ${libbpf_sources})
-set_target_properties(bpf PROPERTIES OUTPUT_NAME bpf)
-target_include_directories(bpf PRIVATE
+add_library(bpf-static STATIC ${libbpf_sources})
+set_target_properties(bpf-static PROPERTIES OUTPUT_NAME bpf)
+target_include_directories(bpf-static PRIVATE
+			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include
+			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include/uapi)
+add_library(bpf-shared SHARED ${libbpf_sources})
+set_target_properties(bpf-shared PROPERTIES OUTPUT_NAME bpf)
+target_include_directories(bpf-shared PRIVATE
 			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include
 			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include/uapi)
 
@@ -84,7 +89,7 @@ set(dwarves_LIB_SRCS dwarves.c dwarves_fprintf.c gobuffer strings
 add_library(dwarves SHARED ${dwarves_LIB_SRCS})
 set_target_properties(dwarves PROPERTIES VERSION 1.0.0 SOVERSION 1)
 set_target_properties(dwarves PROPERTIES INTERFACE_LINK_LIBRARIES "")
-target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} bpf)
+target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} bpf-shared)
 
 set(dwarves_emit_LIB_SRCS dwarves_emit.c)
 add_library(dwarves_emit SHARED ${dwarves_emit_LIB_SRCS})
lib/bpf +1 -1
index b19c6dc..d5fa415 160000
@@ -1 +1 @@
-Subproject commit b19c6dcf623a7adc9e538ddbe2964c2f58dd2417
+Subproject commit d5fa4150f0c3a36e3ce458e1301531bd2edbf74d
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH pahole 1/2] libbpf: pull latest libbpf and build libbpf as shared lib

Em Sun, Feb 17, 2019 at 12:20:17AM -0800, Andrii Nakryiko escreveu:

Quoted 2 lines

Bring in latest changes from libbpf which allow to use btf__dedup() for big binaries (e.g., linux kernel image).

I'm splitting this patch into two, one for the above part and another for the part in the end of this commit message.

Thanks,

Quoted 49 lines

This patch also changes CMakeLists.txt to build libbpf as shared library to satisfy libdwarves shared library compilation.

---
 CMakeLists.txt | 13 +++++++++----
 lib/bpf        |  2 +-
 2 files changed, 10 insertions(+), 5 deletions(-)
CMakeLists.txt +9 -4
index 0cc383a..d6929b4 100644
@@ -72,9 +72,14 @@ if (NOT HAVE_REALLOCARRAY_SUPPORT)
 endif()
 
 file(GLOB libbpf_sources "lib/bpf/src/*.c")
-add_library(bpf STATIC ${libbpf_sources})
-set_target_properties(bpf PROPERTIES OUTPUT_NAME bpf)
-target_include_directories(bpf PRIVATE
+add_library(bpf-static STATIC ${libbpf_sources})
+set_target_properties(bpf-static PROPERTIES OUTPUT_NAME bpf)
+target_include_directories(bpf-static PRIVATE
+			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include
+			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include/uapi)
+add_library(bpf-shared SHARED ${libbpf_sources})
+set_target_properties(bpf-shared PROPERTIES OUTPUT_NAME bpf)
+target_include_directories(bpf-shared PRIVATE
 			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include
 			   ${CMAKE_CURRENT_SOURCE_DIR}/lib/bpf/include/uapi)
 
@@ -84,7 +89,7 @@ set(dwarves_LIB_SRCS dwarves.c dwarves_fprintf.c gobuffer strings
 add_library(dwarves SHARED ${dwarves_LIB_SRCS})
 set_target_properties(dwarves PROPERTIES VERSION 1.0.0 SOVERSION 1)
 set_target_properties(dwarves PROPERTIES INTERFACE_LINK_LIBRARIES "")
-target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} bpf)
+target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} bpf-shared)
 
 set(dwarves_emit_LIB_SRCS dwarves_emit.c)
 add_library(dwarves_emit SHARED ${dwarves_emit_LIB_SRCS})
lib/bpf +1 -1
index b19c6dc..d5fa415 160000
@@ -1 +1 @@
-Subproject commit b19c6dcf623a7adc9e538ddbe2964c2f58dd2417
+Subproject commit d5fa4150f0c3a36e3ce458e1301531bd2edbf74d
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
#3 lore raw

PATCH 2/2 btf_encoder: run BTF deduplication before writing out to ELF

In reply to Andrii Nakryiko

After btf_encoder completes DWARF to BTF 1-to-1 conversion, utilize libbpf to construct struct btf and run btf__dedup() algorithm on it. This significantly reduces number of BTF types and strings section size without losing any information.

---
 libbtf.c | 44 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 10 deletions(-)
libbtf.c +34 -10
index 7b862cf..9c87c12 100644
@@ -17,6 +17,9 @@
 
 #include "libbtf.h"
 #include "lib/bpf/include/uapi/linux/btf.h"
+#include "lib/bpf/include/linux/err.h"
+#include "lib/bpf/src/btf.h"
+#include "lib/bpf/src/libbpf.h"
 #include "dutil.h"
 #include "gobuffer.h"
 #include "dwarves.h"
@@ -566,19 +569,21 @@ int32_t btf_elf__add_func_proto(struct btf_elf *btfe, struct ftype *ftype, uint3
 	return type_id;
 }
 
-static int btf_elf__write(struct btf_elf *btfe)
+static int btf_elf__write(const char *filename, struct btf *btf)
 {
 	GElf_Shdr shdr_mem, *shdr;
 	GElf_Ehdr ehdr_mem, *ehdr;
 	Elf_Data *btf_elf = NULL;
 	Elf_Scn *scn = NULL;
 	Elf *elf = NULL;
+	const void *btf_data;
+	uint32_t btf_size;
 	int fd, err = -1;
 	size_t strndx;
 
-	fd = open(btfe->filename, O_RDWR);
+	fd = open(filename, O_RDWR);
 	if (fd < 0) {
-		fprintf(stderr, "Cannot open %s\n", btfe->filename);
+		fprintf(stderr, "Cannot open %s\n", filename);
 		return -1;
 	}
 
@@ -617,10 +622,12 @@ static int btf_elf__write(struct btf_elf *btfe)
 		}
 	}
 
+	btf_data = btf__get_raw_data(btf, &btf_size);
+
 	if (btf_elf) {
 		/* Exisiting .BTF section found */
-		btf_elf->d_buf = btfe->data;
-		btf_elf->d_size = btfe->size;
+		btf_elf->d_buf = (void *)btf_data;
+		btf_elf->d_size = btf_size;
 		elf_flagdata(btf_elf, ELF_C_SET, ELF_F_DIRTY);
 
 		if (elf_update(elf, ELF_C_NULL) >= 0 &&
@@ -636,7 +643,7 @@ static int btf_elf__write(struct btf_elf *btfe)
 			llvm_objcopy = "llvm-objcopy";
 
 		/* Use objcopy to add a .BTF section */
-		snprintf(tmp_fn, sizeof(tmp_fn), "%s.btfe", btfe->filename);
+		snprintf(tmp_fn, sizeof(tmp_fn), "%s.btf", filename);
 		close(fd);
 		fd = creat(tmp_fn, S_IRUSR | S_IWUSR);
 		if (fd == -1) {
@@ -646,10 +653,9 @@ static int btf_elf__write(struct btf_elf *btfe)
 		}
 
 		snprintf(cmd, sizeof(cmd), "%s --add-section .BTF=%s %s",
-			 llvm_objcopy, tmp_fn, btfe->filename);
+			 llvm_objcopy, tmp_fn, filename);
 
-		if (write(fd, btfe->data, btfe->size) == btfe->size &&
-		    !system(cmd))
+		if (write(fd, btf_data, btf_size) == btf_size && !system(cmd))
 			err = 0;
 
 		unlink(tmp_fn);
@@ -663,9 +669,15 @@ out:
 	return err;
 }
 
+static int libbpf_log(enum libbpf_print_level level, const char *format, va_list args)
+{
+	return vfprintf(stderr, format, args);
+}
+
 int btf_elf__encode(struct btf_elf *btfe, uint8_t flags)
 {
 	struct btf_header *hdr;
+	struct btf *btf;
 
 	/* Empty file, nothing to do, so... done! */
 	if (gobuffer__size(&btfe->types) == 0)
@@ -695,5 +707,17 @@ int btf_elf__encode(struct btf_elf *btfe, uint8_t flags)
 
 	*(char *)(btf_elf__nohdr_data(btfe) + hdr->str_off) = '\0';
 
-	return btf_elf__write(btfe);
+	libbpf_set_print(libbpf_log);
+
+	btf = btf__new(btfe->data, btfe->size);
+	if (IS_ERR(btf)) {
+		fprintf(stderr, "%s: btf__new failed!\n", __func__);
+		return -1;
+	}
+	if (btf__dedup(btf, NULL, NULL)) {
+		fprintf(stderr, "%s: btf__dedup failed!", __func__);
+		return -1;
+	}
+
+	return btf_elf__write(btfe->filename, btf);
 }
Signature · 1 line
2.17.1

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

#5 lore raw

Re: [PATCH pahole 2/2] btf_encoder: run BTF deduplication before writing out to ELF

Quoted 11 lines · Arnaldo Carvalho de Melo

Em Sun, Feb 17, 2019 at 12:20:18AM -0800, Andrii Nakryiko escreveu:

Quoted 6 lines

After btf_encoder completes DWARF to BTF 1-to-1 conversion, utilize libbpf to construct struct btf and run btf__dedup() algorithm on it. This significantly reduces number of BTF types and strings section size without losing any information.

Applied, and added these commit notes, doing the process before and after:

Thanks for additional testing!

Quoted 60 lines

commit dd3a7d3ab3e843867338805df8dd5dfe2769fc13

Author: Andrii Nakryiko <[email protected]>
Date:   Sun Feb 17 00:20:18 2019 -0800
    btf_encoder: run BTF deduplication before writing out to ELF

    After btf_encoder completes DWARF to BTF 0-to-1 conversion, utilize
    libbpf to construct struct btf and run btf__dedup() algorithm on it.
    This significantly reduces number of BTF types and strings section size
    without losing any information.

    Committer testing:

    Before:

      $ cp ../build/v5.0-rc3+/vmlinux .
      $ ls -la vmlinux
      -rwxrwxr-x. 1 acme acme 654357792 Feb 18 10:51 vmlinux
      $ pahole -J vmlinux
      $ ls -la vmlinux
      -rwxrwxr-x. 1 acme acme 824950072 Feb 18 10:52 vmlinux
      $ echo $((824950072 - 654357792))
      170592280
      $
      $ readelf -SW vmlinux  | head -4
      There are 79 section headers, starting at offset 0x312ba978:

      Section Headers:
        [Nr] Name   Type      Address          Off      Size    ES Flg Lk Inf Al
      <SNIP>
        [78] .BTF   PROGBITS  0000000000000000 27053da9 a266bcd 00      0   0  1
        $
      >>> 0xa266bcd
      170290125

    After:

      $ cp ../build/v5.0-rc3+/vmlinux .
      $ ls -la vmlinux
    -rwxrwxr-x. 1 acme acme 654357792 Feb 18 11:01 vmlinux
      $ pahole -J vmlinux
      $ ls -la vmlinux
    -rwxrwxr-x. 1 acme acme 656641544 Feb 18 11:01 vmlinux
      $ echo $((656641544 - 654357792))
    2283752
      $ readelf -SW vmlinux  | grep BTF
      [78] .BTF              PROGBITS        0000000000000000 27053da9 1e3c9e 00      0   0  1
    >>> 0x1e3c9e
    1981598
    >>>

    Signed-off-by: Andrii Nakryiko <[email protected]>
    Tested-by: Arnaldo Carvalho de Melo <[email protected]>
    Cc: Alexei Starovoitov <[email protected]>
    Cc: [email protected]
    Cc: [email protected]
    Cc: [email protected]
    Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
Quoted 6 lines

----------------------------------------------------------------------------------------------

Using btfdiff we still have some things to look at probably bugs in pahole,, mostly about packed data structures pretty printed from BTF, I have to re-read the discussions I had with Yonhghong at some point about that.

Yeah I remember I followed that discussion and looked at pahole code. I think it's btf_loader's part that does bit field adjustment that doesn't handle all the cases well. I'll try to look at that today, when I get time.

Quoted 4 lines

The 'struct sun_disklabel' is interesting, pahole doesn't print it for the DWARF case when pretty printing all structs, but it works for the BTF case, I'll investigate.

I wonder if that has something to do with the fact that btf_dedup also does FWD -> STRUCT/UNION resolution?

Quoted 112 lines

When we ask specifically for it, it works and the same output is produced:

[acme@quaco pahole]$ pahole -C sun_disklabel vmlinux > /tmp/dwarf [acme@quaco pahole]$ pahole -F btf -C sun_disklabel vmlinux > /tmp/btf [acme@quaco pahole]$ diff -u /tmp/dwarf /tmp/btf
[acme@quaco pahole]$

Some more testing:

[acme@quaco pahole]$ pahole -F btf --sizes vmlinux | grep b[pt]f | sort -k2 -nr | head -25

bpf_verifier_env        4736    2
btf_verifier_env        1592    0
bpf_verifier_log        1048    1
bpf_func_state          1008    1
bpf_htab                 576    1
cgroup_bpf               512    0
bpf_scratchpad           512    0
bpf_prog_aux             288    2
bpf_stack_map            256    1
bpf_stab                 256    0
bpf_queue_stack          256    0
bpf_offloaded_map        256    0
bpf_lru                  256    0
bpf_dtab                 256    0
bpf_cpu_map              256    0
bpf_cgroup_storage_map   256    1
bpf_array                256    1
bpf_prog_info            192    0
bpf_map                  192    1
bpf_common_lru           192    0
bpf_sock_ops             184    0
bpf_perf_event_data      184    0
bpf_map_ops              144    0
bpf_lru_list             128    0
btf                      112    1

[acme@quaco pahole]$

'struct btf_verifier_env' is tightly organized, but there are some holes in 'struct bpf_verifier_env':

[acme@quaco pahole]$ pahole -F btf -C bpf_verifier_env vmlinux struct bpf_verifier_env {

        u32                        insn_idx;             /*     0     4 */
        u32                        prev_insn_idx;        /*     4     4 */
        struct bpf_prog *          prog;                 /*     8     8 */
        const struct bpf_verifier_ops  * ops;            /*    16     8 */
        struct bpf_verifier_stack_elem * head;           /*    24     8 */
        int                        stack_size;           /*    32     4 */
        bool                       strict_alignment;     /*    36     1 */

/* XXX 3 bytes hole, try to pack */

struct bpf_verifier_state * cur_state; /* 40 8 */
struct bpf_verifier_state_list * * explored_states; /* 48 8 */
struct bpf_map * used_maps[64]; /* 56 512 */
/* --- cacheline 8 boundary (512 bytes) was 56 bytes ago --- */
u32 used_map_cnt; /* 568 4 */
u32 id_gen; /* 572 4 */
/* --- cacheline 9 boundary (576 bytes) --- */
bool allow_ptr_leaks; /* 576 1 */
bool seen_direct_write; /* 577 1 */

/* XXX 6 bytes hole, try to pack */

struct bpf_insn_aux_data * insn_aux_data; /* 584 8 */
const struct bpf_line_info * prev_linfo; /* 592 8 */
struct bpf_verifier_log log; /* 600 1048 */
/* --- cacheline 25 boundary (1600 bytes) was 48 bytes ago --- */
struct bpf_subprog_info subprog_info[257]; /* 1648 3084 */
/* --- cacheline 73 boundary (4672 bytes) was 60 bytes ago --- */
u32 subprog_cnt; /* 4732 4 */

/* size: 4736, cachelines: 74, members: 19 */ /* sum members: 4727, holes: 2, sum holes: 9 */
};
[acme@quaco pahole]$

[acme@quaco pahole]$ pahole -F btf -C bpf_verifier_env --reorganize vmlinux struct bpf_verifier_env {

        u32                        insn_idx;             /*     0     4 */
        u32                        prev_insn_idx;        /*     4     4 */
        struct bpf_prog *          prog;                 /*     8     8 */
        const struct bpf_verifier_ops  * ops;            /*    16     8 */
        struct bpf_verifier_stack_elem * head;           /*    24     8 */
        int                        stack_size;           /*    32     4 */
        bool                       strict_alignment;     /*    36     1 */
        bool                       seen_direct_write;    /*    37     1 */
        bool                       allow_ptr_leaks;      /*    38     1 */
        /* XXX 1 byte hole, try to pack */

        struct bpf_verifier_state * cur_state;           /*    40     8 */
        struct bpf_verifier_state_list * * explored_states; /*    48     8 */
        struct bpf_map *           used_maps[64];        /*    56   512 */
        /* --- cacheline 8 boundary (512 bytes) was 56 bytes ago --- */
        u32                        used_map_cnt;         /*   568     4 */
        u32                        id_gen;               /*   572     4 */
        /* --- cacheline 9 boundary (576 bytes) --- */
        struct bpf_insn_aux_data * insn_aux_data;        /*   576     8 */
        const struct bpf_line_info  * prev_linfo;        /*   584     8 */
        struct bpf_verifier_log    log;                  /*   592  1048 */
        /* --- cacheline 25 boundary (1600 bytes) was 40 bytes ago --- */
        struct bpf_subprog_info    subprog_info[257];    /*  1640  3084 */
        /* --- cacheline 73 boundary (4672 bytes) was 52 bytes ago --- */
        u32                        subprog_cnt;          /*  4724     4 */

        /* size: 4728, cachelines: 74, members: 19 */
        /* sum members: 4727, holes: 2, sum holes: 1 */
        /* last cacheline: 56 bytes */
};   /* saved 8 bytes! */
Quoted 6 lines

[acme@quaco pahole]$

[acme@quaco pahole]$ pahole -F btf -C bpf_verifier_env --reorganize --show_reorg_steps vmlinux | grep ^/ /* Moving 'seen_direct_write' from after 'allow_ptr_leaks' to after 'strict_alignment' */ /* Moving 'allow_ptr_leaks' from after 'id_gen' to after 'seen_direct_write' */
/* Final reorganized struct: */

Heh, this is nifty, I haven't used that functionality yet!

Quoted 3 lines

[acme@quaco pahole]$

And this is so cool, so much faster :-)

Now we should think about making .BTF part of vmlinux by default ;)

Quoted 22 lines

[acme@quaco pahole]$ time pahole -F btf vmlinux > /tmp/btf

real    0m0.091s
user    0m0.078s
sys     0m0.013s

[acme@quaco pahole]$ time pahole -F dwarf vmlinux > /tmp/dwarf

real    0m14.472s
user    0m14.018s
sys     0m0.426s

[acme@quaco pahole]$ wc -l /tmp/btf
106948 /tmp/btf
[acme@quaco pahole]$ wc -l /tmp/dwarf
105808 /tmp/dwarf
[acme@quaco pahole]$

[acme@quaco pahole]$ time pahole --sizes vmlinux > /dev/null

real    0m14.432s
user    0m13.992s
sys     0m0.413s
Quoted 8 lines

[acme@quaco pahole]$ time pahole -F btf --sizes vmlinux > /dev/null

real    0m0.038s
user    0m0.030s
sys     0m0.008s

[acme@quaco pahole]$

Thanks for all the cool work!

My pleasure, it was fun! :)

Quoted 4 lines

- Arnaldo

$ btfdiff vmlinux

<SNIP>

#6 lore raw

Re: [PATCH pahole 2/2] btf_encoder: run BTF deduplication before writing out to ELF

Em Mon, Feb 18, 2019 at 11:38:41AM -0800, Andrii Nakryiko escreveu:

Quoted 4 lines · Arnaldo Carvalho de Melo
Quoted 1 line

Thanks for all the cool work!

My pleasure, it was fun! :)

So, next step, tag a pahole release and announce it, but I wonder about the libbpf linking, wouldn't be better, for now, to make it link statically with libbpf?

I ask this because libbpf isn't yet generally available, so perhaps we should have some logic to detect if it is available and link against it or if not, use the module stuff we have now and link it statically, wdyt?

Hopefully we get the problems noticed via btfdiff before that.

- Arnaldo

#7 lore raw

Re: [PATCH pahole 2/2] btf_encoder: run BTF deduplication before writing out to ELF

Quoted 7 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 18, 2019 at 11:38:41AM -0800, Andrii Nakryiko escreveu:

Quoted 4 lines · Arnaldo Carvalho de Melo
Quoted 1 line

Thanks for all the cool work!

My pleasure, it was fun! :)

Quoted 8 lines

So, next step, tag a pahole release and announce it, but I wonder about the libbpf linking, wouldn't be better, for now, to make it link statically with libbpf?

I ask this because libbpf isn't yet generally available, so perhaps we should have some logic to detect if it is available and link against it or if not, use the module stuff we have now and link it statically, wdyt?

I agree. Now the question is how to do it.

The easiest way to do this is to make bpf-static an OBJECT library in cmake, which will make it compile as PIC library. But that feature requires cmake 2.8.8. Would you be ok to bump minimum version of cmake to 2.8.8 (it's 2.4.8 right now).

If not, do you now what's the proper way to do this right now with older cmake?

Quoted 4 lines

Hopefully we get the problems noticed via btfdiff before that.

- Arnaldo

#8 lore raw

Re: [PATCH pahole 2/2] btf_encoder: run BTF deduplication before writing out to ELF

Quoted 18 lines · Andrii Nakryiko
Quoted 7 lines · Arnaldo Carvalho de Melo

Em Mon, Feb 18, 2019 at 11:38:41AM -0800, Andrii Nakryiko escreveu:

Quoted 4 lines · Arnaldo Carvalho de Melo
Quoted 1 line

Thanks for all the cool work!

My pleasure, it was fun! :)

Quoted 8 lines

So, next step, tag a pahole release and announce it, but I wonder about the libbpf linking, wouldn't be better, for now, to make it link statically with libbpf?

I ask this because libbpf isn't yet generally available, so perhaps we should have some logic to detect if it is available and link against it or if not, use the module stuff we have now and link it statically, wdyt?

Quoted 6 lines

I agree. Now the question is how to do it.

The easiest way to do this is to make bpf-static an OBJECT library in cmake, which will make it compile as PIC library. But that feature requires cmake 2.8.8. Would you be ok to bump minimum version of cmake to 2.8.8 (it's 2.4.8 right now).

that's old.
llvm does:
cmake_minimum_required(VERSION 3.4.3)

#9 lore raw

Re: [PATCH pahole 2/2] btf_encoder: run BTF deduplication before writing out to ELF

In reply to Andrii Nakryiko

Em Mon, Feb 18, 2019 at 11:38:41AM -0800, Andrii Nakryiko escreveu:

Quoted 8 lines · Arnaldo Carvalho de Melo
Quoted 4 lines

Em Sun, Feb 17, 2019 at 12:20:18AM -0800, Andrii Nakryiko escreveu:
The 'struct sun_disklabel' is interesting, pahole doesn't print it for the DWARF case when pretty printing all structs, but it works for the BTF case, I'll investigate.

I wonder if that has something to do with the fact that btf_dedup also does FWD -> STRUCT/UNION resolution?

Nope, when printing the classes (structs and class) pahole has this show_private_classes option, so that structs and classes that are defined inside other classes or functions are only shown when you ask for that, and that is what sun_disklabel is, it is defined in block/partitions/sun.c as:

int sun_partition(struct parsed_partitions *state)

{
        int i;
        __be16 csum;
        int slot = 1;
        __be16 *ush;
        Sector sect;
        struct sun_disklabel {
                unsigned char info[128];   /* Informative text string */
                struct sun_vtoc {
                    __be32 version;     /* Layout version */
                    char   volume[8];   /* Volume name */
                    __be16 nparts;      /* Number of partitions */
                    struct sun_info {           /* Partition hdrs, sec 2 */
                        __be16 id;
                        __be16 flags;
                    } infos[8];

<SNIP>

This information gets lost when we convert it to BTF, so for btfdiff I'll add that option:

--show_private_classes Show classes that are defined inside other classes
or in functions

When printing from DWARF info.

- Arnaldo