Commit Graph

18 Commits

Author SHA1 Message Date
Artem Savkov 19c4b52105 create-diff-object: -mcount-record support
4.18 adds -mcount-record to KBUILD_FLAGS when supported by the compiler.
This results in most of kpatch_create_mcount_sections()'s work being
already done, so we can at least skip the last part of it that updates
the first instruction in patched functions.

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-07-26 16:51:24 +02:00
Balbir singh 8ef31a0e92 trivial: __powerpc__ should be __powerpc64__
Since the codeset supports just the 64 bit variant, lets move
to __powerpc64__ and use it. I checked the ABI doc as well
and the kernel/gcc.

Signed-off-by: Balbir singh <bsingharora@gmail.com>
2018-06-07 17:33:06 +10:00
Artem Savkov 1638c64fe5 Fix multiple sign-compare warnings
- convert section/symbol indexes and rela->offset to unsigned int as I
    couldn't find any way for them to become negative.
  - cast a number of rela->addend comparisons to int (assuming an 64bit
    system this should be enough)
  - a number of simple for-loop counter conversions to the type it
    compares against

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2018-04-13 16:26:06 +02:00
Joe Lawrence 321bbf9417 kpatch-build: clear Elf_Data d_buf buffer on allocation
Valgrind complains about uninitialized bytes passed to pwrite64(buf)
from kpatch_write_output_elf()'s call to elf_update():

  ==32378== Syscall param pwrite64(buf) points to uninitialised byte(s)
  ==32378==    at 0x5141A03: __pwrite_nocancel (in /usr/lib64/libc-2.23.so)
  ==32378==    by 0x4E46846: ??? (in /usr/lib64/libelf-0.168.so)
  ==32378==    by 0x4E42B88: elf_update (in /usr/lib64/libelf-0.168.so)
  ==32378==    by 0x40C57A: kpatch_write_output_elf (kpatch-elf.c:895)
  ==32378==    by 0x40926F: main (create-diff-object.c:2851)
  ==32378==  Address 0x28d52300 is 0 bytes inside a block of size 56 alloc'd
  ==32378==    at 0x4C2BBAD: malloc (vg_replace_malloc.c:299)
  ==32378==    by 0x40B86A: create_section_pair (kpatch-elf.c:707)
  ==32378==    by 0x406CAE: kpatch_create_patches_sections (create-diff-object.c:2109)
  ==32378==    by 0x4090C5: main (create-diff-object.c:2815)

These are fields which we don't need to populate (like a
funcs[index].new_addr value that will be filled by relocation).  The
easiest way to appease valgrind and not clutter the code is to just
zero-out this entire buffer on allocation.

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2017-10-03 16:42:28 -04:00
Josh Poimboeuf b72027c44e kpatch-build: do symbol/section bundling in create-diff-object
kpatch-elf.c is used by binaries other than create-diff-object, but
create-diff-object is the only one that cares about "bundling".  Move
the bundling to create-diff-object.

Fixes #700.

Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
2017-09-20 23:57:31 -05:00
Josh Poimboeuf 339938c0a9 kpatch-build: clarify ppc64le comments
Clarify some of the comment wording in the new ppc64le code.
2017-07-27 15:23:26 -05:00
Kamalesh Babulal e3ccff0cab kpatch-build: Support gcc-6 function prologue
With gcc-6 the function prologue is changeg by
moving the toc base resolution func - 0x8 bytes:

        .globl my_func
        .type my_func, @function
        .quad .TOC.-my_func
my_func:
        .reloc ., R_PPC64_ENTRY ; optional
        ld r2,-8(r12)
        add r2,r2,r12
        .localentry my_func, .-my_func

Add support for function prologue, along with gcc-5.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-27 12:56:00 +05:30
Kamalesh Babulal c14e6e9118 kpatch-build: Add PPC64le livepatch support
This patch adds support for livepatch hook based module
creation for PPC64le. It introduces PPC64le architecture
bits:
- Add relocation type of R_PPC64_ADDR64 while parsing powerpc ELF.
- Introduce .toc sections mainpulation.
- Skip kpatch specific details for livepatch hook.

Also remove the definition of rela_insn() for powerpc. The only
call site is been guarded by #ifdef x86.

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:40:37 +05:30
Kamalesh Babulal c9e4230d88 kpatch-build: Rename fentry instances to func_profiling
symbol->has_fentry_call is x86 specfic. Rename it to more
generic name, representing the general idea of calling
profiling function at function entry.

