@@ -85,6 +85,7 @@ pub const Thunk = struct {
85
85
value : u64 = 0 ,
86
86
out_n_sect : u8 = 0 ,
87
87
symbols : std .AutoArrayHashMapUnmanaged (MachO.Ref , void ) = .{},
88
+ output_symtab_ctx : MachO.SymtabCtx = .{},
88
89
89
90
pub fn deinit (thunk : * Thunk , allocator : Allocator ) void {
90
91
thunk .symbols .deinit (allocator );
@@ -116,6 +117,34 @@ pub const Thunk = struct {
116
117
}
117
118
}
118
119
120
+ pub fn calcSymtabSize (thunk : * Thunk , macho_file : * MachO ) void {
121
+ thunk .output_symtab_ctx .nlocals = @as (u32 , @intCast (thunk .symbols .keys ().len ));
122
+ for (thunk .symbols .keys ()) | ref | {
123
+ const sym = ref .getSymbol (macho_file ).? ;
124
+ thunk .output_symtab_ctx .strsize += @as (u32 , @intCast (sym .getName (macho_file ).len + "__thunk" .len + 1 ));
125
+ }
126
+ }
127
+
128
+ pub fn writeSymtab (thunk : Thunk , macho_file : * MachO , ctx : anytype ) void {
129
+ var n_strx = thunk .output_symtab_ctx .stroff ;
130
+ for (thunk .symbols .keys (), thunk .output_symtab_ctx .ilocal .. ) | ref , ilocal | {
131
+ const sym = ref .getSymbol (macho_file ).? ;
132
+ const name = sym .getName (macho_file );
133
+ const out_sym = & ctx .symtab .items [ilocal ];
134
+ out_sym .n_strx = n_strx ;
135
+ @memcpy (ctx .strtab .items [n_strx .. ][0.. name .len ], name );
136
+ n_strx += @intCast (name .len );
137
+ @memcpy (ctx .strtab .items [n_strx .. ][0.. "__thunk" .len ], "__thunk" );
138
+ n_strx += @intCast ("__thunk" .len );
139
+ ctx .strtab .items [n_strx ] = 0 ;
140
+ n_strx += 1 ;
141
+ out_sym .n_type = macho .N_SECT ;
142
+ out_sym .n_sect = @intCast (thunk .out_n_sect + 1 );
143
+ out_sym .n_value = @intCast (thunk .getTargetAddress (ref , macho_file ));
144
+ out_sym .n_desc = 0 ;
145
+ }
146
+ }
147
+
119
148
pub fn format (
120
149
thunk : Thunk ,
121
150
comptime unused_fmt_string : []const u8 ,
0 commit comments