| ... | ... | @@ -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 | |
| ... | ... | @@ -1228,7 +1228,11 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void { |
| 1228 | 1228 | self.shrinkTextBlock(&decl.link.macho, code.len); |
| 1229 | 1229 | } |
| 1230 | 1230 | decl.link.macho.size = code.len; |
| 1231 | | symbol.n_strx = try self.updateString(symbol.n_strx, mem.spanZ(decl.name)); |
| 1231 | |
| 1232 | const new_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{mem.spanZ(decl.name)}); |
| 1233 | defer self.base.allocator.free(new_name); |
| 1234 | |
| 1235 | symbol.n_strx = try self.updateString(symbol.n_strx, new_name); |
| 1232 | 1236 | symbol.n_type = macho.N_SECT; |
| 1233 | 1237 | symbol.n_sect = @intCast(u8, self.text_section_index.?) + 1; |
| 1234 | 1238 | symbol.n_desc = 0; |
| ... | ... | @@ -1237,7 +1241,9 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void { |
| 1237 | 1241 | if (self.d_sym) |*ds| |
| 1238 | 1242 | try ds.writeLocalSymbol(decl.link.macho.local_sym_index); |
| 1239 | 1243 | } else { |
| 1240 | | const decl_name = mem.spanZ(decl.name); |
| 1244 | const decl_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{mem.spanZ(decl.name)}); |
| 1245 | defer self.base.allocator.free(decl_name); |
| 1246 | |
| 1241 | 1247 | const name_str_index = try self.makeString(decl_name); |
| 1242 | 1248 | const addr = try self.allocateTextBlock(&decl.link.macho, code.len, required_alignment); |
| 1243 | 1249 | |
| ... | ... | @@ -1376,6 +1382,9 @@ pub fn updateDeclExports( |
| 1376 | 1382 | const decl_sym = &self.locals.items[decl.link.macho.local_sym_index]; |
| 1377 | 1383 | |
| 1378 | 1384 | for (exports) |exp| { |
| 1385 | const exp_name = try std.fmt.allocPrint(self.base.allocator, "_{s}", .{exp.options.name}); |
| 1386 | defer self.base.allocator.free(exp_name); |
| 1387 | |
| 1379 | 1388 | if (exp.options.section) |section_name| { |
| 1380 | 1389 | if (!mem.eql(u8, section_name, "__text")) { |
| 1381 | 1390 | try module.failed_exports.ensureCapacity(module.gpa, module.failed_exports.items().len + 1); |
| ... | ... | @@ -1403,7 +1412,7 @@ pub fn updateDeclExports( |
| 1403 | 1412 | // Otherwise, don't do anything since we already have all the flags |
| 1404 | 1413 | // set that we need for global (strong) linkage. |
| 1405 | 1414 | // n_type == N_SECT | N_EXT |
| 1406 | | if (mem.eql(u8, exp.options.name, "_main")) { |
| 1415 | if (mem.eql(u8, exp_name, "_main")) { |
| 1407 | 1416 | self.entry_addr = decl_sym.n_value; |
| 1408 | 1417 | } |
| 1409 | 1418 | }, |
| ... | ... | @@ -1425,14 +1434,14 @@ pub fn updateDeclExports( |
| 1425 | 1434 | if (exp.link.macho.sym_index) |i| { |
| 1426 | 1435 | const sym = &self.globals.items[i]; |
| 1427 | 1436 | sym.* = .{ |
| 1428 | | .n_strx = try self.updateString(sym.n_strx, exp.options.name), |
| 1437 | .n_strx = try self.updateString(sym.n_strx, exp_name), |
| 1429 | 1438 | .n_type = n_type, |
| 1430 | 1439 | .n_sect = @intCast(u8, self.text_section_index.?) + 1, |
| 1431 | 1440 | .n_desc = n_desc, |
| 1432 | 1441 | .n_value = decl_sym.n_value, |
| 1433 | 1442 | }; |
| 1434 | 1443 | } else { |
| 1435 | | const name_str_index = try self.makeString(exp.options.name); |
| 1444 | const name_str_index = try self.makeString(exp_name); |
| 1436 | 1445 | const i = if (self.globals_free_list.popOrNull()) |i| i else blk: { |
| 1437 | 1446 | _ = self.globals.addOneAssumeCapacity(); |
| 1438 | 1447 | self.export_info_dirty = true; |
| ... | ... | @@ -2235,9 +2244,12 @@ fn makeString(self: *MachO, bytes: []const u8) !u32 { |
| 2235 | 2244 | |
| 2236 | 2245 | try self.string_table.ensureCapacity(self.base.allocator, self.string_table.items.len + bytes.len + 1); |
| 2237 | 2246 | const offset = @intCast(u32, self.string_table.items.len); |
| 2247 | |
| 2238 | 2248 | log.debug("writing new string '{s}' into string table at offset 0x{x}", .{ bytes, offset }); |
| 2249 | |
| 2239 | 2250 | self.string_table.appendSliceAssumeCapacity(bytes); |
| 2240 | 2251 | self.string_table.appendAssumeCapacity(0); |
| 2252 | |
| 2241 | 2253 | try self.string_table_directory.putNoClobber( |
| 2242 | 2254 | self.base.allocator, |
| 2243 | 2255 | try self.base.allocator.dupe(u8, bytes), |