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

fix(debuginfo): Improve .o handling on MachO (#173) #173

Merged
merged 2 commits into from
Mar 17, 2020
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
12 changes: 1 addition & 11 deletions debuginfo/src/dwarf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,6 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {
None => return Err(gimli::read::Error::MissingUnitDie.into()),
};

// Clang's LLD might eliminate an entire compilation unit and simply set the low_pc to zero
// and remove all range entries to indicate that it is missing. Skip such a unit, as it does
// not contain any code that can be executed.
if unit.low_pc == 0 && entry.attr(constants::DW_AT_ranges)?.is_none() {
return Ok(None);
nnethercote marked this conversation as resolved.
Show resolved Hide resolved
}

let language = match entry.attr_value(constants::DW_AT_language)? {
Some(AttributeValue::Language(lang)) => language_from_dwarf(lang),
_ => Language::Unknown,
Expand Down Expand Up @@ -483,11 +476,8 @@ impl<'d, 'a> DwarfUnit<'d, 'a> {
return Ok(tuple);
}

// to go by the logic in dwarf2read a low_pc of 0 can indicate an
// eliminated duplicate when the GNU linker is used.
// TODO: *technically* there could be a relocatable section placed at VA 0
let low_pc = match low_pc {
Some(low_pc) if low_pc != 0 => low_pc,
Some(low_pc) => low_pc,
Copy link
Member

Choose a reason for hiding this comment

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

@nnethercote I'm afraid we'll need to make this check conditional, as you suggested. See #173

_ => return Ok(tuple),
};

Expand Down
54 changes: 19 additions & 35 deletions debuginfo/src/macho.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,6 @@ impl<'d> MachObject<'d> {
self.symbols()
.any(|s| s.name().map_or(false, |n| n.starts_with("__?hidden#")))
}

/// Locates a segment by its name.
fn find_segment(&self, name: &str) -> Option<&mach::segment::Segment<'d>> {
for segment in &self.macho.segments {
if segment.name().map(|seg| seg == name).unwrap_or(false) {
return Some(segment);
}
}

None
}
}

impl fmt::Debug for MachObject<'_> {
Expand Down Expand Up @@ -353,31 +342,26 @@ impl<'d> Dwarf<'d> for MachObject<'d> {
}

fn raw_section(&self, section_name: &str) -> Option<DwarfSection<'d>> {
let segment_name = match section_name {
"eh_frame" => "__TEXT",
_ => "__DWARF",
};

let segment = self.find_segment(segment_name)?;

for section in segment {
if let Ok((header, data)) = section {
if let Ok(sec) = header.name() {
if sec.len() >= 2 && &sec[2..] == section_name {
// In some cases, dsymutil leaves sections headers but removes their data
// from the file. While the addr and size parameters are still set,
// `header.offset` is 0 in that case. We skip them just like the section was
// missing to avoid loading invalid data.
if header.offset == 0 {
return None;
for segment in &self.macho.segments {
for section in segment {
if let Ok((header, data)) = section {
if let Ok(sec) = header.name() {
if sec.len() >= 2 && &sec[2..] == section_name {
// In some cases, dsymutil leaves sections headers but removes their
// data from the file. While the addr and size parameters are still
// set, `header.offset` is 0 in that case. We skip them just like the
// section was missing to avoid loading invalid data.
if header.offset == 0 {
return None;
}

return Some(DwarfSection {
data: Cow::Borrowed(data),
address: header.addr,
offset: u64::from(header.offset),
align: u64::from(header.align),
});
}

return Some(DwarfSection {
data: Cow::Borrowed(data),
address: header.addr,
offset: u64::from(header.offset),
align: u64::from(header.align),
});
}
}
}
Expand Down