Skip to content

Commit

Permalink
Merge pull request #673 from philipc/issue-667
Browse files Browse the repository at this point in the history
read/cfi: implement DW_CFA_AARCH64_negate_ra_state
  • Loading branch information
philipc committed Aug 12, 2023
2 parents bcb5ee0 + 0b6670f commit 3904f11
Show file tree
Hide file tree
Showing 6 changed files with 261 additions and 41 deletions.
11 changes: 11 additions & 0 deletions crates/examples/src/bin/dwarfdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,11 @@ fn dump_eh_frame<R: Reader, W: Write>(
.unwrap_or(mem::size_of::<usize>() as u8);
eh_frame.set_address_size(address_size);

match file.architecture() {
object::Architecture::Aarch64 => eh_frame.set_vendor(gimli::Vendor::AArch64),
_ => {}
}

fn register_name_none(_: gimli::Register) -> Option<&'static str> {
None
}
Expand Down Expand Up @@ -1050,9 +1055,15 @@ fn dump_cfi_instructions<R: Reader, W: Write>(
ArgsSize { size } => {
writeln!(w, " DW_CFA_GNU_args_size ({})", size)?;
}
NegateRaState => {
writeln!(w, " DW_CFA_AARCH64_negate_ra_state")?;
}
Nop => {
writeln!(w, " DW_CFA_nop")?;
}
_ => {
writeln!(w, " {:?}", op)?;
}
},
}
}
Expand Down
21 changes: 19 additions & 2 deletions src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ macro_rules! registers {

/// ARM architecture specific definitions.
///
/// See [DWARF for the ARM Architecture](https://developer.arm.com/documentation/ihi0040/c/).
/// See [DWARF for the ARM Architecture](
/// https://github.com/ARM-software/abi-aa/blob/main/aadwarf32/aadwarf32.rst).
#[derive(Debug, Clone, Copy)]
pub struct Arm;

Expand Down Expand Up @@ -99,6 +100,8 @@ registers!(Arm, {
SPSR_UND = (132, "SPSR_UND"),
SPSR_SVC = (133, "SPSR_SVC"),

RA_AUTH_CODE = (143, "RA_AUTH_CODE"),

R8_USR = (144, "R8_USR"),
R9_USR = (145, "R9_USR"),
R10_USR = (146, "R10_USR"),
Expand Down Expand Up @@ -168,6 +171,11 @@ registers!(Arm, {
D29 = (285, "D29"),
D30 = (286, "D30"),
D31 = (287, "D31"),

TPIDRURO = (320, "TPIDRURO"),
TPIDRURW = (321, "TPIDRURW"),
TPIDPR = (322, "TPIDPR"),
HTPIDPR = (323, "HTPIDPR"),
},
aliases {
SP = (13, "SP"),
Expand Down Expand Up @@ -219,7 +227,8 @@ aliases {

/// ARM 64-bit (AArch64) architecture specific definitions.
///
/// See [DWARF for the ARM 64-bit Architecture](https://developer.arm.com/documentation/ihi0057/b/).
/// See [DWARF for the ARM 64-bit Architecture](
/// https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst).
#[derive(Debug, Clone, Copy)]
pub struct AArch64;

Expand Down Expand Up @@ -256,6 +265,14 @@ registers!(AArch64, {
X29 = (29, "X29"),
X30 = (30, "X30"),
SP = (31, "SP"),
PC = (32, "PC"),
ELR_MODE = (33, "ELR_mode"),
RA_SIGN_STATE = (34, "RA_SIGN_STATE"),
TPIDRRO_EL0 = (35, "TPIDRRO_EL0"),
TPIDR_EL0 = (36, "TPIDR_EL0"),
TPIDR_EL1 = (37, "TPIDR_EL1"),
TPIDR_EL2 = (38, "TPIDR_EL2"),
TPIDR_EL3 = (39, "TPIDR_EL3"),

V0 = (64, "V0"),
V1 = (65, "V1"),
Expand Down
10 changes: 10 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ impl Format {
}
}

/// Which vendor extensions to support.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Vendor {
/// A default set of extensions, including some common GNU extensions.
Default,
/// AAarch64 extensions.
AArch64,
}

/// Encoding parameters that are commonly used for multiple DWARF sections.
///
/// This is intended to be small enough to pass by value.
Expand Down
11 changes: 10 additions & 1 deletion src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@ use core::fmt;
// }
// }
macro_rules! dw {
($(#[$meta:meta])* $struct_name:ident($struct_type:ty) { $($name:ident = $val:expr),+ $(,)? }) => {
($(#[$meta:meta])* $struct_name:ident($struct_type:ty)
{ $($name:ident = $val:expr),+ $(,)? }
$(, aliases { $($alias_name:ident = $alias_val:expr),+ $(,)? })?
) => {
$(#[$meta])*
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct $struct_name(pub $struct_type);

$(
pub const $name: $struct_name = $struct_name($val);
)+
$($(
pub const $alias_name: $struct_name = $struct_name($alias_val);
)+)*

impl $struct_name {
pub fn static_string(&self) -> Option<&'static str> {
Expand Down Expand Up @@ -182,6 +188,9 @@ DwCfa(u8) {
DW_CFA_GNU_window_save = 0x2d,
DW_CFA_GNU_args_size = 0x2e,
DW_CFA_GNU_negative_offset_extended = 0x2f,
},
aliases {
DW_CFA_AARCH64_negate_ra_state = 0x2d,
});

dw!(
Expand Down
Loading

0 comments on commit 3904f11

Please sign in to comment.