Skip to content

kpatch-build: Support Clang/LLVM kernel builds and fix a call padding issue - #1535

Open
howlett wants to merge 5 commits into
dynup:masterfrom
howlett:clang_20
Open

howlett wants to merge 5 commits into
dynup:masterfrom
howlett:clang_20

Conversation

@howlett

@howlett howlett commented Nov 10, 2026

Copy link
Copy Markdown

Even though kpatch is on its way out, there are a number of users on LTS releases that cannot move to klp just yet. Adding support for clang 20 help those users live patch kernels until they are able to move to the newer live patching available on newer kernels.

This series fixes an x86_64 fentry NOP replacement bug on kernels built with function prefix padding and enables kpatch-build to create live patches for kernels built with Clang/LLD/LLVM. Tested against 6.18 and clang 20.

When a kernel is built with function prefix padding (such as
CONFIG_CALL_PADDING / -fpatchable-function-entry=16,16 or CONFIG_FINEIBT),
the function entry point and its __fentry__ NOP are located at
insn_offset (rela->offset - 1) rather than at offset 0 of the function
section.

kpatch_create_ftrace_callsite_sections() already computes insn_offset
from rela->offset - 1, but when converting an R_X86_64_NONE relocation
into a call to __fentry__, it pointed insn at the start of the section
buffer (newdata) instead of newdata + insn_offset, failing with:

  unexpected instruction at the start of the function

Offset insn by insn_offset and drop the redundant reassignment to
sym->sec->data->d_buf.

Fixes: b958ed6 ("create-diff-object: Add ppc64le mcount support")
Signed-off-by: Liam R. Howlett (Google) <liam@infradead.org>
…ocal checks

Clang emits local STT_OBJECT symbols named .compoundliteral (and
.compoundliteral.<N> when multiple compound literals exist in a
translation unit) for C99 compound literals.

since .compoundliteral.<N> contains a dot and does not start with .L,
kpatch_is_normal_static_local() identifies them as compiler generated
objects as function static local variables and aborts in
find_local_sym().

Don't include .compoundliteral* symbols in
kpatch_is_normal_static_local().

Signed-off-by: Liam R. Howlett (Google) <liam@infradead.org>
…atch()

MODULE_DEVICE_TABLE() generates local __mod_device_table__* symbols in
per-object files that are discarded during linking vmlinux. Add
__mod_device_table__* to maybe_discarded_sym() after __export_symbol_*
and __gendwarfksyms_*, and skip the symbols in locals_match() by
checking maybe_discarded_sym().

Signed-off-by: Liam R. Howlett (Google) <liam@infradead.org>
…ed name

When building livepatches against Clang-compiled kernels
compiler-generated local symbols such as .L.str.<N> and
<func>.__UNIQUE_ID_ddebug<N> can receive different numerical suffixes
between the original vmlinux symbol table and the rebuilt object (for
example, when rebuilding the objects for kpatch-build).

Relocate the kpatch_mangled_strcmp() to kpatch-elf.c so that it can be
used in locals_match() for correlating the mangled numeric suffixes and
the dynamic debug ids from LLVM.

Only fall back to the different numeric suffixes in
lookup_local_symbol() if the exact match is not found within the
STT_FILE.

Finally, store the resolved symbol names in a struct
lookup_result::name, allowing the lookup_local_symbol() to match the
targets symbol name in .kpatch.strings and .symbols.

Signed-off-by: Liam R. Howlett (Google) <liam@infradead.org>
Pass through LLVM setting if the correct flags are set
(CONFIG_CC_IS_CLANG, CONFIG_LD_IS_LLD, and CONFIG_AS_IS_LLVM), and the
llvm-objcopy command is accessible.

Also pass any KCFLAGS from the environment when kpatch-build exports
KCFLAGS for object compilation and the final module build.

Signed-off-by: Liam R. Howlett (Google) <liam@infradead.org>
@joe-lawrence

Copy link
Copy Markdown
Contributor

Hi @howlett thanks for MR, I'll try to review some time next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants