Skip to content

Commit fbb9fc1

Browse files
authored
Update gimli dependencies (#421)
* Update addr2line dependency to 0.15.1 * Update object dependency to 0.24.0 * Disable libbacktrace build temporarily An unrelated change has caused this to fail.
1 parent 3356394 commit fbb9fc1

File tree

8 files changed

+37
-52
lines changed

8 files changed

+37
-52
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
- run: cargo build
6565
- run: cargo test
6666
- run: cargo test --features "gimli-symbolize"
67-
- run: cargo test --features "libbacktrace"
67+
# run: cargo test --features "libbacktrace"
6868
- run: cargo check --features "libbacktrace gimli-symbolize"
6969
- run: cargo test --features "serialize-rustc"
7070
- run: cargo test --features "serialize-serde"

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ cpp_demangle = { default-features = false, version = "0.3.0", optional = true }
3636

3737
# Optional dependencies enabled through the `gimli-symbolize` feature, do not
3838
# use these features directly.
39-
addr2line = { version = "0.14.1", optional = true, default-features = false }
39+
addr2line = { version = "0.15.1", optional = true, default-features = false }
4040
miniz_oxide = { version = "0.4.0", optional = true, default-features = false }
4141
[dependencies.object]
42-
version = "0.23"
42+
version = "0.24"
4343
optional = true
4444
default-features = false
4545
features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']

crates/as-if-std/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ bench = false
1515
cfg-if = "1.0"
1616
rustc-demangle = "0.1.4"
1717
libc = { version = "0.2.45", default-features = false }
18-
addr2line = { version = "0.14.1", default-features = false }
18+
addr2line = { version = "0.15.1", default-features = false }
1919
miniz_oxide = { version = "0.4.0", default-features = false }
2020

2121
[dependencies.object]
22-
version = "0.22"
22+
version = "0.24"
2323
default-features = false
2424
features = ['read_core', 'elf', 'macho', 'pe', 'unaligned', 'archive']
2525

src/symbolize/gimli.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,27 +85,13 @@ struct Context<'a> {
8585

8686
impl<'data> Context<'data> {
8787
fn new(stash: &'data Stash, object: Object<'data>) -> Option<Context<'data>> {
88-
fn load_section<'data, S>(stash: &'data Stash, obj: &Object<'data>) -> S
89-
where
90-
S: gimli::Section<gimli::EndianSlice<'data, Endian>>,
91-
{
92-
let data = obj.section(stash, S::section_name()).unwrap_or(&[]);
93-
S::from(EndianSlice::new(data, Endian))
94-
}
95-
96-
let dwarf = addr2line::Context::from_sections(
97-
load_section(stash, &object),
98-
load_section(stash, &object),
99-
load_section(stash, &object),
100-
load_section(stash, &object),
101-
load_section(stash, &object),
102-
load_section(stash, &object),
103-
load_section(stash, &object),
104-
load_section(stash, &object),
105-
load_section(stash, &object),
106-
gimli::EndianSlice::new(&[], Endian),
107-
)
88+
let sections = gimli::Dwarf::load(|id| -> Result<_, ()> {
89+
let data = object.section(stash, id.name()).unwrap_or(&[]);
90+
Ok(EndianSlice::new(data, Endian))
91+
})
10892
.ok()?;
93+
let dwarf = addr2line::Context::from_dwarf(sections).ok()?;
94+
10995
Some(Context { dwarf, object })
11096
}
11197
}

src/symbolize/gimli/coff.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::convert::TryFrom;
33
use object::pe::{ImageDosHeader, ImageSymbol};
44
use object::read::pe::{ImageNtHeaders, ImageOptionalHeader, SectionTable};
55
use object::read::StringTable;
6-
use object::{Bytes, LittleEndian as LE};
6+
use object::LittleEndian as LE;
77

88
#[cfg(target_pointer_width = "32")]
99
type Pe = object::pe::ImageNtHeaders32;
@@ -18,25 +18,25 @@ impl Mapping {
1818
}
1919

2020
pub struct Object<'a> {
21-
data: Bytes<'a>,
21+
data: &'a [u8],
2222
sections: SectionTable<'a>,
2323
symbols: Vec<(usize, &'a ImageSymbol)>,
2424
strings: StringTable<'a>,
2525
}
2626

2727
pub fn get_image_base(data: &[u8]) -> Option<usize> {
28-
let data = Bytes(data);
2928
let dos_header = ImageDosHeader::parse(data).ok()?;
30-
let (nt_headers, _, _) = dos_header.nt_headers::<Pe>(data).ok()?;
29+
let mut offset = dos_header.nt_headers_offset().into();
30+
let (nt_headers, _) = Pe::parse(data, &mut offset).ok()?;
3131
usize::try_from(nt_headers.optional_header().image_base()).ok()
3232
}
3333

