Skip to content

Commit c176648

Browse files
author
Kai Luo
committed
Add more comments about AIX ABI and AIX system API
1 parent 4ec4db3 commit c176648

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/symbolize/gimli/libs_aix.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ use core::mem;
1010

1111
const EXE_IMAGE_BASE: u64 = 0x100000000;
1212

13+
/// On AIX, we use `loadquery` with `L_GETINFO` flag to query libraries mmapped.
14+
/// See https://www.ibm.com/docs/en/aix/7.2?topic=l-loadquery-subroutine for
15+
/// detailed information of `loadquery`.
1316
pub(super) fn native_libraries() -> Vec<Library> {
1417
let mut ret = Vec::new();
1518
unsafe {
@@ -19,7 +22,7 @@ pub(super) fn native_libraries() -> Vec<Library> {
1922
libc::L_GETINFO,
2023
buffer.as_mut_ptr() as *mut libc::c_char,
2124
(mem::size_of::<libc::ld_info>() * buffer.len()) as u32,
22-
) >= 0
25+
) != -1
2326
{
2427
break;
2528
} else {

src/symbolize/gimli/xcoff.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ impl<'a> Object<'a> {
126126
let address = sym.address();
127127
let size = Self::get_concrete_size(&file, &sym);
128128
if name == ".text" || name == ".data" {
129+
// We don't want to include ".text" and ".data" symbols.
130+
// If they are included, since their ranges cover other
131+
// symbols, when searching a symbol for a given address,
132+
// ".text" or ".data" is returned. That's not what we expect.
129133
None
130134
} else {
131135
Some(ParsedSym {
@@ -145,16 +149,19 @@ impl<'a> Object<'a> {
145149
}
146150

147151
pub fn search_symtab<'b>(&'b self, addr: u64) -> Option<&'b [u8]> {
152+
// Symbols, except ".text" and ".data", are sorted and are not overlapped each other,
153+
// so we can just perform a binary search here.
148154
let i = match self.syms.binary_search_by_key(&addr, |sym| sym.address) {
149155
Ok(i) => i,
150156
Err(i) => i.checked_sub(1)?,
151157
};
152158
let sym = self.syms.get(i)?;
153159
if (sym.address..sym.address + sym.size).contains(&addr) {
154-
// FIXME: Should we trim the leading '.' of
155-
// the symbol of a function entry?
156-
// If not, the rust mangler might not work properly.
157-
// Or we should update rust mangler to trim the leading '.'?
160+
// On AIX, for a function call, for example, `foo()`, we have
161+
// two symbols `foo` and `.foo`. `foo` references the function
162+
// descriptor and `.foo` references the function entry. We trim
163+
// the prefix `.` here, so that the rust demangler can work
164+
// properly.
158165
Some(sym.name.trim_start_matches(".").as_bytes())
159166
} else {
160167
None

tests/smoke.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ fn get_actual_fn_pointer(fp: usize) -> usize {
99
// * The environment pointer.
1010
// Deref `fp` directly so that we can get the address of `fp`'s
1111
// entry point in text section.
12+
//
13+
// For TOC, one can find more information in
14+
// https://www.ibm.com/docs/en/aix/7.2?topic=program-understanding-programming-toc.
1215
if cfg!(target_os = "aix") {
1316
unsafe {
1417
let actual_fn_entry = *(fp as *const usize);

0 commit comments

Comments
 (0)