Skip to content

Commit

Permalink
write: add Section::{data, data_mut} accessors (#367)
Browse files Browse the repository at this point in the history
This commit adds `Section::{data, data_mut}` accessors to
`write::Section` to allow accessing data after it's been appended. The
motivation for this is that in Wasmtime we build an `Object` but we try
to patch relocations after the locations of all symbols are known,
handling them before load-time. Currently the logic of
appending-with-alignment is duplicated in Wasmtime but allowing access
to the underlying section data as-been-appended-so-far should enable us
to remove that duplication.
  • Loading branch information
alexcrichton authored Aug 28, 2021
1 parent 0f73488 commit 6178499
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/write/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,22 @@ impl Section {
self.size += size;
offset as u64
}

/// Returns the section as-built so far.
///
/// This requires that the section is not a bss section.
pub fn data(&self) -> &[u8] {
debug_assert!(!self.is_bss());
&self.data
}

/// Returns the section as-built so far.
///
/// This requires that the section is not a bss section.
pub fn data_mut(&mut self) -> &mut [u8] {
debug_assert!(!self.is_bss());
&mut self.data
}
}

/// The section where a symbol is defined.
Expand Down

0 comments on commit 6178499

Please sign in to comment.