Skip to content

Commit

Permalink
fix: cannot lgcc on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Chronostasys committed Aug 29, 2024
1 parent 8c2588f commit 9f0da07
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
33 changes: 31 additions & 2 deletions pl_linker/src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ fn get_linux_lib_paths() -> Vec<String> {
paths
}

// fn get_libgcc_path() -> Result<String, String> {
// let base_path = "/usr/lib/gcc/x86_64-linux-gnu";
// let entries = std::fs::read_dir(base_path).map_err(|e| format!("Failed to read directory {}: {}", base_path, e))?;

// for entry in entries {
// let entry = entry.map_err(|e| format!("Failed to read directory entry: {}", e))?;
// if entry.path().is_dir() {
// let version = entry.file_name().into_string().map_err(|e| format!("Failed to convert OsString to String: {:?}", e))?;
// return Ok(format!("{}/{}", base_path, version));
// }
// }

// Err("No valid gcc version directory found".to_string())
// }


impl Linker for LdLinker {
fn add_object(&mut self, path: &Path) -> Result<(), LinkerError> {
let path_str = path
Expand All @@ -115,9 +131,22 @@ impl Linker for LdLinker {
paths.iter().for_each(|lib| {
self.push_args(&format!("-L{}", lib.as_str()));
});
// // Add the path to the libgcc library
// match get_libgcc_path() {
// Ok(libgcc_dir) => {
// self.push_args(&format!("-L{}", libgcc_dir));
// }
// Err(e) => {
// return Err(LinkerError::LinkError(format!(
// "Failed to get libgcc path: {}",
// e
// )));
// }
// }
// libs and link args
[
"-pie",
"-no-pie",
"-fno-pie",
"-zrelro",
"--hash-style=gnu",
"--build-id",
Expand All @@ -133,7 +162,7 @@ impl Linker for LdLinker {
"-lunwind",
"--no-as-needed",
"-ldl",
"-lgcc",
// "-lgcc",
// "/usr/lib/gcc/x86_64-linux-gnu/<version>/crtendS.o",
"/lib/x86_64-linux-gnu/crtn.o",
]
Expand Down
1 change: 0 additions & 1 deletion vm/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,5 @@ fn main() {

build(&uv_src);


// println!("cargo:rustc-link-lib=static:+whole-archive=uv");
}
22 changes: 22 additions & 0 deletions vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,25 @@ fn millitime() -> i64 {

#[cfg(all(windows, feature = "jitdylib"))]
mod compiler_rt;


// const void *const __dso_handle __attribute__ ((__visibility__ ("hidden"))) = &__dso_handle;


// Declare the symbol in an extern block
#[cfg(target_os = "linux")]
extern "C" {
#[link_name = "__dso_handle"]
static __dso_handle: *const u8;
}

#[cfg(target_os = "linux")]
use std::sync::atomic::AtomicPtr;
#[cfg(target_os = "linux")]
use std::ptr;

// Define the symbol
#[cfg(target_os = "linux")]
#[no_mangle]
#[link_section = ".data"]
pub static __DSO_HANDLE: AtomicPtr<u8> = AtomicPtr::new(ptr::null_mut());

0 comments on commit 9f0da07

Please sign in to comment.