cleanup: remove unneeded patches variable

Signed-off-by: Seth Jennings <sjenning@redhat.com>
fix included syms pointing to non-included sections

Right now, there is a case where a symbol is included but not its
section.  This is the case when the symbol is a rela dependency of
another section by the symbol section (the object or function) has not
changed.  When we migrate the included symbols over to the output kelf
structure however, these symbols are still referencing their old
non-included section via their sec fields.  This is a bug.

This commit adds code to the symbol migration to test whether the
symbol's section was also included.  If so, it updates the symbol's
section index.  If not it sets the section index to UNDEF and its sec
field to NULL.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
merge add-patches-section functionality into create-obj-diff

In preparation for dynamic symbol linking, the symbol lookup logic
is going to move into create-diff-obj anyway.  We might as well
minimize the code duplication and pull this into create-diff-obj.
This avoids having to re-parse the ELF file modify it in-place.

Signed-off-by: Seth Jennings <sjenning@redhat.com>

Conflicts:
	kpatch-build/kpatch-build
rename .patches section to .kpatch.patches

Adding .kpatch to the section name more clearly documents that these
are kpatch related sections.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
dynrelas support, obsoleting link-vmlinux-syms

This adds dynamic linking support for the patch modules.  It is the
first step toward supporting patching module code and relocatable
kernels.

Rela entries that reference non-included local and non-exported global
symbols are converted to "dynrelas".  These dynrelas are relocations
that are done by the core module, not the kernel module linker.  This
allows the core module to apply offsets to the base addresses found
in the base vmlinux or module.

Signed-off-by: Seth Jennings <sjenning@redhat.com>

Conflicts:
	kpatch-build/kpatch-build
fix review comments

Signed-off-by: Seth Jennings <sjenning@redhat.com>
remove redundant rela buffer rebuild

We rebuild the rela section data buffer in kpatch_create_rela_section()
just to rebuild it again later in kpatch_rebuild_rela_section_data()
before writing the output ELF file.

This commit removes the redundant rebuild while retaining the update
for the section header data.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
add teardown/free functions for kpatch_elf data structures

Because create-diff-object is a one-shot program (not a long lived
process) we haven't really bothered with cleaning up and freeing any
allocated memory.  However, freeing data when it passes out of the
logical scope does have debugging benefits.

This commit adds two new functions for tearing down and freeing the
primary struct kpatch_elf data structures.  The idea is the if a stale
pointer still references the old data structure that has passed out of
the logical scope, an issue will be more immediately apparent (i.e. NULL
references).

Signed-off-by: Seth Jennings <sjenning@redhat.com>
Merge pull request #196 from spartacus06/dynamic-symbol-linking

add dynamic symbol linking support (again)
test: tell user to check test.log on error
Merge pull request #197 from jpoimboe/test-log-message

test: tell user to check test.log on error
kpatch: prevent installing a duplicate patch module
kpatch: uninstall should only look in user-installed dir
kpatch: get rid of system-installed modules

The user-installed vs system-installed dichotomy is confusing.  Let's
just have "installed".  RPM-installed modules can just call "kpatch
install" in their post-install step.
kpatch: change --kver to --kernel-version
Merge pull request #199 from jpoimboe/kpatch-install-refactor

kpatch: get rid of system-installed modules
kpatch-build: put cache in ~/.kpatch/src

Since we only ever have one cache at a time, move the kernel source from
~/.kpatch/$(uname -r)/src to ~/.kpatch/src.  This allows ccache to work
between kernel version changes, making it less painful to build for
multiple kernels.  The cache's kernel version is stored in
~/.kpatch/version.
Merge pull request #200 from jpoimboe/kb-cachedir

kpatch-build: put cache in ~/.kpatch/src
delay element reindexing and symbol reordering

Right now, reindexing of the included sections and symbols is done
when they migrate to the output kpatch_elf structure.  However, due
to recently added features, the section and symbol list is not
final at this point, leading to constant tracking of the indexes for
addition sections and symbols added after this point.  Additionally,
symbols have to be in a particular order, adding to the complexity.

This commit delays the reindexing and symbol reordering until the
section and symbol lists are finalized, removing the need to
track indexes and placeholders in the symbol list.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
Merge pull request #201 from spartacus06/delay-reindexing-reordering

delay element reindexing and symbol reordering