Skip to content

Commit e0d57b4

Browse files
committed
fixup! Fixes
1 parent 738623b commit e0d57b4

File tree

3 files changed

+33
-29
lines changed

3 files changed

+33
-29
lines changed

dev/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,6 @@ fn prepare_test_files() {
664664
&["-gstrict-dwarf", "-gdwarf-5", "-gz=zstd"],
665665
);
666666
}
667-
gnu_debugdata(&data_dir.join("test-no-debug.bin"), "test-debugdata.bin");
668667

669668
// Generate this binary by passing the source file name without a
670669
// path to the compiler (which means we need to `cd` into the
@@ -756,6 +755,7 @@ fn prepare_test_files() {
756755
&format!("--add-gnu-debuglink={}", dbg.display()),
757756
],
758757
);
758+
gnu_debugdata(&src, "test-stable-addrs-debugdata.bin");
759759

760760
let elf = data_dir.join("test-stable-addrs-no-dwarf.bin");
761761
objcopy(

src/elf/parser.rs

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@ fn decompress_xz(data: &[u8]) -> Result<Vec<u8>> {
286286
Ok(decompressed)
287287
}
288288

289+
#[cfg(not(feature = "xz"))]
290+
fn decompress_xz(_data: &[u8]) -> Result<Vec<u8>> {
291+
Err(Error::with_unsupported(
292+
"ELF section is xz compressed but xz compression support is not enabled",
293+
))
294+
}
295+
289296

290297
#[derive(Debug)]
291298
struct EhdrExt<'elf> {
@@ -823,26 +830,18 @@ where
823830
Ok(syms)
824831
}
825832

826-
#[cfg(feature = "xz")]
827833
fn parse_debugdata(&self) -> Result<Vec<u8>> {
828834
if let Some(idx) = self.find_section(".gnu_debugdata")? {
829-
let data = self.section_data_raw(idx)?;
830-
if !data.is_empty() {
831-
decompress_xz(&data)
832-
} else {
833-
Ok(Vec::new())
834-
}
835+
// NB: We assume here that `.gnu_debugdata` will never be
836+
// of type `SHT_NOBITS`, which just logically doesn't
837+
// make sense to be used.
838+
self.section_data_raw(idx)
839+
.and_then(|data| decompress_xz(&data))
835840
} else {
836841
Ok(Vec::new())
837842
}
838843
}
839844

840-
#[cfg(not(feature = "xz"))]
841-
fn parse_debugdata(&self) -> Result<Vec<u8>> {
842-
// We don't have the means to decompress it, fake an empty one.
843-
return Ok(Vec::new())
844-
}
845-
846845
fn ensure_symtab_cache(&self) -> Result<&SymbolTableCache<'_>> {
847846
self.symtab.get_or_try_init_(move || {
848847
let mut syms = self.parse_syms(".symtab")? as ElfN_Syms<'_>;
@@ -2215,21 +2214,6 @@ mod tests {
22152214
assert_eq!(new_data, data);
22162215
}
22172216

2218-
/// Make sure that we can look up a symbol residing in `.gnu_debugdata`.
2219-
#[test]
2220-
fn lookup_from_gnu_debugdata() {
2221-
let bin_name = Path::new(&env!("CARGO_MANIFEST_DIR"))
2222-
.join("data")
2223-
.join("test-debugdata.bin");
2224-
2225-
let parser = ElfParser::open(bin_name.as_path()).unwrap();
2226-
let opts = FindAddrOpts::default();
2227-
let addr = parser.find_addr("fibonacci", &opts).unwrap();
2228-
assert_eq!(addr.len(), 1);
2229-
let sym = &addr[0];
2230-
assert_eq!(sym.name, "fibonacci");
2231-
}
2232-
22332217
/// Benchmark creation of our "str2symtab" table.
22342218
///
22352219
/// Creating this table exercises a lot of the parser code paths and

tests/suite/symbolize.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,26 @@ fn symbolize_elf_stripped() {
463463
assert_eq!(result, Symbolized::Unknown(Reason::MissingSyms));
464464
}
465465

466+
/// Make sure that we can symbolize data from a compressed
467+
/// `.gnu_debugdata` section.
468+
#[tag(other_os)]
469+
#[test]
470+
fn symbolize_elf_compressed_gnu_debugdata() {
471+
let path = Path::new(&env!("CARGO_MANIFEST_DIR"))
472+
.join("data")
473+
.join("test-stable-addrs-debugdata.bin");
474+
let src = Source::Elf(Elf::new(path));
475+
let symbolizer = Symbolizer::new();
476+
let result = symbolizer
477+
.symbolize_single(&src, Input::VirtOffset(0x2000200))
478+
.unwrap()
479+
.into_sym()
480+
.unwrap();
481+
482+
assert_eq!(result.name, "factorial");
483+
assert_eq!(result.addr, 0x2000200);
484+
}
485+
466486
/// Check that we can symbolize data in a non-existent ELF binary after
467487
/// caching it.
468488
#[test]

0 commit comments

Comments
 (0)