@@ -395,7 +395,8 @@ impl<
395395 } => {
396396 // eprintln!("unwinding with cui and eh_frame in module {}", module.name);
397397 let text_bytes = text_data. as_ref ( ) . and_then ( |data| {
398- let offset_from_base = u32:: try_from ( data. svma_range . start ) . ok ( ) ?;
398+ let offset_from_base =
399+ u32:: try_from ( data. svma_range . start . checked_sub ( module. base_svma ) ?) . ok ( ) ?;
399400 Some ( TextBytes :: new ( offset_from_base, & data. bytes [ ..] ) )
400401 } ) ;
401402 let stubs_range = if let Some ( stubs_range) = stubs {
@@ -618,15 +619,19 @@ impl<D: Deref<Target = [u8]>> ModuleUnwindDataInternal<D> {
618619 // multiple executable sections such as `__text`, `__stubs`, and `__stub_helper`. If we
619620 // don't have the full `__TEXT` segment contents, we can fall back to the contents of
620621 // just the `__text` section.
621- let text_data = section_info
622- . segment_data ( b"__TEXT" )
623- . zip ( section_info. segment_file_range ( b"__TEXT" ) )
624- . or_else ( || {
625- section_info
626- . section_data ( b"__text" )
627- . zip ( section_info. section_file_range ( b"__text" ) )
628- } )
629- . map ( |( bytes, svma_range) | TextByteData { bytes, svma_range } ) ;
622+ let text_data = if let ( Some ( bytes) , Some ( svma_range) ) = (
623+ section_info. segment_data ( b"__TEXT" ) ,
624+ section_info. segment_svma_range ( b"__TEXT" ) ,
625+ ) {
626+ Some ( TextByteData { bytes, svma_range } )
627+ } else if let ( Some ( bytes) , Some ( svma_range) ) = (
628+ section_info. section_data ( b"__text" ) ,
629+ section_info. section_svma_range ( b"__text" ) ,
630+ ) {
631+ Some ( TextByteData { bytes, svma_range } )
632+ } else {
633+ None
634+ } ;
630635 ModuleUnwindDataInternal :: CompactUnwindInfoAndEhFrame {
631636 unwind_info,
632637 eh_frame : eh_frame. map ( Arc :: new) ,
@@ -763,14 +768,11 @@ pub trait ModuleSectionInfo<D> {
763768 /// Get the given section's memory range, as stated in the module.
764769 fn section_svma_range ( & mut self , name : & [ u8 ] ) -> Option < Range < u64 > > ;
765770
766- /// Get the given section's file range in the module.
767- fn section_file_range ( & mut self , name : & [ u8 ] ) -> Option < Range < u64 > > ;
768-
769771 /// Get the given section's data.
770772 fn section_data ( & mut self , name : & [ u8 ] ) -> Option < D > ;
771773
772- /// Get the given segment's file range in the module.
773- fn segment_file_range ( & mut self , _name : & [ u8 ] ) -> Option < Range < u64 > > {
774+ /// Get the given segment's memory range, as stated in the module.
775+ fn segment_svma_range ( & mut self , _name : & [ u8 ] ) -> Option < Range < u64 > > {
774776 None
775777 }
776778
@@ -804,7 +806,7 @@ pub struct ExplicitModuleSectionInfo<D> {
804806 /// This is used to detect whether we need to do instruction analysis for an address.
805807 pub text_svma : Option < Range < u64 > > ,
806808 /// The data of the `__text` or `.text` section. This is where most of the compiled code is
807- /// stored.
809+ /// stored. For mach-O binaries, this does not need to be supplied if `text_segment` is supplied.
808810 ///
809811 /// This is used to handle function prologues and epilogues in some cases.
810812 pub text : Option < D > ,
@@ -844,11 +846,9 @@ pub struct ExplicitModuleSectionInfo<D> {
844846 pub eh_frame_hdr : Option < D > ,
845847 /// The data of the `.debug_frame` section. The related address range is not needed.
846848 pub debug_frame : Option < D > ,
847- /// The file range of the `__TEXT` segment of mach-O binaries, or the `__text` section if the
848- /// segment is unavailable.
849- pub text_segment_file_range : Option < Range < u64 > > ,
850- /// The data of the `__TEXT` segment of mach-O binaries, or the `__text` section if the segment
851- /// is unavailable.
849+ /// The address range of the `__TEXT` segment of mach-O binaries, if available.
850+ pub text_segment_svma : Option < Range < u64 > > ,
851+ /// The data of the `__TEXT` segment of mach-O binaries, if available.
852852 pub text_segment : Option < D > ,
853853}
854854
@@ -871,9 +871,6 @@ where
871871 _ => None ,
872872 }
873873 }
874- fn section_file_range ( & mut self , _name : & [ u8 ] ) -> Option < Range < u64 > > {
875- None
876- }
877874 fn section_data ( & mut self , name : & [ u8 ] ) -> Option < D > {
878875 match name {
879876 b"__text" | b".text" => self . text . take ( ) ,
@@ -884,9 +881,9 @@ where
884881 _ => None ,
885882 }
886883 }
887- fn segment_file_range ( & mut self , name : & [ u8 ] ) -> Option < Range < u64 > > {
884+ fn segment_svma_range ( & mut self , name : & [ u8 ] ) -> Option < Range < u64 > > {
888885 match name {
889- b"__TEXT" => self . text_segment_file_range . take ( ) ,
886+ b"__TEXT" => self . text_segment_svma . take ( ) ,
890887 _ => None ,
891888 }
892889 }
@@ -926,21 +923,14 @@ mod object {
926923 Some ( section. address ( ) ..section. address ( ) + section. size ( ) )
927924 }
928925
929- fn section_file_range ( & mut self , name : & [ u8 ] ) -> Option < Range < u64 > > {
930- let section = self . section_by_name_bytes ( name) ?;
931- let ( start, size) = section. file_range ( ) ?;
932- Some ( start..start + size)
933- }
934-
935926 fn section_data ( & mut self , name : & [ u8 ] ) -> Option < D > {
936927 let section = self . section_by_name_bytes ( name) ?;
937928 section. data ( ) . ok ( ) . map ( |data| data. into ( ) )
938929 }
939930
940- fn segment_file_range ( & mut self , name : & [ u8 ] ) -> Option < Range < u64 > > {
931+ fn segment_svma_range ( & mut self , name : & [ u8 ] ) -> Option < Range < u64 > > {
941932 let segment = self . segments ( ) . find ( |s| s. name_bytes ( ) == Ok ( Some ( name) ) ) ?;
942- let ( start, size) = segment. file_range ( ) ;
943- Some ( start..start + size)
933+ Some ( segment. address ( ) ..segment. address ( ) + segment. size ( ) )
944934 }
945935
946936 fn segment_data ( & mut self , name : & [ u8 ] ) -> Option < D > {
0 commit comments