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 dwarfdump machO relocations #449

Merged
merged 3 commits into from
Nov 19, 2019
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ os:
osx_image: xcode7.1

rust:
- 1.34.0
- 1.36.0
- nightly
- beta
- stable
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ crossbeam = "0.7.1"
getopts = "0.2"
memmap = "0.7"
num_cpus = "1"
object = "0.12"
object = "0.15"
rayon = "1.0"
regex = "1"
test-assembler = "0.1.3"
typed-arena = "1"
target-lexicon = "0.8"

[features]
read = []
Expand Down
58 changes: 36 additions & 22 deletions examples/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,24 @@ fn add_relocations(
let offset = offset as usize;
match relocation.kind() {
object::RelocationKind::Absolute => {
if let Some(symbol) = file.symbol_by_index(relocation.symbol()) {
let addend = symbol.address().wrapping_add(relocation.addend() as u64);
relocation.set_addend(addend as i64);
if relocations.insert(offset, relocation).is_some() {
println!(
"Multiple relocations for section {} at offset 0x{:08x}",
section.name().unwrap(),
offset
);
match relocation.target() {
object::RelocationTarget::Symbol(symbol_idx) => {
if let Some(symbol) = file.symbol_by_index(symbol_idx) {
let addend = symbol.address().wrapping_add(relocation.addend() as u64);
relocation.set_addend(addend as i64);
} else {
println!(
"Relocation with invalid symbol for section {} at offset 0x{:08x}",
section.name().unwrap(),
offset
);
}
}
} else {
object::RelocationTarget::Section(_section_idx) => {}
}
if relocations.insert(offset, relocation).is_some() {
println!(
"Relocation with invalid symbol for section {} at offset 0x{:08x}",
"Multiple relocations for section {} at offset 0x{:08x}",
section.name().unwrap(),
offset
);
Expand Down Expand Up @@ -514,19 +519,23 @@ where
let out = io::stdout();
if flags.eh_frame {
// TODO: this might be better based on the file format.
let address_size = match file.machine() {
object::Machine::Arm | object::Machine::Mips | object::Machine::X86 => 4,
object::Machine::Arm64 | object::Machine::X86_64 => 8,
object::Machine::Other => mem::size_of::<usize>() as u8,
};
let address_size = file
.architecture()
.pointer_width()
.map(|w| w.bytes())
.unwrap_or(mem::size_of::<usize>() as u8);

fn register_name_none(_: gimli::Register) -> Option<&'static str> {
None
}
let arch_register_name = match file.machine() {
object::Machine::Arm | object::Machine::Arm64 => gimli::Arm::register_name,
object::Machine::X86 => gimli::X86::register_name,
object::Machine::X86_64 => gimli::X86_64::register_name,
let arch_register_name = match file.architecture() {
target_lexicon::Architecture::Arm(_) | target_lexicon::Architecture::Aarch64(_) => {
gimli::Arm::register_name
}
target_lexicon::Architecture::I386
| target_lexicon::Architecture::I586
| target_lexicon::Architecture::I686 => gimli::X86::register_name,
target_lexicon::Architecture::X86_64 => gimli::X86_64::register_name,
_ => register_name_none,
};
let register_name = |register| match arch_register_name(register) {
Expand Down Expand Up @@ -935,7 +944,7 @@ fn dump_types<R: Reader, W: Write>(
let unit = match dwarf.type_unit(header) {
Ok(unit) => unit,
Err(err) => {
writeln_error(w, dwarf, err.into(), "Failed to parse unit root entry")?;
writeln_error(w, dwarf, err.into(), "Failed to parse type unit root entry")?;
continue;
}
};
Expand Down Expand Up @@ -1754,7 +1763,12 @@ fn dump_line<R: Reader, W: Write>(w: &mut W, dwarf: &gimli::Dwarf<R>) -> Result<
let unit = match dwarf.unit(header) {
Ok(unit) => unit,
Err(err) => {
writeln_error(w, dwarf, err.into(), "Failed to parse unit root entry")?;
writeln_error(
w,
dwarf,
err.into(),
"Failed to parse unit root entry for dump_line",
)?;
continue;
}
};
Expand Down