mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 21:58:20 +00:00
Record the .eh_frame sections from each .o file.
This commit is contained in:
@@ -83,7 +83,7 @@ impl Compiler for LLVMCompiler {
|
||||
)
|
||||
.collect::<Result<Vec<_>, CompileError>>()?
|
||||
.into_iter()
|
||||
.map(|(mut compiled_function, function_custom_sections)| {
|
||||
.map(|(mut compiled_function, function_custom_sections, _eh_frame_section_indices)| {
|
||||
let first_section = module_custom_sections.len() as u32;
|
||||
for (_, custom_section) in function_custom_sections.iter() {
|
||||
// TODO: remove this call to clone()
|
||||
|
||||
@@ -43,7 +43,7 @@ pub fn load_object_file<F>(
|
||||
root_section: &str,
|
||||
self_referential_relocation_target: Option<RelocationTarget>,
|
||||
mut symbol_name_to_relocation_target: F,
|
||||
) -> Result<(CompiledFunction, CustomSections), CompileError>
|
||||
) -> Result<(CompiledFunction, CustomSections, Vec<SectionIndex>), CompileError>
|
||||
where
|
||||
F: FnMut(&String) -> Result<Option<RelocationTarget>, CompileError>,
|
||||
{
|
||||
@@ -142,6 +142,20 @@ where
|
||||
// the sections we want to include.
|
||||
worklist.push(root_section_index);
|
||||
visited.insert(root_section_index);
|
||||
|
||||
// Also add any .eh_frame sections.
|
||||
let mut eh_frame_section_indices = vec![];
|
||||
// TODO: this constant has been added to goblin, now waiting for release
|
||||
const SHT_X86_64_UNWIND: u64 = 0x7000_0001;
|
||||
for (index, shdr) in elf.section_headers.iter().enumerate() {
|
||||
if shdr.sh_flags & SHT_X86_64_UNWIND != 0 {
|
||||
let index = ElfSectionIndex::from_usize(index)?;
|
||||
worklist.push(index);
|
||||
visited.insert(index);
|
||||
eh_frame_section_indices.push(index);
|
||||
}
|
||||
}
|
||||
|
||||
while let Some(section_index) = worklist.pop() {
|
||||
for reloc in reloc_sections
|
||||
.get(§ion_index)
|
||||
@@ -241,6 +255,8 @@ where
|
||||
.map(|(_, v)| v)
|
||||
.collect::<PrimaryMap<SectionIndex, _>>();
|
||||
|
||||
let eh_frame_section_indices = eh_frame_section_indices.iter().map(|index| section_to_custom_section.get(index).map_or_else(|| Err(CompileError::Codegen(format!(".eh_frame section with index={:?} was never loaded", index))), |idx| Ok(*idx))).collect::<Result<Vec<SectionIndex>, _>>()?;
|
||||
|
||||
let function_body = FunctionBody {
|
||||
body: section_bytes(root_section_index),
|
||||
unwind_info: None,
|
||||
@@ -271,5 +287,6 @@ where
|
||||
},
|
||||
},
|
||||
custom_sections,
|
||||
eh_frame_section_indices,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ impl FuncTrampoline {
|
||||
}
|
||||
|
||||
let mem_buf_slice = memory_buffer.as_slice();
|
||||
let (function, sections) =
|
||||
let (function, sections, _eh_frame_section_indices) =
|
||||
load_object_file(mem_buf_slice, FUNCTION_SECTION, None, |name: &String| {
|
||||
Err(CompileError::Codegen(format!(
|
||||
"trampoline generation produced reference to unknown function {}",
|
||||
@@ -175,7 +175,7 @@ impl FuncTrampoline {
|
||||
}
|
||||
|
||||
let mem_buf_slice = memory_buffer.as_slice();
|
||||
let (function, sections) =
|
||||
let (function, sections, _eh_frame_section_indices) =
|
||||
load_object_file(mem_buf_slice, FUNCTION_SECTION, None, |name: &String| {
|
||||
Err(CompileError::Codegen(format!(
|
||||
"trampoline generation produced reference to unknown function {}",
|
||||
|
||||
@@ -33,7 +33,7 @@ use wasmer_compiler::wasmparser::{MemoryImmediate, Operator};
|
||||
use wasmer_compiler::{
|
||||
to_wasm_error, wptype_to_type, CompileError, CompiledFunction, CustomSections,
|
||||
FunctionBodyData, GenerateMiddlewareChain, MiddlewareBinaryReader, ModuleTranslationState,
|
||||
RelocationTarget,
|
||||
RelocationTarget, SectionIndex,
|
||||
};
|
||||
use wasmer_runtime::{MemoryPlan, ModuleInfo, TablePlan};
|
||||
|
||||
@@ -76,7 +76,7 @@ impl FuncTranslator {
|
||||
memory_plans: &PrimaryMap<MemoryIndex, MemoryPlan>,
|
||||
_table_plans: &PrimaryMap<TableIndex, TablePlan>,
|
||||
func_names: &SecondaryMap<FunctionIndex, String>,
|
||||
) -> Result<(CompiledFunction, CustomSections), CompileError> {
|
||||
) -> Result<(CompiledFunction, CustomSections, Vec<SectionIndex>), CompileError> {
|
||||
// The function type, used for the callbacks.
|
||||
let function = CompiledFunctionKind::Local(*local_func_index);
|
||||
let func_index = wasm_module.func_index(*local_func_index);
|
||||
|
||||
Reference in New Issue
Block a user