Skip to content

Commit ee39aee

Browse files
committed
fix tidy + address comments
1 parent ead6069 commit ee39aee

File tree

5 files changed

+33
-48
lines changed

5 files changed

+33
-48
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use crate::llvm;
2323
use crate::metadata;
2424
use crate::value::Value;
2525

26+
use log::debug;
2627
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
2728
use rustc_codegen_ssa::mono_item::MonoItemExt;
2829
use rustc_codegen_ssa::traits::*;
@@ -36,7 +37,6 @@ use rustc_middle::mir::mono::{Linkage, Visibility};
3637
use rustc_middle::ty::TyCtxt;
3738
use rustc_session::config::DebugInfo;
3839
use rustc_span::symbol::Symbol;
39-
use log::debug;
4040

4141
use std::ffi::CString;
4242
use std::time::Instant;
@@ -80,23 +80,23 @@ pub fn write_idata_sections<'tcx>(
8080
_tcx: TyCtxt<'tcx>,
8181
raw_dylibs: &[RawDylibImports],
8282
llvm_module: &mut ModuleLlvm,
83-
){
83+
) {
8484
let (idata_llctx, idata_llmod) = (&*llvm_module.llcx, llvm_module.llmod());
8585

86-
8786
let idata_7 = SmallCStr::new(".idata$7");
8887
let idata_6 = SmallCStr::new(".idata$6");
8988

9089
for raw_dylib in raw_dylibs {
91-
debug!("linking raw dylib - {:?}", raw_dylib);
90+
debug!("creating raw dylib idata secions - {:?}", raw_dylib);
9291

9392
let name = CString::new(&*raw_dylib.name.as_str()).unwrap();
9493
let llname = common::bytes_in_context(idata_llctx, name.as_bytes());
9594

96-
let buf = CString::new("dll_name").unwrap();
95+
let buf = format!("import.{}.dll_name", raw_dylib.name);
96+
let buf = CString::new(buf).unwrap();
9797
unsafe {
9898
let llglobal = llvm::LLVMAddGlobal(idata_llmod, common::val_ty(llname), buf.as_ptr());
99-
99+
100100
llvm::LLVMSetInitializer(llglobal, llname);
101101
llvm::LLVMSetGlobalConstant(&llglobal, 1);
102102
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
@@ -115,27 +115,24 @@ pub fn write_idata_sections<'tcx>(
115115
let llname = common::bytes_in_context(idata_llctx, &buf);
116116

117117
let global_name = format!("import.{}.fn.{}", raw_dylib.name, s);
118-
let global_name = CString::new(global_name.as_str()).unwrap();
118+
let global_name = CString::new(global_name).unwrap();
119119

120120
let llglobal = llvm::LLVMAddGlobal(
121-
idata_llmod,
122-
common::val_ty(llname),
123-
global_name.as_ptr()
121+
idata_llmod,
122+
common::val_ty(llname),
123+
global_name.as_ptr(),
124124
);
125-
125+
126126
llvm::LLVMSetInitializer(llglobal, llname);
127127
llvm::LLVMSetGlobalConstant(&llglobal, 1);
128128
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
129129
llvm::LLVMSetSection(llglobal, idata_6.as_ptr());
130-
},
131-
_ => {},
130+
}
131+
_ => {}
132132
}
133133
}
134134
}
135-
136-
137135
}
138-
139136
}
140137

141138
pub struct ValueIter<'ll> {

src/librustc_codegen_llvm/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
9595
tcx: TyCtxt<'tcx>,
9696
raw_dylibs: &[RawDylibImports],
9797
module: &mut ModuleLlvm,
98-
){
98+
) {
9999
base::write_idata_sections(tcx, raw_dylibs, module)
100100
}
101101
fn codegen_allocator<'tcx>(

src/librustc_codegen_ssa/base.rs

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -602,15 +602,16 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
602602
let mut raw_dylib_imports = vec![];
603603
let native_libs = tcx.native_libraries(LOCAL_CRATE);
604604

