From 114da83ad678a86d9bf25e148327a97e0a8809bd Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 4 Nov 2017 15:29:16 -0700 Subject: [PATCH] Avoid using `to_string()` on ExternalName to create strings for symbol names. ExternalName's `to_string()` prepends a '%' for Cretonne's text syntax, but for creating symbol names we just want the raw bytes. --- lib/obj/src/emit_module.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/obj/src/emit_module.rs b/lib/obj/src/emit_module.rs index 2c115c8d84..2462ed836c 100644 --- a/lib/obj/src/emit_module.rs +++ b/lib/obj/src/emit_module.rs @@ -2,6 +2,8 @@ use cretonne::settings; use cretonne::settings::Configurable; use faerie::Artifact; use wasmstandalone_runtime; +use std::error::Error; +use std::str; /// Emits a module that has been emitted with the `WasmRuntime` runtime /// implementation to a native object file. @@ -24,11 +26,13 @@ pub fn emit_module<'module>( for (i, function_relocs) in relocations.iter().enumerate() { assert!(function_relocs.is_empty(), "relocations not supported yet"); let body = &compilation.functions[i]; + let external_name = + wasmstandalone_runtime::get_func_name(compilation.module.imported_funcs.len() + i); + let string_name = str::from_utf8(x.as_ref()).map_err(|err| { + err.description().to_string() + })?; - obj.add_code( - wasmstandalone_runtime::get_func_name(compilation.module.imported_funcs.len() + i), - body.clone(), - ); + obj.add_code(string_name, body.clone()); } Ok(())