This patch converts all instance of symbol->has_fentry_call
to symbol->has_func_profiling and also renames functions:
kpatch_check_fentry_calls() -> kpatch_check_func_profiling_calls()
kpatch_find_fentry_calls() -> kpatch_find_func_profiling_calls()

Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Signed-off-by: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
2017-07-26 14:40:33 +05:30
Josh Poimboeuf 2b39f7d8d8 elf: add .eh_frame* sections to debug section list
SUSE-based kernels have a DWARF unwinder, so they build with the gcc
'-fasynchronous-unwind-tables' flag, which adds .eh_frame and
.eh_frame_hdr sections.  Treat those sections like the other debug
sections.

Fixes: #703
2017-05-11 14:02:08 -05:00
Jessica Yu 900d28fe75 kpatch-elf: add find_rela_by_offset()
Add find_rela_by_offset(), which, given a relocation section and offset,
will return the rela struct with the matching offset.
2017-01-23 12:43:27 -08:00
Jessica Yu 52e2ad66ca kpatch-elf: add kpatch_remove_and_free_section()
Add kpatch_remove_and_free_section(), which, given a section name,
removes and frees all matching sections from the passed in kpatch_elf.
2017-01-23 12:43:05 -08:00
Jessica Yu dac26b8cb2 kpatch-elf: for rela sections, find base section by index rather than name
If there exist multiple sections with the same name (which can happen when
using the --unique option with ld, which will be used to keep multiple
(per-object) .parainstructions and .altinstructions sections separate),
find_section_by_name() will only return the first section name match, which
leads to incorrect base section assignments for rela sections. Fix this by
using the sh_info field of the rela section to find its base section
instead, which contains the index of the section to which the relocation
applies.
2017-01-23 12:43:00 -08:00
Jessica Yu a3108de96a kpatch-elf: fix null dereference when sym->sec is NULL
Make sure sym->sec is not NULL before checking for its rela section
(sym->sec->rela). This fixes a case where an object may have STT_FUNC
symbols whose the sections (sym->sec) were not selected for inclusion (or
are located in another object) and hence these symbols do not have sym->sec
set. This corner case only recently popped up after reusing kpatch_elf_open()
on objects that have been outputted by create-diff-object (and these
objects only contain the necessary sections needed for the patch module).

This will also automatically exclude livepatch symbols from the check,
because they do not have sections associated with them (i.e., sym->sec is
NULL). We do not have to check for fentry calls for klp (SHN_LIVEPATCH)
symbols, because [1] they do not have sections associated with them, [2]
they are not the target functions to be patched, and [3] they are
technically just placeholder symbols for symbol resolution in livepatch.
2017-01-23 12:42:56 -08:00
Jessica Yu 91909e9273 kpatch-elf: ensure SHN_LIVEPATCH syms don't get set to SHN_UNDEF when reindexing elements 2017-01-23 12:42:52 -08:00
Jessica Yu 2c3c44fec2 kpatch-elf: add kpatch_reindex_elements() and kpatch_rebuild_rela_section_data()
Move functions kpatch_reindex_elements() and kpatch_rebuild_rela_section_data()
from create-diff-object.c to kpatch-elf.c. These functions will be used
to rebuild kpatch elf data in create-klp-module and create-kpatch-module,
i.e. during the second "phase" of kpatch-build.
2017-01-23 12:42:47 -08:00
Jessica Yu a343edcff0 kpatch-elf: make is_bundleable() a static function
Since is_bundleable() is only called once by kpatch_create_symbol_list(),
and no other kpatch-build tool will need to call this function, we can
simply make it static and local to kpatch-elf.c
2016-07-12 14:45:18 -07:00
Jessica Yu adcd4581cc kpatch-elf: introduce a common kpatch-elf and logging interface
Introduce a common kpatch elf api by moving all functions and struct
declarations related to manipulating kpatch_elf objects from
create-diff-object to kpatch-elf.{h,c}. Move logging macros to a separate
file log.h, and have kpatch-elf.h include it. These changes will generalize
the kpatch-elf and logging api and make it available to other kpatch-build
tools.
2016-07-12 14:45:16 -07:00