diff --git a/lib/compiler-llvm/src/compiler.rs b/lib/compiler-llvm/src/compiler.rs index afc831405..6ec08c518 100644 --- a/lib/compiler-llvm/src/compiler.rs +++ b/lib/compiler-llvm/src/compiler.rs @@ -65,6 +65,14 @@ impl Compiler for LLVMCompiler { //let data = Arc::new(Mutex::new(0)); let mut func_names = SecondaryMap::new(); + // We're going to "link" the sections by simply appending all compatible + // sections, then building the new relocations. + // TODO: merge constants. + let mut readonly_section = CustomSection { + protection: CustomSectionProtection::Read, + bytes: Vec::new(), + }; + for (func_index, _) in &module.functions { func_names[func_index] = module .func_names @@ -72,7 +80,7 @@ impl Compiler for LLVMCompiler { .cloned() .unwrap_or_else(|| format!("fn{}", func_index.index())); } - let mut outputs = function_body_inputs + let mut functions = function_body_inputs .into_iter() .collect::)>>() .par_iter() @@ -91,49 +99,34 @@ impl Compiler for LLVMCompiler { }) .collect::, CompileError>>()? .into_iter() - .collect::>(); - - // We're going to "link" the sections by simply appending all compatible - // sections, then building the new relocations. - // TODO: merge constants. - let mut readonly_section = CustomSection { - protection: CustomSectionProtection::Read, - bytes: Vec::new(), - }; - /* - let mut readexecute_section = CustomSection { - protection: CustomSectionProtection::Read, - bytes: Vec::new(), - }; - */ - for (ref mut function, ref local_relocations, ref custom_sections) in outputs.values_mut() { - for (local_idx, custom_section) in custom_sections.iter().enumerate() { - let local_idx = local_idx as u32; - // TODO: these section numbers are potentially wrong, if there's - // no Read and only a ReadExecute then ReadExecute is 0. - let (ref mut section, section_num) = match &custom_section.protection { - Read => (&mut readonly_section, SectionIndex::from_u32(0)), - //ReadExecute => (&mut readexecute_section, 1), - }; - let offset = section.bytes.len() as i64; - section.bytes.extend(&custom_section.bytes); - // TODO: we're needlessly rescanning the whole list. - for local_relocation in local_relocations { - if local_relocation.local_section_index == local_idx { - function.relocations.push(Relocation { - kind: local_relocation.kind, - reloc_target: RelocationTarget::CustomSection(section_num), - offset: local_relocation.offset, - addend: local_relocation.addend + offset, - }); + .map(|(mut function, local_relocations, custom_sections)| { + /// We collect the sections data + for (local_idx, custom_section) in custom_sections.iter().enumerate() { + let local_idx = local_idx as u32; + // TODO: these section numbers are potentially wrong, if there's + // no Read and only a ReadExecute then ReadExecute is 0. + let (ref mut section, section_num) = match &custom_section.protection { + CustomSectionProtection::Read => (&mut readonly_section, SectionIndex::from_u32(0)), + //ReadExecute => (&mut readexecute_section, 1), + }; + let offset = section.bytes.len() as i64; + section.bytes.extend(&custom_section.bytes); + // TODO: we're needlessly rescanning the whole list. + for local_relocation in &local_relocations { + if local_relocation.local_section_index == local_idx { + function.relocations.push(Relocation { + kind: local_relocation.kind, + reloc_target: RelocationTarget::CustomSection(section_num), + offset: local_relocation.offset, + addend: local_relocation.addend + offset, + }); + } } } - } - } - - let functions = outputs - .iter_mut() - .map(|(i, (f, _, _))| *f) + Ok(function) + }) + .collect::, CompileError>>()? + .into_iter() .collect::>(); let mut custom_sections = PrimaryMap::new(); diff --git a/lib/compiler/src/section.rs b/lib/compiler/src/section.rs index af0fdbeff..0908f1b90 100644 --- a/lib/compiler/src/section.rs +++ b/lib/compiler/src/section.rs @@ -23,8 +23,8 @@ pub enum CustomSectionProtection { Read, // We don't include `ReadWrite` here because it would complicate freeze // and resumption of executing Modules. - /// A compiled section that is also executable. - ReadExecute, + // We also currently don't include `ReadExecute` as we don't have a way + // to represent relocations for this kind of section. } /// A Section for a `Compilation`.