Skip to content

Commit 6eb846f

Browse files
authored
Merge pull request #18 from philipc/eh_frame_size
Try to determine the size of the eh_frame section
2 parents 1cede08 + 2008b6a commit 6eb846f

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

unwind/src/find_cfi/baremetal.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern "C" {
66
static __text_end: usize;
77
static __ehframehdr_start: usize;
88
static __ehframehdr_end: usize;
9+
static __ehframe_end: usize;
910
}
1011

1112
pub fn find_cfi_sections() -> Vec<EhRef> {
@@ -17,11 +18,13 @@ pub fn find_cfi_sections() -> Vec<EhRef> {
1718
let text_end = &__text_end as *const _ as u64;
1819
let cfi_start = &__ehframehdr_start as *const _ as u64;
1920
let cfi_end = &__ehframehdr_end as *const _ as u64;
21+
let eh_frame_end = &__ehframe_end as *const _ as u64;
2022

2123
cfi.push(EhRef {
2224
obj_base: 0,
2325
text: AddrRange { start: text_start, end: text_end },
2426
cfi: AddrRange { start: cfi_start, end: cfi_end },
27+
ehframe_end,
2528
});
2629
}
2730
trace!("CFI sections: {:?}", cfi);

unwind/src/find_cfi/ld.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use libc::{c_void, c_int, c_char};
22
use std::ffi::CStr;
3-
use std::{slice, mem};
3+
use std::{slice, mem, cmp};
44
use range::AddrRange;
55
use super::EhRef;
66

@@ -60,10 +60,15 @@ extern "C" fn callback(info: *const DlPhdrInfo, size: usize, data: *mut c_void)
6060
if let Some(eh_frame) = phdr.iter().filter(|x| x.type_ == PT_GNU_EH_FRAME).next() {
6161
let start_addr = (*info).addr + text.vaddr;
6262
let cfi_start = (*info).addr + eh_frame.vaddr;
63+
let max_vaddr = phdr.iter().filter(|x| x.type_ == PT_LOAD)
64+
.fold(0, |vaddr, x| cmp::max(vaddr, x.vaddr + x.memsz));
65+
// This is an upper bound, not the exact address.
66+
let ehframe_end = (*info).addr + max_vaddr;
6367
(*data).push(EhRef {
6468
obj_base: (*info).addr,
6569
text: AddrRange { start: start_addr, end: start_addr + text.memsz },
6670
cfi: AddrRange { start: cfi_start, end: cfi_start + eh_frame.memsz },
71+
ehframe_end,
6772
});
6873
}
6974
}

unwind/src/find_cfi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub struct EhRef {
55
pub obj_base: u64,
66
pub text: AddrRange,
77
pub cfi: AddrRange,
8+
pub ehframe_end: u64,
89
}
910

1011
#[cfg(unix)]

unwind/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Default for DwarfUnwinder {
6060
let eh_frame_hdr = EhFrameHdr::new(eh_frame_hdr, NativeEndian).parse(&bases, 8).unwrap();
6161

6262
let cfi_addr = deref_ptr(eh_frame_hdr.eh_frame_ptr());
63-
let cfi_sz = 0x10000000; // FIXME HACK
63+
let cfi_sz = er.ehframe_end.saturating_sub(cfi_addr);
6464

6565
let eh_frame: &'static [u8] = std::slice::from_raw_parts(cfi_addr as *const u8, cfi_sz as usize);
6666
trace!("cfi at {:p} sz {:x}", cfi_addr as *const u8, cfi_sz);

0 commit comments

Comments
 (0)