Skip to content

Commit

Permalink
riscv: Support R_RISCV_ADD64 and R_RISCV_SUB64 relocs
Browse files Browse the repository at this point in the history
These are needed for the __jump_table in modules using
static keys/jump-labels with the layout from
HAVE_ARCH_JUMP_LABEL_RELATIVE on 64bit kernels.

Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
Reviewed-by: Björn Töpel <bjorn.topel@gmail.com>
Tested-by: Björn Töpel <bjorn.topel@gmail.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>
  • Loading branch information
Emil Renner Berthing authored and Palmer Dabbelt committed Jul 30, 2020
1 parent 8e0c02f commit 11a54f4
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions arch/riscv/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,27 @@ static int apply_r_riscv_add32_rela(struct module *me, u32 *location,
return 0;
}

static int apply_r_riscv_add64_rela(struct module *me, u32 *location,
Elf_Addr v)
{
*(u64 *)location += (u64)v;
return 0;
}

static int apply_r_riscv_sub32_rela(struct module *me, u32 *location,
Elf_Addr v)
{
*(u32 *)location -= (u32)v;
return 0;
}

static int apply_r_riscv_sub64_rela(struct module *me, u32 *location,
Elf_Addr v)
{
*(u64 *)location -= (u64)v;
return 0;
}

static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
Elf_Addr v) = {
[R_RISCV_32] = apply_r_riscv_32_rela,
Expand All @@ -290,7 +304,9 @@ static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
[R_RISCV_RELAX] = apply_r_riscv_relax_rela,
[R_RISCV_ALIGN] = apply_r_riscv_align_rela,
[R_RISCV_ADD32] = apply_r_riscv_add32_rela,
[R_RISCV_ADD64] = apply_r_riscv_add64_rela,
[R_RISCV_SUB32] = apply_r_riscv_sub32_rela,
[R_RISCV_SUB64] = apply_r_riscv_sub64_rela,
};

int apply_relocate_add(Elf_Shdr *sechdrs, const char *strtab,
Expand Down

0 comments on commit 11a54f4

Please sign in to comment.