Page MenuHomeFreeBSD

Add kldinfo(8), a simple utility to view module dependencies and their version
AcceptedPublic

Authored by rz_fabmicro.ru on Mon, Oct 12, 2:06 AM.
Tags
None
Referenced Files
F175848462: D60634.id189544.diff
Tue, Oct 13, 9:01 PM
F175830904: D60634.diff
Tue, Oct 13, 5:36 PM
F175822113: D60634.id189544.diff
Tue, Oct 13, 4:04 PM
F175780858: D60634.id.diff
Tue, Oct 13, 7:42 AM
F175777411: D60634.diff
Tue, Oct 13, 6:53 AM
F175767740: D60634.id189544.diff
Tue, Oct 13, 4:47 AM
F175757761: D60634.id189544.diff
Tue, Oct 13, 2:41 AM
F175749199: D60634.diff
Tue, Oct 13, 12:41 AM
Subscribers

Details

Reviewers
adrian
obiwac
kib
markj
imp
Group Reviewers
srcmgr
manpages
Summary

kldinfo utility parses ELF header of a given KLD module file, then searches for
available Kernel Loadable objects and shows their dependency and version
information. If path to file is given the utility tries to open it directly.
It quits if open fails. Otherwise, it searches for .ko in directories set by
kern.module_path sysctl variable. Can be used to show builtin modules in kernel.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 78050
Build 74933: arc lint + arc unit

Event Timeline

so just to be clear, what's the intended difference between this and kldstat ?

The kldstat works with modules loaded into kernel memory, it finds module by its name and prints what module_stat has (id, refs, and a pointer to modspecific_t). It does not print version information and dependencies.

The proposed kldinfo works with files: it parses ELF, searches for KObjs, extracts their dependency and version info and fine-prints what it finds. Note, that one module file may have many KObjs those also may have deps on other modules. Extracting such info from module is not easy, one has to write a script that juggles other tools like nm, objdump, hexdump. Thus, kldinfo is that script written in pure C that does it on its own. ;) No sorting is currently implemented.

To illustrate:

% kldinfo amdgpio
MODULE: amdgpio_acpi                 DEPENDS: kernel                       VERSION: 1501000 1501000 1501000
MODULE: amdgpio                      DEPENDS: acpi                         VERSION:       1       1       1
MODULE: amdgpio                      DEPENDS: gpiobus                      VERSION:       1       1       1
Found 3 dependencies in file /boot/kernel/amdgpio.ko

Calling on kernel file will print all modules built-in into that particular kernel:

% kldinfo /boot/kernel/kernel
MODULE: xpt                          DEPENDS: kernel                       VERSION: 1501000 1501000 1599999
MODULE: xpt                          DEPENDS: cam                          VERSION:       1       1       1
MODULE: cam                          DEPENDS: kernel                       VERSION: 1501000 1501000 1599999
MODULE: aprobe                       DEPENDS: kernel                       VERSION: 1501000 1501000 1599999
MODULE: aprobe                       DEPENDS: cam                          VERSION:       1       1       1
...
MODULE: ixl                          DEPENDS: iflib                        VERSION:       1       1       1
MODULE: smartpqi_pci                 DEPENDS: kernel                       VERSION: 1501000 1501000 1599999
MODULE: smartpqi                     DEPENDS: pci                          VERSION:       1       1       1
MODULE: x86bios                      DEPENDS: kernel                       VERSION: 1501000 1501000 1599999
MODULE: ioapic_pci                   DEPENDS: kernel                       VERSION: 1501000 1501000 1599999
MODULE: apic_nexus                   DEPENDS: kernel                       VERSION: 1501000 1501000 1599999
Found 926 dependencies in file /boot/kernel/kernel

Also, FreeBSD module has three version values: min, preferred and max. All three are printed.

Generally, I like this.
If there's demand, we can add pnp info as well, but that's harder to format and should be separate form this commit.

This revision is now accepted and ready to land.Mon, Oct 12, 10:12 PM

I'll investigate what it takes to extract and fine-print MODULE_PNP_INFO. Will provide a separate patch if something comes out of my keyboard.

I only looked at the single function.
Please ensure that the sources are in KNF, see style(9). Then I will read it more.

sbin/kldinfo/kldinfo.c
46

Why this var is not bool?

59

Indent is wrong. Previous line can be filled more.

63

There must be a blank line between var declarations and statements.

64

Why is this not just str(n)cpy?

66

Why there is so many blank lines in the bodies? They do not serve any purpose.

68

Why new line is only printed for verbose mode?