Skip to content

Commit

Permalink
Merge of #679 - Fix CI for lints and migrations
Browse files Browse the repository at this point in the history
This doesn't fix #678 but will hopefully get CI passing again.

Longer term, I would like to change our dbghelp library loading to be less eek.
  • Loading branch information
workingjubilee authored Jan 2, 2025
2 parents 26ab4af + f696fd3 commit 59cbaf5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
if: contains(matrix.os, 'ubuntu')
env:
RUSTFLAGS: "-C link-arg=-Wl,--compress-debug-sections=zlib"
- run: cargo test
- run: cargo test --features "ruzstd"
if: contains(matrix.os, 'ubuntu-24.04') ||
(contains(matrix.os, 'ubuntu') && contains(matrix.rust, 'nightly'))
env:
Expand Down Expand Up @@ -235,7 +235,7 @@ jobs:
matrix:
target:
- wasm32-unknown-unknown
- wasm32-wasi
- wasm32-wasip1
- x86_64-unknown-fuchsia
- x86_64-fortanix-unknown-sgx
- x86_64-unknown-illumos
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ windows-targets = "0.52.6"

[target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies]
miniz_oxide = { version = "0.8", default-features = false }
ruzstd = { version = "0.7.2", default-features = false }
ruzstd = { version = "0.7.3", default-features = false, optional = true }
addr2line = { version = "0.24.0", default-features = false }
libc = { version = "0.2.156", default-features = false }

Expand All @@ -65,6 +65,8 @@ std = []

serialize-serde = ["serde"]

ruzstd = ["dep:ruzstd"]

#=======================================
# Deprecated/internal features
#
Expand Down
20 changes: 12 additions & 8 deletions src/dbghelp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ macro_rules! dbghelp {
#[allow(dead_code)]
impl Init {
$(pub fn $name(&self) -> $name {
// FIXME: https://github.com/rust-lang/backtrace-rs/issues/678
#[allow(static_mut_refs)]
unsafe {
DBGHELP.$name().unwrap()
}
Expand Down Expand Up @@ -318,24 +320,26 @@ pub fn init() -> Result<Init, ()> {
// functions in it, and that's detailed more below. We only do this
// once, though, so we've got a global boolean indicating whether we're
// done yet or not.
// FIXME: https://github.com/rust-lang/backtrace-rs/issues/678
#[allow(static_mut_refs)]
DBGHELP.ensure_open()?;

static mut INITIALIZED: bool = false;
if !INITIALIZED {
set_optional_options();
set_optional_options(ret.dbghelp());
INITIALIZED = true;
}
Ok(ret)
}
}
fn set_optional_options() -> Option<()> {
unsafe fn set_optional_options(dbghelp: *mut Dbghelp) -> Option<()> {
unsafe {
let orig = DBGHELP.SymGetOptions()?();
let orig = (*dbghelp).SymGetOptions()?();

// Ensure that the `SYMOPT_DEFERRED_LOADS` flag is set, because
// according to MSVC's own docs about this: "This is the fastest, most
// efficient way to use the symbol handler.", so let's do that!
DBGHELP.SymSetOptions()?(orig | SYMOPT_DEFERRED_LOADS);
(*dbghelp).SymSetOptions()?(orig | SYMOPT_DEFERRED_LOADS);

// Actually initialize symbols with MSVC. Note that this can fail, but we
// ignore it. There's not a ton of prior art for this per se, but LLVM
Expand All @@ -349,7 +353,7 @@ fn set_optional_options() -> Option<()> {
// the time, but now that it's using this crate it means that someone will
// get to initialization first and the other will pick up that
// initialization.
DBGHELP.SymInitializeW()?(GetCurrentProcess(), ptr::null_mut(), TRUE);
(*dbghelp).SymInitializeW()?(GetCurrentProcess(), ptr::null_mut(), TRUE);

// The default search path for dbghelp will only look in the current working
// directory and (possibly) `_NT_SYMBOL_PATH` and `_NT_ALT_SYMBOL_PATH`.
Expand All @@ -363,7 +367,7 @@ fn set_optional_options() -> Option<()> {
search_path_buf.resize(1024, 0);

// Prefill the buffer with the current search path.
if DBGHELP.SymGetSearchPathW()?(
if (*dbghelp).SymGetSearchPathW()?(
GetCurrentProcess(),
search_path_buf.as_mut_ptr(),
search_path_buf.len() as _,
Expand All @@ -383,7 +387,7 @@ fn set_optional_options() -> Option<()> {
let mut search_path = SearchPath::new(search_path_buf);

// Update the search path to include the directory of the executable and each DLL.
DBGHELP.EnumerateLoadedModulesW64()?(
(*dbghelp).EnumerateLoadedModulesW64()?(
GetCurrentProcess(),
Some(enum_loaded_modules_callback),
((&mut search_path) as *mut SearchPath) as *mut c_void,
Expand All @@ -392,7 +396,7 @@ fn set_optional_options() -> Option<()> {
let new_search_path = search_path.finalize();

// Set the new search path.
DBGHELP.SymSetSearchPathW()?(GetCurrentProcess(), new_search_path.as_ptr());
(*dbghelp).SymSetSearchPathW()?(GetCurrentProcess(), new_search_path.as_ptr());
}
Some(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ impl Cache {
// never happen, and symbolicating backtraces would be ssssllllooooowwww.
static mut MAPPINGS_CACHE: Option<Cache> = None;

// FIXME: https://github.com/rust-lang/backtrace-rs/issues/678
#[allow(static_mut_refs)]
f(MAPPINGS_CACHE.get_or_insert_with(Cache::new))
}

Expand Down
8 changes: 5 additions & 3 deletions src/symbolize/gimli/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use super::{gimli, Context, Endian, EndianSlice, Mapping, Stash, Vec};
use alloc::sync::Arc;
use core::convert::{TryFrom, TryInto};
use core::str;
use object::elf::{
ELFCOMPRESS_ZLIB, ELFCOMPRESS_ZSTD, ELF_NOTE_GNU, NT_GNU_BUILD_ID, SHF_COMPRESSED,
};
#[cfg(feature = "ruzstd")]
use object::elf::ELFCOMPRESS_ZSTD;
use object::elf::{ELFCOMPRESS_ZLIB, ELF_NOTE_GNU, NT_GNU_BUILD_ID, SHF_COMPRESSED};
use object::read::elf::{CompressionHeader, FileHeader, SectionHeader, SectionTable, Sym};
use object::read::StringTable;
use object::{BigEndian, Bytes, NativeEndian};
Expand Down Expand Up @@ -231,6 +231,7 @@ impl<'a> Object<'a> {
decompress_zlib(data.0, buf)?;
return Some(buf);
}
#[cfg(feature = "ruzstd")]
ELFCOMPRESS_ZSTD => {
let size = usize::try_from(header.ch_size(self.endian)).ok()?;
let buf = stash.allocate(size);
Expand Down Expand Up @@ -357,6 +358,7 @@ fn decompress_zlib(input: &[u8], output: &mut [u8]) -> Option<()> {
}
}

#[cfg(feature = "ruzstd")]
fn decompress_zstd(mut input: &[u8], mut output: &mut [u8]) -> Option<()> {
use ruzstd::frame::ReadFrameHeaderError;
use ruzstd::frame_decoder::FrameDecoderError;
Expand Down

0 comments on commit 59cbaf5

Please sign in to comment.