Skip to content

Fix addend handling and other cleanups for s390#1269

Merged
jpoimboe merged 17 commits intodynup:masterfrom
jpoimboe:reloc-addend
May 19, 2022
Merged

Fix addend handling and other cleanups for s390#1269
jpoimboe merged 17 commits intodynup:masterfrom
jpoimboe:reloc-addend

Conversation

@jpoimboe
Copy link
Member

Several improvements for issues discovered in the review for #1203 .Mostly related to addend handling, but also some other cleanups and an endianness fix.

jpoimboe added 13 commits May 11, 2022 13:55
With '--debug', most of the xtrace output shows the reading of the
.config and Module.symvers files, which isn't very useful and floods the
rest of the xtrace output.  Temporarily disable xtrace before reading
the files.

Signed-off-by: Josh Poimboeuf <[email protected]>
These functions are only called locally, convert them to static.

Signed-off-by: Josh Poimboeuf <[email protected]>
Several functions expect to take a ".rela" section as an argument.  Make
such cases more clear by renaming "sec" -> "relasec".

Signed-off-by: Josh Poimboeuf <[email protected]>
Several functions have a boolean semantic, but don't actually return
bool, which is confusing.  Fix that.

Signed-off-by: Josh Poimboeuf <[email protected]>
It doesn't make sense to disassemble a data section.  That just happened
to work by accident.  PC-relative offsets only need adjusting when
associated with an instruction.

Signed-off-by: Josh Poimboeuf <[email protected]>
…syms()

Add support for R_X86_64_NONE.  With an upstream kernel, it's quite
rare, only used for a few jump labels.  With older kernels it was used
for fentry hooks.  Either way, it should be treated like a PC-relative
relocation.

Signed-off-by: Josh Poimboeuf <[email protected]>
Error out if an unsupported rela is encountered.  This is more robust
than just ignoring it.

Signed-off-by: Josh Poimboeuf <[email protected]>
rela_insn() only cares about the base section.  Convert it to take a
non-rela section as its argument instead of a relasec.

Signed-off-by: Josh Poimboeuf <[email protected]>
Error out if the insn can't be found.

Signed-off-by: Josh Poimboeuf <[email protected]>
Split out the addend offset math into a separate function so it can be
used elsewhere.

Signed-off-by: Josh Poimboeuf <[email protected]>
This issue was only seen in in a text section.  Explicitly check for
that.

Signed-off-by: Josh Poimboeuf <[email protected]>
Empty (zero-length) symbols are possible, allow
kpatch_replace_sections_syms() to work on them.

Signed-off-by: Josh Poimboeuf <[email protected]>
…bols

These sections don't have symbols.  Don't even try to replace references
to them with symbols.

Signed-off-by: Josh Poimboeuf <[email protected]>
@joe-lawrence
Copy link
Contributor

Hi @jpoimboe ,

Check out the internal automated integration test failure emails, there are various complaints like these:

create-diff-object: ERROR: af_netlink.o: kpatch_replace_sections_syms: 1609: .text.jhash+0x95: 
can't find replacement symbol for .rodata.jhash+0 reference

create-diff-object: ERROR: sys.o: kpatch_replace_sections_syms: 1609: .text.prctl_set_mm+0x1c7:
can't find replacement symbol for .rodata.prctl_set_mm+0 reference

create-diff-object: ERROR: fib_frontend.o: kpatch_replace_sections_syms: 1609: .text.rtm_to_fib_config+0x13a:
can't find replacement symbol for .rodata.rtm_to_fib_config+0 reference

create-diff-object: ERROR: array.o: kpatch_replace_sections_syms: 1609: .text.proc_pid_status+0x619:
can't find replacement symbol for .rodata.proc_pid_status+0 reference

@jpoimboe
Copy link
Member Author

Going to squash in this change to fix the integration failures:

diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c
index 8345b16..bebe3bd 100644
--- a/kpatch-build/create-diff-object.c
+++ b/kpatch-build/create-diff-object.c
@@ -1604,7 +1604,7 @@ static void kpatch_replace_sections_syms(struct kpatch_elf *kelf)
                        }
 
                        if (!found && !is_string_literal_section(rela->sym->sec) &&
-                           strcmp(rela->sym->name, ".rodata")) {
+                           strncmp(rela->sym->name, ".rodata", 7)) {
                                ERROR("%s+0x%x: can't find replacement symbol for %s+%ld reference",
                                      relasec->base->name, rela->offset, rela->sym->name, rela->addend);
                        }

jpoimboe added 4 commits May 17, 2022 19:27
If a section reference can't be converted to a symbol reference, error
out to try to prevent unexpected behavior later on.

There are a few sections for which a symbol is optional: .rodata and
string literal sections.  Don't warn about those.

Signed-off-by: Josh Poimboeuf <[email protected]>
The current string extraction is broken for non-section symbols.  Fix
that.

Signed-off-by: Josh Poimboeuf <[email protected]>
Use rela_target_offset() to make the relocation bounds checking more
precise.

Signed-off-by: Josh Poimboeuf <[email protected]>
Otherwise it fails the unit tests on an s390 host.

Signed-off-by: Josh Poimboeuf <[email protected]>
@jpoimboe
Copy link
Member Author

v2:

  • refine .rodata check in missing replacement symbol warning

@jpoimboe jpoimboe merged commit f6e1838 into dynup:master May 19, 2022
@jpoimboe jpoimboe mentioned this pull request May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants