Fix ___tls_get_addr on x86

This commit is contained in:
Jeremy Soller
2025-07-03 10:52:43 -06:00
parent 1550bb54b5
commit 84bbf90ce1
2 changed files with 21 additions and 10 deletions
+19 -8
View File
@@ -2,7 +2,7 @@
#![deny(unsafe_op_in_unsafe_fn)]
use core::alloc::Layout;
use core::{alloc::Layout, arch::global_asm};
use alloc::alloc::alloc_zeroed;
@@ -10,8 +10,8 @@ use crate::{ld_so::tcb::Tcb, platform::types::*};
#[repr(C)]
pub struct dl_tls_index {
pub ti_module: u64,
pub ti_offset: u64,
pub ti_module: usize,
pub ti_offset: usize,
}
#[no_mangle]
@@ -71,9 +71,20 @@ pub unsafe extern "C" fn __tls_get_addr(ti: *mut dl_tls_index) -> *mut c_void {
ptr.cast::<c_void>()
}
// x86 can define a version that does not require stack alignment
// x86 can define a version that passes a pointer to dl_tls_index in eax
#[cfg(target_arch = "x86")]
#[no_mangle]
pub unsafe extern "C" fn ___tls_get_addr(ti: *mut dl_tls_index) -> *mut c_void {
unsafe { __tls_get_addr(ti) }
}
global_asm!(
"
.globl ___tls_get_addr
.type ___tls_get_addr, @function
___tls_get_addr:
push ebp
mov ebp, esp
push eax
call __tls_get_addr
add esp, 4
pop ebp
ret
.size ___tls_get_addr, . - ___tls_get_addr
"
);
+2 -2
View File
@@ -520,8 +520,8 @@ impl Linker {
symbol.as_ptr()
} else {
let mut tls_index = dl_tls_index {
ti_module: obj.tls_module_id as u64,
ti_offset: symbol.value as u64,
ti_module: obj.tls_module_id,
ti_offset: symbol.value,
};
unsafe { __tls_get_addr(&mut tls_index) }