Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse object files with ElfFile64 rather than object::File #8593

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions crates/wasmtime/src/engine/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ use crate::prelude::*;
use crate::{Engine, ModuleVersionStrategy, Precompiled};
use anyhow::{anyhow, bail, ensure, Context, Result};
use core::str::FromStr;
use object::endian::NativeEndian;
#[cfg(any(feature = "cranelift", feature = "winch"))]
use object::write::{Object, StandardSegment};
use object::{File, FileFlags, Object as _, ObjectSection, SectionKind};
use object::{read::elf::ElfFile64, FileFlags, Object as _, ObjectSection, SectionKind};
use serde_derive::{Deserialize, Serialize};
use wasmtime_environ::obj;
use wasmtime_environ::{FlagValue, ObjectKind, Tunables};
Expand Down Expand Up @@ -56,7 +57,7 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> R
// structured well enough to make this easy and additionally it's not really
// a perf issue right now so doing that is left for another day's
// refactoring.
let obj = File::parse(mmap)
let obj = ElfFile64::<NativeEndian>::parse(mmap)
.err2anyhow()
.context("failed to parse precompiled artifact as an ELF")?;
let expected_e_flags = match expected {
Expand Down Expand Up @@ -145,7 +146,7 @@ pub fn append_compiler_info(engine: &Engine, obj: &mut Object<'_>, metadata: &Me
}

fn detect_precompiled<'data, R: object::ReadRef<'data>>(
obj: File<'data, R>,
obj: ElfFile64<'data, NativeEndian, R>,
) -> Option<Precompiled> {
match obj.flags() {
FileFlags::Elf {
Expand All @@ -163,13 +164,13 @@ fn detect_precompiled<'data, R: object::ReadRef<'data>>(
}

pub fn detect_precompiled_bytes(bytes: &[u8]) -> Option<Precompiled> {
detect_precompiled(File::parse(bytes).ok()?)
detect_precompiled(ElfFile64::parse(bytes).ok()?)
}

#[cfg(feature = "std")]
pub fn detect_precompiled_file(path: impl AsRef<std::path::Path>) -> Result<Option<Precompiled>> {
let read_cache = object::ReadCache::new(std::fs::File::open(path)?);
let obj = File::parse(&read_cache)?;
let obj = ElfFile64::parse(&read_cache)?;
Ok(detect_precompiled(obj))
}

Expand Down
5 changes: 3 additions & 2 deletions crates/wasmtime/src/runtime/code_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::runtime::vm::{libcalls, MmapVec, UnwindRegistration};
use anyhow::{anyhow, bail, Context, Result};
use core::mem::ManuallyDrop;
use core::ops::Range;
use object::read::{File, Object, ObjectSection};
use object::endian::NativeEndian;
use object::read::{elf::ElfFile64, Object, ObjectSection};
use object::ObjectSymbol;
use wasmtime_environ::obj;
use wasmtime_jit_icache_coherence as icache_coherence;
Expand Down Expand Up @@ -57,7 +58,7 @@ impl CodeMemory {
/// The returned `CodeMemory` manages the internal `MmapVec` and the
/// `publish` method is used to actually make the memory executable.
pub fn new(mmap: MmapVec) -> Result<Self> {
let obj = File::parse(&mmap[..])
let obj = ElfFile64::<NativeEndian>::parse(&mmap[..])
.err2anyhow()
.with_context(|| "failed to parse internal compilation artifact")?;

Expand Down