From dbaf684db023934162f4c7ba1b912ca2c0f016b2 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Sep 2024 15:36:16 -0700 Subject: [PATCH 1/4] Fixup mystd imports --- src/symbolize/gimli/coff.rs | 4 +++- src/symbolize/gimli/elf.rs | 3 ++- src/symbolize/gimli/libs_aix.rs | 8 +++++--- src/symbolize/gimli/libs_dl_iterate_phdr.rs | 8 +++++--- src/symbolize/gimli/libs_haiku.rs | 10 ++++++---- src/symbolize/gimli/libs_illumos.rs | 8 +++++--- src/symbolize/gimli/libs_libnx.rs | 3 ++- src/symbolize/gimli/libs_macos.rs | 3 ++- src/symbolize/gimli/libs_windows.rs | 3 ++- src/symbolize/gimli/macho.rs | 5 ++++- src/symbolize/gimli/parse_running_mmaps_unix.rs | 6 ++++-- src/symbolize/gimli/xcoff.rs | 6 ++++-- 12 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/symbolize/gimli/coff.rs b/src/symbolize/gimli/coff.rs index 018cb494b..51bfd35bd 100644 --- a/src/symbolize/gimli/coff.rs +++ b/src/symbolize/gimli/coff.rs @@ -1,5 +1,7 @@ -use super::{gimli, Context, Endian, EndianSlice, Mapping, Path, Stash, Vec}; +use super::mystd::fs::Path; +use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; use alloc::sync::Arc; +use alloc::vec::Vec; use core::convert::TryFrom; use object::pe::{ImageDosHeader, ImageSymbol}; use object::read::coff::ImageSymbol as _; diff --git a/src/symbolize/gimli/elf.rs b/src/symbolize/gimli/elf.rs index b73f6aacb..444573fe2 100644 --- a/src/symbolize/gimli/elf.rs +++ b/src/symbolize/gimli/elf.rs @@ -5,8 +5,9 @@ use super::mystd::fs; use super::mystd::os::unix::ffi::{OsStrExt, OsStringExt}; use super::mystd::path::{Path, PathBuf}; use super::Either; -use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash, Vec}; +use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; use alloc::sync::Arc; +use alloc::vec::Vec; use core::convert::{TryFrom, TryInto}; use core::str; use object::elf::{ diff --git a/src/symbolize/gimli/libs_aix.rs b/src/symbolize/gimli/libs_aix.rs index aa4eaff89..509fae1e8 100644 --- a/src/symbolize/gimli/libs_aix.rs +++ b/src/symbolize/gimli/libs_aix.rs @@ -1,11 +1,13 @@ -use super::mystd::borrow::ToOwned; use super::mystd::env; -use super::mystd::ffi::{CStr, OsStr}; +use super::mystd::ffi::OsStr; use super::mystd::io::Error; use super::mystd::os::unix::prelude::*; use super::xcoff; -use super::{Library, LibrarySegment, Vec}; +use super::{Library, LibrarySegment}; +use alloc::borrow::ToOwned; use alloc::vec; +use alloc::vec::Vec; +use core::ffi::CStr; use core::mem; const EXE_IMAGE_BASE: u64 = 0x100000000; diff --git a/src/symbolize/gimli/libs_dl_iterate_phdr.rs b/src/symbolize/gimli/libs_dl_iterate_phdr.rs index 6bee79dd0..d52819f65 100644 --- a/src/symbolize/gimli/libs_dl_iterate_phdr.rs +++ b/src/symbolize/gimli/libs_dl_iterate_phdr.rs @@ -2,11 +2,13 @@ // and typically implement an API called `dl_iterate_phdr` to load // native libraries. -use super::mystd::borrow::ToOwned; use super::mystd::env; -use super::mystd::ffi::{CStr, OsStr}; +use super::mystd::ffi::{OsStr, OsString}; use super::mystd::os::unix::prelude::*; -use super::{parse_running_mmaps, Library, LibrarySegment, OsString, Vec}; +use super::{parse_running_mmaps, Library, LibrarySegment}; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; +use core::ffi::CStr; use core::slice; struct CallbackData { diff --git a/src/symbolize/gimli/libs_haiku.rs b/src/symbolize/gimli/libs_haiku.rs index 87e023e69..ddfd6b475 100644 --- a/src/symbolize/gimli/libs_haiku.rs +++ b/src/symbolize/gimli/libs_haiku.rs @@ -5,11 +5,13 @@ // that section. All the read-only segments of the ELF-binary are in // that part of the address space. -use super::mystd::borrow::ToOwned; -use super::mystd::ffi::{CStr, OsStr}; -use super::mystd::mem::MaybeUninit; +use super::mystd::ffi::OsStr; use super::mystd::os::unix::prelude::*; -use super::{Library, LibrarySegment, Vec}; +use super::{Library, LibrarySegment}; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; +use core::ffi::CStr; +use core::mem::MaybeUninit; pub(super) fn native_libraries() -> Vec { let mut libraries: Vec = Vec::new(); diff --git a/src/symbolize/gimli/libs_illumos.rs b/src/symbolize/gimli/libs_illumos.rs index 4fc510cf5..32b73b62c 100644 --- a/src/symbolize/gimli/libs_illumos.rs +++ b/src/symbolize/gimli/libs_illumos.rs @@ -1,7 +1,9 @@ -use super::mystd::borrow::ToOwned; -use super::mystd::ffi::{CStr, OsStr}; +use super::mystd::ffi::OsStr; use super::mystd::os::unix::prelude::*; -use super::{Library, LibrarySegment, Vec}; +use super::{Library, LibrarySegment}; +use alloc::borrow::ToOwned; +use alloc::vec::Vec; +use core::ffi::CStr; use core::mem; use object::NativeEndian; diff --git a/src/symbolize/gimli/libs_libnx.rs b/src/symbolize/gimli/libs_libnx.rs index 803008ef3..01ef21612 100644 --- a/src/symbolize/gimli/libs_libnx.rs +++ b/src/symbolize/gimli/libs_libnx.rs @@ -1,4 +1,5 @@ -use super::{Library, LibrarySegment, Vec}; +use super::{Library, LibrarySegment}; +use alloc::vec::Vec; // DevkitA64 doesn't natively support debug info, but the build system will // place debug info at the path `romfs:/debug_info.elf`. diff --git a/src/symbolize/gimli/libs_macos.rs b/src/symbolize/gimli/libs_macos.rs index 671505a13..f65811b2b 100644 --- a/src/symbolize/gimli/libs_macos.rs +++ b/src/symbolize/gimli/libs_macos.rs @@ -1,10 +1,11 @@ #![allow(deprecated)] -use super::mystd::ffi::{CStr, OsStr}; +use super::mystd::ffi::OsStr; use super::mystd::os::unix::prelude::*; use super::mystd::prelude::v1::*; use super::{Library, LibrarySegment}; use core::convert::TryInto; +use core::ffi::CStr; use core::mem; // FIXME: replace with ptr::from_ref once MSRV is high enough diff --git a/src/symbolize/gimli/libs_windows.rs b/src/symbolize/gimli/libs_windows.rs index 9afeaf913..6ba63cccb 100644 --- a/src/symbolize/gimli/libs_windows.rs +++ b/src/symbolize/gimli/libs_windows.rs @@ -1,6 +1,7 @@ use super::super::super::windows_sys::*; +use super::mystd::ffi::OsString; use super::mystd::os::windows::prelude::*; -use super::{coff, mmap, Library, LibrarySegment, OsString}; +use super::{coff, mmap, Library, LibrarySegment}; use alloc::vec; use alloc::vec::Vec; use core::mem; diff --git a/src/symbolize/gimli/macho.rs b/src/symbolize/gimli/macho.rs index ef51f1487..c76e7b69a 100644 --- a/src/symbolize/gimli/macho.rs +++ b/src/symbolize/gimli/macho.rs @@ -1,5 +1,8 @@ -use super::{gimli, Box, Context, Endian, EndianSlice, Mapping, Path, Stash, Vec}; +use super::mystd::fs::Path; +use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; +use alloc::boxed::Box; use alloc::sync::Arc; +use alloc::vec::Vec; use core::convert::TryInto; use object::macho; use object::read::macho::{MachHeader, Nlist, Section, Segment as _}; diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index 534492c59..4768475c3 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -2,10 +2,12 @@ // in `mod libs_dl_iterate_phdr` (e.g. linux, freebsd, ...); it may be more // general purpose, but it hasn't been tested elsewhere. +use super::mystd::ffi::OsString; use super::mystd::fs::File; use super::mystd::io::Read; -use super::mystd::str::FromStr; -use super::{OsString, String, Vec}; +use alloc::str::String; +use alloc::vec::Vec; +use core::str::FromStr; #[derive(PartialEq, Eq, Debug)] pub(super) struct MapsEntry { diff --git a/src/symbolize/gimli/xcoff.rs b/src/symbolize/gimli/xcoff.rs index dd308840f..dc9a1790d 100644 --- a/src/symbolize/gimli/xcoff.rs +++ b/src/symbolize/gimli/xcoff.rs @@ -1,9 +1,11 @@ use super::mystd::ffi::{OsStr, OsString}; +use super::mystd::fs::Path; use super::mystd::os::unix::ffi::OsStrExt; -use super::mystd::str; -use super::{gimli, Context, Endian, EndianSlice, Mapping, Path, Stash, Vec}; +use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; use alloc::sync::Arc; +use alloc::vec::Vec; use core::ops::Deref; +use core::str; use object::read::archive::ArchiveFile; use object::read::xcoff::{FileHeader, SectionHeader, XcoffFile, XcoffSymbol}; use object::Object as _; From 78daad3ee95259159fc7f8f497625d774f5c1363 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Sep 2024 17:18:47 -0700 Subject: [PATCH 2/4] Cleanup unnecessary usage of OsString --- src/symbolize/gimli/elf.rs | 40 +++++++++++++------------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/symbolize/gimli/elf.rs b/src/symbolize/gimli/elf.rs index 444573fe2..b9a890e9b 100644 --- a/src/symbolize/gimli/elf.rs +++ b/src/symbolize/gimli/elf.rs @@ -1,11 +1,12 @@ #![allow(clippy::useless_conversion)] -use super::mystd::ffi::{OsStr, OsString}; +use super::mystd::ffi::OsStr; use super::mystd::fs; -use super::mystd::os::unix::ffi::{OsStrExt, OsStringExt}; +use super::mystd::os::unix::ffi::OsStrExt; use super::mystd::path::{Path, PathBuf}; use super::Either; use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; +use alloc::str::String; use alloc::sync::Arc; use alloc::vec::Vec; use core::convert::{TryFrom, TryInto}; @@ -433,25 +434,17 @@ fn locate_build_id(build_id: &[u8]) -> Option { } let mut path = - Vec::with_capacity(BUILD_ID_PATH.len() + BUILD_ID_SUFFIX.len() + build_id.len() * 2 + 1); + String::with_capacity(BUILD_ID_PATH.len() + BUILD_ID_SUFFIX.len() + build_id.len() * 2 + 1); path.extend(BUILD_ID_PATH); - path.push(hex(build_id[0] >> 4)); - path.push(hex(build_id[0] & 0xf)); - path.push(b'/'); + path.push(char::from_digit((build_id[0] >> 4) as u32, 16)?); + path.push(char::from_digit((build_id[0] & 0xf) as u32, 16)?); + path.push('/'); for byte in &build_id[1..] { - path.push(hex(byte >> 4)); - path.push(hex(byte & 0xf)); + path.push(char::from_digit((byte >> 4) as u32, 16)?); + path.push(char::from_digit((byte & 0xf) as u32, 16)?); } path.extend(BUILD_ID_SUFFIX); - Some(PathBuf::from(OsString::from_vec(path))) -} - -fn hex(byte: u8) -> u8 { - if byte < 10 { - b'0' + byte - } else { - b'a' + byte - 10 - } + Some(PathBuf::from(path)) } /// Locate a file specified in a `.gnu_debuglink` section. @@ -468,9 +461,8 @@ fn hex(byte: u8) -> u8 { fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { let path = fs::canonicalize(path).ok()?; let parent = path.parent()?; - let mut f = PathBuf::from(OsString::with_capacity( - DEBUG_PATH.len() + parent.as_os_str().len() + filename.len() + 2, - )); + 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)); // Try "/parent/filename" if it differs from "path" @@ -481,9 +473,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { } // Try "/parent/.debug/filename" - let mut s = OsString::from(f); - s.clear(); - f = PathBuf::from(s); + f.clear(); f.push(parent); f.push(".debug"); f.push(filename); @@ -493,9 +483,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { if debug_path_exists() { // Try "/usr/lib/debug/parent/filename" - let mut s = OsString::from(f); - s.clear(); - f = PathBuf::from(s); + f.clear(); f.push(OsStr::from_bytes(DEBUG_PATH)); f.push(parent.strip_prefix("/").unwrap()); f.push(filename); From 9c8812e856d69100f663533144b609282ef2c111 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Sep 2024 17:28:56 -0700 Subject: [PATCH 3/4] Fix introduced compile failures --- src/symbolize/gimli/coff.rs | 2 +- src/symbolize/gimli/elf.rs | 10 +++++----- src/symbolize/gimli/macho.rs | 2 +- src/symbolize/gimli/parse_running_mmaps_unix.rs | 2 +- src/symbolize/gimli/xcoff.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/symbolize/gimli/coff.rs b/src/symbolize/gimli/coff.rs index 51bfd35bd..031afea0a 100644 --- a/src/symbolize/gimli/coff.rs +++ b/src/symbolize/gimli/coff.rs @@ -1,4 +1,4 @@ -use super::mystd::fs::Path; +use super::mystd::path::Path; use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; use alloc::sync::Arc; use alloc::vec::Vec; diff --git a/src/symbolize/gimli/elf.rs b/src/symbolize/gimli/elf.rs index b9a890e9b..b23b24fcc 100644 --- a/src/symbolize/gimli/elf.rs +++ b/src/symbolize/gimli/elf.rs @@ -6,7 +6,7 @@ use super::mystd::os::unix::ffi::OsStrExt; use super::mystd::path::{Path, PathBuf}; use super::Either; use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; -use alloc::str::String; +use alloc::string::String; use alloc::sync::Arc; use alloc::vec::Vec; use core::convert::{TryFrom, TryInto}; @@ -422,8 +422,8 @@ fn debug_path_exists() -> bool { /// The format of build id paths is documented at: /// https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html fn locate_build_id(build_id: &[u8]) -> Option { - const BUILD_ID_PATH: &[u8] = b"/usr/lib/debug/.build-id/"; - const BUILD_ID_SUFFIX: &[u8] = b".debug"; + const BUILD_ID_PATH: &str = "/usr/lib/debug/.build-id/"; + const BUILD_ID_SUFFIX: &str = ".debug"; if build_id.len() < 2 { return None; @@ -435,7 +435,7 @@ fn locate_build_id(build_id: &[u8]) -> Option { let mut path = String::with_capacity(BUILD_ID_PATH.len() + BUILD_ID_SUFFIX.len() + build_id.len() * 2 + 1); - path.extend(BUILD_ID_PATH); + path.push_str(BUILD_ID_PATH); path.push(char::from_digit((build_id[0] >> 4) as u32, 16)?); path.push(char::from_digit((build_id[0] & 0xf) as u32, 16)?); path.push('/'); @@ -443,7 +443,7 @@ fn locate_build_id(build_id: &[u8]) -> Option { path.push(char::from_digit((byte >> 4) as u32, 16)?); path.push(char::from_digit((byte & 0xf) as u32, 16)?); } - path.extend(BUILD_ID_SUFFIX); + path.push_str(BUILD_ID_SUFFIX); Some(PathBuf::from(path)) } diff --git a/src/symbolize/gimli/macho.rs b/src/symbolize/gimli/macho.rs index c76e7b69a..fcbe60986 100644 --- a/src/symbolize/gimli/macho.rs +++ b/src/symbolize/gimli/macho.rs @@ -1,4 +1,4 @@ -use super::mystd::fs::Path; +use super::mystd::path::Path; use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; use alloc::boxed::Box; use alloc::sync::Arc; diff --git a/src/symbolize/gimli/parse_running_mmaps_unix.rs b/src/symbolize/gimli/parse_running_mmaps_unix.rs index 4768475c3..5803d5dca 100644 --- a/src/symbolize/gimli/parse_running_mmaps_unix.rs +++ b/src/symbolize/gimli/parse_running_mmaps_unix.rs @@ -5,7 +5,7 @@ use super::mystd::ffi::OsString; use super::mystd::fs::File; use super::mystd::io::Read; -use alloc::str::String; +use alloc::string::String; use alloc::vec::Vec; use core::str::FromStr; diff --git a/src/symbolize/gimli/xcoff.rs b/src/symbolize/gimli/xcoff.rs index dc9a1790d..77fd1d3d7 100644 --- a/src/symbolize/gimli/xcoff.rs +++ b/src/symbolize/gimli/xcoff.rs @@ -1,6 +1,6 @@ use super::mystd::ffi::{OsStr, OsString}; -use super::mystd::fs::Path; use super::mystd::os::unix::ffi::OsStrExt; +use super::mystd::path::Path; use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash}; use alloc::sync::Arc; use alloc::vec::Vec; From b9e231e0d053322175c7c3fc3fb973ffaa4d8db1 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Fri, 6 Sep 2024 18:06:49 -0700 Subject: [PATCH 4/4] Remove another unnecessary OsStr usage --- src/symbolize/gimli/elf.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/symbolize/gimli/elf.rs b/src/symbolize/gimli/elf.rs index b23b24fcc..4db6be44d 100644 --- a/src/symbolize/gimli/elf.rs +++ b/src/symbolize/gimli/elf.rs @@ -393,7 +393,7 @@ fn decompress_zstd(mut input: &[u8], mut output: &mut [u8]) -> Option<()> { Some(()) } -const DEBUG_PATH: &[u8] = b"/usr/lib/debug"; +const DEBUG_PATH: &str = "/usr/lib/debug"; fn debug_path_exists() -> bool { cfg_if::cfg_if! { @@ -403,7 +403,7 @@ fn debug_path_exists() -> bool { let mut exists = DEBUG_PATH_EXISTS.load(Ordering::Relaxed); if exists == 0 { - exists = if Path::new(OsStr::from_bytes(DEBUG_PATH)).is_dir() { + exists = if Path::new(DEBUG_PATH).is_dir() { 1 } else { 2 @@ -484,7 +484,7 @@ fn locate_debuglink(path: &Path, filename: &[u8]) -> Option { if debug_path_exists() { // Try "/usr/lib/debug/parent/filename" f.clear(); - f.push(OsStr::from_bytes(DEBUG_PATH)); + f.push(DEBUG_PATH); f.push(parent.strip_prefix("/").unwrap()); f.push(filename); if f.is_file() {