From 48af650c26f747eb44f17e1260cf5b86874c25b6 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Mon, 3 Feb 2025 15:30:45 +0100 Subject: [PATCH 1/4] fix(macho): Map section header name --- symbolic-debuginfo/src/macho/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/symbolic-debuginfo/src/macho/mod.rs b/symbolic-debuginfo/src/macho/mod.rs index 1b9e75d3..2060d925 100644 --- a/symbolic-debuginfo/src/macho/mod.rs +++ b/symbolic-debuginfo/src/macho/mod.rs @@ -466,7 +466,7 @@ impl<'data> Dwarf<'data> for MachObject<'data> { for section in segment.into_iter() { let (header, data) = section.ok()?; if let Ok(sec) = header.name() { - if sec.starts_with("__") && &sec[2..] == section_name { + if sec.starts_with("__") && map_section_name(&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 @@ -490,6 +490,13 @@ impl<'data> Dwarf<'data> for MachObject<'data> { } } +/// See . +fn map_section_name(name: &str) -> &str { + match name { + "debug_str_offs" => "debug_str_offsets", + _ => name, + } +} /// An iterator over symbols in the MachO file. /// /// Returned by [`MachObject::symbols`](struct.MachObject.html#method.symbols). From 7935849924fa85d975c522426ff99f8882e603ea Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 4 Feb 2025 13:12:35 +0100 Subject: [PATCH 2/4] test --- symbolic-debuginfo/src/macho/mod.rs | 11 +++++++++++ symbolic-debuginfo/tests/fixtures/helloworld | Bin 0 -> 9124 bytes 2 files changed, 11 insertions(+) create mode 100644 symbolic-debuginfo/tests/fixtures/helloworld diff --git a/symbolic-debuginfo/src/macho/mod.rs b/symbolic-debuginfo/src/macho/mod.rs index 2060d925..146839e4 100644 --- a/symbolic-debuginfo/src/macho/mod.rs +++ b/symbolic-debuginfo/src/macho/mod.rs @@ -943,4 +943,15 @@ mod tests { let _ = obj.symbol_map(); } + + #[test] + fn test_loads_debug_str_offsets() { + // File generated using dsymutil + let data = std::fs::read("tests/fixtures/helloworld").unwrap(); + + let obj = MachObject::parse(&data).unwrap(); + + assert!(obj.has_section("debug_str_offsets")); + assert_eq!(obj.section("debug_str_offsets").unwrap().data.len(), 48); + } } diff --git a/symbolic-debuginfo/tests/fixtures/helloworld b/symbolic-debuginfo/tests/fixtures/helloworld new file mode 100644 index 0000000000000000000000000000000000000000..2aed7c6cc42f4a52dafd8abbb200622a9ed77e08 GIT binary patch literal 9124 zcmeHNQD|FL7(O@2ZPVSkc1CSYoks1%fxAfyR#4d*nmEhSwKPSuGC15Mr)l)&-f-_t zH?Wf89vtF>3PO?LlMni|!2}0GecT>|JxxT|lP`kPfj;Tx@c-{UCrfTx>7&B=;qUqX z|NQ5>f4=iKB5U0b1p_t41C)B~j3;LM@p4B4Qm|$r_}V%WBbyx?3`$+ERdzd}aDDG{Jm9(` z-FR`1C*~=wxSmtDYCJoPx5e=S);o|LqZ=E8l(wwXb*oD2)~fCMz5IR7@k$+pU@yDe z9uxOr3zX7ab~#ID7fuv|-I(Fc1mkvsJ%NgQ1+4+=Yj)Q*?1+bbDFoLG!B*|=oBMrM zm^*PipPLgsvdQ!Cp(uPT2A+=*#u`gD3=|!-d|th!(cy7alFKnJC^28i2C54i~GI%YjeE6IgGt~ zJZi75x?%pzkAnKdewa_~u0HG+cuR4@c;`9ZB8NG@OFYYHK)3YscZ=g)=6JUNFZ|x| z?-k2g$$(@)G9Vd{3`hnf1CoLN69f2JZ&(@eOUCa%kN7?zP5yoG0QbfBVf+NySflI= ztF$~u*O*ad4xu%NF^|xOQMY_3`A0G!8ITM}1|$QL0m*=5Kr$d1kPJu$BmYjK@JFAj!z&fic+LcHg@SlTq!F5w`!7K8+uif!^LLLGG%N2Rz zm;&=vqWB;RIY5+1GyudKf1E@wq7Eq0f%ssI;A54>prRhbb;@JD8&|Z*kQyV(e&t{? zp+=MMY$R{Dlg{YK=y-Df_=5xPC}2#GX!3}rX+Q{?nsx-tm`*TZW-OX~QF}?7OB{uJ zXtg(pAwsgvrpZzj6K-!)>&$WMww0Qk)-!r0^{gK~JUN{KPoJ9Brw@^|*J!5Km}%Ol zZO5#3nRE2o${E~Y1+*Qa#1`X&joJ8rm~a;t7uNoCD|BOsbxTFRcJ#krL{T|T*(rHqU8y3b*&3O1?W>NqxM5HDkS4Kh}<~ u1qFW#un+WMP;9X+U5_SW&<0x*6M+Gt!!Q8>Y(y9i`Gfv);2p$)kbeMKHfACK literal 0 HcmV?d00001 From cac6971ff3edd17fc6ab8659e19e998fff746c0a Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 4 Feb 2025 13:14:24 +0100 Subject: [PATCH 3/4] doc: changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e87b50b4..b4756d84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +**Fixes** + +- Parse `debug_str_offs` section in Mach-O files ([#895](https://github.com/getsentry/symbolic/pull/895)) + ## 12.13.3 **Improvements** From f51cbefd22e50727cf514e1651e33c6212454e87 Mon Sep 17 00:00:00 2001 From: Joris Bayer Date: Tue, 4 Feb 2025 13:25:07 +0100 Subject: [PATCH 4/4] move test --- symbolic-debuginfo/src/dwarf.rs | 20 ++++++++++++++++++++ symbolic-debuginfo/src/macho/mod.rs | 12 +----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/symbolic-debuginfo/src/dwarf.rs b/symbolic-debuginfo/src/dwarf.rs index 541a5e6f..1714df4d 100644 --- a/symbolic-debuginfo/src/dwarf.rs +++ b/symbolic-debuginfo/src/dwarf.rs @@ -1487,3 +1487,23 @@ impl<'s> Iterator for DwarfFunctionIterator<'s> { } impl std::iter::FusedIterator for DwarfFunctionIterator<'_> {} + +#[cfg(test)] +mod tests { + use super::*; + + use crate::macho::MachObject; + + #[cfg(feature = "macho")] + #[test] + fn test_loads_debug_str_offsets() { + // File generated using dsymutil + + let data = std::fs::read("tests/fixtures/helloworld").unwrap(); + + let obj = MachObject::parse(&data).unwrap(); + + let sections = DwarfSections::from_dwarf(&obj); + assert_eq!(sections.debug_str_offsets.data.len(), 48); + } +} diff --git a/symbolic-debuginfo/src/macho/mod.rs b/symbolic-debuginfo/src/macho/mod.rs index 146839e4..85dbefb0 100644 --- a/symbolic-debuginfo/src/macho/mod.rs +++ b/symbolic-debuginfo/src/macho/mod.rs @@ -808,6 +808,7 @@ impl<'slf, 'd: 'slf> AsSelf<'slf> for MachArchive<'d> { #[cfg(test)] mod tests { + use super::*; #[test] @@ -943,15 +944,4 @@ mod tests { let _ = obj.symbol_map(); } - - #[test] - fn test_loads_debug_str_offsets() { - // File generated using dsymutil - let data = std::fs::read("tests/fixtures/helloworld").unwrap(); - - let obj = MachObject::parse(&data).unwrap(); - - assert!(obj.has_section("debug_str_offsets")); - assert_eq!(obj.section("debug_str_offsets").unwrap().data.len(), 48); - } }