605-
606605
for lib in native_libs.iter() {
607-
match lib.kind {
608-
cstore::NativeLibraryKind::NativeRawDylib => {
609-
if let (Some(dll_name), Some(def_id)) = (lib.name, lib.foreign_module) {
610-
let foreign_modules = tcx.foreign_modules(LOCAL_CRATE);
611-
for f_mod in foreign_modules {
612-
if f_mod.def_id == def_id {
613-
let items = f_mod.foreign_items.iter().map(|&def_id| {
606+
if lib.kind == cstore::NativeLibraryKind::NativeRawDylib {
607+
if let (Some(dll_name), Some(def_id)) = (lib.name, lib.foreign_module) {
608+
let foreign_modules = tcx.foreign_modules(LOCAL_CRATE);
609+
for f_mod in foreign_modules {
610+
if f_mod.def_id == def_id {
611+
let items = f_mod
612+
.foreign_items
613+
.iter()
614+
.map(|&def_id| {
614615
let fn_attrs = tcx.codegen_fn_attrs(def_id);
615616
if fn_attrs.link_name.is_some() {
616617
RawDylibImportName::Name(fn_attrs.link_name.unwrap())
@@ -620,21 +621,15 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
620621
let name = tcx.item_name(def_id);
621622
RawDylibImportName::Name(name)
622623
}
623-
}).collect();
624+
})
625+
.collect();
624626

625-
raw_dylib_imports.push(RawDylibImports {
626-
name: dll_name,
627-
items,
628-
});
629-
}
627+
raw_dylib_imports.push(RawDylibImports { name: dll_name, items });
630628
}
631-
} else {
632-
bug!(
633-
"not enough information to link raw dylib!",
634-
);
635629
}
636-
},
637-
_ => {},
630+
} else {
631+
bug!("not enough information to link raw dylib!",);
632+
}
638633
}
639634
}
640635

@@ -644,11 +639,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
644639
let mut idata_module = backend.new_metadata(tcx, &idata_cgu_name);
645640

646641
tcx.sess.time("write_idata_sections", || {
647-
backend.write_idata_sections(
648-
tcx,
649-
&raw_dylib_imports,
650-
&mut idata_module,
651-
);
642+
backend.write_idata_sections(tcx, &raw_dylib_imports, &mut idata_module);
652643
});
653644

654645
let idata_module = ModuleCodegen {
@@ -659,8 +650,6 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
659650
ongoing_codegen.submit_pre_codegened_module_to_llvm(tcx, idata_module);
660651
}
661652

662-
663-
664653
// We sort the codegen units by size. This way we can schedule work for LLVM
665654
// a bit more efficiently.
666655
let codegen_units = {

src/librustc_codegen_ssa/traits/backend.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub trait CodegenBackend {
8989
) -> Result<(), ErrorReported>;
9090
}
9191

92-
//TODO: Put this somewhere else?
92+
//FIXME: Put this somewhere else?
9393
#[derive(Debug)]
9494
pub enum RawDylibImportName {
9595
Name(Symbol),
@@ -99,10 +99,9 @@ pub enum RawDylibImportName {
9999
#[derive(Debug)]
100100
pub struct RawDylibImports {
101101
pub name: Symbol,
102-
pub items: Vec<RawDylibImportName>
102+
pub items: Vec<RawDylibImportName>,
103103
}
104104

105-
106105
pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Send + Sync {
107106
fn new_metadata(&self, sess: TyCtxt<'_>, mod_name: &str) -> Self::Module;
108107
fn write_compressed_metadata<'tcx>(

src/librustc_codegen_ssa/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ mod write;
3030
pub use self::abi::AbiBuilderMethods;
3131
pub use self::asm::{AsmBuilderMethods, AsmMethods, InlineAsmOperandRef};
3232
pub use self::backend::{Backend, BackendTypes, CodegenBackend, ExtraBackendMethods};
33-
pub use self::backend::{RawDylibImports, RawDylibImportName};
33+
pub use self::backend::{RawDylibImportName, RawDylibImports};
3434
pub use self::builder::{BuilderMethods, OverflowOp};
3535
pub use self::consts::ConstMethods;
3636
pub use self::debuginfo::{DebugInfoBuilderMethods, DebugInfoMethods};

0 commit comments

Comments
 (0)