From d1a86c850eaeb4a9474914787052ba2d412dd23f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 11 Nov 2022 10:08:00 -0700 Subject: [PATCH] Hack to use the correct TLS size for the first TLS module --- src/ld_so/linker.rs | 8 ++++++++ src/ld_so/start.rs | 8 +------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ld_so/linker.rs b/src/ld_so/linker.rs index 53ce3e5e4e..ab52f6375c 100644 --- a/src/ld_so/linker.rs +++ b/src/ld_so/linker.rs @@ -28,6 +28,7 @@ use super::{ debug::{RTLDState, _dl_debug_state, _r_debug}, dso::{is_pie_enabled, DSO}, tcb::{round_up, Master, Tcb}, + ExpectTlsFree, PATH_SEP, }; @@ -226,6 +227,13 @@ impl Linker { self.next_object_id += 1; if let Some(master) = tcb_master { + if self.next_tls_module_id == 0 { + // Hack to allocate TCB on the first TLS module + unsafe { + let tcb = Tcb::new(master.offset).expect_notls("failed to allocate TCB"); + tcb.activate(); + } + } self.next_tls_module_id += 1; self.tls_size = master.offset; tcb_masters.push(master); diff --git a/src/ld_so/start.rs b/src/ld_so/start.rs index b19b4ac414..4a395ffec4 100644 --- a/src/ld_so/start.rs +++ b/src/ld_so/start.rs @@ -17,7 +17,7 @@ use crate::{ ALLOCATOR, }; -use super::{access::accessible, debug::_r_debug, linker::Linker, tcb::Tcb, ExpectTlsFree, PATH_SEP}; +use super::{access::accessible, debug::_r_debug, linker::Linker, tcb::Tcb, PATH_SEP}; use crate::header::sys_auxv::{AT_ENTRY, AT_PHDR}; use goblin::elf::header::header64::SIZEOF_EHDR; @@ -213,12 +213,6 @@ pub extern "C" fn relibc_ld_so_start(sp: &'static mut Stack, ld_entry: usize) -> } }; - // Ensure there is a stub Tcb - unsafe { - let tcb = Tcb::new(0).expect_notls("failed to allocate TCB"); - tcb.activate(); - } - // if we are not running in manual mode, then the main // program is already loaded by the kernel and we want // to use it. on redox, we treat it the same.