diff --git a/Cargo.lock b/Cargo.lock index ef42872f..ab94c9cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1280,6 +1280,7 @@ dependencies = [ [[package]] name = "libm" version = "0.2.8" +source = "git+https://git.alnyan.me/yggdrasil/libm.git#78b62c33fc6a56b6c063c19bbffc5224616b7028" dependencies = [ "rustc-std-workspace-core", ] diff --git a/lib/runtime/Cargo.toml b/lib/runtime/Cargo.toml index 31aecfa4..3914e490 100644 --- a/lib/runtime/Cargo.toml +++ b/lib/runtime/Cargo.toml @@ -10,7 +10,7 @@ yggdrasil-abi = { path = "../abi", features = ["alloc"] } core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" } alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" } -libm = { path = "/home/alnyan/build/sandbox/yggdrasil-packages/libm", optional = true } +libm = { git = "https://git.alnyan.me/yggdrasil/libm.git", optional = true } abi-lib = { path = "../abi-lib" } abi-serde = { path = "../abi-serde" } diff --git a/lib/runtime/build.rs b/lib/runtime/build.rs index 491503c8..c41eeb6a 100644 --- a/lib/runtime/build.rs +++ b/lib/runtime/build.rs @@ -29,13 +29,23 @@ fn build_libm() { let mut build = cc::Build::new(); let rust_target = env::var("TARGET").unwrap(); - let cc_target = rust_target.replace("-lp64", ""); + let cc_target = match rust_target.as_ref() { + "x86_64-unknown-none" | "x86_64-unknown-yggdrasil" => "x86_64-unknown-none", + "aarch64-unknown-none" | "aarch64-unknown-yggdrasil" => "aarch64-unknown-none", + "riscv64-unknown-yggdrasil" | "riscv64-unknown-none" => "riscv64-unknown-none", + _ => todo!("{rust_target:?}"), + }; build .compiler("clang") .flag("-ffreestanding") - .flag("-nostdlib") - .target(&cc_target); + .flag("-nostdlib"); + + if cc_target == "riscv64-unknown-none" { + build.flag("--target=riscv64-unknown-none"); + } else { + build.target(cc_target); + } add_file(&mut build, "libm/e_fmodf.c"); add_file(&mut build, "libm/e_hypotf.c"); diff --git a/lib/runtime/src/process/thread_local/mod.rs b/lib/runtime/src/process/thread_local/mod.rs index 45b7af43..d530c50d 100644 --- a/lib/runtime/src/process/thread_local/mod.rs +++ b/lib/runtime/src/process/thread_local/mod.rs @@ -336,7 +336,7 @@ pub fn get_dtv() -> &'static mut Dtv { unsafe extern "C" fn __tls_get_addr(index: *mut usize) -> *mut c_void { unsafe { let module_id = index.read(); - let offset = index.add(1).read(); - get_dtv().get(module_id).add(offset) + let offset = index.add(1).read() as isize; + get_dtv().get(module_id).offset(offset) } }