MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / get_address

Method get_address

cranelift/jit/src/backend.rs:213–259  ·  view source on GitHub ↗
(&self, name: &ModuleRelocTarget)

Source from the content-addressed store, hash-verified

211 }
212
213 fn get_address(&self, name: &ModuleRelocTarget) -> *const u8 {
214 match name {
215 ModuleRelocTarget::User { .. } => {
216 let (name, linkage) = if ModuleDeclarations::is_function(name) {
217 let func_id = FuncId::from_name(name);
218 match &self.compiled_functions[func_id] {
219 Some(compiled) => return compiled.ptr(),
220 None => {
221 let decl = self.declarations.get_function_decl(func_id);
222 (&decl.name, decl.linkage)
223 }
224 }
225 } else {
226 let data_id = DataId::from_name(name);
227 match &self.compiled_data_objects[data_id] {
228 Some(compiled) => return compiled.ptr(),
229 None => {
230 let decl = self.declarations.get_data_decl(data_id);
231 (&decl.name, decl.linkage)
232 }
233 }
234 };
235 let name = name
236 .as_ref()
237 .expect("anonymous symbol must be defined locally");
238 if let Some(ptr) = self.lookup_symbol(name) {
239 ptr
240 } else if linkage == Linkage::Preemptible {
241 0 as *const u8
242 } else {
243 panic!("can't resolve symbol {name}");
244 }
245 }
246 ModuleRelocTarget::LibCall(libcall) => {
247 let sym = (self.libcall_names)(*libcall);
248 self.lookup_symbol(&sym)
249 .unwrap_or_else(|| panic!("can't resolve libcall {sym}"))
250 }
251 ModuleRelocTarget::FunctionOffset(func_id, offset) => {
252 match &self.compiled_functions[*func_id] {
253 Some(compiled) => return compiled.ptr().wrapping_add(*offset as usize),
254 None => todo!(),
255 }
256 }
257 name => panic!("invalid name {name:?}"),
258 }
259 }
260
261 /// Returns the address of a finalized function.
262 ///

Callers 1

finalize_definitionsMethod · 0.80

Calls 6

get_function_declMethod · 0.80
get_data_declMethod · 0.80
lookup_symbolMethod · 0.80
ptrMethod · 0.45
expectMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected