From 6d8e6afbf208e4aedda88fc44c9755e997f8ac91 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 23 Feb 2024 17:14:23 +0900 Subject: [PATCH] Fix R_PPC64_DTPREL16_LO_DS Fixes https://github.com/rui314/mold/issues/1192 --- elf/arch-ppc64v1.cc | 2 +- elf/arch-ppc64v2.cc | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/elf/arch-ppc64v1.cc b/elf/arch-ppc64v1.cc index 6f3550dff4..3a46b469ff 100644 --- a/elf/arch-ppc64v1.cc +++ b/elf/arch-ppc64v1.cc @@ -263,7 +263,7 @@ void InputSection::apply_reloc_alloc(Context &ctx, u8 *base) { *(ub16 *)loc = lo(S + A - ctx.dtp_addr); break; case R_PPC64_DTPREL16_LO_DS: - *(ub16 *)loc |= ((S + A - ctx.dtp_addr) & 0x3fff) << 2; + *(ub16 *)loc |= (S + A - ctx.dtp_addr) & 0xfffc; break; case R_PPC64_TPREL16_HA: *(ub16 *)loc = ha(S + A - ctx.tp_addr); diff --git a/elf/arch-ppc64v2.cc b/elf/arch-ppc64v2.cc index b253a1f54d..76f37a2feb 100644 --- a/elf/arch-ppc64v2.cc +++ b/elf/arch-ppc64v2.cc @@ -319,6 +319,9 @@ void InputSection::apply_reloc_alloc(Context &ctx, u8 *base) { case R_PPC64_DTPREL16_LO: *(ul16 *)loc = lo(S + A - ctx.dtp_addr); break; + case R_PPC64_DTPREL16_LO_DS: + *(ul16 *)loc |= (S + A - ctx.dtp_addr) & 0xfffc; + break; case R_PPC64_DTPREL34: write34(loc, S + A - ctx.dtp_addr); break; @@ -475,6 +478,7 @@ void InputSection::scan_relocations(Context &ctx) { case R_PPC64_TLSLD: case R_PPC64_DTPREL16_HA: case R_PPC64_DTPREL16_LO: + case R_PPC64_DTPREL16_LO_DS: case R_PPC64_DTPREL34: break; default: