From e6b1664d0ed0a70f621d90abad7a363ee31d0345 Mon Sep 17 00:00:00 2001 From: Josh Poimboeuf Date: Fri, 1 Apr 2022 17:39:18 -0700 Subject: [PATCH] create-diff-object.c: add s390 support for __LINE__ detection Technically we don't support s390 yet, but it's coming soon and there's no harm in merging this one early. In fact this came in handy for testing my endian fixes with #1203. Note it doesn't actually do anything since 'kelf->arch' can't actually get set to 'S390' yet. But it should work nicely with #1203 as it evolves. This is based on the patch from C. Erastus Toe in #1243, though there may still be a few outstanding issues to look at in that PR, based on some of the code review comments. Originally-by: C. Erastus Toe Signed-off-by: Josh Poimboeuf --- kpatch-build/create-diff-object.c | 26 ++++++++++++++++++++++---- kpatch-build/kpatch-elf.h | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c index bb09de0..22bb03e 100644 --- a/kpatch-build/create-diff-object.c +++ b/kpatch-build/create-diff-object.c @@ -579,18 +579,30 @@ out: static unsigned int insn_length(struct kpatch_elf *kelf, void *addr) { - struct insn insn; + struct insn decoded_insn; + char *insn = addr; switch(kelf->arch) { case X86_64: - insn_init(&insn, addr, 1); - insn_get_length(&insn); - return insn.length; + insn_init(&decoded_insn, addr, 1); + insn_get_length(&decoded_insn); + return decoded_insn.length; case PPC64: return 4; + case S390: + switch(insn[0] >> 6) { + case 0: + return 2; + case 1: + case 2: + return 4; + case 3: + return 6; + } + default: ERROR("unsupported arch"); } @@ -638,6 +650,12 @@ static bool insn_is_load_immediate(struct kpatch_elf *kelf, void *addr) break; + case S390: + /* lghi %r4, imm */ + if (insn[0] == 0xa7 && insn[1] == 0x49) + return true; + break; + default: ERROR("unsupported arch"); } diff --git a/kpatch-build/kpatch-elf.h b/kpatch-build/kpatch-elf.h index a593f9c..abc6efd 100644 --- a/kpatch-build/kpatch-elf.h +++ b/kpatch-build/kpatch-elf.h @@ -112,6 +112,7 @@ struct string { enum architecture { PPC64 = 0x1 << 0, X86_64 = 0x1 << 1, + S390 = 0x1 << 2, }; struct kpatch_elf {