Speaker
Description
A series adding LoongArch support to objtool's klp diff subcommand (the
diffing engine klp-build invokes to generate a patch module) is under
review (v4:
https://lore.kernel.org/all/20260724114128.31451-1-dongtai.guo@linux.dev).
A v5, with a reordering requested by the LoongArch maintainer, is in
preparation. Most of the effort went into the interaction between this
tooling and the LoongArch toolchains, and several findings generalize to
any future architecture with aggressive linker relaxation.
This topic walks through the klp-diff issues surfaced across the review
rounds. They are not one bug but a family of toolchain-interaction
failures:
- PC-relative reachability. A livepatch module maps farther than the
+-2GB apcalau12i/addi.dpair can express, so a klp relocation
resolving to a vmlinux symbol overflows. Far calls are already
redirected through a PLT stub by the module loader, but file-local
static data is materialized inline; a new arch hook rewrites those
PC-relative data references to GOT-indirect loads. This is not
Clang-specific: GCC emits the same form. - Local-label anchors. GCC/GAS on LoongArch anchor relocations to
.L*
local labels to keep them relaxable, where klp diff assumed a function
or section symbol plus addend (LLVM folds these labels, so this one is
toolchain-specific). Fix: normalize.L*-anchored relocations back to
their containing function, fix annotation offsets in
create_fake_symbols, and collapseR_LARCH_ADD64/SUB64pairs into one
PC-relative relocation viaarch_normalize_paired_reloc. - Section pairing and inline alternatives. Keep both words of each
-mannotate-tablejumpannotation entry, and define
ARCH_HAS_INLINE_ALTSso the.subsection 1ALTERNATIVE() replacement
is cloned, mirroring arm64.
On the compiler side, livepatch modules on LoongArch require -fPIC
(GOT-indirect access instead of absolute addressing), which collides
with the kernel's -fno-PIE defaults in non-obvious ways (last-one-wins
flag ordering vs KBUILD_CFLAGS_KERNEL), and Clang rejects GCC-style
"awM" special-section flags, requiring ANNOTATE_DATA_SPECIAL.