Add build-id to modinfo#432
Conversation
4136683 to
62c0325
Compare
evelikov
left a comment
There was a problem hiding this comment.
Code-wise this looks good, left some stylistic suggestions - nothing too crazy I hope 😅
|
@evelikov any thoughts about a new build-id subcommand? |
Without having many other sub-command to compare against - the proposed syntax seems a bit odd IMHO. For better or worse I appreciate the style and consistency of the systemd "ctl" tools. Would be in favour if we have a proposal of two how we can structure the existing options (modprobe et al) and see how those will align with the build-id bits. Aside: please add a note - here in PR, in a commit message, or in-code... more or less anywhere - which kernel version introduced support for |
Let the compiler decide depending on the optimization level. Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
Shortcut to the size. Keep this wrapper inline even after the previous de-inlining change: it is a tiny typed helper around elf_get_uint() that avoids repeating the uint32_t size at call sites, while the larger helpers can still be left to the compiler. Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
Read the .note.gnu.build-id section so it can be displayed by modinfo in
a future change. For now this is only added to pretty-print the id, but
later can be refactored to easily compare with the section dump from
/sys/module/<module-name>/.note.gnu.build-id
The section in the elf is potentially available since kernel 4.10 (if
toolchain supports it) and became unconditional since commit
89ff7131f78a ("kbuild: add --hash-style= and --build-id unconditionally")
since minimum toolchain versions got raised.
Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
If available, add the build-id to the info list returned by kmod_module_get_info(). This allows us to compare the build-id of a loaded module versus the build-id of the file. It's rather cumbersome command, but it works: $ ./build/modinfo -F build-id hid AE:7A:2E:37:E0:2B:31:D5:72:7C:87:87:15:8C:05:FA:77:7A:4F:57 $ xxd -p -u -s16 /sys/module/hid/notes/.note.gnu.build-id | sed 's/../&:/g;s/:$//' AE:7A:2E:37:E0:2B:31:D5:72:7C:87:87:15:8C:05:FA:77:7A:4F:57 An option to modinfo to really to just dump the raw value can be added in future. Signed-off-by: Lucas De Marchi <demarchi@kernel.org>
62c0325 to
8ead35d
Compare
Note that the ctl tools in systemd are targeted at talking to a daemon. Once upon a time I wanted to deprecate the standalone modprobe/insmod/... etc and have a unified "kmod ". I'm not pursuing that anymore as I don't really see pressuring need to break people's workflow/scripts. However for new things that don't fit the interface of these old tools, I'd rather use a subcommand for kmod. Here what I want is to give a quick command for kernel module developers to a) check the build-id of a filename/module and b) check if it matches what is loaded in the kernel. I don't think this fits any of modinfo/modprobe/etc. |
Kernel uses -Wl,--build-id in the build system, which causes a .notes.gnu.build-id section to be created containing. This can then be used by people developing modules to make sure the running module is the one that was last built.
I used to rely on srcversion for that purpose, but it has 2 issues:
As per last commit message, this can already be used as is, but is rather cumbersome. I will add more commits later to probably have a
modinfo -F raw-build-idthat simply dumps the section, which would allow to compare with the sysfs with something like:I'm on the fence about that because we could simply leave modinfo alone for that and add built-in tool: