Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various cleanups #673

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/symbolize/gimli/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl<'a> Object<'a> {
let section = self.section_header(".gnu_debuglink")?;
let data = section.data(self.endian, self.data).ok()?;
let len = data.iter().position(|x| *x == 0)?;
let filename = &data[..len];
let filename = OsStr::from_bytes(&data[..len]);
let offset = (len + 1 + 3) & !3;
let crc_bytes = data
.get(offset..offset + 4)
Expand All @@ -332,7 +332,7 @@ impl<'a> Object<'a> {
let section = self.section_header(".gnu_debugaltlink")?;
let data = section.data(self.endian, self.data).ok()?;
let len = data.iter().position(|x| *x == 0)?;
let filename = &data[..len];
let filename = OsStr::from_bytes(&data[..len]);
let build_id = &data[len + 1..];
let path_sup = locate_debugaltlink(path, filename, build_id)?;
Some((path_sup, build_id))
Expand Down Expand Up @@ -460,12 +460,12 @@ fn locate_build_id(build_id: &[u8]) -> Option<PathBuf> {
/// gdb also allows the user to customize the debug search path, but we don't.
///
/// gdb also supports debuginfod, but we don't yet.
fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
fn locate_debuglink(path: &Path, filename: &OsStr) -> Option<PathBuf> {
let path = fs::canonicalize(path).ok()?;
let parent = path.parent()?;
let mut f =
PathBuf::with_capacity(DEBUG_PATH.len() + parent.as_os_str().len() + filename.len() + 2);
let filename = Path::new(OsStr::from_bytes(filename));
let filename = Path::new(filename);

// Try "/parent/filename" if it differs from "path"
f.push(parent);
Expand Down Expand Up @@ -509,8 +509,8 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option<PathBuf> {
/// gdb also allows the user to customize the debug search path, but we don't.
///
/// gdb also supports debuginfod, but we don't yet.
fn locate_debugaltlink(path: &Path, filename: &[u8], build_id: &[u8]) -> Option<PathBuf> {
let filename = Path::new(OsStr::from_bytes(filename));
fn locate_debugaltlink(path: &Path, filename: &OsStr, build_id: &[u8]) -> Option<PathBuf> {
let filename = Path::new(filename);
if filename.is_absolute() {
if filename.is_file() {
return Some(filename.into());
Expand All @@ -528,11 +528,6 @@ fn locate_debugaltlink(path: &Path, filename: &[u8], build_id: &[u8]) -> Option<
locate_build_id(build_id)
}

fn convert_path<R: gimli::Reader>(r: &R) -> Result<PathBuf, gimli::Error> {
let bytes = r.to_slice()?;
Ok(PathBuf::from(OsStr::from_bytes(&bytes)))
}

pub(super) fn handle_split_dwarf<'data>(
package: Option<&gimli::DwarfPackage<EndianSlice<'data, Endian>>>,
stash: &'data Stash,
Expand All @@ -546,10 +541,10 @@ pub(super) fn handle_split_dwarf<'data>(

let mut path = PathBuf::new();
if let Some(p) = load.comp_dir.as_ref() {
path.push(convert_path(p).ok()?);
path.push(OsStr::from_bytes(&p));
}

path.push(convert_path(load.path.as_ref()?).ok()?);
path.push(OsStr::from_bytes(&load.path.as_ref()?));

if let Some(map_dwo) = super::mmap(&path) {
let map_dwo = stash.cache_mmap(map_dwo);
Expand Down
19 changes: 13 additions & 6 deletions src/symbolize/gimli/libs_aix.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
use super::mystd::env;
use super::mystd::ffi::OsStr;
use super::mystd::io::Error;
use super::mystd::os::unix::prelude::*;
use super::xcoff;
use super::{Library, LibrarySegment};
use alloc::borrow::ToOwned;
use alloc::vec;
use alloc::vec::Vec;
use core::ffi::CStr;
use core::ffi::{c_int, CStr};
use core::mem;

const EXE_IMAGE_BASE: u64 = 0x100000000;

extern "C" {
#[link_name = "_Errno"]
fn errno_location() -> *mut c_int;
}

fn errno() -> i32 {
unsafe { (*errno_location()) as i32 }
}

/// On AIX, we use `loadquery` with `L_GETINFO` flag to query libraries mmapped.
/// See https://www.ibm.com/docs/en/aix/7.2?topic=l-loadquery-subroutine for
/// detailed information of `loadquery`.
Expand All @@ -28,15 +36,14 @@ pub(super) fn native_libraries() -> Vec<Library> {
{
break;
} else {
match Error::last_os_error().raw_os_error() {
Some(libc::ENOMEM) => {
match errno() {
libc::ENOMEM => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure if I should keep this change. If you want I will drop this commit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine to me.

buffer.resize(buffer.len() * 2, mem::zeroed::<libc::ld_info>());
}
Some(_) => {
_ => {
// If other error occurs, return empty libraries.
return Vec::new();
}
_ => unreachable!(),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/symbolize/gimli/xcoff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::mystd::ffi::{OsStr, OsString};
use super::mystd::ffi::OsStr;
use super::mystd::os::unix::ffi::OsStrExt;
use super::mystd::path::Path;
use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash};
Expand All @@ -19,7 +19,7 @@ type Xcoff = object::xcoff::FileHeader32;
type Xcoff = object::xcoff::FileHeader64;

impl Mapping {
pub fn new(path: &Path, member_name: &OsString) -> Option<Mapping> {
pub fn new(path: &Path, member_name: &OsStr) -> Option<Mapping> {
let map = super::mmap(path)?;
Mapping::mk(map, |data, stash| {
if member_name.is_empty() {
Expand Down Expand Up @@ -81,7 +81,7 @@ pub fn parse_xcoff(data: &[u8]) -> Option<Image> {
}
}

pub fn parse_image(path: &Path, member_name: &OsString) -> Option<Image> {
pub fn parse_image(path: &Path, member_name: &OsStr) -> Option<Image> {
let map = super::mmap(path)?;
let data = map.deref();
if member_name.is_empty() {
Expand Down
Loading