diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs deleted file mode 100644 index 86df120..0000000 --- a/.git-blame-ignore-revs +++ /dev/null @@ -1 +0,0 @@ -21ef5f60a3a5efa17855a30f6b5c7d1968cd46ba diff --git a/docs/src/quick_start.md b/docs/src/quick_start.md index 9f15ebe..e3ac164 100644 --- a/docs/src/quick_start.md +++ b/docs/src/quick_start.md @@ -32,7 +32,7 @@ Run your application like this: * Alternative method ``` - LD_PRELOAD="/zluda_preload" + LD_AUDIT="/zluda_ld:$LD_AUDIT" ``` where `` is the directory which contains ZLUDA-provided `libcuda.so`: `zluda` if you downloaded a prebuilt package or `target/release` if you built from sources. diff --git a/ptx/src/pass/insert_explicit_load_store.rs b/ptx/src/pass/insert_explicit_load_store.rs index 2805dfa..3350a82 100644 --- a/ptx/src/pass/insert_explicit_load_store.rs +++ b/ptx/src/pass/insert_explicit_load_store.rs @@ -309,9 +309,7 @@ impl<'a, 'input> InsertMemSSAVisitor<'a, 'input> { match remap { RemapAction::PreLdPostSt { .. } => {} RemapAction::LDStSpaceChange { - name, - new_space, - old_space, + name, new_space, .. } => { let generic_var = self .resolver diff --git a/zluda_ld/README.md b/zluda_ld/README.md deleted file mode 100644 index d5b28a4..0000000 --- a/zluda_ld/README.md +++ /dev/null @@ -1,21 +0,0 @@ -This crate is a last resort Linux-specific solution. -Most of the time we can inject ourselves into a process by having users -set `LD_LIBRARY_PATH`. -Unfortunately, there is software out there which dynamically links to CUDA and -CUDA performance libraries using RPATH. On Linux, dynamic linker operates -using approximately this algorithm: -* If path contains `/` treat the name as a (possibly relative) path and just use it -* Otherwise return the first that succeeds: - * Library with this name already loaded into the process - * Try paths in `DT_RPATH` (if `DT_RUNPATH` is not present) - * Try paths in `LD_LIBRARY_PATH` - * Try paths in `DT_RUNPATH` - * Try system paths - -In order to defeat `DT_RPATH` this library needs to be preloaded with `LD_PRELOAD`. -On initialization we also preload all the performance libraries. We also hijack -`dlopen` and on every call to `dlopen` that tries to open a CUDA library we -redirect it to our libraries - -We also expose `zluda_dlopen_noredirect` for the purpose of tracing libraries -so they can load real underlying library and not just get redirected to themselves diff --git a/zluda_ld/src/lib.rs b/zluda_ld/src/lib.rs index e73f769..110c0b3 100644 --- a/zluda_ld/src/lib.rs +++ b/zluda_ld/src/lib.rs @@ -36,8 +36,10 @@ static FILES_FOR_REDIRECT: [&'static str; 14] = [ // Global state, caching some computations that would be otherwise repeated struct GlobalState { - /// The full paths of the file names from `FILES_FOR_REDIRECT` that will be used for redirection + // The full paths of the file names from `FILES_FOR_REDIRECT` that will be used for redirection replacement_paths: Option<[Vec; FILES_FOR_REDIRECT.len()]>, + // List of cookies saved for each redirected file, to avoid self-redirecting + // when e.g. zluda_trace_blas (libcuda.so) tries to load the real libcublas.so cookies: Mutex<[usize; FILES_FOR_REDIRECT.len() / 2]>, } @@ -141,8 +143,7 @@ unsafe fn save_cookie(map: *mut link_map, cookie: *mut usize) -> Option<()> { .get_mut(index) .map(|saved_cookie| { *saved_cookie = cookie as usize; - }); - Some(()) + }) } // Public portion of glibc's struct link_map. Additional private fields omitted. diff --git a/zluda_trace_common/src/lib.rs b/zluda_trace_common/src/lib.rs index b7ef00d..547e982 100644 --- a/zluda_trace_common/src/lib.rs +++ b/zluda_trace_common/src/lib.rs @@ -47,9 +47,8 @@ pub fn dlopen_local_noredirect<'a>( #[cfg(unix)] pub(crate) mod os { - use libc::{c_char, c_int}; use libloading::os; - use std::{borrow::Cow, ffi::c_void, mem}; + use std::borrow::Cow; pub fn open_driver() -> Result { unsafe { @@ -67,29 +66,7 @@ pub(crate) mod os { pub unsafe fn dlopen_local_noredirect<'a>( path: Cow<'a, str>, ) -> Result { - fn terminate_with_nul<'a>(path: Cow<'a, str>) -> Cow<'a, str> { - let path = if !path.ends_with('\0') { - let mut path = path.into_owned(); - path.push('\0'); - Cow::Owned(path) - } else { - path - }; - path - } - let zluda_dlopen_noredirect = - unsafe { libc::dlsym(libc::RTLD_DEFAULT, c"zluda_dlopen_noredirect".as_ptr()) }; - let zluda_dlopen_noredirect = mem::transmute::< - _, - Option *mut c_void>, - >(zluda_dlopen_noredirect); - let dlopen = zluda_dlopen_noredirect.unwrap_or(libc::dlopen); - let path = terminate_with_nul(path); - Ok(libloading::os::unix::Library::from_raw(dlopen( - path.as_ptr().cast(), - os::unix::RTLD_LOCAL | os::unix::RTLD_LAZY, - )) - .into()) + libloading::Library::new(&*path) } }