Skip to content
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
26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ backtrace = "0.3.75"
bumpalo = "3.20.0"
mutatis = {version = "0.3.2", features = ["alloc"] }
cc = "1.2.41"
object = { version = "0.38.1", default-features = false, features = ['read_core', 'elf'] }
object = { version = "0.39.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.100", default-features = false }
Expand Down
12 changes: 5 additions & 7 deletions crates/environ/src/address_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Data structures to provide transformation of the source

use object::{Bytes, LittleEndian, U32Bytes};
use object::{Bytes, LittleEndian, U32};
use serde_derive::{Deserialize, Serialize};

/// Single source location to generated address mapping.
Expand Down Expand Up @@ -63,18 +63,16 @@ impl Default for FilePos {

/// Parse an `ELF_WASMTIME_ADDRMAP` section, returning the slice of code offsets
/// and the slice of associated file positions for each offset.
fn parse_address_map(
section: &[u8],
) -> Option<(&[U32Bytes<LittleEndian>], &[U32Bytes<LittleEndian>])> {
fn parse_address_map(section: &[u8]) -> Option<(&[U32<LittleEndian>], &[U32<LittleEndian>])> {
let mut section = Bytes(section);
// NB: this matches the encoding written by `append_to` in the
// `compile::address_map` module.
let count = section.read::<U32Bytes<LittleEndian>>().ok()?;
let count = section.read::<U32<LittleEndian>>().ok()?;
let count = usize::try_from(count.get(LittleEndian)).ok()?;
let (offsets, section) =
object::slice_from_bytes::<U32Bytes<LittleEndian>>(section.0, count).ok()?;
object::slice_from_bytes::<U32<LittleEndian>>(section.0, count).ok()?;
let (positions, section) =
object::slice_from_bytes::<U32Bytes<LittleEndian>>(section, count).ok()?;
object::slice_from_bytes::<U32<LittleEndian>>(section, count).ok()?;
debug_assert!(section.is_empty());
Some((offsets, positions))
}
Expand Down
10 changes: 5 additions & 5 deletions crates/environ/src/compile/address_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::InstructionAddressMap;
use crate::obj::ELF_WASMTIME_ADDRMAP;
use crate::prelude::*;
use object::write::{Object, StandardSegment};
use object::{LittleEndian, SectionKind, U32Bytes};
use object::{LittleEndian, SectionKind, U32};
use std::ops::Range;

/// Builder for the address map section of a wasmtime compilation image.
Expand All @@ -14,8 +14,8 @@ use std::ops::Range;
/// into an `Object`.
#[derive(Default)]
pub struct AddressMapSection {
offsets: Vec<U32Bytes<LittleEndian>>,
positions: Vec<U32Bytes<LittleEndian>>,
offsets: Vec<U32<LittleEndian>>,
positions: Vec<U32<LittleEndian>>,
last_offset: u32,
}

Expand Down Expand Up @@ -58,8 +58,8 @@ impl AddressMapSection {
}
last_srcloc = Some(srcloc);

self.offsets.push(U32Bytes::new(LittleEndian, pos));
self.positions.push(U32Bytes::new(LittleEndian, srcloc));
self.offsets.push(U32::new(LittleEndian, pos));
self.positions.push(U32::new(LittleEndian, srcloc));
}
self.last_offset = func_end;
}
Expand Down
42 changes: 20 additions & 22 deletions crates/environ/src/compile/frame_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
FrameInstPos, FrameStackShape, FrameStateSlotOffset, FrameTableDescriptorIndex, FrameValType,
FuncKey, WasmHeapTopType, WasmValType, prelude::*,
};
use object::{LittleEndian, U32Bytes};
use object::{LittleEndian, U32};
use std::collections::{HashMap, hash_map::Entry};

