From 25794c6003efbeaf59ecff5b94c20ee238591496 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 22 Aug 2024 11:09:55 +0900 Subject: [PATCH] Refactor --- src/arch-loongarch.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/arch-loongarch.cc b/src/arch-loongarch.cc index 0916cc83d1..e793fbff5b 100644 --- a/src/arch-loongarch.cc +++ b/src/arch-loongarch.cc @@ -587,17 +587,18 @@ void InputSection::apply_reloc_alloc(Context &ctx, u8 *base) { // // Note that if section-shrinking relaxation is enabled, nop may be // completely deleted. - if (removed_bytes == 0) { - if (sym.has_tlsdesc(ctx)) + if (sym.has_tlsdesc(ctx)) { + if (removed_bytes == 0) { write_j20(loc, hi20(sym.get_tlsdesc_addr(ctx) + A, P)); - else - *(ul32 *)loc = 0x0340'0000; // nop - } else { - // Rewrite pcalau12i + addi.d with pcaddi - assert(removed_bytes == 4); - *(ul32 *)loc = 0x1800'0000 | get_rd(*(ul32 *)loc); // pcaddi - write_j20(loc, (sym.get_tlsdesc_addr(ctx) + A - P) >> 2); - i += 3; + } else { + // Rewrite pcalau12i + addi.d with pcaddi + assert(removed_bytes == 4); + *(ul32 *)loc = 0x1800'0000 | get_rd(*(ul32 *)loc); // pcaddi + write_j20(loc, (sym.get_tlsdesc_addr(ctx) + A - P) >> 2); + i += 3; + } + } else if (removed_bytes == 0) { + *(ul32 *)loc = 0x0340'0000; // nop } break; case R_LARCH_TLS_DESC_PC_LO12: