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