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

Method object

crates/environ/src/compile/mod.rs:319–361  ·  view source on GitHub ↗

Creates a new `Object` file which is used to build the results of a compilation into. The returned object file will have an appropriate architecture/endianness for `self.triple()`, but at this time it is always an ELF file, regardless of target platform.

(&self, kind: ObjectKind)

Source from the content-addressed store, hash-verified

317 /// architecture/endianness for `self.triple()`, but at this time it is
318 /// always an ELF file, regardless of target platform.
319 fn object(&self, kind: ObjectKind) -> Result<Object<'static>> {
320 use target_lexicon::Architecture::*;
321
322 let triple = self.triple();
323 let (arch, flags) = match triple.architecture {
324 X86_32(_) => (Architecture::I386, 0),
325 X86_64 => (Architecture::X86_64, 0),
326 Arm(_) => (Architecture::Arm, 0),
327 Aarch64(_) => (Architecture::Aarch64, 0),
328 S390x => (Architecture::S390x, 0),
329 Riscv64(_) => (Architecture::Riscv64, 0),
330 // XXX: the `object` crate won't successfully build an object
331 // with relocations and such if it doesn't know the
332 // architecture, so just pretend we are riscv64. Yolo!
333 //
334 // Also note that we add some flags to `e_flags` in the object file
335 // to indicate that it's pulley, not actually riscv64. This is used
336 // by `wasmtime objdump` for example.
337 Pulley32 | Pulley32be => (Architecture::Riscv64, obj::EF_WASMTIME_PULLEY32),
338 Pulley64 | Pulley64be => (Architecture::Riscv64, obj::EF_WASMTIME_PULLEY64),
339 architecture => {
340 bail!("target architecture {architecture:?} is unsupported");
341 }
342 };
343 let mut obj = Object::new(
344 BinaryFormat::Elf,
345 arch,
346 match triple.endianness().unwrap() {
347 target_lexicon::Endianness::Little => object::Endianness::Little,
348 target_lexicon::Endianness::Big => object::Endianness::Big,
349 },
350 );
351 obj.flags = FileFlags::Elf {
352 os_abi: obj::ELFOSABI_WASMTIME,
353 e_flags: flags
354 | match kind {
355 ObjectKind::Module => obj::EF_WASMTIME_MODULE,
356 ObjectKind::Component => obj::EF_WASMTIME_COMPONENT,
357 },
358 abi_version: 0,
359 };
360 Ok(obj)
361 }
362
363 /// Returns the target triple that this compiler is compiling for.
364 fn triple(&self) -> &target_lexicon::Triple;

Callers 2

build_module_artifactsFunction · 0.80

Calls 5

OkFunction · 0.85
newFunction · 0.50
tripleMethod · 0.45
unwrapMethod · 0.45
endiannessMethod · 0.45

Tested by

no test coverage detected