Skip to content

Add support for DWARF debug info usage for kernel module address symbolization#1391

Merged
d-e-s-o merged 5 commits intolibbpf:mainfrom
d-e-s-o:topic/kernel-mod-syms
Feb 26, 2026
Merged

Add support for DWARF debug info usage for kernel module address symbolization#1391
d-e-s-o merged 5 commits intolibbpf:mainfrom
d-e-s-o:topic/kernel-mod-syms

Conversation

@danielocfb
Copy link
Copy Markdown
Collaborator

Please see individual commits for descriptions.

@danielocfb danielocfb requested a review from anakryiko December 19, 2025 14:21
@danielocfb danielocfb force-pushed the topic/kernel-mod-syms branch 4 times, most recently from 5941d58 to a2e3f78 Compare December 19, 2025 14:46
@d-e-s-o d-e-s-o force-pushed the topic/kernel-mod-syms branch 4 times, most recently from ace6526 to c724915 Compare December 26, 2025 18:31
@danielocfb danielocfb added the blocked The pull request is blocked and cannot progress at the moment. label Jan 8, 2026
Copy link
Copy Markdown
Member

@anakryiko anakryiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, great to see this happening (and sorry for delay!)

left minor questions/comments, but non are blocking

Comment thread src/kernel/modmap.rs Outdated
}

// Each line has format:
// <module_name> <size> <instances> <dependencies> <state> <offset>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not offset, absolute start address (and just for comment completeness there could be extra flags afterwards in ()

Comment thread src/kernel/modmap.rs
let addr = if let Ok(addr) = Addr::from_str_radix(addr.trim_start_matches("0x"), 16) {
// A start address of 0 means that the address was
// masked -- it is not usable for our purposes.
if addr == 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have some means to emit warning (for debugging)? might be useful

looking at kernel code (I was curious how this /proc/modules file is generated), I think either all module addresses will be zero (if kptr_restrict sysctl is set, or not enough capabilities to see real kernel address) or they will all be valid, so you can really break out of here and save time (and logging spam, if you decide to log this condition)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way it would manifest is that we'd report Reason::MissingSyms when symbolizing and there are no modules. It's the same mechanism we use for stripped ELF binaries or masked /proc/kallsyms addresses.

Comment thread src/kernel/resolver.rs


#[cfg(feature = "xz")]
fn decompress_xz(path: &Path) -> Result<NamedTempFile> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious, will this temporary file be deleted by blazesym when ElfResolver is destroyed, or it will stay in /tmp and is expected to be cleaned up eventually outside of blazesym's control?

Copy link
Copy Markdown
Collaborator

@d-e-s-o d-e-s-o Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, once the NamedTempFile leaves scope the file will be removed (so in this case that would be by the time KernelResolver::find_sym returns, on the current call path), so there shouldn't be any left overs.

@d-e-s-o d-e-s-o force-pushed the topic/kernel-mod-syms branch from c724915 to a332212 Compare January 12, 2026 18:28
@d-e-s-o
Copy link
Copy Markdown
Collaborator

d-e-s-o commented Jan 12, 2026

Rebased and address review comments. Thanks for the review. This support is still blocked on ELF relocations and/or additional testing.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 93.26599% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.60%. Comparing base (06f646b) to head (4043f56).

Files with missing lines Patch % Lines
src/kernel/depmod.rs 90.97% 13 Missing ⚠️
src/kernel/resolver.rs 87.80% 5 Missing ⚠️
src/kernel/modmap.rs 97.89% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1391      +/-   ##
==========================================
+ Coverage   95.53%   95.60%   +0.06%     
==========================================
  Files          54       56       +2     
  Lines        9213     9500     +287     
==========================================
+ Hits         8802     9082     +280     
- Misses        411      418       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@d-e-s-o d-e-s-o force-pushed the topic/kernel-mod-syms branch 2 times, most recently from f972e4a to b11be98 Compare January 29, 2026 21:56
Adjust our CI infra to build the test_hexdump kernel module with DWARF
debug information. We shall use this module for testing of kernel module
symbolization support down the line. To that end, already make sure that
we load it when running the main test suite.
We are also going to need to enable module unload support for our
kernel, because otherwise /proc/modules are b0rked.

Signed-off-by: Daniel Müller <deso@posteo.net>
Add an integration test for kernel module symbolization using DWARF
debug information.

Signed-off-by: Daniel Müller <deso@posteo.net>
@d-e-s-o d-e-s-o force-pushed the topic/kernel-mod-syms branch 2 times, most recently from c5ac5fd to 4043f56 Compare February 26, 2026 18:06
@d-e-s-o d-e-s-o removed the blocked The pull request is blocked and cannot progress at the moment. label Feb 26, 2026
@d-e-s-o d-e-s-o force-pushed the topic/kernel-mod-syms branch 5 times, most recently from f93fde0 to ea692e7 Compare February 26, 2026 19:12
Add a parser for /proc/modules style files, ModMap. /proc/modules
contains information about memory ranges of modules. We need such
information in order to understand which module a given kernel address
belongs to. On top of just parsing contents, objects of this type
provide the means for querying the module name that an address belongs
to, if any.

Signed-off-by: Daniel Müller <deso@posteo.net>
Add logic for parsing depmod binary files. These files basically
contain a search tree for efficiently looking up module paths (relative
to a base directory) given a module name. Making such a lookup possible
enables the loading of module binaries, which may contain DWARF debug
information for symbolization that resolves source code information (as
opposed to /proc/kallsyms, which only has limited function granularity
for addresses).

Signed-off-by: Daniel Müller <deso@posteo.net>
Add support for looking up and incorporating DWARF information for
symbolization of kernel module addresses. So far we have only supported
using DWARF for addresses belonging to the core kernel. We rely on the
previously introduced /proc/modules map for deciding whether an address
belongs to a kernel module. We then use the depmod file for looking up
the kernel module, optionally taking into account debug links as usual.

We also support compressed kernel modules and decompress them
transparently on the fly. To make that work, add the flat2 dependency to
handle gzip headers properly. That requires us to downgrade miniz_oxide,
because upstream can't get their act together and update, and we
certainly don't want to duplicate the dependency.

Signed-off-by: Daniel Müller <deso@posteo.net>
@d-e-s-o d-e-s-o force-pushed the topic/kernel-mod-syms branch from ea692e7 to e70d36a Compare February 26, 2026 19:21
@d-e-s-o d-e-s-o force-pushed the topic/kernel-mod-syms branch from e70d36a to 95a9afe Compare February 26, 2026 21:01
@d-e-s-o d-e-s-o enabled auto-merge (rebase) February 26, 2026 21:01
@d-e-s-o d-e-s-o merged commit 05cddf3 into libbpf:main Feb 26, 2026
43 checks passed
@d-e-s-o d-e-s-o deleted the topic/kernel-mod-syms branch February 26, 2026 21:23
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.

3 participants