Commit Graph

1000 Commits

Author SHA1 Message Date
Joe Lawrence 6115a1a4e7
Merge pull request #1397 from joe-lawrence/small-upstream-kernel-fixes
Small upstream kernel fixes
2024-07-18 13:59:29 -04:00
Sumanth Korikkar 5695dce6de s390/kpatch-build: add -fPIE flag with -mno-pic-data-is-text-relative
-mno-pic-data-is-text-relative compiler flag expects -fPIC/-fPIE flag
along with it.  Since kernel commit 778666df60f0 ("s390: compile
relocatable kernel without -fPIE"), the -fPIC/-fPIE flag is missing when
creating kpatch module and this can lead to the following error:

cc1: error: ‘-mno-pic-data-is-text-relative’ cannot be used without
‘-fpic’/‘-fPIC’.

Previously kpatch-build didnt show up this issue, as the previous kernel
was built with -fPIE.

However, kpatch build could fail with kernel commit 778666df60f0 ("s390:
compile relocatable kernel without -fPIE"), where -fPIE is not included.
Hence, include it in kpatch-build for all kernels < 6.10.0

Note:
Latest s390 kernel is built with -fPIC flag.
i.e. kernel commit 00cda11d3b2e ("s390: Compile kernel with -fPIC and
link with -no-pie"). Hence, there is no need to explicitly add it again
in kpatch-build.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2024-06-24 14:28:33 +02:00
Joe Lawrence 7d89578c6f kpatch-build: suppress make directory info for `make kernelversion`
When invoking kpatch-build through integration testing, like:

  $ make PATCH_DIR="linux-6.9.0" \
         KPATCH_BUILD_OPTS="--sourcedir /root/linux" \
         integration-slow

results in an error as kpatch-build's `make kernelversion` adds
directory information to its output:

  make[2]: Entering directory '/root/linux'
  6.9.0
  make[2]: Leaving directory '/root/linux'

This screws up kpatch-build's assignment of the make output to
LOCALVERSION, which was expecting only "6.9.0".

Add --no-print-directory to the make invocation to avoid the undesired
entering / leaving directory info.

Fixes: 629b5acf3d ("kpatch-build: Fix setlocalversion issue with 6.3 kernel")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-06-07 11:12:51 -04:00
Joe Lawrence 77d9346383 kpatch-build: fix setlocalversion for pre-v6.3 kernels
Commit 629b5acf3d ("kpatch-build: Fix setlocalversion issue with 6.3
kernel") fixed VERMAGIC_STRING between kpatch original/patched kernel
builds by creating a temporary scripts/setlocalversion script.	This was
accomplished by saving the output from `make kernelversion` into a
KERNELVERSION environment variable and running the (original)
scripts/setlocalversion to gather a "vX.Y" + "<src version>" pair of
strings.

Unfortunately pre-v6.3 scripts/setlocalversion does not use the
KERNELVERSION environment variable, so the same efforts results in an
unusable "<NULL>" + "<src version>" version string pair.

Restore the original `scripts/setlocalversion --save-scmversion`
invocation for source trees that (still) support the --save-scmversion
option.

Fixes: 629b5acf3d ("kpatch-build: Fix setlocalversion issue with 6.3 kernel")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-06-07 10:22:03 -04:00
Joe Lawrence 711ee6d322 kpatch-build: fix USERSRCDIR builds
Commit 69e71f8dcc ("kpatch-build: cleanup kernel file backup/restore")
consolidated a bunch of kernel-tree copy and restoring.  As part of that
effort, when kpatch-build is invoked with a -s|--sourcedir USERSRCDIR
value the vmlinux file is now saved to "$TEMPDIR/kernel-backup/" and not
simply "$TEMPDIR/".  This results in kpatch-build confusion like:

  readelf: /home/jolawren/.kpatch/tmp/vmlinux: Error: No such file

Update the VMLINUX reassignment in this case to point to the new path.

Fixes: 69e71f8dcc ("kpatch-build: cleanup kernel file backup/restore")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-06-07 10:21:42 -04:00
Joe Lawrence 63cc79c225 kpatch-build: fix DISTRO check when specifying USERSRCDIR
When kpatch-build is invoked with a -s|--sourcedir USERSRCDIR value,
kpatch-build doesn't source the /etc/os-release file as it can't assume
that the user-specified kernel source config matches any particular
distribution.  Subsequent is_supported_{rpm,deb}_distro() function calls
will result in ugly syntax errors like:

  kpatch-build: line 697: SUPPORTED_RPM_DISTROS: bad array subscript
  kpatch-build: line 692: SUPPORTED_DEB_DISTROS: bad array subscript

Enhance the is_supported_{rpm,deb}_distro() functions to check that a
non-NULL distribution string argument exists before indexing the
SUPPORTED_{RPM,DEB}_DISTROS associative arrays.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-06-07 10:21:39 -04:00
Puranjay Mohan 90a92f9492 Recognize Amazon Linux ID in kpatch-build
Make kpatch-build aware about the ID of Amazon Linux distributions. No
other special changes are needed.

Signed-off-by: Puranjay Mohan <pjy@amazon.com>
2024-06-05 12:08:36 +00:00
Joe Lawrence bb93ac9c65
Merge pull request #1393 from joe-lawrence/ld-orphan-error
Fix builds with CONFIG_ERROR
2024-05-14 22:20:58 -04:00
Joe Lawrence 69e71f8dcc kpatch-build: cleanup kernel file backup/restore
Temporarily editing kernel tree sources has become a recurring
requirement in kpatch-build.  Pull the saving/restoring of these files
into a common function helpers to standardize the pattern.

Reported-and-tested-by: Zhijun Wang <zhijwang@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-05-07 15:38:27 -04:00
Joe Lawrence 56dfdbeb5b kpatch-build: demote CONFIG_LD_ORPHAN_WARN_LEVEL
Upstream kernel v6.1+ commit linux@e1789d7c752e ("kbuild: upgrade the
orphan section warning to an error if CONFIG_WERROR is set") and
CONFIG_WERROR will result in failed kernel builds due to the linker
reporting tons of "unplaced orphan section `.text.<function>`
<object-file.o>" errors.

Workaround this by temporarily demoting such errors in the top-level
kernel Makefile.

Reported-and-tested-by: Zhijun Wang <zhijwang@redhat.com>
Closes: #1391 ("CONFIG_WERROR=y and CONFIG_LD_ORPHAN_WARN_LEVEL="error" break kpatch-build")
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-05-07 15:34:03 -04:00
Ryan Sullivan 36ba2b8dfc kpatch-build: handle paravirt absence in Linux v6.8+
Upstream kernel commit f7af6977621a ("x86/paravirt: Remove no longer
needed paravirt patching code") v6.8+ removed the .parainstructions
section and its paravirt_patch_site struct. Therefore this checks the
kernel version and does not export the struct size if the kernel
version is >= v6.8.0, avoiding the code path for it in
create-diff-object.c entirely.

Fixes: https://github.com/dynup/kpatch/issues/1380

Signed-off-by: Ryan Sullivan <rysulliv@redhat.com>
2024-05-03 16:06:23 -04:00
Longjun Luo 57936d3fad kpatch-build: add support for OpenCloudOS
OpenCloudOS is a centos-like Linux distribution.
I test kpatch in OpenCloudOS V8 and V9.
It works well in V9. But v8 itself has two problems:
1. no available epol repo, so kpatch can't install ccache.
2. executing 'uname -r' can't get an accurate kernel version.

Both problems have been notified to the OpenCloudOS community.
After they fix these problems, kpatch will work well in all versions.

Signed-off-by: Longjun Luo <luolongjuna@gmail.com>
2024-03-19 10:51:07 +08:00
Josh Poimboeuf 0edd6e42bf
Merge pull request #1368 from wardenjohn/devel
Support Anolis OS in a more elegant way
2024-01-22 11:58:58 -06:00
zhangyongde.zyd d511792998 kpatch-build: Support distro Anolis OS
Support Anolis OS

Signed-off-by: Wardenjohn<zhangwarden@gmail.com>
2024-01-17 15:44:47 +08:00
zhangyongde.zyd 89c494f023 kpatch-build: simplify distro support
Rather than adding yet another set of conditionals to handle the Anolis
OS distribution, refactor the SUPPORTED_DISTROS code using an
associative array.  The array is keyed by the short distro name, and
contains the longer distribution description.

Signed-off-by: Wardenjohn<zhangwarden@gmail.com>
2024-01-17 12:45:17 +08:00
Hongchen Zhang e4da489e7e kpatch-build: check if gawk is installed
kpatch-build uses gawk to find special section, but gawk is not
always installed. So check if gawk is installed.

Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
2023-12-12 16:43:15 +08:00
Josh Poimboeuf 922cd45809
Merge pull request #1358 from heuza/fix_ub
Fix undefined behavior problem when using list_foreach_entry
2023-09-11 19:17:04 -05:00
laokz 671fe2ce01 kpatch-build: fix missed parameter of verify_patch_files
Verify_patch_files() use `lsdiff` to get patches' path and verify
they are supported. To be consistent with apply_patches() which
using `patch -p1`, `lsdiff` should use '--strip=1' paremeter.

Close: #1357

Signed-off-by: Kai Zhang <zhangkai@iscas.ac.cn>
2023-08-28 22:13:15 +08:00
Weinan Liu fb22714ae9 Fix undefined behavior problem when using list_foreach_entry
This upstream list.h offsetof implementation rely on undefined behavior implementation. Using __builtin_offsetof to fix this problem.
2023-08-10 00:22:53 +00:00
Joe Lawrence f58eaee1a1 kpatch-build: skip mangling for powerpc cpu feature relocations
PowerPC implements alternative instructions with __ftr_fixup and
__ftr_alt_* sections, for example net/core/dev.o:

  Disassembly of section __ftr_alt_97:

  0000000000000000 <__ftr_alt_97>:
     0: 3c 00 40 7c pause_short
     4: 3c 00 40 7c pause_short
     8: 3c 00 40 7c pause_short
     c: 3c 00 40 7c pause_short

  Disassembly of section __ftr_fixup:

  0000000000000000 <__ftr_fixup>:
     0: 00 00 00 00 .long 0x0
     4: 00 00 04 00 .long 0x40000
    ...
    10: R_PPC64_REL64 .text.napi_busy_loop+0x1cc
    18: R_PPC64_REL64 .text.napi_busy_loop+0x1dc
    20: R_PPC64_REL64 __ftr_alt_97+0x20
    28: R_PPC64_REL64 __ftr_alt_97+0x2c
    34: 00 00 04 00 .long 0x40000
    ...
    40: R_PPC64_REL64 .text.napi_busy_loop+0x3c0
    48: R_PPC64_REL64 .text.napi_busy_loop+0x3d0
    50: R_PPC64_REL64 __ftr_alt_97+0x24
    58: R_PPC64_REL64 __ftr_alt_97+0x30
    64: 00 00 04 00 .long 0x40000
    ...
    70: R_PPC64_REL64 .text.napi_threaded_poll+0x170
    78: R_PPC64_REL64 .text.napi_threaded_poll+0x180
    80: R_PPC64_REL64 __ftr_alt_97+0x28
    88: R_PPC64_REL64 __ftr_alt_97+0x34
    94: 00 00 04 00 .long 0x40000
    ...
    a0: R_PPC64_REL64 .text.net_rx_action+0x1a0
    a8: R_PPC64_REL64 .text.net_rx_action+0x1b0
    b0: R_PPC64_REL64 __ftr_alt_97+0x2c
    b8: R_PPC64_REL64 __ftr_alt_97+0x38

Like .altinstr_{aux,replacement}, __ftr_alt sections don't have symbols
associated with them and may skip kpatch_replace_sections_syms()'s rela
mangling.  As __ftr_fixup references __ftr_alt_* directly,
kpatch_process_special_sections() will already include __ftr_alt_* as
part of the "group" handling in kpatch_regenerate_special_section().

Reported-by: Zhijun Wang <zhijwang@redhat.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-07-26 14:46:21 -04:00
Josh Poimboeuf 8a00d03bb8
Merge pull request #1346 from jpoimboe/locals-match-empty
lookup: skip duplicate local symbol table check for files without locals
2023-07-20 18:12:15 -05:00
Josh Poimboeuf f8d2534210
Merge pull request #1339 from bhllamoreaux/photon-os-support
kpatch-build: support Photon OS distribution
2023-06-20 17:01:27 -07:00
Brennan Lamoreaux 758881bd5f kpatch-build: support for Photon OS
VMware's Photon OS uses kpatch to build kernel livepatches, starting with 3.0.

Add some changes to support Photon OS in kpatch, so we can use kpatch-build
in Photon like:
kpatch-build <name>.patch.

This commit integrates Photon OS support into existing kpatch-build support code
for various distros.
2023-06-05 22:08:03 +00:00
Josh Poimboeuf 75927e7bbb lookup: skip duplicate local symbol table check for files without locals
If the file doesn't have local object/func symbols, any empty match will
do, and duplicate matching local symbol lists aren't a problem.

Fixes #1345.

Reported-by: lzwycc <lzw32321226@163.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2023-06-05 09:49:30 -07:00
Josh Poimboeuf 73cdcb15ab
Merge pull request #1322 from joe-lawrence/v6.2-support
Upstream kernel v6.2 support
2023-04-14 16:17:28 -05:00
Josh Poimboeuf 0dc10cad76
Merge pull request #1336 from jpoimboe/setlocalversion
kpatch-build: Fix setlocalversion issue with 6.3 kernel
2023-03-17 12:27:41 -05:00
Joe Lawrence 4df1528cd9 gcc-plugin: update gcc-common.h for gcc-13
Backport this kernel commit to kpatch's version of gcc-common.h:

commit e6a71160cc145e18ab45195abf89884112e02dfb
Author: Kees Cook <keescook@chromium.org>
Date:   Wed Jan 18 12:21:35 2023 -0800

    gcc-plugins: Reorganize gimple includes for GCC 13

    The gimple-iterator.h header must be included before gimple-fold.h
    starting with GCC 13. Reorganize gimple headers to work for all GCC
    versions.

    Reported-by: Palmer Dabbelt <palmer@rivosinc.com>
    Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
    Link: https://lore.kernel.org/all/20230113173033.4380-1-palmer@rivosinc.com/
    Cc: linux-hardening@vger.kernel.org
    Signed-off-by: Kees Cook <keescook@chromium.org>

Note that we can't directly copy the gcc-plugin headers from the kernel
as has it has dropped gcc-4.9 and older support since v5.16.  Distros
like rhel-7 still use gcc-4.8, so manually cherry pick changes into the
kpatch tree.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-03-16 22:05:43 -07:00
Joe Lawrence 3e54c63b17 create-diff-object: support x86 NOP-padded functions
Kernel v6.2+ commit bea75b33895f ("x86/Kconfig: Introduce function
padding") added 16 bytes of NOP padding in front of each function.

For objects built with --function-sections, this means that function
symbols no longer sit at the beginning of their respective ELF sections,
but 16 bytes offset.

In the same release, kernel v6.2+ commit 9f2899fe36a6 ("objtool: Add
option to generate prefix symbols") adds ELF function symbols with
prefix "__pfx_" to indicate the start of a function, inclusive of
NOP-padding.

For example:

  $ objdump -Dr -j.text.cmdline_proc_show fs/proc/cmdline.o
  ...
  Disassembly of section .text.cmdline_proc_show:

  0000000000000000 <__pfx_cmdline_proc_show>:
     0:   90                      nop
     1:   90                      nop
     2:   90                      nop
     3:   90                      nop
     4:   90                      nop
     5:   90                      nop
     6:   90                      nop
     7:   90                      nop
     8:   90                      nop
     9:   90                      nop
     a:   90                      nop
     b:   90                      nop
     c:   90                      nop
     d:   90                      nop
     e:   90                      nop
     f:   90                      nop

  0000000000000010 <cmdline_proc_show>:
    10:   e8 00 00 00 00          callq  15 <cmdline_proc_show+0x5>
                          11: R_X86_64_PLT32      __fentry__-0x4
    15:   55                      push   %rbp
    16:   48 8b 35 00 00 00 00    mov    0x0(%rip),%rsi        # 1d <cmdline_proc_show+0xd>
                          19: R_X86_64_PC32       saved_command_line-0x4
    1d:   48 89 fd                mov    %rdi,%rbp
    20:   e8 00 00 00 00          callq  25 <cmdline_proc_show+0x15>
                          21: R_X86_64_PLT32      seq_puts-0x4
    25:   48 89 ef                mov    %rbp,%rdi
    28:   be 0a 00 00 00          mov    $0xa,%esi
    2d:   e8 00 00 00 00          callq  32 <cmdline_proc_show+0x22>
                          2e: R_X86_64_PLT32      seq_putc-0x4
    32:   31 c0                   xor    %eax,%eax
    34:   5d                      pop    %rbp
    35:   e9 00 00 00 00          jmpq   3a <cmdline_proc_show+0x2a>
                          36: R_X86_64_PLT32      __x86_return_thunk-0x4

Kpatch-build needs to gracefully handle NOP-padding when it is present.
At the same time, it should include "__pfx_<function>" symbols when
their respective functions change, but not treat prefix such functions
as first-class functions.

This also adds support for CONFIG_CFI_CLANG, which also creates prefixed
symbols with the name "__cfi_<function>".

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2023-03-16 22:05:33 -07:00
Joe Lawrence 2ddeccccb2 kpatch-elf: copy ELF e_flags from patched .o
Kernel v6.2+ commit de3d098dd1fc ("powerpc/64: Add module check for ELF
ABI version") now verifies the ELF header e_flags for its ABI value and
refuse to load modules with complaint, "Invalid module architecture in
ELF header: 21"

Like other ELF header details, copy the flags from the reference ELF
input file to the new ELF file to avoid module load errors.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-03-15 15:26:34 -07:00
Joe Lawrence 7d22fefa35 create-diff-object: ignore __patchable_function_entries
Kernel v6.2+ commit bea75b33895f ("x86/Kconfig: Introduce function
padding") introduces the -fpatchable-function-entry=16,16 build flag on
x86.  This leverages compiler support for generating a
__patchable_function_entries section similar to __mcount_loc.

That said, x86 still utilizes __mcount_loc even when
__patchable_function_entries exists.  The latter point to the __pfx
symbols, but the section is discarded in the vmlinux link and isn't used
regardless, for ftrace or for any other purpose.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-03-15 15:25:10 -07:00
Joe Lawrence 831a22bd1c
Merge pull request #1332 from sumanthkorikkar/ubsan-support
support ubsan for kpatch
2023-03-15 12:49:46 -04:00
Josh Poimboeuf 629b5acf3d kpatch-build: Fix setlocalversion issue with 6.3 kernel
The kernel has a VERMAGIC_STRING, e.g. "6.2.0".  The module loader uses
that string to ensure that all loaded modules' version strings match the
kernel's.

If the kernel source is in a git tree, and if there are uncommitted
changes, the version string will have a '+' or "-dirty" appended to it,
like "6.1.0+" or "6.2.0-dirty".  This dirty tree detection is done by
the setlocalversion script.

This affects kpatch-build in a few ways.  When it builds the original
kernel, in some cases there are uncommitted changes to the makefiles.
When it builds the patched kernel, there are additional uncommitted
changes due to the .patch file being applied.

We want to avoid the VERMAGIC_STRING changing between builds.  Otherwise
it would cause problems:

  - object code which uses that string would change unnecessarily,
    causing a false positive change detected by create-diff-object

  - the linked patch module would report the wrong version, resulting in
    the module failing to load due to version mismatch.

Up until now, the version was prevented from changing by running
`setlocalversion --save-scmversion` before the build.  That command
hard-codes the version by saving it to a file which is then
automatically read later during future invocations of the kernel build.

Unfortunately that feature was removed in the 6.3 merge window with
commit f6e09b07cc12 ("kbuild: do not put .scmversion into the source
tarball").  So we need to come up with a new approach.

Fix it by temporarily replacing the setlocalversion script with a
one-liner which just echo's the original version.  I think this is
unfortunately the best we can do, as we really can't handle
VERMAGIC_STRING changing, either during/between kernel builds or during
the module link.

Fixes #1335.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2023-03-13 14:40:24 -07:00
Sumanth Korikkar 85344cf524 support ubsan for kpatch
ubsan generates .data..Lubsan_data* sections as follows:

1. int main(int argc, char **argv) {
        int arr[100];
        arr[101] = 1;
        printf("arr[101] = %d", arr[101]);
        return 0;
}

2. 1a:   50 10 b0 ac          st      %r1,172(%r11)
      int arr[100];
      arr[101] = 1;
1e:   a7 39 00 65             lghi    %r3,101
22:   c0 20 00 00 00 00       larl    %r2,22 <main+0x22>
            24: R_390_PC32DBL       .data..Lubsan_data1+0x2
28:   c0 e5 00 00 00 00       brasl   %r14,28 <main+0x28>
            2a: R_390_PLT32DBL      __ubsan_handle_out_of_bounds+0x2

3. 0000000000000000 <.data..Lubsan_data1>:
0: R_390_64     .rodata              <=== source_location.location->file_name
8: 00 00 00 04  .long   0x00000004   <=== source_location.location->line
c: 00 00 00 05  .long   0x00000005   <=== source_location.location->column

10: R_390_64    .data..Lubsan_type0   <== source_location->array_type
18: R_390_64    .data..Lubsan_type1   <=== source_location->index_type

4. Avoid correlating the *.data.Lubsan* sections. This means
   included function points to new *.data.Lubsan* sections.

Signed-off-by: Sumanth Korikkar <sumanthk@linux.ibm.com>
2023-03-02 17:31:09 +01:00
Joe Lawrence 75421ca94c create-diff-object: batch report unsupported sibling calls
Like unsupported jump labels and static call sites, batch report all
unsupported sibling calls so the kpatch developer doesn't need to
iteratively find them all.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-02-17 11:49:38 -05:00
Joe Lawrence 6b78bd5c67 create-diff-object: support .call_sites sections
Kernel v6.2+ commits 00abd3840812 ("objtool: Add .call_sites section")
and e81dc127ef69 ("x86/callthunks: Add call patching for call depth
tracking") added .call_sites sections to object files.  These are filled
with an array of s32 values.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-01-16 09:33:55 -05:00
Joe Lawrence 934b3b3c0c kpatch-build: ignore init/version-timestamp.o
Kernel v6.1+ commit 2df8220cc511 ("kbuild: build init/built-in.a just
once") split init_uts_ns and linux_banner out to
init/version-timestamp.c from init/version.c

Add init/version-timestamp.o to the list of object files that kpatch-cc
won't add to its changed_objs list.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-01-16 09:33:55 -05:00
Joe Lawrence bb57564e60 kpatch-build: paravirt_patch_site is x86-only
Architectures like ppc64le may set CONFIG_PARAVIRT=y but do not
necessarily implement via struct paravirt_patch_site.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-01-16 09:33:55 -05:00
Josh Poimboeuf 48854d5633 create-diff-object: rename "dynrela" -> "klp_reloc"
The term "dynrela" was invented before klp relocations ever existed.
They're basically the same thing: special livepatch-specific relocations
which get applied when the patched object gets loaded or patched.
They're necessary due to a) the need to access unexported symbols; and
b) late module patching.

The different names are confusing.  Consolidate them by replacing
"dynrela" with "klp_reloc" (code) or "klp relocation" (English).

Note there's still some antiquated code in the kpatch core module and in
the pre-4.7 klp patch template which still use the "dynrela" naming.
That code is mostly dead anyway so I've just left it alone.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-12-01 14:00:09 -08:00
Josh Poimboeuf 042cde03b3 kpatch-build: fix "make check"
For some reason the github version of 'make check' just started
complaining about these:

shellcheck kpatch/kpatch kpatch-build/kpatch-build kpatch-build/kpatch-cc

In kpatch-build/kpatch-build line 455:
	while [[ "${filedir#$common/}" = "$filedir" ]]; do
                            ^-----^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.

Did you mean:
	while [[ "${filedir#"$common"/}" = "$filedir" ]]; do

In kpatch-build/kpatch-build line 460:
	result="${result}${filedir#$common/}"
                                   ^-----^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.

Did you mean:
	result="${result}${filedir#"$common"/}"

In kpatch-build/kpatch-cc line 26:
			relobj=${obj##$KPATCH_GCC_SRCDIR/}
                                      ^----------------^ SC2295 (info): Expansions inside ${..} need to be quoted separately, otherwise they match as patterns.

Did you mean:
			relobj=${obj##"$KPATCH_GCC_SRCDIR"/}

For more information:
  https://www.shellcheck.net/wiki/SC2295 -- Expansions inside ${..} need to b...
make: *** [Makefile:70: check] Error 1
Error: Process completed with exit code 2.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 19:04:23 -08:00
Josh Poimboeuf 92c178b6a3 create-diff-object: use errx() instead of err()
Otherwise on recent distros it appends the errno to the error message,
like:

  create-diff-object: ERROR: x86.o: kpatch_regenerate_special_section: 2633: Found 1 unsupported static call(s) in the patched code. Use KPATCH_STATIC_CALL() instead.: Success

which is not what we want in most cases.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf f83218ad12 create-diff-object: detect unsupported static calls
Similar to jump labels, static calls aren't supported when the static
call key was originally defined in a module rather than in vmlinux.
Detect those cases and either remove them (in the case of tracepoints)
or error out.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf 56bd8c4d0d create-diff-object: refactor jump label filtering
Convert the hard-coded should_keep_jump_label() to a proper callback,
since static calls will need a similar filter.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf 87ad96760a create-diff-object: fix s390 special_section initializer spacing
Align the s390 special_section initializers to improve readability and
for consistency with the rest.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-30 12:58:31 -08:00
Josh Poimboeuf 901445a54f create-diff-object: fix __UNIQUE_ID() variable correlation
kpatch_mangled_strcmp() only ignores the digits after the period, but in
the case of __UNIQUE_ID(), the symbol names have random digits before
the period due to the use of `__COUNTER__`.  Make sure such symbols are
properly correlated.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-11-21 19:46:18 -08:00
Josh Poimboeuf 1d7e8a74bb kpatch-build: support Linux 5.19 .cmd file format
Rewrite kobj_find() to deal with Linux 5.19, where the .cmd files use
object file paths relative to the .cmd file rather than relative to the
root of the kernel tree.

While at it, add several performance enhancements to prevent all
currently known deep finds.

This is all quite fiddly.  But it works.

Fixes #1277.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Josh Poimboeuf 7861240f48 kpatch-build: Add find_kobj() short-circuit for OOT modules
When patching an OOT module, the parent object is always the OOT module.
Hard-code that to prevent the need for any further special casing in
find_kobj() (e.g., commit 9143e88f16 ("kpatch-build: fix
find_parent_obj")).

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Josh Poimboeuf 1ead10d2b2 kpatch-cc: Add more file ignores
These files aren't in the kernel proper, and can be ignored.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2022-10-12 16:55:31 -07:00
Joe Lawrence 6507700d02
Merge pull request #1305 from joe-lawrence/llvm-from-swine
Collection of small llvm fixes
2022-10-04 10:06:23 -04:00
Joe Lawrence 13182e50b0 gcc-plugin: update headers for gcc-12
Fix build error seen on gcc (GCC) 12.1.1 20220507 (Red Hat 12.1.1-1):

  g++ -MMD -MP -I../kmod/patch -Iinsn -Wall -Wsign-compare -Wno-sign-conversion -g -Werror -shared -I/usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include -Igcc-plugins -fPIC -fno-rtti -O2 -Wall gcc-plugins/ppc64le-plugin.c -o gcc-plugins/ppc64le-plugin.so
  In file included from /usr/include/features.h:490,
                   from /usr/include/bits/libc-header-start.h:33,
                   from /usr/include/stdio.h:27,
                   from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/system.h:46,
                   from /usr/lib/gcc/ppc64le-redhat-linux/12/plugin/include/gcc-plugin.h:28,
                   from gcc-plugins/gcc-common.h:6,
                   from gcc-plugins/ppc64le-plugin.c:1:
  /usr/include/bits/error-ldbl.h:23:1: error: type of ‘error’ is unknown
     23 | __LDBL_REDIR_DECL (error)
        | ^~~~~~~~~~~~~~~~~
  /usr/include/bits/error-ldbl.h:23:1: error: ‘int error’ redeclared as different kind of entity
     23 | __LDBL_REDIR_DECL (error)
        | ^~~~~~~~~~~~~~~~~
  In file included from gcc-plugins/ppc64le-plugin.c:2:
  /usr/include/error.h:31:13: note: previous declaration ‘void error(int, int, const char*, ...)’
     31 | extern void error (int __status, int __errnum, const char *__format, ...)
        |             ^~~~~
  make[1]: *** [Makefile:39: gcc-plugins/ppc64le-plugin.so] Error 1

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-09-27 16:41:48 -04:00
Pete Swain 85781b7ea7 create-diff-object: ignore .llvm.* sections
Clang FDO adds a new, ignorable ELF section, .llvm.call-graph-profile

Generalize to ignore all .llvm.*

Signed-off-by: Pete Swain <swine@google.com>
Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com> [subject line]
2022-09-27 15:56:06 -04:00