Skip to content

Comments

elf_reader: add tests for ELF objects without BTF#1939

Merged
ti-mo merged 2 commits intocilium:mainfrom
puwun:test/elf-reader-nobtf
Feb 18, 2026
Merged

elf_reader: add tests for ELF objects without BTF#1939
ti-mo merged 2 commits intocilium:mainfrom
puwun:test/elf-reader-nobtf

Conversation

@puwun
Copy link
Contributor

@puwun puwun commented Jan 19, 2026

Adds infrastructure to test loading of ELF objects compiled without BTF information, verifying the fix from #1807

Changes:

  • Added testdata/loader_nobtf.c using legacy map definitions.
  • Updated Makefile to compile this new test data with -g0 (no BTF).
  • Added TestLoadCollectionSpecWithoutBTF to verify successful parsing when spec.Types is nil.

Fixes: #1810

@puwun puwun requested a review from a team as a code owner January 19, 2026 07:55
@ti-mo
Copy link
Contributor

ti-mo commented Jan 28, 2026

@puwun Thanks for picking this up! After looking at this for a bit, I think it would be preferable to reuse the existing loader.c as much as possible to increase coverage. I suggest the following:

  • move BTF map definitions to a new loader_maps_btf.h
  • create a new loader_maps_bpf.h with equivalent bpf_map_def-based definitions, ignoring {bpf,btf}_decl_map since their purpose is testing decl tags on maps, which doesn't exist pre-BTF
  • #ifndef __NOBTF__, #include "loader_maps_btf.h", #else, #include "loader_maps_bpf.h"
  • build loader.c twice, additionally specifying -D__NOBTF__ along with the -g0 flag
  • Add a subtest to TestLoadCollectionSpec for the no-btf version. You'll want to do a similar thing with the CollectionSpec under test where you populate a part of CollectionSpec.Maps in the BTF-enabled subtest, since some maps will only be present when BTF is enabled.

Try to make only the strictly-necessary changes to keep things straightforward to review. Thank you!

@puwun puwun force-pushed the test/elf-reader-nobtf branch from 0c9fc75 to d7485d5 Compare January 28, 2026 11:08
@puwun
Copy link
Contributor Author

puwun commented Feb 5, 2026

@ti-mo thanks, updated 👍

When the ELF has no BTF, ex.extInfo will be nil. This was overlooked in a
recent refactor.

Signed-off-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo force-pushed the test/elf-reader-nobtf branch from d7485d5 to b0adcf6 Compare February 18, 2026 16:41
@ti-mo ti-mo force-pushed the test/elf-reader-nobtf branch 2 times, most recently from 30f5825 to affa282 Compare February 18, 2026 19:03
Adds infrastructure to test loading of ELF objects compiled without BTF information.

Signed-off-by: Pavan More <pavansmore05@gmail.com>
Co-authored-by: Timo Beckers <timo@isovalent.com>
@ti-mo ti-mo force-pushed the test/elf-reader-nobtf branch from affa282 to eb0f746 Compare February 18, 2026 19:11
@ti-mo ti-mo merged commit ee67e7f into cilium:main Feb 18, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure the ELF reader works for objects built without BTF

2 participants