Remove LLVM Object library-based .o reader.

This commit is contained in:
Nick Lewycky
2020-05-04 20:40:51 -07:00
parent 72899ccd47
commit 830cebc91b

View File

@ -398,104 +398,6 @@ impl FuncTranslator {
}
}
/*
let object = memory_buffer.create_object_file().map_err(|()| {
CompileError::Codegen("failed to create object file from llvm ir".to_string())
})?;
let mut bytes = vec![];
let mut relocations = vec![];
let mut local_relocations = vec![];
let mut required_custom_sections = vec![];
for section in object.get_sections() {
match section.get_name().map(std::ffi::CStr::to_bytes) {
Some(b"wasmer_function") => {
bytes.extend(section.get_contents().to_vec());
}
Some(b".relawasmer_function") | Some(b".relwasmer_function") => {
for rel in section.get_relocations() {
let (i, cs) = rel.get_type();
let kind = match (i, cs.to_bytes()) {
(1, b"R_X86_64_64") => RelocationKind::Abs8,
_ => unimplemented!("unknown relocation kind {:?}", rel.get_type()),
};
let mut reloc_target = None;
let mut target = None;
// TODO: fix inkwell API so we don't have a for loop
// which always breaks after the first entry.
for symbol in rel.get_symbols() {
target = symbol
.get_name()
.map(|cs| String::from(cs.to_str().unwrap()));
break;
}
// TODO: use a lookup table instead of a linear scan
if let Some(ref target) = &target {
if let Some((index, _)) =
func_names.iter().find(|(_, name)| *name == target)
{
let local_index = wasm_module
.local_func_index(index)
.expect("Only local functions should be relocated");
reloc_target = Some(RelocationTarget::LocalFunc(local_index));
} else {
if let Some(libcall) = libcalls.get(&target.to_string()) {
reloc_target = Some(RelocationTarget::LibCall(*libcall));
}
}
}
if reloc_target.is_some() {
let reloc_target = reloc_target.unwrap();
relocations.push(Relocation {
kind,
reloc_target,
offset: rel.get_offset() as u32,
// TODO: it appears the LLVM C API has no way to
// retrieve the addend.
addend: 0,
});
} else {
if let Some(ref target) = &target {
let local_section_index = required_custom_sections.len() as u32;
required_custom_sections.push(target.clone());
local_relocations.push(LocalRelocation {
kind,
local_section_index,
offset: rel.get_offset() as u32,
// TODO: it appears the LLVM C API has no way to
// retrieve the addend.
addend: 0,
});
}
}
}
}
_ => {}
};
}
// TODO: verify that we see all of them
let mut custom_sections = vec![];
custom_sections.resize(
required_custom_sections.len(),
CustomSection {
protection: CustomSectionProtection::Read,
bytes: SectionBody::default(),
},
);
for section in object.get_sections() {
if let Some(name) = section.get_name().map(std::ffi::CStr::to_bytes) {
if let Some(index) = required_custom_sections
.iter()
.position(|n| n.as_bytes() == name)
{
custom_sections[index].bytes.extend(section.get_contents());
}
}
}
*/
let mut custom_sections = vec![];
custom_sections.resize(
required_custom_sections.len(),