@@ -163,7 +163,7 @@ fn find_header(data: &'_ [u8]) -> Option<(&'_ Mach, &'_ [u8])> {
163163pub struct Object < ' a > {
164164 endian : NativeEndian ,
165165 data : & ' a [ u8 ] ,
166- dwarf : Option < & ' a [ MachSection ] > ,
166+ dwarf : Option < ( & ' a MachSegment , & ' a [ MachSection ] ) > ,
167167 syms : Vec < ( & ' a [ u8 ] , u64 ) > ,
168168 syms_sort_by_name : bool ,
169169 // Only set for executables/libraries, and not the source object files.
@@ -185,7 +185,10 @@ impl<'a> Object<'a> {
185185 if let Some ( ( segment, section_data) ) = MachSegment :: from_command ( command) . ok ( ) ? {
186186 // Object files should have all sections in a single unnamed segment load command.
187187 if segment. name ( ) == b"__DWARF" || ( is_object && segment. name ( ) == b"" ) {
188- dwarf = segment. sections ( endian, section_data) . ok ( ) ;
188+ dwarf = segment
189+ . sections ( endian, section_data)
190+ . ok ( )
191+ . map ( |sections| ( segment, sections) ) ;
189192 }
190193 } else if let Some ( symtab) = command. symtab ( ) . ok ( ) ? {
191194 let symbols = symtab. symbols :: < Mach , _ > ( endian, data) . ok ( ) ?;
@@ -228,16 +231,19 @@ impl<'a> Object<'a> {
228231
229232 pub fn section ( & self , _: & Stash , name : & str ) -> Option < & ' a [ u8 ] > {
230233 let name = name. as_bytes ( ) ;
231- let dwarf = self . dwarf ?;
232- let section = dwarf. into_iter ( ) . find ( |section| {
233- let section_name = section. name ( ) ;
234- section_name == name || {
235- section_name. starts_with ( b"__" )
236- && name. starts_with ( b"." )
237- && & section_name[ 2 ..] == & name[ 1 ..]
238- }
239- } ) ?;
240- Some ( section. data ( self . endian , self . data ) . ok ( ) ?)
234+ let ( segment, sections) = self . dwarf ?;
235+ let ( section, offset) = segment
236+ . section_offsets ( self . endian , sections)
237+ . filter_map ( |section| section. ok ( ) )
238+ . find ( |( section, _offset) | {
239+ let section_name = section. name ( ) ;
240+ section_name == name || {
241+ section_name. starts_with ( b"__" )
242+ && name. starts_with ( b"." )
243+ && & section_name[ 2 ..] == & name[ 1 ..]
244+ }
245+ } ) ?;
246+ Some ( section. data ( self . endian , self . data , offset) . ok ( ) ?)
241247 }
242248
243249 pub fn search_symtab < ' b > ( & ' b self , addr : u64 ) -> Option < & ' b [ u8 ] > {
0 commit comments