diff options
| author | Michael Woerister <michaelwoerister@posteo> | 2018-07-16 08:57:49 +0200 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo> | 2018-07-16 08:57:49 +0200 |
| commit | b822e699c3e811f929fd69046095c1d6eb9abd22 (patch) | |
| tree | d18fec3f7882dca43be036aa8dde18d5f4acf227 /src/librustc_codegen_llvm | |
| parent | 99140df0bd5a4dd77db28d78e73df4b5f6ba79a6 (diff) | |
| download | rust-b822e699c3e811f929fd69046095c1d6eb9abd22.tar.gz rust-b822e699c3e811f929fd69046095c1d6eb9abd22.zip | |
Revert "Use callback-based interface to load ThinLTO import data into rustc."
This reverts commit e045a6cd8c0235a26ef11e6cd9a13ebd817f1265.
Diffstat (limited to 'src/librustc_codegen_llvm')
| -rw-r--r-- | src/librustc_codegen_llvm/back/lto.rs | 74 | ||||
| -rw-r--r-- | src/librustc_codegen_llvm/base.rs | 2 |
2 files changed, 44 insertions, 32 deletions
diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index 55499552f5c..a68f22b2651 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -805,7 +805,7 @@ pub struct ThinLTOImports { impl ThinLTOImports { - pub fn new() -> ThinLTOImports { + pub fn new_empty() -> ThinLTOImports { ThinLTOImports { imports: FxHashMap(), } @@ -813,46 +813,58 @@ impl ThinLTOImports { /// Load the ThinLTO import map from ThinLTOData. unsafe fn from_thin_lto_data(data: *const llvm::ThinLTOData) -> ThinLTOImports { + let raw_data: *const llvm::ThinLTOModuleImports = + llvm::LLVMRustGetThinLTOModuleImports(data); - fn module_name_to_str(c_str: &CStr) -> &str { - match c_str.to_str() { - Ok(s) => s, - Err(e) => { - bug!("Encountered non-utf8 LLVM module name `{}`: {}", - c_str.to_string_lossy(), - e) - } + assert!(!raw_data.is_null()); + + let mut imports = FxHashMap(); + let mut module_ptr = raw_data; + let mut module_index = 0; + + loop { + let mut entry_ptr: *const llvm::ThinLTOModuleName = *module_ptr; + + if entry_ptr.is_null() { + break; } - } - unsafe extern "C" fn imported_module_callback(payload: *mut libc::c_void, - importing_module_name: *const libc::c_char, - imported_module_name: *const libc::c_char) { - let map = &mut* (payload as *mut ThinLTOImports); + let importing_module_name = CStr::from_ptr(*entry_ptr) + .to_str() + .expect("Non-utf8 LLVM module name encountered") + .to_owned(); + + entry_ptr = entry_ptr.offset(1); - let importing_module_name = CStr::from_ptr(importing_module_name); - let importing_module_name = module_name_to_str(&importing_module_name); - let imported_module_name = CStr::from_ptr(imported_module_name); - let imported_module_name = module_name_to_str(&imported_module_name); + let mut imported_modules = vec![]; - if !map.imports.contains_key(importing_module_name) { - map.imports.insert(importing_module_name.to_owned(), vec![]); + loop { + let imported_module_name = *entry_ptr; + + if imported_module_name.is_null() { + break + } + + let imported_module_name = CStr::from_ptr(imported_module_name) + .to_str() + .expect("Non-utf8 LLVM module name encountered") + .to_owned(); + + imported_modules.push(imported_module_name); + entry_ptr = entry_ptr.offset(1); } - map.imports - .get_mut(importing_module_name) - .unwrap() - .push(imported_module_name.to_owned()); + imports.insert(importing_module_name, imported_modules); + + module_ptr = module_ptr.offset(1); + module_index += 1; } - let mut map = ThinLTOImports { - imports: FxHashMap(), - }; + assert_eq!(module_index, imports.len()); - llvm::LLVMRustGetThinLTOModuleImports(data, - imported_module_callback, - &mut map as *mut _ as *mut libc::c_void); - map + ThinLTOImports { + imports + } } pub fn save_to_file(&self, path: &Path) -> io::Result<()> { diff --git a/src/librustc_codegen_llvm/base.rs b/src/librustc_codegen_llvm/base.rs index 451e5cf9a60..603ee78585e 100644 --- a/src/librustc_codegen_llvm/base.rs +++ b/src/librustc_codegen_llvm/base.rs @@ -1360,7 +1360,7 @@ fn load_thin_lto_imports(sess: &Session) -> lto::ThinLTOImports { ); if !path.exists() { - return lto::ThinLTOImports::new(); + return lto::ThinLTOImports::new_empty(); } match lto::ThinLTOImports::load_from_file(&path) { |
