linux-kernelorg-stable/tools/include/linux
Josh Poimboeuf dd590d4d57 objtool/klp: Introduce klp diff subcommand for diffing object files
Add a new klp diff subcommand which performs a binary diff between two
object files and extracts changed functions into a new object which can
then be linked into a livepatch module.

This builds on concepts from the longstanding out-of-tree kpatch [1]
project which began in 2012 and has been used for many years to generate
livepatch modules for production kernels.  However, this is a complete
rewrite which incorporates hard-earned lessons from 12+ years of
maintaining kpatch.

Key improvements compared to kpatch-build:

  - Integrated with objtool: Leverages objtool's existing control-flow
    graph analysis to help detect changed functions.

  - Works on vmlinux.o: Supports late-linked objects, making it
    compatible with LTO, IBT, and similar.

  - Simplified code base: ~3k fewer lines of code.

  - Upstream: No more out-of-tree #ifdef hacks, far less cruft.

  - Cleaner internals: Vastly simplified logic for symbol/section/reloc
    inclusion and special section extraction.

  - Robust __LINE__ macro handling: Avoids false positive binary diffs
    caused by the __LINE__ macro by introducing a fix-patch-lines script
    (coming in a later patch) which injects #line directives into the
    source .patch to preserve the original line numbers at compile time.

Note the end result of this subcommand is not yet functionally complete.
Livepatch needs some ELF magic which linkers don't like:

  - Two relocation sections (.rela*, .klp.rela*) for the same text
    section.

  - Use of SHN_LIVEPATCH to mark livepatch symbols.

Unfortunately linkers tend to mangle such things.  To work around that,
klp diff generates a linker-compliant intermediate binary which encodes
the relevant KLP section/reloc/symbol metadata.

After module linking, a klp post-link step (coming soon) will clean up
the mess and convert the linked .ko into a fully compliant livepatch
module.

Note this subcommand requires the diffed binaries to have been compiled
with -ffunction-sections and -fdata-sections, and processed with
'objtool --checksum'.  Those constraints will be handled by a klp-build
script introduced in a later patch.

Without '-ffunction-sections -fdata-sections', reliable object diffing
would be infeasible due to toolchain limitations:

  - For intra-file+intra-section references, the compiler might
    occasionally generated hard-coded instruction offsets instead of
    relocations.

  - Section-symbol-based references can be ambiguous:

    - Overlapping or zero-length symbols create ambiguity as to which
      symbol is being referenced.

    - A reference to the end of a symbol (e.g., checking array bounds)
      can be misinterpreted as a reference to the next symbol, or vice
      versa.

A potential future alternative to '-ffunction-sections -fdata-sections'
would be to introduce a toolchain option that forces symbol-based
(non-section) relocations.

Acked-by: Petr Mladek <pmladek@suse.com>
Tested-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
2025-10-14 14:50:18 -07:00
..
sched
unaligned
align.h
args.h tools/testing: add linux/args.h header and fix radix, VMA tests 2025-08-19 16:35:54 -07:00
arm-smccc.h
atomic.h tools/include: implement a couple of atomic_t ops 2025-09-13 16:55:24 -07:00
bitfield.h
bitmap.h tools bitmap: Add missing asm-generic/bitsperlong.h include 2025-10-02 15:09:32 -03:00
bitops.h
bits.h tools headers: Sync linux/bits.h with the kernel source 2025-08-18 12:38:42 -07:00
btf_ids.h
bug.h
build_bug.h tools headers: Syncronize linux/build_bug.h with the kernel sources 2025-06-16 14:05:11 -03:00
cache.h
cfi_types.h tools headers: kcfi: rename missed CONFIG_CFI_CLANG 2025-10-07 08:21:33 -07:00
compiler-gcc.h
compiler.h tools headers: Add stub definition for __iomem 2025-08-27 12:14:06 -06:00
compiler_types.h
const.h
container_of.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
coresight-pmu.h
ctype.h
debugfs.h
delay.h
err.h
export.h
filter.h
find.h
ftrace.h
gfp.h
gfp_types.h tools include: Replace tools linux/gfp_types.h with kernel version 2025-10-02 15:11:03 -03:00
hash.h
hashtable.h
init.h
interrupt.h
interval_tree_generic.h interval_tree: Fix ITSTATIC usage for *_subtree_search() 2025-10-14 14:45:22 -07:00
io.h tools headers: Import asm-generic MMIO helpers 2025-08-27 12:14:06 -06:00
jhash.h
kallsyms.h kallsyms: fix build without execinfo 2025-07-09 21:07:51 -07:00
kasan-tags.h
kconfig.h
kern_levels.h
kernel.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
linkage.h
list.h
list_sort.h
livepatch_external.h objtool/klp: Introduce klp diff subcommand for diffing object files 2025-10-14 14:50:18 -07:00
log2.h
math.h
math64.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
mm.h
module.h
moduleparam.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
mutex.h
nmi.h
numa.h
objtool_types.h objtool: Add ANNOTATE_DATA_SPECIAL 2025-10-14 14:50:16 -07:00
overflow.h
panic.h
pci_ids.h tools headers: Add symlink to linux/pci_ids.h 2025-08-27 12:14:07 -06:00
pfn.h
poison.h
prandom.h lib/rbtree: enable userland test suite for rbtree related data structure 2025-03-17 12:17:00 -07:00
rbtree.h
rbtree_augmented.h
rcu.h
refcount.h mm: make vma cache SLAB_TYPESAFE_BY_RCU 2025-03-16 22:06:21 -07:00
ring_buffer.h
rwsem.h
seq_file.h
sizes.h
slab.h tools/testing: Add support for prefilled slab sheafs 2025-09-29 09:25:00 +02:00
spinlock.h
static_call_types.h
string.h objtool/klp: Introduce klp diff subcommand for diffing object files 2025-10-14 14:50:18 -07:00
stringify.h
time64.h
types.h lib/rbtree: add random seed 2025-03-17 12:17:00 -07:00
unaligned.h
zalloc.h