Thread (35 messages) 35 messages, 2 authors, 2021-02-17

Re: [PATCH dwarves v3 4/5] btf_encoder: Add .BTF section using libelf

From: Giuliano Procida <hidden>
Date: 2021-02-09 15:06:23

On Mon, 8 Feb 2021 at 22:29, Andrii Nakryiko [off-list ref] wrote:
On Fri, Feb 5, 2021 at 5:42 AM Giuliano Procida [off-list ref] wrote:
quoted
pahole -J uses libelf directly when updating a .BTF section. However,
it uses llvm-objcopy to add .BTF sections. This commit switches to
using libelf for both cases.

This eliminates pahole's dependency on llvm-objcopy. One unfortunate
side-effect is that vmlinux actually increases in size. It seems that
llvm-objcopy modifies the .strtab section, discarding many strings. I
speculate that is it discarding strings not referenced from .symtab
and updating the references therein.

Layout is left completely up to libelf and existing section offsets
are likely to change.

Signed-off-by: Giuliano Procida <redacted>
---
Logic looks correct. One nit below.

Acked-by: Andrii Nakryiko <andrii@kernel.org>
quoted
 libbtf.c | 127 +++++++++++++++++++++++++++++++++++--------------------
 1 file changed, 81 insertions(+), 46 deletions(-)
diff --git a/libbtf.c b/libbtf.c
index 4ae7150..9f4abb3 100644
--- a/libbtf.c
+++ b/libbtf.c
@@ -698,6 +698,7 @@ int32_t btf_elf__add_datasec_type(struct btf_elf *btfe, const char *section_name

 static int btf_elf__write(const char *filename, struct btf *btf)
 {
+       const char dot_BTF[] = ".BTF";
it's a constant, so more appropriate name would be DOT_BTF, but that
"dot_" notation in the name of the variable throws me off, honestly.
libbpf is using BTF_SEC_NAME for this, which IMO makes more sense as a
name for the constant
Ack. Changed. I'll wait a day for further comments before reposting.

Thanks again,
Giuliano.
quoted
        GElf_Ehdr ehdr;
        Elf_Data *btf_data = NULL;
        Elf *elf = NULL;
@@ -705,6 +706,7 @@ static int btf_elf__write(const char *filename, struct btf *btf)
        uint32_t raw_btf_size;
        int fd, err = -1;
        size_t strndx;
+       void *str_table = NULL;

        fd = open(filename, O_RDWR);
        if (fd < 0) {
[...]
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help