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

Method define_function_inner

cranelift/object/src/backend.rs:638–679  ·  view source on GitHub ↗
(
        &mut self,
        func_id: FuncId,
        alignment: u64,
        bytes: &[u8],
        relocs: Vec<ObjectRelocRecord>,
    )

Source from the content-addressed store, hash-verified

636
637impl ObjectModule {
638 fn define_function_inner(
639 &mut self,
640 func_id: FuncId,
641 alignment: u64,
642 bytes: &[u8],
643 relocs: Vec<ObjectRelocRecord>,
644 ) -> Result<(), ModuleError> {
645 info!("defining function {func_id} with bytes");
646 let decl = self.declarations.get_function_decl(func_id);
647 let decl_name = decl.linkage_name(func_id);
648 if !decl.linkage.is_definable() {
649 return Err(ModuleError::InvalidImportDefinition(decl_name.into_owned()));
650 }
651
652 let &mut (symbol, ref mut defined) = self.functions[func_id].as_mut().unwrap();
653 if *defined {
654 return Err(ModuleError::DuplicateDefinition(decl_name.into_owned()));
655 }
656 *defined = true;
657
658 let align = alignment.max(self.isa.symbol_alignment());
659 let section = if self.per_function_section {
660 // FIXME pass empty symbol name once add_subsection produces `.text` as section name
661 // instead of `.text.` when passed an empty symbol name. (object#748) Until then pass
662 // `subsection` to produce `.text.subsection` as section name to reduce confusion.
663 self.object
664 .add_subsection(StandardSection::Text, b"subsection")
665 } else {
666 self.object.section_id(StandardSection::Text)
667 };
668 let offset = self.object.add_symbol_data(symbol, section, bytes, align);
669
670 if !relocs.is_empty() {
671 self.relocs.push(SymbolRelocs {
672 section,
673 offset,
674 relocs,
675 });
676 }
677
678 Ok(())
679 }
680
681 /// Finalize all relocations and output an object.
682 pub fn finish(mut self) -> ObjectProduct {

Callers 2

define_function_bytesMethod · 0.80

Calls 11

OkFunction · 0.85
get_function_declMethod · 0.80
linkage_nameMethod · 0.80
is_definableMethod · 0.80
into_ownedMethod · 0.80
symbol_alignmentMethod · 0.80
unwrapMethod · 0.45
as_mutMethod · 0.45
maxMethod · 0.45
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected