Make more code work with no_std. (#407)

* Make more code work with no_std.

no_std support is still incomplete, but this patch takes care of the
bulk of the straightforward parts.
This commit is contained in:
Dan Gohman
2019-10-08 16:53:32 -07:00
committed by GitHub
parent c0b37bb713
commit 8e1b44b29c
100 changed files with 380 additions and 270 deletions

View File

@@ -1,10 +1,18 @@
//! Debug utils for WebAssembly using Cranelift.
use alloc::string::String;
use alloc::vec::Vec;
use cranelift_codegen::isa::TargetFrontendConfig;
use faerie::{Artifact, Decl};
use failure::Error;
use target_lexicon::{BinaryFormat, Triple};
use wasmtime_environ::{ModuleAddressMap, ModuleVmctxInfo, ValueLabelsRanges};
#[cfg(not(feature = "std"))]
use hashbrown::{hash_map, HashMap, HashSet};
#[cfg(feature = "std")]
use std::collections::{hash_map, HashMap, HashSet};
pub use crate::read_debuginfo::{read_debuginfo, DebugInfoData, WasmFileInfo};
pub use crate::transform::transform_dwarf;
pub use crate::write_debuginfo::{emit_dwarf, ResolvedSymbol, SymbolResolver};
@@ -16,6 +24,7 @@ mod write_debuginfo;
#[macro_use]
extern crate failure_derive;
extern crate alloc;
struct FunctionRelocResolver {}
impl SymbolResolver for FunctionRelocResolver {
@@ -71,12 +80,12 @@ pub fn emit_debugsections_image(
assert!(funcs.len() > 0);
let mut segment_body: (usize, usize) = (!0, 0);
for (body_ptr, body_len) in funcs.iter() {
segment_body.0 = ::std::cmp::min(segment_body.0, *body_ptr as usize);
segment_body.1 = ::std::cmp::max(segment_body.1, *body_ptr as usize + body_len);
segment_body.0 = ::core::cmp::min(segment_body.0, *body_ptr as usize);
segment_body.1 = ::core::cmp::max(segment_body.1, *body_ptr as usize + body_len);
}
let segment_body = (segment_body.0 as *const u8, segment_body.1 - segment_body.0);
let body = unsafe { ::std::slice::from_raw_parts(segment_body.0, segment_body.1) };
let body = unsafe { ::core::slice::from_raw_parts(segment_body.0, segment_body.1) };
obj.declare_with("all", Decl::function(), body.to_vec())?;
emit_dwarf(&mut obj, dwarf, &resolver)?;