Skip to contentSkip to conversation

pahole: Don't fail when encoding BTF on an object with no DWARF info

PATCH Applied Arnaldo Carvalho de Melo 2 participants 4 messages Jul 22, 2025 – Jul 31, 2025 BPF

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pahole: Don't fail when encoding BTF on an object with no DWARF info

If pahole is asked to encode BTF for a file with no DWARF info, don't fail, just skip it.

This is the case, for instance, in this file in a kernel build with DWARF info generation enabled:

  $ pahole ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  libbpf: failed to find '.BTF' ELF section in ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  pahole: file '../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o' has no supported type information.
  $

Before it was failing when encoding BTF for it, now:

  $ pahole --btf_encode ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  $ echo $?
  0
  $
---
 pahole.c | 7 +++++++
 1 file changed, 7 insertions(+)
pahole.c +7 -0
index 333e71ab65924d2c..a001ec86ef1b0908 100644
@@ -3659,6 +3659,13 @@ try_sole_arg_as_class_names:
 			remaining = argc;
 			goto try_sole_arg_as_class_names;
 		}
+
+		if (btf_encode || ctf_encode) {
+			// If encoding is asked for and there is no DEBUG info to encode from,
+			// there are no errors, continue...
+			goto out_ok;
+		}
+
 		if (argv[remaining] != NULL) {
 			cus__fprintf_load_files_err(cus, "pahole", argv + remaining, err, stderr);
 		} else {
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Arnaldo Carvalho de Melo

If pahole is asked to encode BTF for a file with no DWARF info, don't fail, just skip it.

This is the case, for instance, in this file in a kernel build with DWARF info generation enabled:

  $ pahole ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  libbpf: failed to find '.BTF' ELF section in ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  pahole: file '../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o' has no supported type information.
  $
Quoted 8 lines

Before it was failing when encoding BTF for it, now:

  $ pahole --btf_encode ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  $ echo $?
  0
  $

Only potential issue I can see is that in the usual case of encoding BTF from DWARF in the kernel we'd probably like to fall over if we can't encode BTF due to DWARF absence. However current Kconfig dependencies of CONFIG_DEBUG_INFO_BTF mean this can't happen in practice I think so

Quoted 22 lines
---
 pahole.c | 7 +++++++
 1 file changed, 7 insertions(+)
pahole.c +7 -0
index 333e71ab65924d2c..a001ec86ef1b0908 100644
@@ -3659,6 +3659,13 @@ try_sole_arg_as_class_names:
 			remaining = argc;
 			goto try_sole_arg_as_class_names;
 		}
+
+		if (btf_encode || ctf_encode) {
+			// If encoding is asked for and there is no DEBUG info to encode from,
+			// there are no errors, continue...
+			goto out_ok;
+		}
+
 		if (argv[remaining] != NULL) {
 			cus__fprintf_load_files_err(cus, "pahole", argv + remaining, err, stderr);
 		} else {
#2 lore raw
Quoted 19 lines · Alan Maguire
Quoted 17 lines · Arnaldo Carvalho de Melo

If pahole is asked to encode BTF for a file with no DWARF info, don't fail, just skip it.

This is the case, for instance, in this file in a kernel build with DWARF info generation enabled:

  $ pahole ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  libbpf: failed to find '.BTF' ELF section in ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  pahole: file '../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o' has no supported type information.
  $

Before it was failing when encoding BTF for it, now:

  $ pahole --btf_encode ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  $ echo $?
  0
  $
Quoted 6 lines
Quoted 1 line

Only potential issue I can see is that in the usual case of encoding BTF from DWARF in the kernel we'd probably like to fall over if we can't encode BTF due to DWARF absence. However current Kconfig dependencies of CONFIG_DEBUG_INFO_BTF mean this can't happen in practice I think so

Right, this is an exception, just some .o files out of thousands end up without DWARF.

So I think that if we take --btf_encode as "Encode BTF from DWARF, if DWARF is available" is a good interpretation of intent.

- Arnaldo

Quoted 1 line

Thanks!

- Arnaldo

Quoted 22 lines
Quoted 22 lines
---
 pahole.c | 7 +++++++
 1 file changed, 7 insertions(+)
pahole.c +7 -0
index 333e71ab65924d2c..a001ec86ef1b0908 100644
@@ -3659,6 +3659,13 @@ try_sole_arg_as_class_names:
 			remaining = argc;
 			goto try_sole_arg_as_class_names;
 		}
+
+		if (btf_encode || ctf_encode) {
+			// If encoding is asked for and there is no DEBUG info to encode from,
+			// there are no errors, continue...
+			goto out_ok;
+		}
+
 		if (argv[remaining] != NULL) {
 			cus__fprintf_load_files_err(cus, "pahole", argv + remaining, err, stderr);
 		} else {
Applied
#3 lore raw
Quoted 30 lines · Arnaldo Carvalho de Melo
Quoted 19 lines · Alan Maguire
Quoted 17 lines · Arnaldo Carvalho de Melo

If pahole is asked to encode BTF for a file with no DWARF info, don't fail, just skip it.

This is the case, for instance, in this file in a kernel build with DWARF info generation enabled:

  $ pahole ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  libbpf: failed to find '.BTF' ELF section in ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  pahole: file '../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o' has no supported type information.
  $

Before it was failing when encoding BTF for it, now:

  $ pahole --btf_encode ../build/v6.15.0-rc4+/arch/x86/purgatory/purgatory.o
  $ echo $?
  0
  $
Quoted 6 lines
Quoted 1 line

Only potential issue I can see is that in the usual case of encoding BTF from DWARF in the kernel we'd probably like to fall over if we can't encode BTF due to DWARF absence. However current Kconfig dependencies of CONFIG_DEBUG_INFO_BTF mean this can't happen in practice I think so

Right, this is an exception, just some .o files out of thousands end up without DWARF.

Quoted 9 lines

So I think that if we take --btf_encode as "Encode BTF from DWARF, if DWARF is available" is a good interpretation of intent.

- Arnaldo

Quoted 1 line

Thanks!

Applied to the next branch of

https://git.kernel.org/pub/scm/devel/pahole/pahole.git/

Thanks!

Alan