Skip to content

Commit

Permalink
[LoongArch] Fix TLSDESC relaxation
Browse files Browse the repository at this point in the history
R_LARCH_TLS_DESC_PC_HI20 is a GOT-loading relocation, so we need to
compute the distance to the symbol's GOT entry instead of to the
symbol's address.
  • Loading branch information
rui314 committed Aug 21, 2024
1 parent 6a1742e commit 127ba25
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/arch-loongarch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,9 @@ void shrink_section(Context<E> &ctx, InputSection<E> &isec, bool use_rvc) {
rels[i + 2].r_type == R_LARCH_TLS_DESC_PC_LO12 &&
rels[i + 2].r_offset == rels[i].r_offset + 4 &&
rels[i + 3].r_type == R_LARCH_RELAX) {
i64 dist = compute_distance(ctx, sym, isec, r);
u64 P = isec.get_addr() + r.r_offset;
i64 dist = sym.get_tlsdesc_addr(ctx) + r.r_addend - P;

u32 insn1 = *(ul32 *)(isec.contents.data() + rels[i].r_offset);
u32 insn2 = *(ul32 *)(isec.contents.data() + rels[i].r_offset + 4);

Expand Down

0 comments on commit 127ba25

Please sign in to comment.