Hi, George,

On Fri, Jul 24, 2026 at 7:41 PM George Guo <[email protected]> wrote:
>
> This series adds LoongArch support for the klp-build livepatch tooling,
> enabling automated livepatch module generation using objtool on
> LoongArch.
>
> It is based on Josh Poimboeuf's klp-build series [1] (see base-commit
> below, unchanged from v1-v3) and extends it with the LoongArch-specific
> objtool and build pieces, plus the toolchain and relocation fixes
> required to make livepatch modules load, generate, and run correctly
> under both GCC and Clang.
>
> Collaboration
> =============
>
> Patch 1 ("objtool/LoongArch: Add arch_adjusted_addend() for KLP support")
> and patch 7 ("LoongArch: Add livepatch build (KLP) support") overlap with
> WangYuli's earlier LoongArch KLP work [2]. Both now carry
> Co-developed-by/Signed-off-by: WangYuli.
>
> WangYuli, please check that the attribution is recorded correctly. If you
> consider any other patch in this series to overlap your work, point it out
> and I will add the tags in the final version.
>
> Overview
> ========
>
>  - Patches 1-8: the LoongArch objtool hooks, special-section marking
>    (including the inline ALTERNATIVE() replacement), the combined
>    -fPIC / -mno-direct-extern-access build fix, EFI linking, the syscall
>    patching macro, and wiring up LoongArch klp-build.
>  - Patches 9-14: objtool/klp-diff fixes found by running the full
>    klp-build flow under GCC and Clang.
>
> Testing
> =======
>
> The klp-build integration tests were run on LoongArch under both GCC and
> Clang: cmdline-string, proc-version, data-new, gcc-static-local-var-6,
> syscall, new-globals, new-function, and shadow-newpid. All of them now
> generate a livepatch module, load it, and run.
>
> new-function and shadow-newpid did not build under Clang before this
> version; the new objtool/klp-diff patches fix the Clang-specific
> failures the suite surfaced. Joe Lawrence's test case was also
> reproduced end to end on a Clang-built kernel in a VM (patch load,
> tracepoint toggle, clean unload).
>
> Changes since v3 [3]
> ====================
>
>  - Merged the two build-flag patches (-mno-direct-extern-access and
>    -fPIC) into one. The combined patch is one complete thought: for
>    LoongArch KLP builds, replace the arch's KBUILD_CFLAGS_KERNEL (dropping
>    -fPIE and -mdirect-extern-access) and add -fPIC via KCFLAGS. (Joe
>    Lawrence)
>  - Moved the LoongArch config checks (CONFIG_RELOCATABLE,
>    CONFIG_AS_HAS_EXPLICIT_RELOCS) into validate_config(). (Joe Lawrence)
>  - Patch 4 (EFI): fixed the changelog wording and added the
>    "/* from the EFI stub */" comment on the wildcard, matching arm64 and
>    riscv. (Joe Lawrence)
>  - Patch 6 (syscall macro): pad the line continuations with tabs. (Joe
>    Lawrence)
>  - New patch 12: enable inline ALTERNATIVE() cloning. Joe hit
>    "can't find new instruction" livepatching a function that contains an
>    ALTERNATIVE(). Mark the .subsection 1 replacement with
>    ANNOTATE_DATA_SPECIAL (patch 2) and define ARCH_HAS_INLINE_ALTS for
>    LoongArch objtool (patch 12), mirroring arm64. (Joe Lawrence)
>  - New patch 13: keep the tablejump annotation table entries. klp-diff
>    dropped the table-side word of each .discard.tablejump_annotate pair,
>    which crashed objtool on the patch module.
>  - New patch 14: rewrite PC-relative data references to GOT. File-local
>    static data uses a direct pcalau12i/addi.d pair that cannot reach
>    vmlinux from the far livepatch module; convert it to a GOT-indirect
>    load when the klp relocation is created. This affects GCC and Clang.
>
> On patch 11 (fold paired ADD/SUB relocations): Clang's integrated
> assembler emits the ADD64/SUB64 pair for a "sym - ." whose symbol is
> undefined in the current object, where GAS with -mthin-add-sub emits a
> single R_LARCH_64_PCREL. Reported to LLVM as issue #210052 [4]. The fold
> is kept regardless, since shipping Clang emits the pair.
>
> [1] 
> https://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git/log/?h=klp-build-arm64
> [2] 
> https://lore.kernel.org/loongarch/[email protected]/
> [3] https://lore.kernel.org/all/[email protected]/
> [4] https://github.com/llvm/llvm-project/issues/210052
>
> George Guo (14):
>   objtool/LoongArch: Add arch_adjusted_addend() for KLP support
>   LoongArch: Mark special sections for KLP support
>   livepatch/klp-build: use -fPIC and drop direct-extern-access on
>     LoongArch
>   LoongArch: Fix EFI linking with -fdata-sections
>   objtool/klp: Add LoongArch jump opcode bytes support
>   klp-build: Add LoongArch syscall patching macro
>   LoongArch: Add livepatch build (KLP) support
>   LoongArch: Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY
>   objtool/klp: Convert local label references
>   objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for local label
>     references
>   objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCREL
>   objtool/LoongArch: Enable inline alternative cloning for KLP
>   objtool/klp: Keep LoongArch tablejump annotation table entries
>   objtool/klp: Rewrite PC-relative data references to GOT on LoongArch

It is better to reorganize this series like this:

objtool/klp: Convert local label references
objtool/klp: Fix ANNOTATE_DATA_SPECIAL parsing for local label references
objtool/klp: Add LoongArch jump opcode bytes support
objtool/klp: Fold LoongArch paired ADD/SUB relocations into PCREL
objtool/klp: Keep LoongArch tablejump annotation table entries
objtool/klp: Rewrite PC-relative data references to GOT on LoongArch
objtool/LoongArch: Add arch_adjusted_addend() for KLP support
objtool/LoongArch: Enable inline alternative cloning for KLP
klp-build: use -fPIC and drop direct-extern-access on LoongArch
klp-build: Add LoongArch syscall patching macro
LoongArch: Mark special sections for KLP support
LoongArch: Fix EFI linking with -fdata-sections
LoongArch: Add livepatch build (KLP) support
LoongArch: Select FTRACE_MCOUNT_USE_PATCHABLE_FUNCTION_ENTRY
Huacai

>
>  arch/loongarch/Kconfig                        |   2 +
>  arch/loongarch/include/asm/alternative-asm.h  |  10 +-
>  arch/loongarch/include/asm/alternative.h      |  11 +-
>  arch/loongarch/include/asm/asm-extable.h      |  10 +-
>  arch/loongarch/include/asm/bug.h              |   1 +
>  arch/loongarch/include/asm/jump_label.h       |   2 +
>  arch/loongarch/kernel/asm-offsets.c           |  18 ++
>  arch/loongarch/kernel/vmlinux.lds.S           |   2 +-
>  include/linux/livepatch_helpers.h             |  22 ++
>  scripts/livepatch/klp-build                   |  43 +++-
>  tools/arch/loongarch/include/asm/inst.h       |  11 +
>  tools/objtool/Makefile                        |   3 +-
>  tools/objtool/arch/loongarch/decode.c         | 212 ++++++++++++++++++
>  .../objtool/arch/loongarch/include/arch/elf.h |  35 +++
>  tools/objtool/klp-diff.c                      | 105 ++++++++-
>  15 files changed, 473 insertions(+), 14 deletions(-)
>
>
> base-commit: 85afaba140a4b9f20fe8c8a64b24fc85f022d981
> --
> 2.53.0
>

Reply via email to