Re: [PATCH bpf-next v2] libbpf: ignore .eh_frame sections when parsing elf files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Aug 26, 2021 at 5:10 AM Toke Høiland-Jørgensen <toke@xxxxxxxxxx> wrote:
>
> When .eh_frame and .rel.eh_frame sections are present in BPF object files,
> libbpf produces errors like this when loading the file:
>
> libbpf: elf: skipping unrecognized data section(32) .eh_frame
> libbpf: elf: skipping relo section(33) .rel.eh_frame for section(32) .eh_frame
>
> It is possible to get rid of the .eh_frame section by adding
> -fno-asynchronous-unwind-tables to the compilation, but we have seen
> multiple examples of these sections appearing in BPF files in the wild,
> most recently in samples/bpf, fixed by:
> 5a0ae9872d5c ("bpf, samples: Add -fno-asynchronous-unwind-tables to BPF Clang invocation")
>
> While the errors are technically harmless, they look odd and confuse users.

These warnings point out invalid set of compiler flags used for
compiling BPF object files, though. Which is a good thing and should
incentivize anyone getting those warnings to check and fix how they do
BPF compilation. Those .eh_frame sections shouldn't be present in BPF
object files at all, and that's what libbpf is trying to say.

I don't know exactly in which situations that .eh_frame section is
added, but looking at our selftests (and now samples/bpf as well),
where we use -target bpf, we don't need
-fno-asynchronous-unwind-tables at all.

So instead of hiding the problem, let's use this as an opportunity to
fix those user's compilation flags instead.

> So let's make libbpf filter out those sections, by adding .eh_frame to the
> filter check in is_sec_name_dwarf().
>
> v2:
> - Expand explanation in the commit message
>
> Signed-off-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
> ---
>  tools/lib/bpf/libbpf.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 88d8825fc6f6..b1dc97b95965 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -2909,7 +2909,8 @@ static Elf_Data *elf_sec_data(const struct bpf_object *obj, Elf_Scn *scn)
>  static bool is_sec_name_dwarf(const char *name)
>  {
>         /* approximation, but the actual list is too long */
> -       return strncmp(name, ".debug_", sizeof(".debug_") - 1) == 0;
> +       return (strncmp(name, ".debug_", sizeof(".debug_") - 1) == 0 ||
> +               strncmp(name, ".eh_frame", sizeof(".eh_frame") - 1) == 0);
>  }
>
>  static bool ignore_elf_section(GElf_Shdr *hdr, const char *name)
> --
> 2.33.0
>




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux