Skip to content

Commit

Permalink
Fix encoding of .eh_frame for small LSDA encoding (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 authored Mar 30, 2024
1 parent 1130ac1 commit 7294ff0
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/write/cfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,16 +341,18 @@ impl FrameDescriptionEntry {
}

if cie.has_augmentation() {
let mut augmentation_length = 0u64;
if self.lsda.is_some() {
augmentation_length += u64::from(encoding.address_size);
}
w.write_uleb128(augmentation_length)?;
let augmentation_length_offset = w.len();
w.write_u8(0)?;
let augmentation_length_base = w.len();

debug_assert_eq!(self.lsda.is_some(), cie.lsda_encoding.is_some());
if let (Some(lsda), Some(lsda_encoding)) = (self.lsda, cie.lsda_encoding) {
w.write_eh_pointer(lsda, lsda_encoding, encoding.address_size)?;
}

let augmentation_length = (w.len() - augmentation_length_base) as u64;
debug_assert!(augmentation_length < 0x80);
w.write_udata_at(augmentation_length_offset, augmentation_length, 1)?;
}

let mut prev_offset = 0;
Expand Down Expand Up @@ -911,9 +913,18 @@ mod tests {
frames.add_fde(cie2_id, fde4.clone());

let mut cie3 = CommonInformationEntry::new(encoding, 1, 8, X86_64::RA);
cie3.fde_address_encoding = constants::DW_EH_PE_pcrel;
cie3.lsda_encoding = Some(constants::DW_EH_PE_pcrel);
cie3.personality = Some((constants::DW_EH_PE_pcrel, Address::Constant(0x1235)));
cie3.fde_address_encoding = constants::DwEhPe(
constants::DW_EH_PE_pcrel.0 | constants::DW_EH_PE_sdata4.0,
);
cie3.lsda_encoding = Some(constants::DwEhPe(
constants::DW_EH_PE_pcrel.0 | constants::DW_EH_PE_sdata4.0,
));
cie3.personality = Some((
constants::DwEhPe(
constants::DW_EH_PE_pcrel.0 | constants::DW_EH_PE_sdata4.0,
),
Address::Constant(0x1235),
));
cie3.signal_trampoline = true;
let cie3_id = frames.add_cie(cie3.clone());
assert_ne!(cie2_id, cie3_id);
Expand Down

0 comments on commit 7294ff0

Please sign in to comment.