5–7 Oct 2026
Europe/Prague timezone

Bringing klp-build to LoongArch: toolchain lessons for the next architecture

7 Oct 2026, 17:30
30m
"Club A" (Prague Congress Centre)

"Club A"

Prague Congress Centre

53
Live Patching MC Live Patching MC

Speaker

dongtai guo

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 a pcalau12i/addi.d pair 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 collapse R_LARCH_ADD64/SUB64 pairs into one
    PC-relative relocation via arch_normalize_paired_reloc.
  • Section pairing and inline alternatives. Keep both words of each
    -mannotate-tablejump annotation entry, and define
    ARCH_HAS_INLINE_ALTS so the .subsection 1 ALTERNATIVE() 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.

Author

Presentation materials

There are no materials yet.