Skip to content

objtool,livepatch: klp-build livepatch module generation

Josh Poimboeuf live-patching lkml 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest63 patches 28 repliesIn review
  2. v364 patches 18 repliesSuperseded
  3. v262 patches 71 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v1 RFC31 patches62 repliesSuperseded

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/63s390/vmlinux.lds.S: Prevent thunk functions from getting placed with normal textarch/s390/include/asm/nospec-insn.h arch/s390/kernel/vmlinux.lds.S+2 -20 replies
2/63vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macrosinclude/asm-generic/vmlinux.lds.h scripts/module.lds.S+17 -353 replies
3/63x86/module: Improve relocation error messagesarch/x86/kernel/module.c kernel/livepatch/core.c+11 -80 replies
4/63x86/kprobes: Remove STACK_FRAME_NON_STANDARD annotationarch/x86/kernel/kprobes/opt.c+0 -40 replies
5/63compiler: Tweak __UNIQUE_ID() naminginclude/linux/compiler.h+5 -10 replies
6/63compiler.h: Make addressable symbols less of an eyesoreinclude/linux/compiler.h+1 -10 replies
7/63elfnote: Change ELFNOTE() to use __UNIQUE_ID()include/linux/elfnote.h+5 -80 replies
8/63kbuild: Remove 'kmod_' prefix from __KBUILD_MODNAMEinclude/linux/init.h scripts/Makefile.lib+3 -26 replies
9/63modpost: Ignore unresolved section bounds symbolsscripts/mod/modpost.c+5 -00 replies
10/63x86/alternative: Refactor INT3 call emulation selftestarch/x86/kernel/alternative.c+28 -230 replies
11/63interval_tree: Sync interval_tree_generic.h with toolstools/include/linux/interval_tree_generic.h tools/objtool/sync-check.sh+3 -60 replies
12/63interval_tree: Fix ITSTATIC usage for *_subtree_search()include/linux/interval_tree.h include/linux/interval_tree_generic.h include/linux/mm.h +1 more+8 -20 replies
12/63interval_tree: Fix ITSTATIC usage for *_subtree_search()drivers/infiniband/hw/usnic/usnic_uiom_interval_tree.h include/linux/interval_tree.h include/linux/interval_tree_generic.h +3 more+13 -20 replies
13/63objtool: Make find_symbol_containing() less arbitrarytools/objtool/elf.c+20 -50 replies
14/63objtool: Fix broken error handling in read_symbols()tools/objtool/elf.c+3 -70 replies
15/63objtool: Propagate elf_truncate_section() error in elf_write()tools/objtool/elf.c+2 -30 replies
16/63objtool: Remove error handling boilerplatetools/objtool/check.c tools/objtool/special.c+59 -1010 replies
17/63objtool: Add empty symbols to the symbol tree againtools/objtool/elf.c+2 -80 replies
18/63objtool: Fix interval tree insertion for zero-length symbolstools/objtool/elf.c+1 -10 replies
19/63objtool: Fix weak symbol detectiontools/objtool/elf.c+4 -40 replies
20/63objtool: Fix x86 addend calculationtools/objtool/arch/loongarch/decode.c tools/objtool/arch/powerpc/decode.c tools/objtool/arch/x86/decode.c +2 more+17 -170 replies
21/63objtool: Fix __pa_symbol() relocation handlingtools/objtool/arch/x86/decode.c+12 -10 replies
22/63objtool: Fix "unexpected end of section" warning for alternativestools/objtool/check.c+1 -40 replies
23/63objtool: Check for missing annotation entries in read_annotate()tools/objtool/check.c+5 -00 replies
24/63objtool: Const string cleanuptools/objtool/arch/loongarch/decode.c tools/objtool/arch/powerpc/decode.c tools/objtool/arch/x86/decode.c +3 more+10 -100 replies
25/63objtool: Clean up compiler flag usagetools/objtool/Makefile tools/objtool/check.c tools/objtool/elf.c+13 -80 replies
26/63objtool: Remove .parainstructions referencetools/objtool/check.c+0 -10 replies
27/63objtool: Convert elf iterator macros to use 'struct elf'tools/objtool/check.c tools/objtool/include/objtool/elf.h tools/objtool/orc_gen.c+17 -170 replies
28/63objtool: Add section/symbol type helperstools/objtool/arch/x86/special.c tools/objtool/check.c tools/objtool/elf.c +2 more+108 -420 replies
29/63objtool: Mark .cold subfunctionstools/objtool/check.c tools/objtool/elf.c tools/objtool/include/objtool/elf.h+17 -170 replies
30/63objtool: Fix weak symbol hole detection for .cold functionstools/objtool/check.c tools/objtool/include/objtool/check.h+45 -420 replies
31/63objtool: Mark prefix functionstools/objtool/check.c tools/objtool/elf.c tools/objtool/include/objtool/elf.h+14 -40 replies
32/63objtool: Simplify reloc offset calculation in unwind_read_hints()tools/objtool/check.c+1 -80 replies
33/63objtool: Avoid emptying lists for duplicate sectionstools/objtool/check.c+0 -40 replies
34/63objtool: Rename --Werror to --werrorscripts/Makefile.lib scripts/Makefile.vmlinux_o tools/objtool/builtin-check.c+3 -30 replies
35/63objtool: Resurrect --backup optiontools/objtool/builtin-check.c tools/objtool/check.c tools/objtool/include/objtool/builtin.h+16 -160 replies
36/63objtool: Reindent check_options[]tools/objtool/builtin-check.c+27 -270 replies
37/63objtool: Refactor add_jump_destinations()tools/objtool/check.c tools/objtool/include/objtool/elf.h+106 -1200 replies
38/63objtool: Simplify special symbol handling in elf_update_symbol()tools/objtool/elf.c+2 -30 replies
39/63objtool: Generalize elf_create_symbol()tools/objtool/elf.c tools/objtool/include/objtool/elf.h+69 -530 replies
40/63objtool: Generalize elf_create_section()tools/objtool/elf.c tools/objtool/include/objtool/elf.h tools/objtool/orc_gen.c+77 -540 replies
41/63objtool: Add elf_create_data()tools/objtool/elf.c tools/objtool/include/objtool/elf.h+54 -220 replies
42/63objtool: Add elf_create_reloc() and elf_init_reloc()tools/objtool/elf.c tools/objtool/include/objtool/elf.h+165 -140 replies
43/63objtool: Add elf_create_file()tools/objtool/builtin-check.c tools/objtool/elf.c tools/objtool/include/objtool/elf.h+147 -40 replies
44/63objtool: Add annotype() helpertools/objtool/arch/loongarch/orc.c tools/objtool/arch/powerpc/decode.c tools/objtool/arch/x86/decode.c +7 more+18 -160 replies
45/63objtool: Move ANNOTATE* macros to annotate.hinclude/linux/annotate.h include/linux/objtool.h+110 -890 replies
46/63objtool: Add ANNOTATE_DATA_SPECIALinclude/linux/annotate.h include/linux/objtool_types.h tools/include/linux/objtool_types.h+41 -120 replies
47/63x86/asm: Annotate special section entriesarch/x86/include/asm/alternative.h arch/x86/include/asm/asm.h arch/x86/include/asm/bug.h +3 more+15 -10 replies
48/63objtool: Unify STACK_FRAME_NON_STANDARD entry sizesinclude/linux/objtool.h+1 -10 replies
49/63objtool/klp: Add --checksum option to generate per-function checksumstools/objtool/Makefile tools/objtool/builtin-check.c tools/objtool/check.c +6 more+289 -2711 replies
50/63objtool/klp: Add --debug-checksum=<funcs> to show per-instruction checksumstools/objtool/builtin-check.c tools/objtool/check.c tools/objtool/include/objtool/builtin.h +3 more+70 -00 replies
51/63objtool/klp: Introduce klp diff subcommand for diffing object filesMAINTAINERS include/linux/livepatch.h include/linux/livepatch_external.h +20 more+2088 -594 replies
52/63objtool/klp: Add --debug option to show cloning decisionstools/objtool/include/objtool/warn.h tools/objtool/klp-diff.c tools/objtool/objtool.c+99 -00 replies
53/63objtool/klp: Add post-link subcommand to finalize livepatch modulestools/objtool/Build tools/objtool/builtin-klp.c tools/objtool/include/objtool/klp.h +1 more+174 -10 replies
54/63objtool: Refactor prefix symbol creation codetools/objtool/check.c tools/objtool/elf.c tools/objtool/include/objtool/elf.h+46 -320 replies
55/63objtool: Add base objtool support for livepatch modulestools/objtool/check.c tools/objtool/elf.c tools/objtool/include/objtool/elf.h +1 more+53 -70 replies
56/63livepatch: Add CONFIG_KLP_BUILDarch/x86/Kconfig kernel/livepatch/Kconfig+13 -00 replies
57/63kbuild,objtool: Defer objtool validation step for CONFIG_KLP_BUILDscripts/Makefile.lib scripts/link-vmlinux.sh+3 -20 replies
58/63livepatch/klp-build: Introduce fix-patch-lines script to avoid __LINE__ diff noiseMAINTAINERS scripts/livepatch/fix-patch-lines+80 -00 replies
59/63livepatch/klp-build: Add stub init code for livepatch modulesscripts/livepatch/init.c+108 -00 replies
60/63livepatch/klp-build: Introduce klp-build script for generating livepatch modulesscripts/Makefile.lib scripts/livepatch/fix-patch-lines scripts/livepatch/klp-build +1 more+749 -30 replies
61/63livepatch/klp-build: Add --debug option to show cloning decisionsscripts/livepatch/klp-build+13 -30 replies
62/63livepatch/klp-build: Add --show-first-changed option to show function divergencescripts/livepatch/klp-build+78 -40 replies
63/63livepatch: Introduce source code helpers for livepatch modulesinclude/linux/livepatch_helpers.h+77 -00 replies