/// Builder for a stackslot descriptor.
Expand Down Expand Up @@ -230,19 +230,19 @@ impl FrameStateSlotBuilder {
pub struct FrameTableBuilder {
/// (offset, length) pairs into `frame_descriptor_data`, indexed
/// by frame descriptor number.
frame_descriptor_ranges: Vec<U32Bytes<LittleEndian>>,
frame_descriptor_ranges: Vec<U32<LittleEndian>>,
frame_descriptor_data: Vec<u8>,

/// Offset from frame slot up to FP for each frame descriptor.
frame_descriptor_fp_offsets: Vec<U32Bytes<LittleEndian>>,
frame_descriptor_fp_offsets: Vec<U32<LittleEndian>>,

progpoint_pcs: Vec<U32Bytes<LittleEndian>>,
progpoint_descriptor_offsets: Vec<U32Bytes<LittleEndian>>,
progpoint_descriptor_data: Vec<U32Bytes<LittleEndian>>,
progpoint_pcs: Vec<U32<LittleEndian>>,
progpoint_descriptor_offsets: Vec<U32<LittleEndian>>,
progpoint_descriptor_data: Vec<U32<LittleEndian>>,

breakpoint_pcs: Vec<U32Bytes<LittleEndian>>,
breakpoint_patch_offsets: Vec<U32Bytes<LittleEndian>>,
breakpoint_patch_data_ends: Vec<U32Bytes<LittleEndian>>,
breakpoint_pcs: Vec<U32<LittleEndian>>,
breakpoint_patch_offsets: Vec<U32<LittleEndian>>,
breakpoint_patch_data_ends: Vec<U32<LittleEndian>>,

breakpoint_patch_data: Vec<u8>,
}
Expand All @@ -264,11 +264,11 @@ impl FrameTableBuilder {
u32::try_from(self.frame_descriptor_fp_offsets.len()).unwrap(),
);
self.frame_descriptor_fp_offsets
.push(U32Bytes::new(LittleEndian, slot_to_fp_offset));
.push(U32::new(LittleEndian, slot_to_fp_offset));
self.frame_descriptor_ranges
.push(U32Bytes::new(LittleEndian, start));
.push(U32::new(LittleEndian, start));
self.frame_descriptor_ranges
.push(U32Bytes::new(LittleEndian, end));
.push(U32::new(LittleEndian, end));

index
}
Expand All @@ -295,34 +295,32 @@ impl FrameTableBuilder {
}

let start = u32::try_from(self.progpoint_descriptor_data.len()).unwrap();
self.progpoint_pcs
.push(U32Bytes::new(LittleEndian, pc_and_pos));
self.progpoint_pcs.push(U32::new(LittleEndian, pc_and_pos));
self.progpoint_descriptor_offsets
.push(U32Bytes::new(LittleEndian, start));
.push(U32::new(LittleEndian, start));

for (i, &(wasm_pc, frame_descriptor, stack_shape)) in frames.iter().enumerate() {
debug_assert!(wasm_pc < 0x8000_0000);
let not_last = i < (frames.len() - 1);
let wasm_pc = wasm_pc | if not_last { 0x8000_0000 } else { 0 };
self.progpoint_descriptor_data
.push(U32Bytes::new(LittleEndian, wasm_pc));
.push(U32::new(LittleEndian, wasm_pc));
self.progpoint_descriptor_data
.push(U32Bytes::new(LittleEndian, frame_descriptor.0));
.push(U32::new(LittleEndian, frame_descriptor.0));
self.progpoint_descriptor_data
.push(U32Bytes::new(LittleEndian, stack_shape.0));
.push(U32::new(LittleEndian, stack_shape.0));
}
}

/// Add one breakpoint patch.
pub fn add_breakpoint_patch(&mut self, wasm_pc: u32, patch_start_native_pc: u32, patch: &[u8]) {
self.breakpoint_pcs
.push(U32Bytes::new(LittleEndian, wasm_pc));
self.breakpoint_pcs.push(U32::new(LittleEndian, wasm_pc));
self.breakpoint_patch_offsets
.push(U32Bytes::new(LittleEndian, patch_start_native_pc));
.push(U32::new(LittleEndian, patch_start_native_pc));
self.breakpoint_patch_data.extend(patch.iter().cloned());
let end = u32::try_from(self.breakpoint_patch_data.len()).unwrap();
self.breakpoint_patch_data_ends
.push(U32Bytes::new(LittleEndian, end));
.push(U32::new(LittleEndian, end));
}

