From 32077ee341ed7fe3fde862ad0e32881ce4c1a21e Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Thu, 5 Dec 2024 23:33:41 +1100 Subject: [PATCH] fix(ld.so): set tls module id to 0 if no tls Signed-off-by: Anhad Singh --- src/ld_so/dso.rs | 6 +++++- src/ld_so/linker.rs | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ld_so/dso.rs b/src/ld_so/dso.rs index b8322ba41a..62d20aae81 100644 --- a/src/ld_so/dso.rs +++ b/src/ld_so/dso.rs @@ -100,7 +100,11 @@ impl DSO { dependencies: elf.libraries.iter().map(|s| s.to_string()).collect(), init_array: init_array, fini_array: fini_array, - tls_module_id: tls_module_id, + tls_module_id: if tcb_master.is_some() { + tls_module_id + } else { + 0 + }, tls_offset: tls_offset, }; return Ok((dso, tcb_master)); diff --git a/src/ld_so/linker.rs b/src/ld_so/linker.rs index 9e15266c01..175cb62a8d 100644 --- a/src/ld_so/linker.rs +++ b/src/ld_so/linker.rs @@ -201,6 +201,11 @@ impl Linker { tcb.setup_dtv(tcb_masters.len()); for obj in new_objects.iter() { + if obj.tls_module_id == 0 { + // No TLS for this object. + continue; + } + if cfg!(any(target_arch = "x86", target_arch = "x86_64")) { // Below the TP tcb.dtv_mut().unwrap()[obj.tls_module_id - 1] =