Skip to content

Commit 4b4ed51

Browse files
committed
kpatch/LoongArch: Add initial support for kpatch
Add initial support for LoongArch. Signed-off-by: George Guo <[email protected]>
1 parent ad28ab1 commit 4b4ed51

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

kpatch-build/create-diff-object.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ static bool is_gcc6_localentry_bundled_sym(struct kpatch_elf *kelf,
180180
return false;
181181
case S390:
182182
return false;
183+
case LOONGARCH64:
184+
return false;
183185
default:
184186
ERROR("unsupported arch");
185187
}
@@ -694,6 +696,11 @@ static bool insn_is_load_immediate(struct kpatch_elf *kelf, void *addr)
694696

695697
break;
696698

699+
case LOONGARCH64:
700+
/* to be done */
701+
702+
break;
703+
697704
case S390:
698705
/* arg2: lghi %r3, imm */
699706
if (insn[0] == 0xa7 && insn[1] == 0x39)
@@ -2420,22 +2427,22 @@ static bool static_call_sites_group_filter(struct lookup_table *lookup,
24202427
static struct special_section special_sections[] = {
24212428
{
24222429
.name = "__bug_table",
2423-
.arch = X86_64 | PPC64 | S390,
2430+
.arch = X86_64 | PPC64 | S390 | LOONGARCH64,
24242431
.group_size = bug_table_group_size,
24252432
},
24262433
{
24272434
.name = ".fixup",
2428-
.arch = X86_64 | PPC64 | S390,
2435+
.arch = X86_64 | PPC64 | S390 | LOONGARCH64,
24292436
.group_size = fixup_group_size,
24302437
},
24312438
{
24322439
.name = "__ex_table", /* must come after .fixup */
2433-
.arch = X86_64 | PPC64 | S390,
2440+
.arch = X86_64 | PPC64 | S390 | LOONGARCH64,
24342441
.group_size = ex_table_group_size,
24352442
},
24362443
{
24372444
.name = "__jump_table",
2438-
.arch = X86_64 | PPC64 | S390,
2445+
.arch = X86_64 | PPC64 | S390 | LOONGARCH64,
24392446
.group_size = jump_table_group_size,
24402447
.group_filter = jump_table_group_filter,
24412448
},
@@ -2456,7 +2463,7 @@ static struct special_section special_sections[] = {
24562463
},
24572464
{
24582465
.name = ".altinstructions",
2459-
.arch = X86_64 | S390,
2466+
.arch = X86_64 | S390 | LOONGARCH64,
24602467
.group_size = altinstructions_group_size,
24612468
},
24622469
{

kpatch-build/kpatch-elf.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ unsigned int absolute_rela_type(struct kpatch_elf *kelf)
142142
return R_X86_64_64;
143143
case S390:
144144
return R_390_64;
145+
case LOONGARCH64:
146+
return R_LARCH_64;
145147
default:
146148
ERROR("unsupported arch");
147149
}
@@ -206,6 +208,7 @@ long rela_target_offset(struct kpatch_elf *kelf, struct section *relasec,
206208

207209
switch(kelf->arch) {
208210
case PPC64:
211+
case LOONGARCH64:
209212
add_off = 0;
210213
break;
211214
case X86_64:
@@ -261,6 +264,7 @@ unsigned int insn_length(struct kpatch_elf *kelf, void *addr)
261264
return decoded_insn.length;
262265

263266
case PPC64:
267+
case LOONGARCH64:
264268
return 4;
265269

266270
case S390:
@@ -593,6 +597,9 @@ struct kpatch_elf *kpatch_elf_open(const char *name)
593597
case EM_S390:
594598
kelf->arch = S390;
595599
break;
600+
case EM_LOONGARCH:
601+
kelf->arch = LOONGARCH64;
602+
break;
596603
default:
597604
ERROR("Unsupported target architecture");
598605
}

kpatch-build/kpatch-elf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ enum architecture {
116116
PPC64 = 0x1 << 0,
117117
X86_64 = 0x1 << 1,
118118
S390 = 0x1 << 2,
119+
LOONGARCH64 = 0x1 << 3,
119120
};
120121

121122
struct kpatch_elf {

0 commit comments

Comments
 (0)