3434
impl<'a> Object<'a> {
3535
fn parse(data: &'a [u8]) -> Option<Object<'a>> {
36-
let data = Bytes(data);
3736
let dos_header = ImageDosHeader::parse(data).ok()?;
38-
let (nt_headers, _, nt_tail) = dos_header.nt_headers::<Pe>(data).ok()?;
39-
let sections = nt_headers.sections(nt_tail).ok()?;
37+
let mut offset = dos_header.nt_headers_offset().into();
38+
let (nt_headers, _) = Pe::parse(data, &mut offset).ok()?;
39+
let sections = nt_headers.sections(data, offset).ok()?;
4040
let symtab = nt_headers.symbols(data).ok()?;
4141
let strings = symtab.strings();
4242
let image_base = usize::try_from(nt_headers.optional_header().image_base()).ok()?;
@@ -78,8 +78,7 @@ impl<'a> Object<'a> {
7878
.section_by_name(self.strings, name.as_bytes())?
7979
.1
8080
.pe_data(self.data)
81-
.ok()?
82-
.0,
81+
.ok()?,
8382
)
8483
}
8584

src/symbolize/gimli/elf.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct Object<'a> {
2929
/// We could use a literal instead, but this helps ensure correctness.
3030
endian: NativeEndian,
3131
/// The entire file data.
32-
data: Bytes<'a>,
32+
data: &'a [u8],
3333
sections: SectionTable<'a, Elf>,
3434
strings: StringTable<'a>,
3535
/// List of pre-parsed and sorted symbols by base address.
@@ -38,7 +38,6 @@ pub struct Object<'a> {
3838

3939
impl<'a> Object<'a> {
4040
fn parse(data: &'a [u8]) -> Option<Object<'a>> {
41-
let data = object::Bytes(data);
4241
let elf = Elf::parse(data).ok()?;
4342
let endian = elf.endian().ok()?;
4443
let sections = elf.sections(endian, data).ok()?;
@@ -90,7 +89,7 @@ impl<'a> Object<'a> {
9089

9190
pub fn section(&self, stash: &'a Stash, name: &str) -> Option<&'a [u8]> {
9291
if let Some(section) = self.section_header(name) {
93-
let mut data = section.data(self.endian, self.data).ok()?;
92+
let mut data = Bytes(section.data(self.endian, self.data).ok()?);
9493

9594
// Check for DWARF-standard (gABI) compression, i.e., as generated
9695
// by ld's `--compress-debug-sections=zlib-gabi` flag.
@@ -131,7 +130,7 @@ impl<'a> Object<'a> {
131130
}
132131
})
133132
.next()?;
134-
let mut data = compressed_section.data(self.endian, self.data).ok()?;
133+
let mut data = Bytes(compressed_section.data(self.endian, self.data).ok()?);
135134
if data.read_bytes(8).ok()?.0 != b"ZLIB\0\0\0\0" {
136135
return None;
137136
}

src/symbolize/gimli/libs_macos.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(super) fn native_libraries() -> Vec<Library> {
1919
fn native_library(i: u32) -> Option<Library> {
2020
use object::macho;
2121
use object::read::macho::{MachHeader, Segment};
22-
use object::{Bytes, NativeEndian};
22+
use object::NativeEndian;
2323

2424
// Fetch the name of this library which corresponds to the path of
2525
// where to load it as well.
@@ -47,7 +47,7 @@ fn native_library(i: u32) -> Option<Library> {
4747
header as *const _ as *const u8,
4848
mem::size_of_val(header) + header.sizeofcmds.get(endian) as usize,
4949
);
50-
(header.load_commands(endian, Bytes(data)).ok()?, endian)
50+
(header.load_commands(endian, data).ok()?, endian)
5151
}
5252
macho::MH_MAGIC_64 => {
5353
let endian = NativeEndian;
@@ -56,7 +56,7 @@ fn native_library(i: u32) -> Option<Library> {
5656
header as *const _ as *const u8,
5757
mem::size_of_val(header) + header.sizeofcmds.get(endian) as usize,
5858
);
59-
(header.load_commands(endian, Bytes(data)).ok()?, endian)
59+
(header.load_commands(endian, data).ok()?, endian)
6060
}
6161
_ => return None,
6262
}

src/symbolize/gimli/macho.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Mapping {
2020
// First up we need to load the unique UUID which is stored in the macho
2121
// header of the file we're reading, specified at `path`.
2222
let map = super::mmap(path)?;
23-
let (macho, data) = find_header(Bytes(&map))?;
23+
let (macho, data) = find_header(&map)?;
2424
let endian = macho.endian().ok()?;
2525
let uuid = macho.uuid(endian, data).ok()??;
2626

@@ -40,7 +40,7 @@ impl Mapping {
4040
// file. This should have the symbol table for at least some
4141
// symbolication purposes.
4242
Mapping::mk(map, |data, stash| {
43-
let (macho, data) = find_header(Bytes(data))?;
43+
let (macho, data) = find_header(data)?;
4444
let endian = macho.endian().ok()?;
4545
let obj = Object::parse(macho, endian, data)?;
4646
Context::new(stash, obj)
@@ -73,7 +73,7 @@ impl Mapping {
7373
let entry = entry.ok()?;
7474
let map = super::mmap(&entry.path())?;
7575
let candidate = Mapping::mk(map, |data, stash| {
76-
let (macho, data) = find_header(Bytes(data))?;
76+
let (macho, data) = find_header(data)?;
7777
let endian = macho.endian().ok()?;
7878
let entry_uuid = macho.uuid(endian, data).ok()??;
7979
if entry_uuid != uuid {
@@ -91,7 +91,7 @@ impl Mapping {
9191
}
9292
}
9393

94-
fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
94+
fn find_header(data: &'_ [u8]) -> Option<(&'_ Mach, &'_ [u8])> {
9595
use object::endian::BigEndian;
9696

9797
let desired_cpu = || {
@@ -108,6 +108,7 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
108108
}
109109
};
110110

111+
let mut data = Bytes(data);
111112
match data
112113
.clone()
113114
.read::<object::endian::U32<NativeEndian>>()
@@ -149,13 +150,13 @@ fn find_header(mut data: Bytes<'_>) -> Option<(&'_ Mach, Bytes<'_>)> {
149150
_ => return None,
150151
}
151152

152-
Mach::parse(data).ok().map(|h| (h, data))
153+
Mach::parse(data.0).ok().map(|h| (h, data.0))
153154
}
154155

155156
// This is used both for executables/libraries and source object files.
156157
pub struct Object<'a> {
157158
endian: NativeEndian,
158-
data: Bytes<'a>,
159+
data: &'a [u8],
159160
dwarf: Option<&'a [MachSection]>,
160161
syms: Vec<(&'a [u8], u64)>,
161162
syms_sort_by_name: bool,
@@ -166,7 +167,7 @@ pub struct Object<'a> {
166167
}
167168

168169
impl<'a> Object<'a> {
169-
fn parse(mach: &'a Mach, endian: NativeEndian, data: Bytes<'a>) -> Option<Object<'a>> {
170+
fn parse(mach: &'a Mach, endian: NativeEndian, data: &'a [u8]) -> Option<Object<'a>> {
170171
let is_object = mach.filetype(endian) == object::macho::MH_OBJECT;
171172
let mut dwarf = None;
172173
let mut syms = Vec::new();
@@ -181,7 +182,7 @@ impl<'a> Object<'a> {
181182
dwarf = segment.sections(endian, section_data).ok();
182183
}
183184
} else if let Some(symtab) = command.symtab().ok()? {
184-
let symbols = symtab.symbols::<Mach>(endian, data).ok()?;
185+
let symbols = symtab.symbols::<Mach, _>(endian, data).ok()?;
185186
syms = symbols
186187
.iter()
187188
.filter_map(|nlist: &MachNlist| {
@@ -230,7 +231,7 @@ impl<'a> Object<'a> {
230231
&& &section_name[2..] == &name[1..]
231232
}
232233
})?;
233-
Some(section.data(self.endian, self.data).ok()?.0)
234+
Some(section.data(self.endian, self.data).ok()?)
234235
}
235236

236237
pub fn search_symtab<'b>(&'b self, addr: u64) -> Option<&'b [u8]> {
@@ -299,9 +300,9 @@ fn object_mapping(path: &[u8]) -> Option<Mapping> {
299300
.members()
300301
.filter_map(Result::ok)
301302
.find(|m| m.name() == member_name)?;
302-
Bytes(member.data())
303+
member.data(data).ok()?
303304
}
304-
None => Bytes(data),
305+
None => data,
305306
};
306307
let (macho, data) = find_header(data)?;
307308
let endian = macho.endian().ok()?;

0 commit comments

Comments
 (0)