From b887ad1ce649329043c72eae97249cd3f971d678 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 7 May 2025 21:04:31 -0600 Subject: [PATCH] Fix DTPOFF relocation --- src/ld_so/dso.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ld_so/dso.rs b/src/ld_so/dso.rs index 0886fc1275..6688ce75fd 100644 --- a/src/ld_so/dso.rs +++ b/src/ld_so/dso.rs @@ -862,13 +862,17 @@ impl DSO { match reloc.kind { RelocationKind::DTPMOD => set_usize(self.tls_module_id), + //TODO: Subtract DTP_OFFSET, which is 0x800 on riscv64, 0 on x86? RelocationKind::DTPOFF => { - if s != 0 { - set_usize(s - b); + if reloc.sym.0 > 0 { + let (sym, _) = sym + .as_ref() + .expect("RelocationKind::DTPOFF called without valid symbol"); + set_usize(sym.value + a); } else { - set_usize(s); + set_usize(a); } - } + }, RelocationKind::GOT => set_usize(s), RelocationKind::OFFSET => set_usize((s + a).wrapping_sub(p)), RelocationKind::RELATIVE => set_usize(b + a),