@@ -362,8 +362,8 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
362
362
363
363
self .base .file = file ;
364
364
365
- // Create dSYM bundle.
366
365
if (! options .strip and options .module != null ) {
366
+ // Create dSYM bundle.
367
367
const dir = options .module .? .zig_cache_artifact_directory ;
368
368
log .debug ("creating {s}.dSYM bundle in {s}" , .{ sub_path , dir .path });
369
369
@@ -1223,7 +1223,11 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
1223
1223
self .shrinkTextBlock (& decl .link .macho , code .len );
1224
1224
}
1225
1225
decl .link .macho .size = code .len ;
1226
- symbol .n_strx = try self .updateString (symbol .n_strx , mem .spanZ (decl .name ));
1226
+
1227
+ const new_name = try std .fmt .allocPrint (self .base .allocator , "_{s}" , .{mem .spanZ (decl .name )});
1228
+ defer self .base .allocator .free (new_name );
1229
+
1230
+ symbol .n_strx = try self .updateString (symbol .n_strx , new_name );
1227
1231
symbol .n_type = macho .N_SECT ;
1228
1232
symbol .n_sect = @intCast (u8 , self .text_section_index .? ) + 1 ;
1229
1233
symbol .n_desc = 0 ;
@@ -1232,7 +1236,9 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
1232
1236
if (self .d_sym ) | * ds |
1233
1237
try ds .writeLocalSymbol (decl .link .macho .local_sym_index );
1234
1238
} else {
1235
- const decl_name = mem .spanZ (decl .name );
1239
+ const decl_name = try std .fmt .allocPrint (self .base .allocator , "_{s}" , .{mem .spanZ (decl .name )});
1240
+ defer self .base .allocator .free (decl_name );
1241
+
1236
1242
const name_str_index = try self .makeString (decl_name );
1237
1243
const addr = try self .allocateTextBlock (& decl .link .macho , code .len , required_alignment );
1238
1244
@@ -1371,6 +1377,9 @@ pub fn updateDeclExports(
1371
1377
const decl_sym = & self .locals .items [decl .link .macho .local_sym_index ];
1372
1378
1373
1379
for (exports ) | exp | {
1380
+ const exp_name = try std .fmt .allocPrint (self .base .allocator , "_{s}" , .{exp .options .name });
1381
+ defer self .base .allocator .free (exp_name );
1382
+
1374
1383
if (exp .options .section ) | section_name | {
1375
1384
if (! mem .eql (u8 , section_name , "__text" )) {
1376
1385
try module .failed_exports .ensureCapacity (module .gpa , module .failed_exports .items ().len + 1 );
@@ -1398,7 +1407,7 @@ pub fn updateDeclExports(
1398
1407
// Otherwise, don't do anything since we already have all the flags
1399
1408
// set that we need for global (strong) linkage.
1400
1409
// n_type == N_SECT | N_EXT
1401
- if (mem .eql (u8 , exp . options . name , "_main" )) {
1410
+ if (mem .eql (u8 , exp_name , "_main" )) {
1402
1411
self .entry_addr = decl_sym .n_value ;
1403
1412
}
1404
1413
},
@@ -1420,14 +1429,14 @@ pub fn updateDeclExports(
1420
1429
if (exp .link .macho .sym_index ) | i | {
1421
1430
const sym = & self .globals .items [i ];
1422
1431
sym .* = .{
1423
- .n_strx = try self .updateString (sym .n_strx , exp . options . name ),
1432
+ .n_strx = try self .updateString (sym .n_strx , exp_name ),
1424
1433
.n_type = n_type ,
1425
1434
.n_sect = @intCast (u8 , self .text_section_index .? ) + 1 ,
1426
1435
.n_desc = n_desc ,
1427
1436
.n_value = decl_sym .n_value ,
1428
1437
};
1429
1438
} else {
1430
- const name_str_index = try self .makeString (exp . options . name );
1439
+ const name_str_index = try self .makeString (exp_name );
1431
1440
const i = if (self .globals_free_list .popOrNull ()) | i | i else blk : {
1432
1441
_ = self .globals .addOneAssumeCapacity ();
1433
1442
self .export_info_dirty = true ;
@@ -2230,9 +2239,12 @@ fn makeString(self: *MachO, bytes: []const u8) !u32 {
2230
2239
2231
2240
try self .string_table .ensureCapacity (self .base .allocator , self .string_table .items .len + bytes .len + 1 );
2232
2241
const offset = @intCast (u32 , self .string_table .items .len );
2242
+
2233
2243
log .debug ("writing new string '{s}' into string table at offset 0x{x}" , .{ bytes , offset });
2244
+
2234
2245
self .string_table .appendSliceAssumeCapacity (bytes );
2235
2246
self .string_table .appendAssumeCapacity (0 );
2247
+
2236
2248
try self .string_table_directory .putNoClobber (
2237
2249
self .base .allocator ,
2238
2250
try self .base .allocator .dupe (u8 , bytes ),
0 commit comments