Skip to content

Commit ead6069

Browse files
committed
string constants
1 parent 89df677 commit ead6069

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

src/librustc_codegen_llvm/base.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,61 @@ pub fn write_compressed_metadata<'tcx>(
7979
pub fn write_idata_sections<'tcx>(
8080
_tcx: TyCtxt<'tcx>,
8181
raw_dylibs: &[RawDylibImports],
82-
_llvm_module: &mut ModuleLlvm,
82+
llvm_module: &mut ModuleLlvm,
8383
){
84+
let (idata_llctx, idata_llmod) = (&*llvm_module.llcx, llvm_module.llmod());
85+
86+
87+
let idata_7 = SmallCStr::new(".idata$7");
88+
let idata_6 = SmallCStr::new(".idata$6");
89+
8490
for raw_dylib in raw_dylibs {
8591
debug!("linking raw dylib - {:?}", raw_dylib);
86-
//TODO: emit.
92+
93+
let name = CString::new(&*raw_dylib.name.as_str()).unwrap();
94+
let llname = common::bytes_in_context(idata_llctx, name.as_bytes());
95+
96+
let buf = CString::new("dll_name").unwrap();
97+
unsafe {
98+
let llglobal = llvm::LLVMAddGlobal(idata_llmod, common::val_ty(llname), buf.as_ptr());
99+
100+
llvm::LLVMSetInitializer(llglobal, llname);
101+
llvm::LLVMSetGlobalConstant(&llglobal, 1);
102+
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
103+
llvm::LLVMSetSection(llglobal, idata_7.as_ptr());
104+
105+
for item in &raw_dylib.items {
106+
match item {
107+
RawDylibImportName::Name(s) => {
108+
let mut buf = vec![0, 0];
109+
buf.extend(s.as_str().as_bytes());
110+
111+
if buf.len() % 2 == 1 {
112+
buf.push(0);
113+
}
114+
115+
let llname = common::bytes_in_context(idata_llctx, &buf);
116+
117+
let global_name = format!("import.{}.fn.{}", raw_dylib.name, s);
118+
let global_name = CString::new(global_name.as_str()).unwrap();
119+
120+
let llglobal = llvm::LLVMAddGlobal(
121+
idata_llmod,
122+
common::val_ty(llname),
123+
global_name.as_ptr()
124+
);
125+
126+
llvm::LLVMSetInitializer(llglobal, llname);
127+
llvm::LLVMSetGlobalConstant(&llglobal, 1);
128+
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
129+
llvm::LLVMSetSection(llglobal, idata_6.as_ptr());
130+
},
131+
_ => {},
132+
}
133+
}
134+
}
135+
136+
87137
}
88138

89139
}

0 commit comments

Comments
 (0)