Link the compiled functions together, resolving relocations, and append them to the given ELF file.
(
self,
mut obj: object::write::Object<'static>,
engine: &'a Engine,
compiled_funcs: Vec<(String, FuncKey, Box<dyn Any + Send + Sync>)>,
translations: PrimaryMa
| 1121 | /// Link the compiled functions together, resolving relocations, and append |
| 1122 | /// them to the given ELF file. |
| 1123 | fn link_and_append_code<'a>( |
| 1124 | self, |
| 1125 | mut obj: object::write::Object<'static>, |
| 1126 | engine: &'a Engine, |
| 1127 | compiled_funcs: Vec<(String, FuncKey, Box<dyn Any + Send + Sync>)>, |
| 1128 | translations: PrimaryMap<StaticModuleIndex, ModuleTranslation<'_>>, |
| 1129 | dwarf_package_bytes: Option<&[u8]>, |
| 1130 | ) -> Result<(wasmtime_environ::ObjectBuilder<'a>, Artifacts)> { |
| 1131 | // Append all the functions to the ELF file. |
| 1132 | // |
| 1133 | // The result is a vector parallel to `compiled_funcs` where |
| 1134 | // `symbol_ids_and_locs[i]` is the symbol ID and function location of |
| 1135 | // `compiled_funcs[i]`. |
| 1136 | let compiler = engine.try_compiler()?; |
| 1137 | let tunables = engine.tunables(); |
| 1138 | let symbol_ids_and_locs = compiler.append_code( |
| 1139 | &mut obj, |
| 1140 | &compiled_funcs, |
| 1141 | &|_caller_index: usize, callee: FuncKey| { |
| 1142 | self.indices.get(&callee).copied().unwrap_or_else(|| { |
| 1143 | panic!("cannot resolve relocation! no index for callee {callee:?}") |
| 1144 | }) |
| 1145 | }, |
| 1146 | )?; |
| 1147 | |
| 1148 | // If requested, generate and add DWARF information. |
| 1149 | if tunables.debug_native { |
| 1150 | compiler.append_dwarf( |
| 1151 | &mut obj, |
| 1152 | &translations, |
| 1153 | &|module, func| { |
| 1154 | let i = self.indices[&FuncKey::DefinedWasmFunction(module, func)]; |
| 1155 | let (symbol, _) = symbol_ids_and_locs[i]; |
| 1156 | let (_, _, compiled_func) = &compiled_funcs[i]; |
| 1157 | (symbol, &**compiled_func) |
| 1158 | }, |
| 1159 | dwarf_package_bytes, |
| 1160 | tunables, |
| 1161 | )?; |
| 1162 | } |
| 1163 | |
| 1164 | let mut table_builder = CompiledFunctionsTableBuilder::new(); |
| 1165 | for (key, compiled_func_index) in &self.indices { |
| 1166 | let (_, func_loc) = symbol_ids_and_locs[*compiled_func_index]; |
| 1167 | let src_loc = self |
| 1168 | .start_srclocs |
| 1169 | .get(key) |
| 1170 | .copied() |
| 1171 | .unwrap_or_else(FilePos::none); |
| 1172 | table_builder.push_func(*key, func_loc, src_loc); |
| 1173 | } |
| 1174 | |
| 1175 | let mut obj = wasmtime_environ::ObjectBuilder::new(obj, tunables); |
| 1176 | let modules = translations |
| 1177 | .into_iter() |
| 1178 | .map(|(_, translation)| obj.append(translation)) |
| 1179 | .collect::<Result<PrimaryMap<_, _>>>()?; |
| 1180 |
no test coverage detected