Migrating code to object (from faerie) (#1848)

* Using the "object" library everywhere in wasmtime.
* scroll_derive
This commit is contained in:
Yury Delendik
2020-06-10 11:27:00 -05:00
committed by GitHub
parent 5d01603390
commit e5b81bbc28
13 changed files with 166 additions and 77 deletions

View File

@@ -1,17 +1,29 @@
use anyhow::Result;
use faerie::{Artifact, Decl};
use object::write::{Object, StandardSection, Symbol, SymbolSection};
use object::{SymbolFlags, SymbolKind, SymbolScope};
/// Declares data segment symbol
pub fn declare_table(obj: &mut Artifact, index: usize) -> Result<()> {
pub fn declare_table(obj: &mut Object, index: usize) -> Result<()> {
let name = format!("_table_{}", index);
obj.declare(name, Decl::data())?;
let _symbol_id = obj.add_symbol(Symbol {
name: name.as_bytes().to_vec(),
value: 0,
size: 0,
kind: SymbolKind::Data,
scope: SymbolScope::Linkage,
weak: false,
section: SymbolSection::Undefined,
flags: SymbolFlags::None,
});
Ok(())
}
/// Emit segment data and initialization location
pub fn emit_table(obj: &mut Artifact, index: usize) -> Result<()> {
pub fn emit_table(obj: &mut Object, index: usize) -> Result<()> {
let name = format!("_table_{}", index);
let symbol_id = obj.symbol_id(name.as_bytes()).unwrap();
let section_id = obj.section_id(StandardSection::Data);
// FIXME: We need to initialize table using function symbols
obj.define(name, Vec::new())?;
obj.add_symbol_data(symbol_id, section_id, &[], 1);
Ok(())
}