A lightweight WebAssembly runtime that is fast, secure, and standards-compliant
Update object dependency to 0.40.0 (#14096)
Philip Craig158959344567
diff --git a/Cargo.lock b/Cargo.lockindex d459cc9f0d..f2c0b89cd8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1007,7 +1007,7 @@ dependencies = ["cranelift-module","gimli 0.33.0","log",- "object 0.39.0",+ "object 0.40.0","target-lexicon 0.13.5",]@@ -1827,9 +1827,6 @@ name = "hashbrown"version = "0.16.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100"-dependencies = [- "foldhash 0.2.0",-][[package]]name = "hashbrown"@@ -2465,7 +2462,7 @@ name = "min-platform-host"version = "49.0.0"dependencies = ["libloading",- "object 0.39.0",+ "object 0.40.0","wasmtime",]@@ -2631,12 +2628,12 @@ dependencies = [[[package]]name = "object"-version = "0.39.0"+version = "0.40.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "63944c133d03f44e75866bbd160b95af0ec3f6a13d936d69d31c81078cbc5baf"+checksum = "dd229a0361b9d0d4396176e02d65897f487eebeab7caa6d443855ee152ca0b9c"dependencies = ["crc32fast",- "hashbrown 0.16.1",+ "hashbrown 0.17.0","indexmap 2.14.0","memchr",]@@ -4352,7 +4349,7 @@ version = "49.0.0"dependencies = ["bitflags 2.11.1","byte-array-literals",- "object 0.39.0",+ "object 0.40.0","wasip1","wasm-encoder 0.254.0","wit-bindgen-rust-macro 0.60.0",@@ -4600,7 +4597,7 @@ dependencies = ["log","mach2 0.6.0","memfd",- "object 0.39.0",+ "object 0.40.0","once_cell","postcard","proptest",@@ -4708,7 +4705,7 @@ dependencies = ["log","memchr","num_cpus",- "object 0.39.0",+ "object 0.40.0","pin-project-lite","pulley-interpreter","rand 0.10.1",@@ -4787,7 +4784,7 @@ dependencies = ["hashbrown 0.17.0","indexmap 2.14.0","log",- "object 0.39.0",+ "object 0.40.0","postcard","rustc-demangle","semver",@@ -4962,7 +4959,7 @@ dependencies = ["gimli 0.33.0","itertools 0.14.0","log",- "object 0.39.0",+ "object 0.40.0","pulley-interpreter","smallvec 1.15.1","target-lexicon 0.13.5",@@ -5039,7 +5036,7 @@ name = "wasmtime-internal-jit-debug"version = "49.0.0"dependencies = ["cc",- "object 0.39.0",+ "object 0.40.0","rustix 1.1.4","wasmtime-internal-versioned-export-macros",]@@ -5059,7 +5056,7 @@ version = "49.0.0"dependencies = ["cranelift-codegen","log",- "object 0.39.0",+ "object 0.40.0","wasmtime-environ",]@@ -5079,7 +5076,7 @@ dependencies = ["cranelift-codegen","gimli 0.33.0","log",- "object 0.39.0",+ "object 0.40.0","target-lexicon 0.13.5","wasmparser 0.254.0","wasmtime-environ",@@ -5274,7 +5271,7 @@ version = "49.0.0"dependencies = ["json-from-wast","log",- "object 0.39.0",+ "object 0.40.0","serde_json","tokio","wasmparser 0.254.0",diff --git a/Cargo.toml b/Cargo.tomlindex 6aafcf9e60..71b8795bfe 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -398,7 +398,7 @@ backtrace = "0.3.76"bumpalo = "3.20.2"mutatis = { version = "0.5.2", features = ["alloc", "derive", "check"] }cc = "1.2.0" # intentionally smaller-than-latest to accommodate rust-lang/rust-object = { version = "0.39.0", default-features = false, features = ['read_core', 'elf'] }+object = { version = "0.40.0", default-features = false, features = ['read_core', 'elf'] }gimli = { version = "0.33.0", default-features = false, features = ['read'] }addr2line = { version = "0.26.0", default-features = false }anyhow = { version = "1.0.103", default-features = false }diff --git a/cranelift/object/src/backend.rs b/cranelift/object/src/backend.rsindex b8d7eb9c44..2aa58c1c63 100644--- a/cranelift/object/src/backend.rs+++ b/cranelift/object/src/backend.rs@@ -16,7 +16,7 @@ use object::write::{};use object::{BinaryFormat, RelocationEncoding, RelocationFlags, RelocationKind, SectionFlags, SectionKind,- SymbolFlags, SymbolKind, SymbolScope, elf,+ SymbolFlags, SymbolKind, SymbolScope, elf, macho,};use std::collections::HashMap;use std::collections::hash_map::Entry;@@ -175,12 +175,7 @@ impl ObjectBuilder {/// See the following for details:/// <https://github.com/rust-lang/rust/blob/1.95.0/compiler/rustc_codegen_ssa/src/back/metadata.rs#L408-L425>fn macho_build_version(triple: &Triple) -> Option<object::write::MachOBuildVersion> {- use target_lexicon::{DeploymentTarget, OperatingSystem::*};-- fn pack_version(v: DeploymentTarget) -> u32 {- let (major, minor, patch) = (v.major as u32, v.minor as u32, v.patch as u32);- (major << 16) | (minor << 8) | patch- }+ use target_lexicon::OperatingSystem::*;match triple.operating_system {Darwin(v) | MacOSX(v) | IOS(v) | TvOS(v) | VisionOS(v) | WatchOS(v) | XROS(v) => {@@ -206,7 +201,7 @@ fn macho_build_version(triple: &Triple) -> Option<object::write::MachOBuildVersi(WatchOS(_), _) => PLATFORM_WATCHOS,_ => {warn!("unsupported OS/environment: {triple}");- 0+ PLATFORM_UNKNOWN}};@@ -214,7 +209,7 @@ fn macho_build_version(triple: &Triple) -> Option<object::write::MachOBuildVersibuild_version.platform = platform;build_version.minos = if let Some(v) = v {- pack_version(v)+ macho::Version::new(v.major, v.minor, v.patch)} else {// The `minos` in object files is useful for diagnostics, as// it tells the linker whether the file supports a given OS -@@ -223,12 +218,12 @@ fn macho_build_version(triple: &Triple) -> Option<object::write::MachOBuildVersi//// Using `0.0.0` here should be fine if we don't have the data// available.- 0+ macho::Version(0)};// Setting a 0 SDK version is fine, it's only relevant for the// final linked binary.- build_version.sdk = 0;+ build_version.sdk = macho::Version(0);Some(build_version)}@@ -577,18 +572,18 @@ impl Module for ObjectModule {);match self.object.section_flags_mut(section) {- SectionFlags::MachO { flags } => {+ SectionFlags::MachO { flags, .. } => {// There are no default flags for the `SectionKind`s that// we've specified above, so it's fine to override.//// (If we don't want to override, we'll have to be careful// with how we set these, to ensure we set the section// type properly).- assert_eq!(*flags, 0);+ assert_eq!(flags.0, 0);*flags = macho_flags;}_ => {- if macho_flags != 0 {+ if macho_flags.0 != 0 {unreachable!("unsupported Mach-O flags for this platform: {macho_flags:?}");}}@@ -600,12 +595,12 @@ impl Module for ObjectModule {if used {match self.object.format() {object::BinaryFormat::Elf => match self.object.section_flags_mut(section) {- SectionFlags::Elf { sh_flags } => *sh_flags |= u64::from(elf::SHF_GNU_RETAIN),+ SectionFlags::Elf { sh_flags, .. } => *sh_flags |= elf::SHF_GNU_RETAIN,_ => unreachable!(),},object::BinaryFormat::Coff => {}object::BinaryFormat::MachO => match self.object.symbol_flags_mut(symbol) {- SymbolFlags::MachO { n_desc } => *n_desc |= object::macho::N_NO_DEAD_STRIP,+ SymbolFlags::MachO { n_desc, .. } => *n_desc |= macho::N_NO_DEAD_STRIP,_ => unreachable!(),},_ => unreachable!(),@@ -1181,7 +1176,7 @@ struct ObjectRelocRecord {fn parse_section(section: &str,binary_format: BinaryFormat,-) -> Result<(&str, &str, u32), anyhow::Error> {+) -> Result<(&str, &str, macho::SectionFlags), anyhow::Error> {match binary_format {// See https://github.com/llvm/llvm-project/blob/main/llvm/lib/MC/MCSectionMachO.cppBinaryFormat::MachO => {@@ -1213,7 +1208,7 @@ fn parse_section(.iter().find(|(name, _)| *name == section_type){- *val+ (*val).into()} else {let types = list_valid_values(MACHO_SECTION_TYPES);return section_err(&format!(@@ -1244,7 +1239,7 @@ fn parse_section(Ok((segment_name, section_name, macho_flags))}// Otherwise, assume no segment and flags.- _ => Ok(("", section, 0)),+ _ => Ok(("", section, macho::S_REGULAR.into())),}}@@ -1255,7 +1250,7 @@ fn parse_section(// See also the Mac OS X Assembler Reference:// <https://leopard-adc.pepas.com/documentation/DeveloperTools/Reference/Assembler/040-Assembler_Directives/asm_directives.html#//apple_ref/doc/uid/TP30000823-TPXREF102>#[rustfmt::skip]-const MACHO_SECTION_TYPES: &[(&str, u32)] = {+const MACHO_SECTION_TYPES: &[(&str, macho::SectionType)] = {use object::macho::*;&[("regular", S_REGULAR),@@ -1284,7 +1279,7 @@ const MACHO_SECTION_TYPES: &[(&str, u32)] = {]};-const MACHO_SECTION_ATTRIBUTES: &[(&str, u32)] = {+const MACHO_SECTION_ATTRIBUTES: &[(&str, macho::SectionFlags)] = {use object::macho::*;&[("pure_instructions", S_ATTR_PURE_INSTRUCTIONS),@@ -1301,7 +1296,7 @@ const MACHO_SECTION_ATTRIBUTES: &[(&str, u32)] = {]};-fn list_valid_values(items: &[(&str, u32)]) -> String {+fn list_valid_values<T>(items: &[(&str, T)]) -> String {let mut items = items.iter().peekable();let mut result = String::new();if let Some((item, _)) = items.next() {@@ -1326,7 +1321,7 @@ mod tests {fn section() {assert_eq!(parse_section("__DATA,__mod_init_func,mod_init_funcs", BinaryFormat::MachO).unwrap(),- ("__DATA", "__mod_init_func", S_MOD_INIT_FUNC_POINTERS),+ ("__DATA", "__mod_init_func", S_MOD_INIT_FUNC_POINTERS.into()),);assert_eq!(parse_section(@@ -1339,11 +1334,11 @@ mod tests {assert_eq!(parse_section("__TEXT,__text", BinaryFormat::MachO).unwrap(),- ("__TEXT", "__text", S_REGULAR),+ ("__TEXT", "__text", S_REGULAR.into()),);assert_eq!(parse_section("__TEXT,__text,regular", BinaryFormat::MachO).unwrap(),- ("__TEXT", "__text", S_REGULAR),+ ("__TEXT", "__text", S_REGULAR.into()),);assert_eq!(parse_section(diff --git a/crates/cranelift/src/obj.rs b/crates/cranelift/src/obj.rsindex bbb7f72355..632fda4c4d 100644--- a/crates/cranelift/src/obj.rs+++ b/crates/cranelift/src/obj.rs@@ -88,11 +88,10 @@ impl<'a> ModuleTextBuilder<'a> {// try to call `Mmap::make_executable`, which makes Pulley more// portable.if compiler.triple().is_pulley() {- let section = obj.section_mut(text_section);- assert!(matches!(section.flags, SectionFlags::None));- section.flags = SectionFlags::Elf {- sh_flags: obj::SH_WASMTIME_NOT_EXECUTED,+ let SectionFlags::Elf { sh_flags, .. } = obj.section_flags_mut(text_section) else {+ unreachable!();};+ *sh_flags = obj::SH_WASMTIME_NOT_EXECUTED;}Self {diff --git a/crates/environ/src/compile/mod.rs b/crates/environ/src/compile/mod.rsindex 984ba3c917..620f627392 100644--- a/crates/environ/src/compile/mod.rs+++ b/crates/environ/src/compile/mod.rs@@ -321,12 +321,12 @@ pub trait Compiler: Send + Sync {let triple = self.triple();let (arch, flags) = match triple.architecture {- X86_32(_) => (Architecture::I386, 0),- X86_64 => (Architecture::X86_64, 0),- Arm(_) => (Architecture::Arm, 0),- Aarch64(_) => (Architecture::Aarch64, 0),- S390x => (Architecture::S390x, 0),- Riscv64(_) => (Architecture::Riscv64, 0),+ X86_32(_) => (Architecture::I386, object::elf::FileFlags(0)),+ X86_64 => (Architecture::X86_64, object::elf::FileFlags(0)),+ Arm(_) => (Architecture::Arm, object::elf::FileFlags(0)),+ Aarch64(_) => (Architecture::Aarch64, object::elf::FileFlags(0)),+ S390x => (Architecture::S390x, object::elf::FileFlags(0)),+ Riscv64(_) => (Architecture::Riscv64, object::elf::FileFlags(0)),// XXX: the `object` crate won't successfully build an object// with relocations and such if it doesn't know the// architecture, so just pretend we are riscv64. Yolo!diff --git a/crates/environ/src/compile/module_artifacts.rs b/crates/environ/src/compile/module_artifacts.rsindex c9e1f302ad..ff11c4b03a 100644--- a/crates/environ/src/compile/module_artifacts.rs+++ b/crates/environ/src/compile/module_artifacts.rs@@ -284,22 +284,14 @@ impl FinishedObject for Vec<u8> {struct ObjectVec(Vec<u8>);impl WritableBuffer for ObjectVec {- fn len(&self) -> usize {- self.0.len()- }-- fn reserve(&mut self, additional: usize) -> Result<(), ()> {+ fn reserve(&mut self, additional: u64) -> Result<(), ()> {assert_eq!(self.0.len(), 0, "cannot reserve twice");- self.0 = Vec::with_capacity(additional);+ self.0 = Vec::with_capacity(additional as usize);Ok(())}- fn resize(&mut self, new_len: usize) {- if new_len <= self.0.len() {- self.0.truncate(new_len)- } else {- self.0.extend(vec![0; new_len - self.0.len()])- }+ fn write_zeros(&mut self, additional: u64) {+ self.0.extend(vec![0; additional as usize])}fn write_bytes(&mut self, val: &[u8]) {diff --git a/crates/environ/src/obj.rs b/crates/environ/src/obj.rsindex 718c7873d9..bb2aa987fe 100644--- a/crates/environ/src/obj.rs+++ b/crates/environ/src/obj.rs@@ -7,29 +7,29 @@ use core::fmt;////// This is just a constant that seems reasonable in the sense it's unlikely to/// clash with others.-pub const ELFOSABI_WASMTIME: u8 = 200;+pub const ELFOSABI_WASMTIME: object::elf::OsAbi = object::elf::OsAbi(200);/// Flag for the `e_flags` field in the ELF header indicating a compiled/// module.-pub const EF_WASMTIME_MODULE: u32 = 1 << 0;+pub const EF_WASMTIME_MODULE: object::elf::FileFlags = object::elf::FileFlags(1 << 0);/// Flag for the `e_flags` field in the ELF header indicating a compiled/// component.-pub const EF_WASMTIME_COMPONENT: u32 = 1 << 1;+pub const EF_WASMTIME_COMPONENT: object::elf::FileFlags = object::elf::FileFlags(1 << 1);/// Flag for the `e_flags` field in the ELF header indicating compiled code for/// pulley32-pub const EF_WASMTIME_PULLEY32: u32 = 1 << 2;+pub const EF_WASMTIME_PULLEY32: object::elf::FileFlags = object::elf::FileFlags(1 << 2);/// Flag for the `e_flags` field in the ELF header indicating compiled code for/// pulley64-pub const EF_WASMTIME_PULLEY64: u32 = 1 << 3;+pub const EF_WASMTIME_PULLEY64: object::elf::FileFlags = object::elf::FileFlags(1 << 3);/// Flag for the `sh_flags` field in the ELF text section that indicates that/// the text section does not itself need to be executable. This is used for the/// Pulley target, for example, to indicate that it does not need to be made/// natively executable as it does not contain actual native code.-pub const SH_WASMTIME_NOT_EXECUTED: u64 = 1 << 0;+pub const SH_WASMTIME_NOT_EXECUTED: object::elf::SectionFlags = object::elf::SectionFlags(1 << 0);/// A custom Wasmtime-specific section of our compilation image which stores/// mapping data from offsets in the image to offset in the original wasmdiff --git a/crates/wasi-preview1-component-adapter/build.rs b/crates/wasi-preview1-component-adapter/build.rsindex 2b1f7f95d0..38de08f7d4 100644--- a/crates/wasi-preview1-component-adapter/build.rs+++ b/crates/wasi-preview1-component-adapter/build.rs@@ -267,7 +267,7 @@ fn build_archive(wasm: &[u8]) -> Vec<u8> {let mut symbol_table = Vec::new();symbol_table.extend_from_slice(bytes_of(&U32::new(BigEndian, syms.len() as u32)));for _ in syms.iter() {- symbol_table.extend_from_slice(bytes_of(&U32::new(BigEndian, 0)));+ symbol_table.extend_from_slice(bytes_of(&U32::new(BigEndian, 0u32)));}for s in syms.iter() {symbol_table.extend_from_slice(&std::ffi::CString::new(*s).unwrap().into_bytes_with_nul());@@ -295,13 +295,11 @@ fn build_archive(wasm: &[u8]) -> Vec<u8> {// Now that we have the starting offset of the `intrinsics.o` file go back// and fill in the offset within the symbol table generated earlier.- let member_offset = archive.len();+ let member_offset = u32::try_from(archive.len()).unwrap();for (index, _) in syms.iter().enumerate() {let index = index + 1;- archive[symtab_offset + (index * 4)..][..4].copy_from_slice(bytes_of(&U32::new(- BigEndian,- member_offset.try_into().unwrap(),- )));+ archive[symtab_offset + (index * 4)..][..4]+ .copy_from_slice(bytes_of(&U32::new(BigEndian, member_offset)));}archive.extend_from_slice(object::bytes_of(&object::archive::Header {diff --git a/crates/wasmtime/src/compile/runtime.rs b/crates/wasmtime/src/compile/runtime.rsindex 39328ee588..6ccc8ddd34 100644--- a/crates/wasmtime/src/compile/runtime.rs+++ b/crates/wasmtime/src/compile/runtime.rs@@ -210,30 +210,22 @@ impl FinishedObject for MmapVecWrapper {}impl WritableBuffer for ObjectMmap {- fn len(&self) -> usize {- self.len- }-- fn reserve(&mut self, additional: usize) -> Result<(), ()> {+ fn reserve(&mut self, additional: u64) -> Result<(), ()> {assert!(self.mmap.is_none(), "cannot reserve twice");- self.mmap = match MmapVec::with_capacity_and_alignment(additional, self.alignment) {- Ok(mmap) => Some(mmap),- Err(e) => {- self.err = Some(e);- return Err(());- }- };+ self.mmap =+ match MmapVec::with_capacity_and_alignment(additional as usize, self.alignment)+ {+ Ok(mmap) => Some(mmap),+ Err(e) => {+ self.err = Some(e);+ return Err(());+ }+ };Ok(())}- fn resize(&mut self, new_len: usize) {- // Resizing always appends 0 bytes and since new mmaps start out as 0- // bytes we don't actually need to do anything as part of this other- // than update our own length.- if new_len <= self.len {- return;- }- self.len = new_len;+ fn write_zeros(&mut self, additional: u64) {+ self.len += additional as usize;}fn write_bytes(&mut self, val: &[u8]) {diff --git a/crates/wasmtime/src/engine/serialization.rs b/crates/wasmtime/src/engine/serialization.rsindex cc91db370f..b335db1cca 100644--- a/crates/wasmtime/src/engine/serialization.rs+++ b/crates/wasmtime/src/engine/serialization.rs@@ -72,7 +72,7 @@ pub fn check_compatible(engine: &Engine, mmap: &[u8], expected: ObjectKind) -> RObjectKind::Component => obj::EF_WASMTIME_COMPONENT,};ensure!(- (header.e_flags(endian) & expected_e_flags) == expected_e_flags,+ header.e_flags(endian).contains(expected_e_flags),"incompatible object file format");@@ -156,12 +156,12 @@ fn detect_precompiled<'data, R: object::ReadRef<'data>>(os_abi: obj::ELFOSABI_WASMTIME,abi_version: 0,e_flags,- } if e_flags & obj::EF_WASMTIME_MODULE != 0 => Some(Precompiled::Module),+ } if e_flags.contains(obj::EF_WASMTIME_MODULE) => Some(Precompiled::Module),FileFlags::Elf {os_abi: obj::ELFOSABI_WASMTIME,abi_version: 0,e_flags,- } if e_flags & obj::EF_WASMTIME_COMPONENT != 0 => Some(Precompiled::Component),+ } if e_flags.contains(obj::EF_WASMTIME_COMPONENT) => Some(Precompiled::Component),_ => None,}}diff --git a/crates/wasmtime/src/profiling_agent/jitdump.rs b/crates/wasmtime/src/profiling_agent/jitdump.rsindex dc760aad4f..9f8ed3e8fd 100644--- a/crates/wasmtime/src/profiling_agent/jitdump.rs+++ b/crates/wasmtime/src/profiling_agent/jitdump.rs@@ -34,14 +34,14 @@ pub fn new() -> Result<Box<dyn ProfilingAgent>> {if jitdump_file.is_none() {let filename = format!("./jit-{}.dump", process::id());let e_machine = match target_lexicon::HOST.architecture {- Architecture::X86_64 => elf::EM_X86_64 as u32,- Architecture::X86_32(_) => elf::EM_386 as u32,- Architecture::Arm(_) => elf::EM_ARM as u32,- Architecture::Aarch64(_) => elf::EM_AARCH64 as u32,- Architecture::S390x => elf::EM_S390 as u32,+ Architecture::X86_64 => elf::EM_X86_64,+ Architecture::X86_32(_) => elf::EM_386,+ Architecture::Arm(_) => elf::EM_ARM,+ Architecture::Aarch64(_) => elf::EM_AARCH64,+ Architecture::S390x => elf::EM_S390,_ => unimplemented!("unrecognized architecture"),};- *jitdump_file = Some(JitDumpFile::new(filename, e_machine)?);+ *jitdump_file = Some(JitDumpFile::new(filename, e_machine.0 as u32)?);}Ok(Box::new(JitDumpAgent {diff --git a/crates/wasmtime/src/runtime/code_memory.rs b/crates/wasmtime/src/runtime/code_memory.rsindex 6078b5091c..6130c7f641 100644--- a/crates/wasmtime/src/runtime/code_memory.rs+++ b/crates/wasmtime/src/runtime/code_memory.rs@@ -202,7 +202,10 @@ impl CodeMemory {".text" => {text = range;- if section_header.sh_flags(endian) & obj::SH_WASMTIME_NOT_EXECUTED != 0 {+ if section_header+ .sh_flags(endian)+ .contains(obj::SH_WASMTIME_NOT_EXECUTED)+ {needs_executable = false;}}diff --git a/src/disas.rs b/src/disas.rsindex 808042d3e2..4dc42747d9 100644--- a/src/disas.rs+++ b/src/disas.rs@@ -36,7 +36,7 @@ pub fn disas(elf: &ElfFile64<'_, Endianness>, func: &[u8], addr: u64) -> Result<FileFlags::Elf { e_flags, .. } => e_flags,_ => bail!("not an ELF file"),};- if e_flags & (obj::EF_WASMTIME_PULLEY32 | obj::EF_WASMTIME_PULLEY64) != 0 {+ if e_flags.intersects(obj::EF_WASMTIME_PULLEY32 | obj::EF_WASMTIME_PULLEY64) {return disas_pulley(func, addr);} else {"riscv64"diff --git a/supply-chain/imports.lock b/supply-chain/imports.lockindex c6d597160b..4dab166414 100644--- a/supply-chain/imports.lock+++ b/supply-chain/imports.lock@@ -1744,8 +1744,8 @@ user-login = "philipc"user-name = "Philip Craig"[[publisher.object]]-version = "0.39.0"-when = "2026-03-29"+version = "0.40.0"+when = "2026-08-01"user-id = 4415user-login = "philipc"user-name = "Philip Craig"