Reviews trailers per patch

1 of 64 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchHeiko CarstensJoe LawrencePetr MladekAnders Roxell
SeriesTested-off-by A-b
1/63A-b
2/63
3/63
4/63
5/63
6/63
7/63
8/63T-b
9/63
10/63
11/63
12/63
12/63
13/63
14/63
15/63
16/63
17/63
18/63
19/63
20/63
21/63
22/63
23/63
24/63
25/63
26/63
27/63
28/63
29/63
30/63
31/63
32/63
33/63
34/63
35/63
36/63
37/63
38/63
39/63
40/63
41/63
42/63
43/63
44/63
45/63
46/63
47/63
48/63
49/63
50/63
51/63
52/63
53/63
54/63
55/63
56/63
57/63
58/63
59/63
60/63
61/63
62/63
63/63

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v4 thread

Cover letter [PATCH v4 00/63] objtool,livepatch: klp-build livepatch module generation

Changes since v3 (https://lore.kernel.org/[email protected]):

- Get rid of the SHF_MERGE+SHF_WRITE toolchain shenanigans in favor of simple .discard.annotate_data annotations
- Fix potential double free in elf_create_reloc()
- Sync interval_tree_generic.h (Peter)
- Refactor prefix symbol creation error handling
- Rebase on tip/master and fix new issue (--checksum getting added with --noabs)

(v3..v4 diff below)

----

This series introduces new objtool features and a klp-build script to generate livepatch modules using a source .patch as input.

This builds on concepts from the longstanding out-of-tree kpatch [1] project which began in 2012 and has been used for many years to generate livepatch modules for production kernels. However, this is a complete rewrite which incorporates hard-earned lessons from 12+ years of maintaining kpatch.

Key improvements compared to kpatch-build:

- Integrated with objtool: Leverages objtool's existing control-flow graph analysis to help detect changed functions.

- Works on vmlinux.o: Supports late-linked objects, making it compatible with LTO, IBT, and similar.

- Simplified code base: ~3k fewer lines of code.

- Upstream: No more out-of-tree #ifdef hacks, far less cruft.

- Cleaner internals: Vastly simplified logic for symbol/section/reloc inclusion and special section extraction.

- Robust __LINE__ macro handling: Avoids false positive binary diffs caused by the __LINE__ macro by introducing a fix-patch-lines script which injects #line directives into the source .patch to preserve the original line numbers at compile time.

The primary user interface is the klp-build script which does the following:

- Builds an original kernel with -function-sections and -fdata-sections, plus objtool function checksumming.

- Applies the .patch file and rebuilds the kernel using the same options.

- Runs 'objtool klp diff' to detect changed functions and generate intermediate binary diff objects.

- Builds a kernel module which links the diff objects with some livepatch module init code (scripts/livepatch/init.c).

- Finalizes the livepatch module (aka work around linker wreckage) using 'objtool klp post-link'.

I've tested with a variety of patches on defconfig and Fedora-config kernels with both GCC and Clang.

These patches can also be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/jpoimboe/linux.git klp-build-v3

Please test!

[1] https://github.com/dynup/kpatch

Josh Poimboeuf (63):
s390/vmlinux.lds.S: Prevent thunk functions from getting placed with
normal text
vmlinux.lds: Unify TEXT_MAIN, DATA_MAIN, and related macros x86/module: Improve relocation error messages
x86/kprobes: Remove STACK_FRAME_NON_STANDARD annotation
compiler: Tweak __UNIQUE_ID() naming
compiler.h: Make addressable symbols less of an eyesore
elfnote: Change ELFNOTE() to use __UNIQUE_ID()
kbuild: Remove 'kmod_' prefix from __KBUILD_MODNAME
modpost: Ignore unresolved section bounds symbols x86/alternative: Refactor INT3 call emulation selftest
interval_tree: Sync interval_tree_generic.h with tools
interval_tree: Fix ITSTATIC usage for *_subtree_search()
objtool: Make find_symbol_containing() less arbitrary
objtool: Fix broken error handling in read_symbols()
objtool: Propagate elf_truncate_section() error in elf_write()
objtool: Remove error handling boilerplate
objtool: Add empty symbols to the symbol tree again
objtool: Fix interval tree insertion for zero-length symbols
objtool: Fix weak symbol detection
objtool: Fix x86 addend calculation
objtool: Fix __pa_symbol() relocation handling
objtool: Fix "unexpected end of section" warning for alternatives
objtool: Check for missing annotation entries in read_annotate()
objtool: Const string cleanup
objtool: Clean up compiler flag usage
objtool: Remove .parainstructions reference
objtool: Convert elf iterator macros to use 'struct elf'
objtool: Add section/symbol type helpers
objtool: Mark .cold subfunctions
objtool: Fix weak symbol hole detection for .cold functions
objtool: Mark prefix functions
objtool: Simplify reloc offset calculation in unwind_read_hints()
objtool: Avoid emptying lists for duplicate sections
objtool: Rename --Werror to --werror
objtool: Resurrect --backup option
objtool: Reindent check_options[]
objtool: Refactor add_jump_destinations()
objtool: Simplify special symbol handling in elf_update_symbol()
objtool: Generalize elf_create_symbol()
objtool: Generalize elf_create_section()
objtool: Add elf_create_data()
objtool: Add elf_create_reloc() and elf_init_reloc()
objtool: Add elf_create_file()
objtool: Add annotype() helper
objtool: Move ANNOTATE* macros to annotate.h
objtool: Add ANNOTATE_DATA_SPECIAL
x86/asm: Annotate special section entries
objtool: Unify STACK_FRAME_NON_STANDARD entry sizes objtool/klp: Add --checksum option to generate per-function checksums objtool/klp: Add --debug-checksum=<funcs> to show per-instruction
checksums
objtool/klp: Introduce klp diff subcommand for diffing object files objtool/klp: Add --debug option to show cloning decisions objtool/klp: Add post-link subcommand to finalize livepatch modules
objtool: Refactor prefix symbol creation code
objtool: Add base objtool support for livepatch modules
livepatch: Add CONFIG_KLP_BUILD
kbuild,objtool: Defer objtool validation step for CONFIG_KLP_BUILD livepatch/klp-build: Introduce fix-patch-lines script to avoid
__LINE__ diff noise
livepatch/klp-build: Add stub init code for livepatch modules livepatch/klp-build: Introduce klp-build script for generating
livepatch modules
livepatch/klp-build: Add --debug option to show cloning decisions livepatch/klp-build: Add --show-first-changed option to show function
divergence
livepatch: Introduce source code helpers for livepatch modules

 MAINTAINERS                                   |    3 +-
 arch/s390/include/asm/nospec-insn.h           |    2 +-
 arch/s390/kernel/vmlinux.lds.S                |    2 +-
 arch/x86/Kconfig                              |    1 +
 arch/x86/include/asm/alternative.h            |    4 +
 arch/x86/include/asm/asm.h                    |    5 +
 arch/x86/include/asm/bug.h                    |    1 +
 arch/x86/include/asm/cpufeature.h             |    1 +
 arch/x86/include/asm/jump_label.h             |    1 +
 arch/x86/kernel/alternative.c                 |   51 +-
 arch/x86/kernel/kprobes/opt.c                 |    4 -
 arch/x86/kernel/module.c                      |   15 +-
 include/asm-generic/vmlinux.lds.h             |   40 +-
 include/linux/annotate.h                      |  134 ++
 include/linux/compiler.h                      |    8 +-
 include/linux/elfnote.h                       |   13 +-
 include/linux/init.h                          |    3 +-
 include/linux/interval_tree.h                 |    4 +
 include/linux/interval_tree_generic.h         |    2 +-
 include/linux/livepatch.h                     |   25 +-
 include/linux/livepatch_external.h            |   76 +
 include/linux/livepatch_helpers.h             |   77 +
 include/linux/mm.h                            |    2 +
 include/linux/objtool.h                       |   96 +-
 include/linux/objtool_types.h                 |    2 +
 kernel/livepatch/Kconfig                      |   12 +
 kernel/livepatch/core.c                       |    8 +-
 scripts/Makefile.lib                          |    7 +-
 scripts/Makefile.vmlinux_o                    |    2 +-
 scripts/link-vmlinux.sh                       |    3 +-
 scripts/livepatch/fix-patch-lines             |   79 +
 scripts/livepatch/init.c                      |  108 ++
 scripts/livepatch/klp-build                   |  827 ++++++++
 scripts/mod/modpost.c                         |    5 +
 scripts/module.lds.S                          |   22 +-
 tools/include/linux/interval_tree_generic.h   |   10 +-
 tools/include/linux/livepatch_external.h      |   76 +
 tools/include/linux/objtool_types.h           |    2 +
 tools/include/linux/string.h                  |   14 +
 tools/objtool/Build                           |    4 +-
 tools/objtool/Makefile                        |   48 +-
 tools/objtool/arch/loongarch/decode.c         |    6 +-
 tools/objtool/arch/loongarch/orc.c            |    1 -
 tools/objtool/arch/powerpc/decode.c           |    7 +-
 tools/objtool/arch/x86/decode.c               |   63 +-
 tools/objtool/arch/x86/orc.c                  |    1 -
 tools/objtool/arch/x86/special.c              |    2 +-
 tools/objtool/builtin-check.c                 |   96 +-
 tools/objtool/builtin-klp.c                   |   53 +
 tools/objtool/check.c                         |  875 +++++----
 tools/objtool/elf.c                           |  781 ++++++--
 tools/objtool/include/objtool/arch.h          |    5 +-
 tools/objtool/include/objtool/builtin.h       |   11 +-
 tools/objtool/include/objtool/check.h         |    6 +-
 tools/objtool/include/objtool/checksum.h      |   43 +
 .../objtool/include/objtool/checksum_types.h  |   25 +
 tools/objtool/include/objtool/elf.h           |  196 +-
 tools/objtool/include/objtool/endianness.h    |    9 +-
 tools/objtool/include/objtool/klp.h           |   35 +
 tools/objtool/include/objtool/objtool.h       |    4 +-
 tools/objtool/include/objtool/util.h          |   19 +
 tools/objtool/include/objtool/warn.h          |   40 +
 tools/objtool/klp-diff.c                      | 1723 +++++++++++++++++
 tools/objtool/klp-post-link.c                 |  168 ++
 tools/objtool/objtool.c                       |   42 +-
 tools/objtool/orc_dump.c                      |    1 -
 tools/objtool/orc_gen.c                       |    9 +-
 tools/objtool/special.c                       |   14 +-
 tools/objtool/sync-check.sh                   |    2 +
 tools/objtool/weak.c                          |    7 +
 70 files changed, 5152 insertions(+), 891 deletions(-)
 create mode 100644 include/linux/annotate.h
 create mode 100644 include/linux/livepatch_external.h
 create mode 100644 include/linux/livepatch_helpers.h
 create mode 100755 scripts/livepatch/fix-patch-lines
 create mode 100644 scripts/livepatch/init.c
 create mode 100755 scripts/livepatch/klp-build
 create mode 100644 tools/include/linux/livepatch_external.h
 create mode 100644 tools/objtool/builtin-klp.c
 create mode 100644 tools/objtool/include/objtool/checksum.h
 create mode 100644 tools/objtool/include/objtool/checksum_types.h
 create mode 100644 tools/objtool/include/objtool/klp.h
 create mode 100644 tools/objtool/include/objtool/util.h
 create mode 100644 tools/objtool/klp-diff.c
 create mode 100644 tools/objtool/klp-post-link.c
Signature · 1 line
2.50.0
arch/Kconfig +0 -3
index 4fb74eade61af..b13e86ad23e2f 100644
@@ -1368,9 +1368,6 @@ config HAVE_NOINSTR_HACK
 config HAVE_NOINSTR_VALIDATION
 	bool
 
-config NEED_MODULE_PERMISSIONS_FIX
-	bool
-
 config HAVE_UACCESS_VALIDATION
 	bool
 	select OBJTOOL
arch/um/include/asm/Kbuild +1 -0
index 1b9b82bbe3220..b6810db24ca4d 100644
@@ -5,6 +5,7 @@ generic-y += device.h
 generic-y += dma-mapping.h
 generic-y += emergency-restart.h
 generic-y += exec.h
+generic-y += extable.h
 generic-y += ftrace.h
 generic-y += hw_irq.h
 generic-y += irq_regs.h
arch/um/include/shared/common-offsets.h +0 -3
index a6f77cb6aa7e1..8ca66a1918c3a 100644
@@ -18,6 +18,3 @@ DEFINE(UM_NSEC_PER_USEC, NSEC_PER_USEC);
 DEFINE(UM_KERN_GDT_ENTRY_TLS_ENTRIES, GDT_ENTRY_TLS_ENTRIES);
 
 DEFINE(UM_SECCOMP_ARCH_NATIVE, SECCOMP_ARCH_NATIVE);
-
-DEFINE(ALT_INSTR_SIZE, sizeof(struct alt_instr));
-DEFINE(EXTABLE_SIZE,   sizeof(struct exception_table_entry));
arch/x86/Kconfig +0 -1
index 073274e35da5e..986d31587e999 100644
@@ -305,7 +305,6 @@ config X86
 	select HOTPLUG_SPLIT_STARTUP		if SMP && X86_32
 	select IRQ_FORCED_THREADING
 	select LOCK_MM_AND_FIND_VMA
-	select NEED_MODULE_PERMISSIONS_FIX
 	select NEED_PER_CPU_EMBED_FIRST_CHUNK
 	select NEED_PER_CPU_PAGE_FIRST_CHUNK
 	select NEED_SG_DMA_LENGTH
arch/x86/include/asm/alternative.h +6 -3
index eb24d9ba30d7f..b14c045679e16 100644
@@ -197,8 +197,8 @@ static inline int alternatives_text_reserved(void *start, void *end)
 	"773:\n"
 
 #define ALTINSTR_ENTRY(ft_flags)					      \
-	".pushsection .altinstructions, \"aM\", @progbits, "		      \
-		      __stringify(ALT_INSTR_SIZE) "\n"			      \
+	".pushsection .altinstructions,\"a\"\n"				      \
+	ANNOTATE_DATA_SPECIAL						      \
 	" .long 771b - .\n"				/* label           */ \
 	" .long 774f - .\n"				/* new instruction */ \
 	" .4byte " __stringify(ft_flags) "\n"		/* feature + flags */ \
@@ -208,6 +208,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
 
 #define ALTINSTR_REPLACEMENT(newinstr)		/* replacement */	\
 	".pushsection .altinstr_replacement, \"ax\"\n"			\
+	ANNOTATE_DATA_SPECIAL						\
 	"# ALT: replacement\n"						\
 	"774:\n\t" newinstr "\n775:\n"					\
 	".popsection\n"
@@ -338,6 +339,7 @@ void nop_func(void);
  * instruction. See apply_alternatives().
  */
 .macro altinstr_entry orig alt ft_flags orig_len alt_len
+	ANNOTATE_DATA_SPECIAL
 	.long \orig - .
 	.long \alt - .
 	.4byte \ft_flags
@@ -361,11 +363,12 @@ void nop_func(void);
 741:									\
 	.skip -(((744f-743f)-(741b-740b)) > 0) * ((744f-743f)-(741b-740b)),0x90	;\
 742:									\
-	.pushsection .altinstructions, "aM", @progbits, ALT_INSTR_SIZE ;\
+	.pushsection .altinstructions,"a" ;				\
 	altinstr_entry 740b,743f,flag,742b-740b,744f-743f ;		\
 	.popsection ;							\
 	.pushsection .altinstr_replacement,"ax"	;			\
 743:									\
+	ANNOTATE_DATA_SPECIAL ;						\
 	newinst	;							\
 744:									\
 	.popsection ;
arch/x86/include/asm/asm.h +13 -14
index ecb28d2bc6730..bd62bd87a841e 100644
@@ -2,6 +2,8 @@
 #ifndef _ASM_X86_ASM_H
 #define _ASM_X86_ASM_H
 
+#include <linux/annotate.h>
+
 #ifdef __ASSEMBLER__
 # define __ASM_FORM(x, ...)		x,## __VA_ARGS__
 # define __ASM_FORM_RAW(x, ...)		x,## __VA_ARGS__
@@ -124,21 +126,18 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
 
 #ifdef __KERNEL__
 
-#ifndef COMPILE_OFFSETS
-#include <asm/asm-offsets.h>
-#endif
-
 # include <asm/extable_fixup_types.h>
 
 /* Exception table entry */
 #ifdef __ASSEMBLER__
 
-# define _ASM_EXTABLE_TYPE(from, to, type)				\
-	.pushsection "__ex_table", "aM", @progbits, EXTABLE_SIZE;	\
-	.balign 4 ;							\
-	.long (from) - . ;						\
-	.long (to) - . ;						\
-	.long type ;							\
+# define _ASM_EXTABLE_TYPE(from, to, type)			\
+	.pushsection "__ex_table","a" ;				\
+	.balign 4 ;						\
+	ANNOTATE_DATA_SPECIAL ;					\
+	.long (from) - . ;					\
+	.long (to) - . ;					\
+	.long type ;						\
 	.popsection
 
 # ifdef CONFIG_KPROBES
@@ -181,18 +180,18 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
 	".purgem extable_type_reg\n"
 
 # define _ASM_EXTABLE_TYPE(from, to, type)			\
-	" .pushsection __ex_table, \"aM\", @progbits, "		\
-		       __stringify(EXTABLE_SIZE) "\n"		\
+	" .pushsection \"__ex_table\",\"a\"\n"			\
 	" .balign 4\n"						\
+	ANNOTATE_DATA_SPECIAL					\
 	" .long (" #from ") - .\n"				\
 	" .long (" #to ") - .\n"				\
 	" .long " __stringify(type) " \n"			\
 	" .popsection\n"
 
 # define _ASM_EXTABLE_TYPE_REG(from, to, type, reg)				\
-	" .pushsection __ex_table, \"aM\", @progbits, "				\
-		       __stringify(EXTABLE_SIZE) "\n"				\
+	" .pushsection \"__ex_table\",\"a\"\n"					\
 	" .balign 4\n"								\
+	ANNOTATE_DATA_SPECIAL							\
 	" .long (" #from ") - .\n"						\
 	" .long (" #to ") - .\n"						\
 	DEFINE_EXTABLE_TYPE_REG							\
arch/x86/include/asm/bug.h +2 -1
index db1522fdbd108..3910db28e2f5b 100644
@@ -56,7 +56,8 @@
 
 #define _BUG_FLAGS_ASM(ins, file, line, flags, size, extra)		\
 	"1:\t" ins "\n"							\
-	".pushsection __bug_table, \"aM\", @progbits, " size "\n"	\
+	".pushsection __bug_table,\"aw\"\n"				\
+	ANNOTATE_DATA_SPECIAL						\
 	__BUG_ENTRY(file, line, flags)					\
 	"\t.org 2b + " size "\n"					\
 	".popsection\n"							\
arch/x86/include/asm/cpufeature.h +1 -0
index 893cbca37fe99..fc5f32d4da6e1 100644
@@ -101,6 +101,7 @@ static __always_inline bool _static_cpu_has(u16 bit)
 	asm goto(ALTERNATIVE_TERNARY("jmp 6f", %c[feature], "", "jmp %l[t_no]")
 		".pushsection .altinstr_aux,\"ax\"\n"
 		"6:\n"
+		ANNOTATE_DATA_SPECIAL
 		" testb %[bitnum], %a[cap_byte]\n"
 		" jnz %l[t_yes]\n"
 		" jmp %l[t_no]\n"
arch/x86/include/asm/jump_label.h +7 -11
index 7a6b0e5d85c19..e0a6930a4029a 100644
@@ -12,17 +12,13 @@
 #include <linux/stringify.h>
 #include <linux/types.h>
 
-#ifndef COMPILE_OFFSETS
-#include <generated/bounds.h>
-#endif
-
-#define JUMP_TABLE_ENTRY(key, label)				\
-	".pushsection __jump_table,  \"aM\", @progbits, "	\
-	__stringify(JUMP_ENTRY_SIZE) "\n\t"			\
-	_ASM_ALIGN "\n\t"					\
-	".long 1b - . \n\t"					\
-	".long " label " - . \n\t"				\
-	_ASM_PTR " " key " - . \n\t"				\
+#define JUMP_TABLE_ENTRY(key, label)			\
+	".pushsection __jump_table,  \"aw\" \n\t"	\
+	_ASM_ALIGN "\n\t"				\
+	ANNOTATE_DATA_SPECIAL				\
+	".long 1b - . \n\t"				\
+	".long " label " - . \n\t"			\
+	_ASM_PTR " " key " - . \n\t"			\
 	".popsection \n\t"
 
 /* This macro is also expanded on the Rust side. */
arch/x86/include/asm/static_call.h +1 -2
index e03ad9bbbf59d..41502bd2afd64 100644
@@ -58,8 +58,7 @@
 	ARCH_DEFINE_STATIC_CALL_TRAMP(name, __static_call_return0)
 
 #define ARCH_ADD_TRAMP_KEY(name)					\
-	asm(".pushsection .static_call_tramp_key, \"aM\", @progbits, "	\
-	    __stringify(STATIC_CALL_TRAMP_KEY_SIZE) "\n"		\
+	asm(".pushsection .static_call_tramp_key, \"a\"		\n"	\
 	    ".long " STATIC_CALL_TRAMP_STR(name) " - .		\n"	\
 	    ".long " STATIC_CALL_KEY_STR(name) " - .		\n"	\
 	    ".popsection					\n")
arch/x86/kernel/asm-offsets.c +0 -3
index 0586d237b8866..32ba599a51f88 100644
@@ -124,7 +124,4 @@ static void __used common(void)
 	OFFSET(ARIA_CTX_rounds, aria_ctx, rounds);
 #endif
 
-	BLANK();
-	DEFINE(ALT_INSTR_SIZE,	 sizeof(struct alt_instr));
-	DEFINE(EXTABLE_SIZE,	 sizeof(struct exception_table_entry));
 }
arch/x86/um/shared/sysdep/kernel-offsets.h +0 -2
index 8215a0200ddd9..6fd1ed4003992 100644
@@ -1,5 +1,4 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-#define COMPILE_OFFSETS
 #include <linux/stddef.h>
 #include <linux/sched.h>
 #include <linux/elf.h>
@@ -8,7 +7,6 @@
 #include <linux/audit.h>
 #include <asm/mman.h>
 #include <asm/seccomp.h>
-#include <asm/extable.h>
 
 /* workaround for a warning with -Wmissing-prototypes */
 void foo(void);
include/linux/annotate.h new file +134 -0

134 lines not on this page · raw message

include/linux/interval_tree.h +4 -0
index 2b8026a399064..9d5791e9f737a 100644
@@ -19,6 +19,10 @@ extern void
 interval_tree_remove(struct interval_tree_node *node,
 		     struct rb_root_cached *root);
 
+extern struct interval_tree_node *
+interval_tree_subtree_search(struct interval_tree_node *node,
+			     unsigned long start, unsigned long last);
+
 extern struct interval_tree_node *
 interval_tree_iter_first(struct rb_root_cached *root,
 			 unsigned long start, unsigned long last);
include/linux/interval_tree_generic.h +1 -1
index 1b400f26f63d6..c5a2fed49eb0d 100644
@@ -77,7 +77,7 @@ ITSTATIC void ITPREFIX ## _remove(ITSTRUCT *node,			      \
  *   Cond2: start <= ITLAST(node)					      \
  */									      \
 									      \
-static ITSTRUCT *							      \
+ITSTATIC ITSTRUCT *							      \
 ITPREFIX ## _subtree_search(ITSTRUCT *node, ITTYPE start, ITTYPE last)	      \
 {									      \
 	while (true) {							      \
include/linux/livepatch_helpers.h +0 -2
index 337bee91d7daf..99d68d0773fa8 100644
@@ -36,8 +36,6 @@
 		__PASTE(__KLP_POST_UNPATCH_PREFIX, KLP_OBJNAME) = func
 
 /*
- * KLP_STATIC_CALL
- *
  * Replace static_call() usage with this macro when create-diff-object
  * recommends it due to the original static call key living in a module.
  *
include/linux/mm.h +2 -0
index 1ae97a0b8ec75..69baa9a1e2cb4 100644
@@ -3265,6 +3265,8 @@ void vma_interval_tree_insert_after(struct vm_area_struct *node,
 				    struct rb_root_cached *root);
 void vma_interval_tree_remove(struct vm_area_struct *node,
 			      struct rb_root_cached *root);
+struct vm_area_struct *vma_interval_tree_subtree_search(struct vm_area_struct *node,
+				unsigned long start, unsigned long last);
 struct vm_area_struct *vma_interval_tree_iter_first(struct rb_root_cached *root,
 				unsigned long start, unsigned long last);
 struct vm_area_struct *vma_interval_tree_iter_next(struct vm_area_struct *node,
include/linux/objtool.h +5 -96

148 lines not on this page · raw message

include/linux/objtool_types.h +2 -0
index aceac94632c8a..c6def4049b1ae 100644
@@ -67,4 +67,6 @@ struct unwind_hint {
 #define ANNOTYPE_REACHABLE		8
 #define ANNOTYPE_NOCFI			9
 
+#define ANNOTYPE_DATA_SPECIAL		1
+
 #endif /* _LINUX_OBJTOOL_TYPES_H */
include/linux/static_call.h +6 -0
index 5210612817f2e..78a77a4ae0ea8 100644
@@ -172,6 +172,12 @@ struct static_call_mod {
 	struct static_call_site *sites;
 };
 
+/* For finding the key associated with a trampoline */
+struct static_call_tramp_key {
+	s32 tramp;
+	s32 key;
+};
+
 extern void __static_call_update(struct static_call_key *key, void *tramp, void *func);
 extern int static_call_mod_init(struct module *mod);
 extern int static_call_text_reserved(void *start, void *end);
include/linux/static_call_types.h +0 -6
index eb772df625d4e..5a00b8b2cf9fc 100644
@@ -34,12 +34,6 @@ struct static_call_site {
 	s32 key;
 };
 
-/* For finding the key associated with a trampoline */
-struct static_call_tramp_key {
-	s32 tramp;
-	s32 key;
-};
-
 #define DECLARE_STATIC_CALL(name, func)					\
 	extern struct static_call_key STATIC_CALL_KEY(name);		\
 	extern typeof(func) STATIC_CALL_TRAMP(name);
kernel/bounds.c +0 -13
index f9bc13727721e..29b2cd00df2cc 100644
@@ -6,16 +6,12 @@
  */
 
 #define __GENERATING_BOUNDS_H
-#define COMPILE_OFFSETS
 /* Include headers that define the enum constants of interest */
 #include <linux/page-flags.h>
 #include <linux/mmzone.h>
 #include <linux/kbuild.h>
 #include <linux/log2.h>
 #include <linux/spinlock_types.h>
-#include <linux/jump_label.h>
-#include <linux/static_call_types.h>
-#include <linux/objtool_types.h>
 
 int main(void)
 {
@@ -32,15 +28,6 @@ int main(void)
 #else
 	DEFINE(LRU_GEN_WIDTH, 0);
 	DEFINE(__LRU_REFS_WIDTH, 0);
-#endif
-#if defined(CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE) && defined(CONFIG_JUMP_LABEL)
-	DEFINE(JUMP_ENTRY_SIZE, sizeof(struct jump_entry));
-#endif
-#ifdef CONFIG_HAVE_STATIC_CALL_INLINE
-	DEFINE(STATIC_CALL_TRAMP_KEY_SIZE, sizeof(struct static_call_tramp_key));
-#endif
-#ifdef CONFIG_OBJTOOL
-	DEFINE(UNWIND_HINT_SIZE, sizeof(struct unwind_hint));
 #endif
 	/* End of constants */
 
scripts/Makefile.lib +1 -0
index 28a1c08e3b221..f4b33919ec371 100644
@@ -173,6 +173,7 @@ ifdef CONFIG_OBJTOOL
 
 objtool := $(objtree)/tools/objtool/objtool
 
+objtool-args-$(CONFIG_KLP_BUILD)			+= --checksum
 objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK)		+= --hacks=jump_label
 objtool-args-$(CONFIG_HAVE_NOINSTR_HACK)		+= --hacks=noinstr
 objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING)	+= --hacks=skylake
scripts/Makefile.modfinal +5 -14
index 7a888e1ff70f2..542ba462ed3ec 100644
@@ -28,24 +28,12 @@ ccflags-remove-y := $(CC_FLAGS_CFI)
 .module-common.o: $(srctree)/scripts/module-common.c FORCE
 	$(call if_changed_rule,cc_o_c)
 
-ifdef CONFIG_NEED_MODULE_PERMISSIONS_FIX
-cmd_fix_mod_permissions =						\
-	$(OBJCOPY) --set-section-flags __jump_table=alloc,data		\
-		   --set-section-flags __bug_table=alloc,data $@	\
-		   --set-section-flags .static_call_sites=alloc,data $@
-endif
-
 quiet_cmd_ld_ko_o = LD [M]  $@
       cmd_ld_ko_o =							\
 	$(LD) -r $(KBUILD_LDFLAGS)					\
 		$(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE)		\
 		-T $(objtree)/scripts/module.lds -o $@ $(filter %.o, $^)
 
-define rule_ld_ko_o
-	$(call cmd_and_savecmd,ld_ko_o)
-	$(call cmd,fix_mod_permissions)
-endef
-
 quiet_cmd_btf_ko = BTF [M] $@
       cmd_btf_ko = 							\
 	if [ ! -f $(objtree)/vmlinux ]; then				\
@@ -58,11 +46,14 @@ quiet_cmd_btf_ko = BTF [M] $@
 # Same as newer-prereqs, but allows to exclude specified extra dependencies
 newer_prereqs_except = $(filter-out $(PHONY) $(1),$?)
 
-if_changed_rule_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check),$(rule_$(1)),@:)
+# Same as if_changed, but allows to exclude specified extra dependencies
+if_changed_except = $(if $(call newer_prereqs_except,$(2))$(cmd-check),      \
+	$(cmd);                                                              \
+	printf '%s\n' 'savedcmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
 
 # Re-generate module BTFs if either module's .ko or vmlinux changed
 %.ko: %.o %.mod.o .module-common.o $(objtree)/scripts/module.lds $(and $(CONFIG_DEBUG_INFO_BTF_MODULES),$(KBUILD_BUILTIN),$(objtree)/vmlinux) FORCE
-	+$(call if_changed_rule_except,ld_ko_o,$(objtree)/vmlinux)
+	+$(call if_changed_except,ld_ko_o,$(objtree)/vmlinux)
 ifdef CONFIG_DEBUG_INFO_BTF_MODULES
 	+$(if $(newer-prereqs),$(call cmd,btf_ko))
 endif
scripts/livepatch/klp-build +2 -6
index e47056f75475e..881e052e7faef 100755
@@ -489,11 +489,8 @@ clean_kernel() {
 
 build_kernel() {
 	local log="$TMP_DIR/build.log"
-	local objtool_args=()
 	local cmd=()
 
-	objtool_args=("--checksum")
-
 	cmd=("make")
 
 	# When a patch to a kernel module references a newly created unexported
@@ -516,7 +513,6 @@ build_kernel() {
 	cmd+=("$VERBOSE")
 	cmd+=("-j$JOBS")
 	cmd+=("KCFLAGS=-ffunction-sections -fdata-sections")
-	cmd+=("OBJTOOL_ARGS=${objtool_args[*]}")
 	cmd+=("vmlinux")
 	cmd+=("modules")
 
@@ -794,7 +790,7 @@ process_args "$@"
 do_init
 
 if (( SHORT_CIRCUIT <= 1 )); then
-	status "Validating patches"
+	status "Validating patch(es)"
 	validate_patches
 	status "Building original kernel"
 	clean_kernel
@@ -804,7 +800,7 @@ if (( SHORT_CIRCUIT <= 1 )); then
 fi
 
 if (( SHORT_CIRCUIT <= 2 )); then
-	status "Fixing patches"
+	status "Fixing patch(es)"
 	fix_patches
 	apply_patches
 	status "Building patched kernel"
scripts/mod/devicetable-offsets.c +0 -1
index ef2ffb68f69d1..d3d00e85edf73 100644
@@ -1,5 +1,4 @@
 // SPDX-License-Identifier: GPL-2.0
-#define COMPILE_OFFSETS
 #include <linux/kbuild.h>
 #include <linux/mod_devicetable.h>
 
tools/include/linux/interval_tree_generic.h +2 -6
index c0ec9dbdfbaf2..c5a2fed49eb0d 100644
@@ -104,12 +104,8 @@ ITPREFIX ## _subtree_search(ITSTRUCT *node, ITTYPE start, ITTYPE last)	      \
 		if (ITSTART(node) <= last) {		/* Cond1 */	      \
 			if (start <= ITLAST(node))	/* Cond2 */	      \
 				return node;	/* node is leftmost match */  \
-			if (node->ITRB.rb_right) {			      \
-				node = rb_entry(node->ITRB.rb_right,	      \
-						ITSTRUCT, ITRB);	      \
-				if (start <= node->ITSUBTREE)		      \
-					continue;			      \
-			}						      \
+			node = rb_entry(node->ITRB.rb_right, ITSTRUCT, ITRB); \
+			continue;					      \
 		}							      \
 		return NULL;	/* No match */				      \
 	}								      \
tools/include/linux/objtool_types.h +2 -0
index aceac94632c8a..c6def4049b1ae 100644
@@ -67,4 +67,6 @@ struct unwind_hint {
 #define ANNOTYPE_REACHABLE		8
 #define ANNOTYPE_NOCFI			9
 
+#define ANNOTYPE_DATA_SPECIAL		1
+
 #endif /* _LINUX_OBJTOOL_TYPES_H */
tools/include/linux/static_call_types.h +0 -6
index eb772df625d4e..5a00b8b2cf9fc 100644
@@ -34,12 +34,6 @@ struct static_call_site {
 	s32 key;
 };
 
-/* For finding the key associated with a trampoline */
-struct static_call_tramp_key {
-	s32 tramp;
-	s32 key;
-};
-
 #define DECLARE_STATIC_CALL(name, func)					\
 	extern struct static_call_key STATIC_CALL_KEY(name);		\
 	extern typeof(func) STATIC_CALL_TRAMP(name);
tools/objtool/arch/loongarch/orc.c +0 -1
index b58c5ff443c92..ffd3a3c858ae7 100644
@@ -5,7 +5,6 @@
 #include <objtool/check.h>
 #include <objtool/orc.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruction *insn)
 {
tools/objtool/arch/powerpc/decode.c +0 -1
index d4cb02120a6bd..3a9b748216edc 100644
@@ -7,7 +7,6 @@
 #include <objtool/arch.h>
 #include <objtool/warn.h>
 #include <objtool/builtin.h>
-#include <objtool/endianness.h>
 
 int arch_ftrace_match(const char *name)
 {
tools/objtool/arch/x86/decode.c +0 -1
index 6f3aa117027a6..5c72beeaa3a71 100644
@@ -19,7 +19,6 @@
 #include <objtool/elf.h>
 #include <objtool/arch.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 #include <objtool/builtin.h>
 #include <arch/elf.h>
 
tools/objtool/arch/x86/orc.c +0 -1
index 7176b9ec5b058..735e150ca6b73 100644
@@ -5,7 +5,6 @@
 #include <objtool/check.h>
 #include <objtool/orc.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 int init_orc_entry(struct orc_entry *orc, struct cfi_state *cfi, struct instruction *insn)
 {
tools/objtool/builtin-check.c +1 -2
index c4e45236a561d..b20b0077449b2 100644
@@ -74,7 +74,7 @@ static int parse_hacks(const struct option *opt, const char *str, int unset)
 static const struct option check_options[] = {
 	OPT_GROUP("Actions:"),
 	OPT_BOOLEAN(0,		 "checksum", &opts.checksum, "generate per-function checksums"),
-	OPT_BOOLEAN(0  ,	 "cfi", &opts.cfi, "annotate kernel control flow integrity (kCFI) function preambles"),
+	OPT_BOOLEAN(0,		 "cfi", &opts.cfi, "annotate kernel control flow integrity (kCFI) function preambles"),
 	OPT_CALLBACK_OPTARG('h', "hacks", NULL, NULL, "jump_label,noinstr,skylake", "patch toolchain bugs/limitations", parse_hacks),
 	OPT_BOOLEAN('i',	 "ibt", &opts.ibt, "validate and annotate IBT"),
 	OPT_BOOLEAN('m',	 "mcount", &opts.mcount, "annotate mcount/fentry calls for ftrace"),
@@ -162,7 +162,6 @@ static bool opts_valid(void)
 		return false;
 	}
 
-
 #ifndef BUILD_KLP
 	if (opts.checksum) {
 		ERROR("--checksum not supported; install xxhash-devel and recompile");
tools/objtool/check.c +60 -41

178 lines not on this page · raw message

tools/objtool/elf.c +29 -34

90 lines not on this page · raw message

tools/objtool/include/objtool/builtin.h +1 -1
index 8a0d42aa4d858..bb0b25eb08ba4 100644
@@ -10,6 +10,7 @@
 struct opts {
 	/* actions: */
 	bool cfi;
+	bool checksum;
 	bool dump_orc;
 	bool hack_jump_label;
 	bool hack_noinstr;
@@ -25,7 +26,6 @@ struct opts {
 	bool sls;
 	bool stackval;
 	bool static_call;
-	bool checksum;
 	bool uaccess;
 	int prefix;
 
tools/objtool/include/objtool/elf.h +17 -6
index 64e75ade01c90..21d8b825fd8f0 100644
@@ -14,12 +14,15 @@
 #include <linux/rbtree.h>
 #include <linux/jhash.h>
 
+#include <objtool/endianness.h>
 #include <objtool/checksum_types.h>
 #include <arch/elf.h>
 
 #define SEC_NAME_LEN		1024
 #define SYM_NAME_LEN		512
 
+#define bswap_if_needed(elf, val) __bswap_if_needed(&elf->ehdr, val)
+
 #ifdef LIBELF_USE_DEPRECATED
 # define elf_getshdrnum    elf_getshnum
 # define elf_getshdrstrndx elf_getshstrndx
@@ -146,8 +149,6 @@ struct symbol *elf_create_symbol(struct elf *elf, const char *name,
 				 unsigned int type, unsigned long offset,
 				 size_t size);
 struct symbol *elf_create_section_symbol(struct elf *elf, struct section *sec);
-struct symbol *elf_create_prefix_symbol(struct elf *elf, struct symbol *orig,
-					size_t size);
 
 void *elf_add_data(struct elf *elf, struct section *sec, const void *data,
 		   size_t size);
@@ -274,7 +275,7 @@ static inline bool is_local_sym(struct symbol *sym)
 
 static inline bool is_prefix_func(struct symbol *sym)
 {
-	return is_func_sym(sym) && sym->prefix;
+	return sym->prefix;
 }
 
 static inline bool is_reloc_sec(struct section *sec)
@@ -414,6 +415,15 @@ static inline void set_reloc_type(struct elf *elf, struct reloc *reloc, unsigned
 	mark_sec_changed(elf, reloc->sec, true);
 }
 
+static inline unsigned int annotype(struct elf *elf, struct section *sec,
+				    struct reloc *reloc)
+{
+	unsigned int type;
+
+	type = *(u32 *)(sec->data->d_buf + (reloc_idx(reloc) * 8) + 4);
+	return bswap_if_needed(elf, type);
+}
+
 #define RELOC_JUMP_TABLE_BIT 1UL
 
 /* Does reloc mark the beginning of a jump table? */
@@ -445,9 +455,6 @@ static inline void set_sym_next_reloc(struct reloc *reloc, struct reloc *next)
 #define sec_for_each_sym(sec, sym)					\
 	list_for_each_entry(sym, &sec->symbol_list, list)
 
-#define sec_for_each_sym_continue_reverse(sec, sym)			\
-	list_for_each_entry_continue_reverse(sym, &sec->symbol_list, list)
-
 #define sec_prev_sym(sym)						\
 	sym->sec && sym->list.prev != &sym->sec->symbol_list ?		\
 	list_prev_entry(sym, list) : NULL
@@ -467,6 +474,10 @@ static inline void set_sym_next_reloc(struct reloc *reloc, struct reloc *next)
 #define for_each_reloc_from(rsec, reloc)				\
 	for (; reloc; reloc = rsec_next_reloc(rsec, reloc))
 
+#define for_each_reloc_continue(rsec, reloc)				\
+	for (reloc = rsec_next_reloc(rsec, reloc); reloc;		\
+	     reloc = rsec_next_reloc(rsec, reloc))
+
 #define sym_for_each_reloc(elf, sym, reloc)				\
 	for (reloc = find_reloc_by_dest_range(elf, sym->sec,		\
 					      sym->offset, sym->len);	\
tools/objtool/include/objtool/endianness.h +4 -5
index 4d2aa9b0fe2fd..aebcd23386685 100644
@@ -4,7 +4,6 @@
 
 #include <linux/kernel.h>
 #include <endian.h>
-#include <objtool/elf.h>
 
 /*
  * Does a byte swap if target file endianness doesn't match the host, i.e. cross
@@ -12,16 +11,16 @@
  * To be used for multi-byte values conversion, which are read from / about
  * to be written to a target native endianness ELF file.
  */
-static inline bool need_bswap(struct elf *elf)
+static inline bool need_bswap(GElf_Ehdr *ehdr)
 {
 	return (__BYTE_ORDER == __LITTLE_ENDIAN) ^
-	       (elf->ehdr.e_ident[EI_DATA] == ELFDATA2LSB);
+	       (ehdr->e_ident[EI_DATA] == ELFDATA2LSB);
 }
 
-#define bswap_if_needed(elf, val)					\
+#define __bswap_if_needed(ehdr, val)					\
 ({									\
 	__typeof__(val) __ret;						\
-	bool __need_bswap = need_bswap(elf);				\
+	bool __need_bswap = need_bswap(ehdr);				\
 	switch (sizeof(val)) {						\
 	case 8:								\
 		__ret = __need_bswap ? bswap_64(val) : (val); break;	\
tools/objtool/include/objtool/objtool.h +0 -2
index 731965a742e99..f7051bbe0bcb2 100644
@@ -14,8 +14,6 @@
 
 #define __weak __attribute__((weak))
 
-#define SYM_CHECKSUM_SEC ".discard.sym_checksum"
-
 struct pv_state {
 	bool clean;
 	struct list_head targets;
tools/objtool/klp-diff.c +138 -92

277 lines not on this page · raw message

tools/objtool/orc_dump.c +0 -1
index 1dd9fc18fe624..5a979f52425ab 100644
@@ -8,7 +8,6 @@
 #include <objtool/objtool.h>
 #include <objtool/orc.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 int orc_dump(const char *filename)
 {
tools/objtool/orc_gen.c +0 -1
index 9d380abc2ed35..1045e1380ffde 100644
@@ -12,7 +12,6 @@
 #include <objtool/check.h>
 #include <objtool/orc.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 struct orc_list_entry {
 	struct list_head list;
tools/objtool/special.c +0 -1
index fc2cf8dba1c03..e262af9171436 100644
@@ -15,7 +15,6 @@
 #include <objtool/builtin.h>
 #include <objtool/special.h>
 #include <objtool/warn.h>
-#include <objtool/endianness.h>
 
 struct special_entry {
 	const char *sec;
tools/objtool/sync-check.sh +1 -0
index e1d98fb031575..e38167ca56a95 100755
@@ -16,6 +16,7 @@ arch/x86/include/asm/orc_types.h
 arch/x86/include/asm/emulate_prefix.h
 arch/x86/lib/x86-opcode-map.txt
 arch/x86/tools/gen-insn-attr-x86.awk
+include/linux/interval_tree_generic.h
 include/linux/livepatch_external.h
 include/linux/static_call_types.h
 "