Skip to content

Commit 78f1a49

Browse files
author
Kai Luo
committed
Correct avma -> svma conversion
1 parent 3895acd commit 78f1a49

File tree

2 files changed

+48
-11
lines changed

2 files changed

+48
-11
lines changed

src/symbolize/gimli/libs_aix.rs

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use super::mystd::borrow::ToOwned;
22
use super::mystd::ffi::{CStr, OsStr};
33
use super::mystd::os::unix::prelude::*;
4+
use super::{mmap, xcoff};
45
use super::{Library, LibrarySegment, Vec};
56

7+
const EXE_IMAGE_BASE: u64 = 0x100000000;
8+
69
pub(super) fn native_libraries() -> Vec<Library> {
710
let mut ret = Vec::new();
811
unsafe {
@@ -26,17 +29,25 @@ pub(super) fn native_libraries() -> Vec<Library> {
2629
loop {
2730
let text_base = (*current).ldinfo_textorg as usize;
2831
if text_base != 0 {
29-
let text_size = (*current).ldinfo_textsize as usize;
3032
let bytes = CStr::from_ptr(&(*current).ldinfo_filename[0]).to_bytes();
31-
let name = OsStr::from_bytes(bytes).to_owned();
32-
ret.push(Library {
33-
name,
34-
segments: vec![LibrarySegment {
35-
stated_virtual_memory_address: text_base,
36-
len: text_size,
37-
}],
38-
bias: 0,
39-
});
33+
let mut name = OsStr::from_bytes(bytes).to_owned();
34+
if text_base == EXE_IMAGE_BASE as usize {
35+
if let Ok(exe) = std::env::current_exe() {
36+
name = exe.into_os_string();
37+
}
38+
}
39+
if let Some(map) = mmap(name.as_ref()) {
40+
if let Some(image) = xcoff::get_text_image(&map) {
41+
ret.push(Library {
42+
name,
43+
segments: vec![LibrarySegment {
44+
stated_virtual_memory_address: image.base as usize,
45+
len: image.size,
46+
}],
47+
bias: (text_base + image.offset).wrapping_sub(image.base as usize),
48+
});
49+
}
50+
};
4051
}
4152
if (*current).ldinfo_next == 0 {
4253
break;

src/symbolize/gimli/xcoff.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use super::{Context, Mapping, Path, Stash, Vec};
2-
use object::read::xcoff::{FileHeader, SectionHeader, SectionTable, XcoffFile};
2+
use object::read::xcoff::FileHeader;
3+
use object::read::xcoff::SectionHeader;
4+
use object::read::xcoff::XcoffFile;
35
use object::Object as _;
46
use object::ObjectSection as _;
57
use object::ObjectSymbol as _;
@@ -29,6 +31,30 @@ pub struct Object<'a> {
2931
file: XcoffFile<'a, Xcoff>,
3032
}
3133

34+
pub struct Image {
35+
pub offset: usize,
36+
pub base: u64,
37+
pub size: usize,
38+
}
39+
40+
pub fn get_text_image(data: &[u8]) -> Option<Image> {
41+
let mut offset = 0;
42+
let header = Xcoff::parse(data, &mut offset).ok()?;
43+
let aux_header = header.aux_header(data, &mut offset).ok()?;
44+
let sections = header.sections(data, &mut offset).ok()?;
45+
if let Some(section) = sections.iter().find(|s| {
46+
let name = std::str::from_utf8(&s.s_name()[0..5]).unwrap();
47+
return name == ".text";
48+
}) {
49+
return Some(Image {
50+
offset: section.s_scnptr() as usize,
51+
base: section.s_paddr() as u64,
52+
size: section.s_size() as usize,
53+
});
54+
}
55+
return None;
56+
}
57+
3258
impl<'a> Object<'a> {
3359
fn parse(data: &'a [u8]) -> Option<Object<'a>> {
3460
let file = XcoffFile::parse(data).ok()?;

0 commit comments

Comments
 (0)