Merge pull request #186 from spartacus06/dynamic-symbol-linking

add dynamic symbol linking support
fix list corruption in special section handlers

The kpatch_regenerate_* functions use a local list_head to construct the
new list.  While the local list_head is copied to the sec->relas after
it is built, the neighboring nodes in the list are not updated, leading
to list corruption.

This commit uses list_replace() which updates the neighbor nodes properly.

Regression introduced by PR #117 5d36dd1.

Fixes #185.

Signed-off-by: Seth Jennings <sjenning@redhat.com>
Merge pull request #188 from spartacus06/fix-list-corruption

fix list corruption in special section handlers
test: do load/unload testing for modules that don't have tests

Do some basic load/unload tests for all the test modules, even if they
don't have a corresponding -LOADED.test file.
test: add make targets
test: add basic tests for special sections

One of the tests is now failing:

    ERROR: smp-locks-section: kpatch replace failed

I suspect the issue is the vmlinux mismatch problem.  Fix for that
coming soon.
Merge pull request #190 from jpoimboe/test-special-sections

add tests for special sections
Revert #186 (add dynamic symbol linking support)

We merged PR #186 a little too hastily.  It seg faults with the new
parainstructions-section.patch in the integration test suite.  Reverting
it for now until we get it figured out.

This reverts commit e1177e3a03d28858181d577745b159cd7ba694b0.
This reverts commit 880e271841177551ccf20e7c758a666ad813c196.
This reverts commit 2de5f6cbfb43ca4db2ecdb62770647f9d7c8ee6b.
This reverts commit 38b7ac74ad9d1eafac17721af5841b184dfda00d.
This reverts commit 108cd9f95ebfb69d81ef0a6ea41de23212d9cfc1.
Merge pull request #191 from jpoimboe/revert-dynamic

Revert #186 (add dynamic symbol linking support)
kpatch-build: use original vmlinux

There's at least one case in the kernel (ddebug_proc_show) where the
compiled instructions are affected by the source file path given to gcc.
Which means that compiling the kernel with O= will result in many of the
function addresses changing.  This causes a mismatch between the locally
compiled vmlinux and the original vmlinux, which is very dangerous,
since we need the addresses to be correct.

The easy fix is just to use the original vmlinux for all the function
addresses.

Other potential ways to fix it which we might want to consider in the
future:

- use a combination of the old System.map and the new vmlinux to find
  the addresses.  The function ordering should be the same.  For
  non-duplicate symbols, use System.map.  For duplicate symbols, use
  vmlinux to find what order the symbol comes in.  e.g. the 2nd
  occurrence of foo() in System.map.  It adds a little complexity to the
  lookup code, but seems safe and wouldn't require the kernel debuginfo
  package.  However, this may not help us for patching modules.

- do something similar at runtime, i.e. use kallsyms_lookup_name for
  non-dups and kallsyms_on_each_symbol for dups, and look for the nth
  occurrence of the symbol (value of n is decided at build time).  This
  has the complexity of the previous option but it's done at runtime
  rather than build time, so... why?  Doing it at build time is better.

- compile the kernel in place.  This basically means no more caching
  because recompiling with --function-sections causes everything to be
  recompiled again.  This is bad for kpatch developers' SSDs...
Merge pull request #192 from jpoimboe/vmlinux-mismatch

kpatch-build: use original vmlinux
cleanup: remove unneeded patches variable

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>
fix seg fault on parainstructions change

The .parainstructions section is not bundled with a function symbol and,
therefore, doesn't have a function symbol that references the text
section.  The only symbolic reference to the .parainstruction section is
the SECTION symbol itself.  This symbolic reference is needed by the new
dynrelas code to reference the section data.

This commit ensures that if the .parainstruction bundle (text or rela
section) has changed, the section symbol is also included so that the
dynrela entry can reference the text section.  The dynrela generation
code is updated to use the section symbol as a fallback if there is no
function symbol that pairs with the text section.

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