@@ -133,7 +133,8 @@ fn map_symbol(
133133 if symbol. is_weak ( ) {
134134 flags |= SymbolFlag :: Weak ;
135135 }
136- if file. format ( ) == object:: BinaryFormat :: Elf && symbol. scope ( ) == object:: SymbolScope :: Linkage
136+ if matches ! ( file. format( ) , object:: BinaryFormat :: Elf | object:: BinaryFormat :: MachO )
137+ && symbol. scope ( ) == object:: SymbolScope :: Linkage
137138 {
138139 flags |= SymbolFlag :: Hidden ;
139140 }
@@ -252,20 +253,22 @@ fn add_section_symbols(sections: &[Section], symbols: &mut Vec<Symbol>) {
252253
253254 // `section.size` can include extra padding, so instead prefer using the address that the
254255 // last symbol ends at when there are any symbols in the section.
256+ // Compute size as a section-relative offset (important for non-zero section.address, e.g. Mach-O).
255257 let size = symbols
256258 . iter ( )
257259 . filter ( |s| {
258260 s. section == Some ( section_idx) && s. kind == SymbolKind :: Object && s. size > 0
259261 } )
260262 . map ( |s| s. address + s. size )
261263 . max ( )
262- . unwrap_or ( section. size ) ;
264+ . unwrap_or ( section. address + section. size )
265+ . saturating_sub ( section. address ) ;
263266
264267 symbols. push ( Symbol {
265268 name,
266269 demangled_name : None ,
267270 normalized_name : None ,
268- address : 0 ,
271+ address : section . address ,
269272 size,
270273 kind : SymbolKind :: Section ,
271274 section : Some ( section_idx) ,
@@ -579,6 +582,9 @@ fn map_section_relocations(
579582 let flags = match reloc. flags ( ) {
580583 object:: RelocationFlags :: Elf { r_type } => RelocationFlags :: Elf ( r_type) ,
581584 object:: RelocationFlags :: Coff { typ } => RelocationFlags :: Coff ( typ) ,
585+ object:: RelocationFlags :: MachO { r_type, r_pcrel, r_length } => {
586+ RelocationFlags :: MachO { r_type, r_pcrel, r_length }
587+ }
582588 flags => bail ! ( "Unhandled relocation flags: {:?}" , flags) ,
583589 } ;
584590 let target_symbol = match symbol_indices. get ( symbol_index. 0 ) . copied ( ) {
0 commit comments