@@ -2085,8 +2085,19 @@ fn add_linked_symbol_object(
2085
2085
file. set_mangling ( object:: write:: Mangling :: None ) ;
2086
2086
}
2087
2087
2088
+ // ld64 requires a relocation to load undefined symbols, see below.
2089
+ let ld64_section_helper = if file. format ( ) == object:: BinaryFormat :: MachO {
2090
+ Some ( file. add_section (
2091
+ file. segment_name ( object:: write:: StandardSegment :: Text ) . to_vec ( ) ,
2092
+ "__text" . into ( ) ,
2093
+ object:: SectionKind :: Text ,
2094
+ ) )
2095
+ } else {
2096
+ None
2097
+ } ;
2098
+
2088
2099
for ( sym, kind) in symbols. iter ( ) {
2089
- file. add_symbol ( object:: write:: Symbol {
2100
+ let symbol = file. add_symbol ( object:: write:: Symbol {
2090
2101
name : sym. clone ( ) . into ( ) ,
2091
2102
value : 0 ,
2092
2103
size : 0 ,
@@ -2100,6 +2111,23 @@ fn add_linked_symbol_object(
2100
2111
section : object:: write:: SymbolSection :: Undefined ,
2101
2112
flags : object:: SymbolFlags :: None ,
2102
2113
} ) ;
2114
+
2115
+ // TODO: Explain.
2116
+ if let Some ( section) = ld64_section_helper {
2117
+ // TODO: Use architecture-specific data.
2118
+ let offset = file. section_mut ( section) . append_data ( & [ 0 , 0 , 0 , 20 ] , 4 ) ;
2119
+ file. add_relocation ( section, object:: write:: Relocation {
2120
+ offset,
2121
+ addend : 0 ,
2122
+ symbol,
2123
+ flags : object:: write:: RelocationFlags :: MachO {
2124
+ r_type : object:: macho:: ARM64_RELOC_BRANCH26 ,
2125
+ r_pcrel : true ,
2126
+ r_length : 2 ,
2127
+ } ,
2128
+ } )
2129
+ . expect ( "failed adding relocation" ) ;
2130
+ }
2103
2131
}
2104
2132
2105
2133
let path = tmpdir. join ( "symbols.o" ) ;
0 commit comments