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

Method new

cranelift/object/src/backend.rs:49–129  ·  view source on GitHub ↗

Create a new `ObjectBuilder` using the given Cranelift target, that can be passed to [`ObjectModule::new`]. The `libcall_names` function provides a way to translate `cranelift_codegen`'s [`ir::LibCall`] enum to symbols. LibCalls are inserted in the IR as part of the legalization for certain floating point instructions, and for stack probes. If you don't know what to use for this argument, use [`c

(
        isa: OwnedTargetIsa,
        name: V,
        libcall_names: Box<dyn Fn(ir::LibCall) -> String + Send + Sync>,
    )

Source from the content-addressed store, hash-verified

47 /// floating point instructions, and for stack probes. If you don't know what to use for this
48 /// argument, use [`cranelift_module::default_libcall_names`].
49 pub fn new<V: Into<Vec<u8>>>(
50 isa: OwnedTargetIsa,
51 name: V,
52 libcall_names: Box<dyn Fn(ir::LibCall) -> String + Send + Sync>,
53 ) -> ModuleResult<Self> {
54 let mut file_flags = object::FileFlags::None;
55 let binary_format = match isa.triple().binary_format {
56 target_lexicon::BinaryFormat::Elf => object::BinaryFormat::Elf,
57 target_lexicon::BinaryFormat::Coff => object::BinaryFormat::Coff,
58 target_lexicon::BinaryFormat::Macho => object::BinaryFormat::MachO,
59 target_lexicon::BinaryFormat::Wasm => {
60 return Err(ModuleError::Backend(anyhow!(
61 "binary format wasm is unsupported",
62 )));
63 }
64 target_lexicon::BinaryFormat::Unknown => {
65 return Err(ModuleError::Backend(anyhow!("binary format is unknown")));
66 }
67 other => {
68 return Err(ModuleError::Backend(anyhow!(
69 "binary format {other} not recognized"
70 )));
71 }
72 };
73 let architecture = match isa.triple().architecture {
74 target_lexicon::Architecture::X86_32(_) => object::Architecture::I386,
75 target_lexicon::Architecture::X86_64 => object::Architecture::X86_64,
76 target_lexicon::Architecture::Arm(_) => object::Architecture::Arm,
77 target_lexicon::Architecture::Aarch64(_) => object::Architecture::Aarch64,
78 target_lexicon::Architecture::Riscv64(_) => {
79 if binary_format != object::BinaryFormat::Elf {
80 return Err(ModuleError::Backend(anyhow!(
81 "binary format {binary_format:?} is not supported for riscv64",
82 )));
83 }
84
85 // FIXME(#4994): Get the right float ABI variant from the TargetIsa
86 let mut eflags = object::elf::EF_RISCV_FLOAT_ABI_DOUBLE;
87
88 // Set the RVC eflag if we have the C extension enabled.
89 let has_c = isa
90 .isa_flags()
91 .iter()
92 .filter(|f| f.name == "has_zca" || f.name == "has_zcd")
93 .all(|f| f.as_bool().unwrap_or_default());
94 if has_c {
95 eflags |= object::elf::EF_RISCV_RVC;
96 }
97
98 file_flags = object::FileFlags::Elf {
99 os_abi: object::elf::ELFOSABI_NONE,
100 abi_version: 0,
101 e_flags: eflags,
102 };
103 object::Architecture::Riscv64
104 }
105 target_lexicon::Architecture::S390x => object::Architecture::S390x,
106 architecture => {

Callers

nothing calls this directly

Calls 11

BackendClass · 0.85
OkFunction · 0.85
macho_build_versionFunction · 0.85
newFunction · 0.50
tripleMethod · 0.45
allMethod · 0.45
iterMethod · 0.45
isa_flagsMethod · 0.45
as_boolMethod · 0.45
unwrapMethod · 0.45
endiannessMethod · 0.45

Tested by

no test coverage detected