Skip to content

pahole: Bug fixes and small improvements

Arnaldo Carvalho de Melo bpf dwarves 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest31 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/31cmake: Update minimum required version from 3.5 to 3.10CMakeLists.txt+1 -10 replies
2/31Fix -Wsign-compare warnings across the codebasebtf_encoder.c btf_loader.c dwarf_loader.c +4 more+17 -260 replies
3/31btf_encoder: Fix interior pointer free and missing NULL checkbtf_encoder.c+15 -10 replies
4/31dwarves: Fix missing list head initialization in type__clone_membersdwarves.c+6 -00 replies
5/31pahole: Fix instance memory leak on early returns in prototype__stdio_fprintf_valuepahole.c+28 -170 replies
6/31ctf_loader, libctf: Fix error path resource leaksctf_loader.c libctf.c+7 -20 replies
7/31dwarves: Don't search for holes before member byte sizes are cachedcodiff.c ctracer.c dwarves.c+4 -110 replies
8/31dwarf_loader: Allocate type_dcu via dwarf_cu__new to fix dangling stack pointerdwarf_loader.c+25 -160 replies
9/31dwarf_loader: Fix annotation failure leaks in variable and typedef creationdwarf_loader.c+9 -20 replies
10/31btf_encoder: Use btf_encoder__tag_type() for all type ID computationsbtf_encoder.c+9 -80 replies
11/31pahole: Fix --errno typo that decrements instead of negatingpahole.c+3 -30 replies
12/31dwarves: Fix heap buffer overflow in languages__parse reallocdwarves.c+1 -10 replies
13/31btf_encoder: Fix early cleanup crashes in btf_encoder__new/deletebtf_encoder.c+7 -50 replies
14/31btf_encoder, libctf: Add elf_strptr NULL checks and fix kfunc boundsbtf_encoder.c libctf.c pahole.c+18 -80 replies
15/31dwarf_loader: Fix --fixup_silly_bitfields condition checkdwarf_loader.c+6 -20 replies
16/31dwarf_loader: Skip libdw__lock when elfutils is built thread-safedwarf_loader.c+24 -100 replies
17/31dwarf_loader: Fix data race in tag__init() decl_file string cachedwarf_loader.c+8 -10 replies
18/31pahole: Fix parse_btf_features("all") being a silent no-oppahole.c+23 -00 replies
19/31dwarves: Fix variable shadowing in __cus__find_struct_by_name()dwarves.c+2 -10 replies
20/31dutil: Add exec_objcopy() shell-injection-safe helperdutil.c dutil.h+75 -00 replies
21/31btf_encoder: Fall back to objcopy when llvm-objcopy is not availablebtf_encoder.c libctf.c+36 -150 replies
22/31dwarf_loader, btf_loader: Replace stale FIXME/XXX comments with explanationsbtf_loader.c dwarf_loader.c+26 -310 replies
23/31pahole: Skip inline expansions during BTF encodingpahole.c+1 -30 replies
24/31pahole: Use fseek for seekable files in --prettify and --seek_bytespahole.c+39 -300 replies
25/31pahole: Guard pipe_seek() against negative offsetspahole.c+44 -140 replies
26/31gobuffer: Remove 5 dead functions found via coverage analysisgobuffer.c gobuffer.h+0 -820 replies
27/31dwarves: Remove 6 dead functions found via coverage analysisdwarves.c dwarves.h+1 -990 replies
28/31pfunct, dwarves_fprintf: Mark file-local functions as staticdwarves_fprintf.c pfunct.c+3 -30 replies
29/31btf_encoder: Fix multi-dimensional array encodingbtf_encoder.c+260 -390 replies
30/31btf_loader: Fix multi-dimensional array loadingbtf_loader.c tests/btf_arrays.sh+194 -100 replies
31/31btfdiff: Remove --flat_arrays now that pahole encodes multi dim arrays in BTFbtfdiff+0 -10 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCHES 00/31] pahole: Bug fixes and small improvements

Hi,

Here are 31 patches fixing pre-existing bugs found via coverage
analysis, AI-assisted review (sashiko), and manual testing. No new features.

Critical kernel build path fix:
Multi-dimensional arrays (e.g. int[2][3]) were incorrectly collapsed into flat arrays (int[6]) in BTF encoding. The encoder wrote only the total element count; the loader read only the first dimension. Both now preserve the full dimension chain using chained BTF_KIND_ARRAY nodes, matching bpftool and kernel verifier format.

Before: pahole -F btf showed int a[3][4] as int a[12]
After: int a[2][3][4] encodes as three chained BTF_KIND_ARRAY nodes
and round-trips correctly

Bug fixes found via coverage analysis:
- Fix interior pointer free and missing NULL check in btf_encoder
- Fix missing list head initialization in type__clone_members
- Fix instance memory leak on 14 early returns in prototype__stdio_fprintf_value
- Fix error path resource leaks in ctf_loader and libctf
- Fix early cleanup crashes in btf_encoder__new/delete
- Fix dangling stack pointer: allocate type_dcu via dwarf_cu__new
- Fix annotation failure leaks in variable and typedef creation
- Fix --errno typo that decrements instead of negating
- Fix heap buffer overflow in languages__parse realloc
- Fix parse_btf_features("all") being a silent no-op
- Fix --fixup_silly_bitfields condition check
- Fix data race in tag__init() decl_file string cache
- Fix variable shadowing in __cus__find_struct_by_name
- Fix phantom holes when class__find_holes ran before byte sizes were cached (eliminates 36 false "BRAIN FART ALERT" on Firefox)
- Add elf_strptr NULL checks and fix kfunc bounds in btf_encoder
- Use btf_encoder__tag_type() for all type ID computations

Other improvements:
- Fix -Wsign-compare warnings across the codebase
- cmake: Update minimum required version from 3.5 to 3.10
- Skip inline expansions during BTF encoding (performance)
- Use fseek for seekable files in --prettify and --seek_bytes
- Guard pipe_seek() against negative offsets
- Fall back to GNU objcopy when llvm-objcopy is not available
- Add exec_objcopy() shell-injection-safe helper
- Skip libdw__lock when elfutils >= 0.194 is built thread-safe
- Replace stale FIXME/XXX comments with explanations
- Remove 11 dead functions found via coverage analysis
- Mark file-local functions as static

There are several other series that will result in way more coverage and regression tests and will add support for more rust DWARF tags, DWARF partial units that will allow us to build the kernel with most of the CONFIG_DEBUG_ DWARF options (DWARF5, etc), only split DWARF (skeletons) is left for after these series are applied.

The end result for tests/tests is this, that runs in parallel and mimics the 'perf test' output:

⬢ [acme@toolbx pahole]$ ./build-and-test-cmd.sh
<SNIP>
Testing pahole version:
v1.31-215-gcd4504f549af6fe7

Verbose mode enabled - showing diagnostic information:
Architecture: x86_64
CPUs: 32
Memory: 60.4 GB
Swap: 8.0 GB
Parallelism: unlimited (all tests run in parallel)
Tip: On low-memory systems, use -j to limit parallelism (e.g., -j 4 or -j 1)
Test artifacts: /tmp/pahole-tests/
Compiler: gcc (GCC) 16.1.1 20260515 (Red Hat 16.1.1-2)
libc: ldd (GNU libc) 2.43
bpftool: bpftool v7.6.0
VMLINUX: not set
PERF_BIN: not set
PERF_SRC_DIR: not set

  1: dwarves_emit.c: _Atomic type compile emission.                     : Ok
  2: _Atomic type display and --skip_emitting_atomic_typedefs.          : Ok
  3: Auxiliary tools: pglobal, prefcnt, dtagnames.                      : Ok
  4: Bitfield layout and data member filtering.                         : Ok
  5: dwarf_loader coverage: bitfields, templates, enums, inlines.       : Ok
  6: Bitfield typedef recoding (tag__recode_dwarf_bitfield).            : Ok
  7: DW_FORM_block byte order conversion.                               : Skip
  8: BTF arena type tag encoding for kfuncs.                            : Ok
  9: BTF multi-dimensional array encoding and round-trip.               : Ok
 10: BTF bitfield encoding and loading round-trip.                      : Ok
 11: BTF VAR and DATASEC encoding for global variables.                 : Ok
 12: BTF deduplication of array types across CUs.                       : Ok
 13: Distilled base BTF generation.                                     : Skip
 14: BTF encoding options.                                              : Ok
 15: BTF encoder coverage.                                              : Ok
 16: BTF encoder comprehensive feature coverage.                        : Ok
 17: BTF_KIND_FWD encoding and loading round-trip.                      : Ok
 18: BTF encoding with invalid symbol names.                            : Ok
 21: BTF FLOAT and ENUM64 type encoding.                                : Ok
 22: Check BTF type tag order.                                          : Ok
 23: BTF encoder verbose logging coverage.                              : Ok
 24: BTF encoding into ELF via pahole -J (btf_encoder__write_elf).      : Ok
 25: BTF true_signature: clang optimized aggregate parameters (2 structs: Ok
 26: BTF true_signature: clang optimized aggregate parameters (2 structs: Ok
 27: BTF true_signature: clang optimized with large union parameter     : Ok
 28: BTF true_signature: clang optimized parameters (scalar)            : Ok
 29: BTF true_signature: clang optimized with stack parameters (9 params: Ok
 30: BTF true_signature: clang optimized with stack parameters (non-stat: Ok
 31: Class name list from file.                                         : Ok
 32: CLI display and filtering options.                                 : Ok
 33: codiff struct comparison.                                          : Ok
 34: codiff coverage: terse, functions, verbose, multi-CU.              : Ok
 35: codiff member change coverage.                                     : Ok
 36: codiff multi-CU: __cus__find_cu_by_name coverage.                  : Ok
 37: codiff --terse (-t) type change reporting.                         : Ok
 38: Compile emission pipeline.                                         : Ok
 39: Compilable output and type filtering.                              : Ok
 40: Recursive container search and verbose counts.                     : Ok
 41: Type containment and pointer search.                               : Ok
 42: C++ advanced DWARF tag coverage.                                   : Ok
 43: C++ cleanup: delete_tags coverage for lexblock, parameter packs.   : Ok
 44: C++ inheritance and namespace printing.                            : Ok
 45: C++ value parameter pack and shadow definition disambiguation.     : Ok
 46: C++ namespace and using-declaration display.                       : Ok
 47: C++ variadic template parameter pack handling.                     : Ok
 48: C++ template pretty printing round-trip.                           : Ok
 49: C++ template template parameter pretty printing round-trip.        : Ok
 51: Class name filtering.                                              : Ok
 52: Default BTF on a system without BTF.                               : Ok
 53: Display format options.                                            : Ok
 54: dwarf_loader.c edge cases: bitfield recode, inlining, call sites.  : Ok
 55: dwarves.c core API coverage.                                       : Ok
 56: DWZ alternate debug file type resolution.                          : Ok
 57: Legacy atomic_ base type emission via --compile (hand-crafted DWARF: Ok
 58: Atomic typedef emission.                                           : Ok
 59: dwarves_emit.c / dwarves_reorganize.c coverage.                    : Ok
 60: DW_TAG_atomic_type member handling via --compile.                  : Ok
 61: Type emission (--compile) and atomic typedefs.                     : Ok
 62: Enumerator search.                                                 : Ok
 63: Expand pointers option.                                            : Ok
 64: Type expansion and anonymous struct options.                       : Ok
 65: Flexible arrays accounting.                                        : Ok
 66: dwarves_fprintf.c coverage: fn-ptr members, labels, C++ types.     : Ok
 67: Validation of GCC optimized parameters in default BTF.             : Ok
 68: Validation of BTF encoding of true_signatures.                     : Skip (no optimizations applied.)
 69: Compare parallel vs merged CU loading for inter-CU type references.: Ok
 70: Multi-file loading (cus__load_files).                              : Ok
 71: Version output.                                                    : Ok
 72: Struct packing and reorganization.                                 : Ok
 73: pahole coverage: sort, word_size unions, prettify bitfields.       : Ok
 74: Format coverage: count, skip, structs, hex, contains, first_obj_onl: Ok
 75: Header, range and seek_bytes prettify paths.                       : Ok
 76: pahole.c scattered option paths.                                   : Ok
 77: pdwtags DWARF tag display.                                         : Ok
 78: Check that pfunct can print btf_decl_tags read from BTF.           : Ok
 79: pfunct --class and --expand_types.                                 : Ok
 80: pfunct coverage: symtab, class, expand_types, compile.             : Ok
 81: pfunct function statistics.                                        : Ok
 82: pglobal basic: variables, functions, static exclusion.             : Ok
 83: prefcnt.c: reference counting coverage.                            : Ok
 84: prettify_bitfield                                                  : Ok
 85: Pretty printing of files using DWARF type information.             : Ok
 86: Prototype expression parsing and prettify.                         : Ok
 87: Cacheline boundary display with large structs.                     : Ok
 88: Sizes and holes display.                                           : Ok
 89: Small files coverage: elf_symtab, gobuffer, dutil, pglobal.        : Ok
 90: Sort with multi-CU deduplication.                                  : Ok
 91: Sort output and separator.                                         : Ok
 92: Statistics and filtering options.                                  : Ok
 93: Typedef chain display.                                             : Ok
 94: Word size LP resizing.                                             : Ok
 95: Union word_size resize and packable hex.                           : Ok
 96: Validation of BTF encoding of functions.                           : Ok
 50: ctracer: struct method tracing generation.                         : Ok
 20: Split BTF encoding (vmlinux base + kernel module).                 : Ok
 19: BTF encoding with kernel vmlinux.                                  : Ok
 98: Parallel reproducible DWARF Loading/Serial BTF encoding.           : Ok
 97: BTF encoding on vmlinux.                                           : Ok

Saved timing data to .test-times (98 tests)

⬢ [acme@toolbx pahole]$

Cheers,

- Arnaldo

 CMakeLists.txt       |    2 +-
 btf_encoder.c        |  550 +++++++++++++------
 btf_loader.c         |   60 ++-
 btfdiff              |    1 -
 codiff.c             |    8 +-
 ctracer.c            |    2 +-
 ctf_encoder.c        |    2 +-
 ctf_loader.c         |   16 +-
 dutil.c              |   46 ++
 dutil.h              |    1 +
 dwarf_loader.c       |  122 ++--
 dwarves.c            |   95 +---
 dwarves.h            |   21 +-
 dwarves_emit.c       |    2 +-
 dwarves_fprintf.c    |   74 +--
 gobuffer.c           |   49 --
 gobuffer.h           |    5 -
 libctf.c             |   14 +-
 pahole.c             |   63 ++-
 pfunct.c             |   14 +-
 tests/btf_arrays.sh  |  158 ++++++
 21 files changed, 864 insertions(+), 441 deletions(-)

Arnaldo Carvalho de Melo (31):
cmake: Update minimum required version from 3.5 to 3.10
Fix -Wsign-compare warnings across the codebase
btf_encoder: Fix interior pointer free and missing NULL check
dwarves: Fix missing list head initialization in type__clone_members
pahole: Fix instance memory leak on early returns in prototype__stdio_fprintf_value ctf_loader, libctf: Fix error path resource leaks
dwarves: Don't search for holes before member byte sizes are cached
dwarf_loader: Allocate type_dcu via dwarf_cu__new to fix dangling stack pointer
dwarf_loader: Fix annotation failure leaks in variable and typedef creation
btf_encoder: Use btf_encoder__tag_type() for all type ID computations
pahole: Fix --errno typo that decrements instead of negating
dwarves: Fix heap buffer overflow in languages__parse realloc
btf_encoder: Fix early cleanup crashes in btf_encoder__new/delete btf_encoder, libctf: Add elf_strptr NULL checks and fix kfunc bounds
dwarf_loader: Fix --fixup_silly_bitfields condition check
dwarf_loader: Skip libdw__lock when elfutils is built thread-safe
dwarf_loader: Fix data race in tag__init() decl_file string cache
pahole: Fix parse_btf_features("all") being a silent no-op
dwarves: Fix variable shadowing in __cus__find_struct_by_name()
dutil: Add exec_objcopy() shell-injection-safe helper
btf_encoder: Fall back to objcopy when llvm-objcopy is not available dwarf_loader, btf_loader: Replace stale FIXME/XXX comments with explanations
pahole: Skip inline expansions during BTF encoding
pahole: Use fseek for seekable files in --prettify and --seek_bytes
pahole: Guard pipe_seek() against negative offsets
gobuffer: Remove 5 dead functions found via coverage analysis
dwarves: Remove 6 dead functions found via coverage analysis
pfunct, dwarves_fprintf: Mark file-local functions as static
btf_encoder: Fix multi-dimensional array encoding
btf_loader: Fix multi-dimensional array loading
btfdiff: Remove --flat_arrays now that pahole encodes multi dim arrays
in BTF

 CMakeLists.txt       |   2 +-
 btf_encoder.c        | 406 +++++++++++++++++++++++++++++++++++--------
 btf_loader.c         |  53 ++++--
 btfdiff              |   1 -
 codiff.c             |   3 +
 ctf_loader.c         |   8 +-
 ctracer.c            |   1 +
 dutil.c              |  72 ++++++++
 dutil.h              |   3 +
 dwarf_loader.c       | 157 ++++++++++-------
 dwarves.c            | 111 ++----------
 dwarves.h            |  13 --
 dwarves_fprintf.c    |   5 +-
 dwarves_reorganize.c |   6 +-
 gobuffer.c           |  74 --------
 gobuffer.h           |   8 -
 libctf.c             |  10 +-
 pahole.c             | 177 +++++++++++++------
 pfunct.c             |   4 +-
 tests/btf_arrays.sh  | 158 +++++++++++++++++
 20 files changed, 861 insertions(+), 411 deletions(-)
 create mode 100755 tests/btf_arrays.sh
Signature · 1 line
2.55.0