Skip to content

Commit 1651079

Browse files
committed
Inline Linker type
1 parent f3d4de0 commit 1651079

1 file changed

Lines changed: 13 additions & 35 deletions

File tree

  • compiler/rustc_codegen_llvm/src/back

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -297,19 +297,27 @@ fn fat_lto(
297297

298298
// For all serialized bitcode files we parse them and link them in as we did
299299
// above, this is all mostly handled in C++.
300-
let mut linker = Linker::new(llmod);
300+
let linker = unsafe { llvm::LLVMRustLinkerNew(llmod) };
301301
for (bc_decoded, name) in serialized_modules {
302302
let _timer = prof
303303
.generic_activity_with_arg_recorder("LLVM_fat_lto_link_module", |recorder| {
304304
recorder.record_arg(format!("{name:?}"))
305305
});
306306
info!("linking {:?}", name);
307307
let data = bc_decoded.data();
308-
linker
309-
.add(data)
310-
.unwrap_or_else(|()| write::llvm_err(dcx, LlvmError::LoadBitcode { name }));
308+
309+
unsafe {
310+
if !llvm::LLVMRustLinkerAdd(
311+
linker,
312+
data.as_ptr() as *const libc::c_char,
313+
data.len(),
314+
) {
315+
llvm::LLVMRustLinkerFree(linker);
316+
write::llvm_err(dcx, LlvmError::LoadBitcode { name })
317+
}
318+
}
311319
}
312-
drop(linker);
320+
unsafe { llvm::LLVMRustLinkerFree(linker) };
313321
save_temp_bitcode(cgcx, &module, "lto.input");
314322

315323
// Internalize everything below threshold to help strip out more modules and such.
@@ -327,36 +335,6 @@ fn fat_lto(
327335
module
328336
}
329337

330-
pub(crate) struct Linker<'a>(&'a mut llvm::Linker<'a>);
331-
332-
impl<'a> Linker<'a> {
333-
pub(crate) fn new(llmod: &'a llvm::Module) -> Self {
334-
unsafe { Linker(llvm::LLVMRustLinkerNew(llmod)) }
335-
}
336-
337-
pub(crate) fn add(&mut self, bytecode: &[u8]) -> Result<(), ()> {
338-
unsafe {
339-
if llvm::LLVMRustLinkerAdd(
340-
self.0,
341-
bytecode.as_ptr() as *const libc::c_char,
342-
bytecode.len(),
343-
) {
344-
Ok(())
345-
} else {
346-
Err(())
347-
}
348-
}
349-
}
350-
}
351-
352-
impl Drop for Linker<'_> {
353-
fn drop(&mut self) {
354-
unsafe {
355-
llvm::LLVMRustLinkerFree(&mut *(self.0 as *mut _));
356-
}
357-
}
358-
}
359-
360338
/// Prepare "thin" LTO to get run on these modules.
361339
///
362340
/// The general structure of ThinLTO is quite different from the structure of

0 commit comments

Comments
 (0)