Repository navigation
Conversation
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) <[email protected]>
|
Hi @howlett thanks for MR, I'll try to review some time next week. |
joe-lawrence
left a comment
There was a problem hiding this comment.
See inline comments, and also commit msg nitpick ("create-diff-object: ignore Clang .compoundliteral symbols in static local checks"):
"Since .compoundliteral. contains a dot and does not start with .L, kpatch_is_normal_static_local() identifies them as compiler generated function static local variables and aborts in find_local_syms()."
|
|
||
| return false; | ||
| } | ||
|
|
There was a problem hiding this comment.
It's been a while since I've wrapped my head around the fuzzy symbol matching, a few maybe dumb questions:
- This would match "foo.1" with "foo.2", do we need to worry about "foo" and "foo.1" ?
- The corresponding commit message mentioned, ".__UNIQUE_ID_ddebug" with no '.' character -- is that a typo, or does this function handle "...ddebug10" correctly?
- Related to (1) and (2): which specific symbols are hitting this fallback in lookup_local_symbol()? Could we share or refactor the logic with kpatch_mangled_strcmp() ?
There was a problem hiding this comment.
-
Correct. The lookup is trying to pick a numbered mangled symbol and not the bare named one. The builds are changing the numbers.
-
Yes, typo in the commit message
-
Clang's function-scoped static with a different number. We could use the same loop for the character matching, but the number part is where it falls apart. Even if all the assets are saved, it can still drift so there's no way around the numbering issue that I have found.
| break; | ||
|
|
||
| if (sym->bind == STB_LOCAL && | ||
| sym->type == lookup_sym->type && |
There was a problem hiding this comment.
Is comparing the types only important to this new fallback / local mangled check? Should it also apply to the first (pre-existing) comparison a few lines up the function?
There was a problem hiding this comment.
yes. When the fallback happens, then we're using a weaker matching that could be pared with an object from the same stem. The first per-existing comparison doesn't need to be so strict because the function name match is exact.
|
@liu-song-6 : I don't know if you're still using kpatch-build anymore, but perhaps these Clang/LLVM changes might be interesting to you? |
|
/packit test |
|
/packit test --id integration-upstream |
|
It looks like x86_64 and s390 testing failed due to infrastructure issues? |
|
Hi @howlett, from the x86_64 (may have been internal only) integration tests run: and on the system itself: This reproduces when manually trying to build the new-globals.patch by itself: FWIW I see those same errors before this MR's commit (we also blow up on the instruction padding problem that this MR fixes). I'd assume the changed section complains aren't related, but @howlett do any of the integration tests in test/integration/linux-6.17.0/ build for your llvm/clang/kernel-config combination? |
|
Thanks for running the tests and providing the results. Yes, the failure already existed and I'll need to fix this as well. I'll do this all in a single patch set since it looks like some environment variables are involved and make logical sense to keep together. |
…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 function static local variables and aborts in find_local_syms(). Don't include .compoundliteral* symbols in kpatch_is_normal_static_local(). Signed-off-by: Liam R. Howlett (Google) <[email protected]>
…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) <[email protected]>
…ed name When building livepatches against Clang-compiled kernels, compiler-generated local symbols such as <func>.<var>.<N> and <func>.__UNIQUE_ID_ddebug<N> can receive different numerical suffixes between the original vmlinux symbol table and the rebuilt object. Move kpatch_mangled_strcmp() to kpatch-elf.c so it can be used in locals_match() for correlating mangled numeric suffixes and LLVM dynamic debug ids, and add kpatch_mangled_sym_equal() to share the '.<digits>' matching logic when both symbols carry a numeric suffix. Only fall back to kpatch_mangled_sym_equal() in lookup_local_symbol() if an exact match is not found within the STT_FILE. Finally, store the resolved symbol name in struct lookup_result::name, allowing lookup_local_symbol() to match the target's symbol name in .kpatch.strings and .symbols. Signed-off-by: Liam R. Howlett (Google) <[email protected]>
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. Signed-off-by: Liam R. Howlett (Google) <[email protected]>
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) <[email protected]>
scripts/Makefile.clang defaults to the integrated assembler unless LLVM_IAS=0 is passed on the make command line. If the target kernel was built with Clang and GNU as (CONFIG_CC_IS_CLANG=y without CONFIG_AS_IS_LLVM), kpatch-build ends up rebuilding objects with the wrong assembler. Add LLVM_IAS=0 to MAKEVARS when CONFIG_CC_IS_CLANG is set and CONFIG_AS_IS_LLVM is not. Signed-off-by: Liam R. Howlett (Google) <[email protected]>
Clang's integrated assembler can leave local .Ltmp<N> symbols in .symtab. When a patch adds or splits functions, the .Ltmp<N> numbering shifts across sections and create-diff-object fails with: symbol changed sections: .Ltmp1 Extend the LoongArch local-label pass in kpatch-elf.c to convert relocations against .Ltmp* labels to section symbols and drop the .Ltmp* symbols from the symbol list. Only match .Ltmp* on non-LoongArch so mapping symbols like $x and $d on aarch64 are left alone. If a section had no STT_SECTION symbol of its own, create one when rewriting the relocation and check both sides have secsym before correlating them in kpatch_correlate_section(). Signed-off-by: Liam R. Howlett (Google) <[email protected]>
symbol_get() emits a local __notrim[] char array in .no_trim_symbol for modpost (__notrim.<N> on GCC, <func>.__notrim on Clang), which the linker scripts discard from vmlinux and modules. Ignore .no_trim_symbol alongside .discard and treat its symbols as special statics in create-diff-object. Also skip __notrim symbols in maybe_discarded_sym() so locals_match() does not fail matching the object's local symbols against vmlinux. Signed-off-by: Liam R. Howlett (Google) <[email protected]>
x86's SYM_PIC_ALIAS() creates global __pi_<sym> aliases in object files for the early startup code. The startup objects reference them with hidden visibility, so the linker turns __pi_<sym> into local symbols in vmlinux and locals_match() fails to match the object file. Add __pi_* to maybe_discarded_sym() so locals_match() skips them. Signed-off-by: Liam R. Howlett (Google) <[email protected]>
|
Here is the updated series. It addresses the review comments and split sout KCFLAGS into its own commit, the other variable LLVM_IAS as well - which explains your .Ltmp symbol issue. My testing shows this passing, and I would appreciate it if you ran your tests again. Thanks again for looking at this. |
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.