Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Sep 20, 2023
1 parent 9ee10ba commit 9e09e74
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions elf/arch-riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ static void write_jtype(u8 *loc, u32 val) {
}

static void write_citype(u8 *loc, u32 val) {
val += 0x800;
*(ul16 *)loc &= 0b111'0'11111'00000'11;
*(ul16 *)loc |= bit(val, 17) << 12 | bits(val, 16, 12) << 2;
*(ul16 *)loc |= bit(val, 5) << 12 | bits(val, 4, 0) << 2;
}

static void write_cbtype(u8 *loc, u32 val) {
Expand Down Expand Up @@ -415,7 +414,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
// Rewrite LUI with C.LUI
i64 rd = get_rd(rel.r_offset);
*(ul16 *)loc = 0b011'0'00000'00000'01 | (rd << 7);
write_citype(loc, S + A);
write_citype(loc, (S + A + 0x800) >> 12);
} else if (removed_bytes == 0) {
check(S + A, -(1LL << 31), 1LL << 31);
write_utype(loc, S + A);
Expand Down

0 comments on commit 9e09e74

Please sign in to comment.