/// Serialize the framd-table data section, taking a closure to
Expand Down
20 changes: 9 additions & 11 deletions crates/environ/src/compile/stack_maps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::obj::ELF_WASMTIME_STACK_MAP;
use crate::prelude::*;
use cranelift_bitset::CompoundBitSet;
use object::write::{Object, StandardSegment};
use object::{LittleEndian, SectionKind, U32Bytes};
use object::{LittleEndian, SectionKind, U32};

/// Builder for the `ELF_WASMTIME_STACK_MAP` section in compiled executables.
///
Expand Down Expand Up @@ -71,9 +71,9 @@ use object::{LittleEndian, SectionKind, U32Bytes};
/// more.
#[derive(Default)]
pub struct StackMapSection {
pcs: Vec<U32Bytes<LittleEndian>>,
pointers_to_stack_map: Vec<U32Bytes<LittleEndian>>,
stack_map_data: Vec<U32Bytes<LittleEndian>>,
pcs: Vec<U32<LittleEndian>>,
pointers_to_stack_map: Vec<U32<LittleEndian>>,
stack_map_data: Vec<U32<LittleEndian>>,
last_offset: u32,
}

Expand Down Expand Up @@ -103,16 +103,15 @@ impl StackMapSection {
}

// Record parallel entries in `pcs`/`pointers_to_stack_map`.
self.pcs.push(U32Bytes::new(LittleEndian, code_offset));
self.pointers_to_stack_map.push(U32Bytes::new(
self.pcs.push(U32::new(LittleEndian, code_offset));
self.pointers_to_stack_map.push(U32::new(
LittleEndian,
u32::try_from(self.stack_map_data.len()).unwrap(),
));

// The frame data starts with the frame size and is then followed by
// `offsets` represented as a bit set.
self.stack_map_data
.push(U32Bytes::new(LittleEndian, frame_size));
self.stack_map_data.push(U32::new(LittleEndian, frame_size));

let mut bits = CompoundBitSet::<u32>::default();
for offset in frame_offsets {
Expand All @@ -121,10 +120,9 @@ impl StackMapSection {
}
let count = bits.iter_scalars().count();
self.stack_map_data
.push(U32Bytes::new(LittleEndian, count as u32));
.push(U32::new(LittleEndian, count as u32));
for scalar in bits.iter_scalars() {
self.stack_map_data
.push(U32Bytes::new(LittleEndian, scalar.0));
self.stack_map_data.push(U32::new(LittleEndian, scalar.0));
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/environ/src/compile/trap_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::TrapInformation;
use crate::obj::ELF_WASMTIME_TRAPS;
use crate::prelude::*;
use object::write::{Object, StandardSegment};
use object::{LittleEndian, SectionKind, U32Bytes};
use object::{LittleEndian, SectionKind, U32};
use std::ops::Range;

/// A helper structure to build the custom-encoded section of a wasmtime
Expand All @@ -13,7 +13,7 @@ use std::ops::Range;
/// `lookup_trap_code` below with the resulting section.
#[derive(Default)]
pub struct TrapEncodingBuilder {
offsets: Vec<U32Bytes<LittleEndian>>,
offsets: Vec<U32<LittleEndian>>,
traps: Vec<u8>,
last_offset: u32,
}
Expand Down Expand Up @@ -45,7 +45,7 @@ impl TrapEncodingBuilder {
for info in traps {
let pos = func_start + info.code_offset;
assert!(pos >= self.last_offset);
self.offsets.push(U32Bytes::new(LittleEndian, pos));
self.offsets.push(U32::new(LittleEndian, pos));
self.traps.push(info.trap_code as u8);
self.last_offset = pos;
}
Expand Down
Loading
Loading