]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
libbpf: Fix output .symtab byte-order during linking
authorTony Ambardar <tony.ambardar@gmail.com>
Mon, 16 Sep 2024 08:37:42 +0000 (01:37 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 4 Oct 2024 00:47:36 +0000 (17:47 -0700)
Object linking output data uses the default ELF_T_BYTE type for '.symtab'
section data, which disables any libelf-based translation. Explicitly set
the ELF_T_SYM type for output to restore libelf's byte-order conversion,
noting that input '.symtab' data is already correctly translated.

Fixes: faf6ed321cf6 ("libbpf: Add BPF static linker APIs")
Signed-off-by: Tony Ambardar <tony.ambardar@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/87868bfeccf3f51aec61260073f8778e9077050a.1726475448.git.tony.ambardar@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/linker.c

index e0005c6ade88a2ac1d3a358764d27b39eac61062..6985ab0f1ca9e8a1eafca8138f50f86445236993 100644 (file)
@@ -396,6 +396,8 @@ static int init_output_elf(struct bpf_linker *linker, const char *file)
                pr_warn_elf("failed to create SYMTAB data");
                return -EINVAL;
        }
+       /* Ensure libelf translates byte-order of symbol records */
+       sec->data->d_type = ELF_T_SYM;
 
        str_off = strset__add_str(linker->strtab_strs, sec->sec_name);
        if (str_off < 0)