Skip to content

Commit

Permalink
fix: add more sub set relocate handlers
Browse files Browse the repository at this point in the history
Signed-off-by: Hanyuan Zhao <hanyuan-z@qq.com>
  • Loading branch information
gtxzsxxk committed Nov 19, 2023
1 parent 842095e commit e9ee3cf
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions arch/riscv/kernel/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,28 @@ static int apply_r_riscv_add64_rela(struct module *me, u32 *location,
return 0;
}

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

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

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

static int apply_r_riscv_sub32_rela(struct module *me, u32 *location,
Elf_Addr v)
{
Expand All @@ -284,6 +306,35 @@ static int apply_r_riscv_sub64_rela(struct module *me, u32 *location,
return 0;
}

static int apply_r_riscv_set6_rela(struct module *me, u32 *location,
Elf_Addr v)
{
*(u8 *)location &= 0xc0;
*(u8 *)location |= (u8)v & 0x3f;
return 0;
}

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

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

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

static int apply_r_riscv_pcrel_32_rela(struct module *me, u32 *location,
Elf_Addr v)
{
Expand Down Expand Up @@ -313,8 +364,15 @@ static int (*reloc_handlers_rela[]) (struct module *me, u32 *location,
[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_SUB6] = apply_r_riscv_sub6_rela,
[R_RISCV_SUB8] = apply_r_riscv_sub8_rela,
[R_RISCV_SUB16] = apply_r_riscv_sub16_rela,
[R_RISCV_SUB32] = apply_r_riscv_sub32_rela,
[R_RISCV_SUB64] = apply_r_riscv_sub64_rela,
[R_RISCV_SET6] = apply_r_riscv_set6_rela,
[R_RISCV_SET8] = apply_r_riscv_set8_rela,
[R_RISCV_SET16] = apply_r_riscv_set16_rela,
[R_RISCV_SET32] = apply_r_riscv_set32_rela,
[R_RISCV_32_PCREL] = apply_r_riscv_pcrel_32_rela,
};

Expand Down

0 comments on commit e9ee3cf

Please sign in to comment.