authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2025-06-04 01:42:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-06-06 23:42:14-07:00
log5986bdf868a58cdef2adf58ff27b6526eafd99fe
tree5310161f00ef5adaa1baf62bac4d4ba646f26ab2
parente96d86064eb81977f254fa8f36481b7d150cb3b6

Compilation: enable the x86_64 backend by default for debug builds

Closes #22257

15 files changed, 216 insertions(+), 104 deletions(-)

build.zig+2-2
...@@ -437,8 +437,8 @@ pub fn build(b: *std.Build) !void {...@@ -437,8 +437,8 @@ pub fn build(b: *std.Build) !void {
437 .skip_non_native = skip_non_native,437 .skip_non_native = skip_non_native,
438 .skip_libc = skip_libc,438 .skip_libc = skip_libc,
439 .use_llvm = use_llvm,439 .use_llvm = use_llvm,
440 // 2520100864 was observed on an x86_64-linux-gnu host.440 // 2923515904 was observed on an x86_64-linux-gnu host.
441 .max_rss = 2772110950,441 .max_rss = 3100000000,
442 }));442 }));
443443
444 test_modules_step.dependOn(tests.addModuleTests(b, .{444 test_modules_step.dependOn(tests.addModuleTests(b, .{
src/Compilation.zig+8-5
...@@ -7225,7 +7225,7 @@ fn buildOutputFromZig(...@@ -7225,7 +7225,7 @@ fn buildOutputFromZig(
7225 assert(out.* == null);7225 assert(out.* == null);
7226 out.* = crt_file;7226 out.* = crt_file;
72277227
7228 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);7228 comp.queueLinkTaskMode(crt_file.full_object_path, &config);
7229}7229}
72307230
7231pub const CrtFileOptions = struct {7231pub const CrtFileOptions = struct {
...@@ -7349,7 +7349,7 @@ pub fn build_crt_file(...@@ -7349,7 +7349,7 @@ pub fn build_crt_file(
7349 try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node);7349 try comp.updateSubCompilation(sub_compilation, misc_task_tag, prog_node);
73507350
7351 const crt_file = try sub_compilation.toCrtFile();7351 const crt_file = try sub_compilation.toCrtFile();
7352 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);7352 comp.queueLinkTaskMode(crt_file.full_object_path, &config);
73537353
7354 {7354 {
7355 comp.mutex.lock();7355 comp.mutex.lock();
...@@ -7359,11 +7359,14 @@ pub fn build_crt_file(...@@ -7359,11 +7359,14 @@ pub fn build_crt_file(
7359 }7359 }
7360}7360}
73617361
7362pub fn queueLinkTaskMode(comp: *Compilation, path: Cache.Path, output_mode: std.builtin.OutputMode) void {7362pub fn queueLinkTaskMode(comp: *Compilation, path: Cache.Path, config: *const Compilation.Config) void {
7363 comp.queueLinkTasks(switch (output_mode) {7363 comp.queueLinkTasks(switch (config.output_mode) {
7364 .Exe => unreachable,7364 .Exe => unreachable,
7365 .Obj => &.{.{ .load_object = path }},7365 .Obj => &.{.{ .load_object = path }},
7366 .Lib => &.{.{ .load_archive = path }},7366 .Lib => &.{switch (config.link_mode) {
7367 .static => .{ .load_archive = path },
7368 .dynamic => .{ .load_dso = path },
7369 }},
7367 });7370 });
7368}7371}
73697372
src/Compilation/Config.zig+9-5
...@@ -195,10 +195,7 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -195,10 +195,7 @@ pub fn resolve(options: Options) ResolveError!Config {
195 // Note that using the LLVM backend does not necessarily mean using LLVM libraries.195 // Note that using the LLVM backend does not necessarily mean using LLVM libraries.
196 // For example, Zig can emit .bc and .ll files directly, and this is still considered196 // For example, Zig can emit .bc and .ll files directly, and this is still considered
197 // using "the LLVM backend".197 // using "the LLVM backend".
198 const use_llvm = b: {198 const can_use_llvm = b: {
199 // If we have no zig code to compile, no need for LLVM.
200 if (!options.have_zcu) break :b false;
201
202 // If emitting to LLVM bitcode object format, must use LLVM backend.199 // If emitting to LLVM bitcode object format, must use LLVM backend.
203 if (options.emit_llvm_ir or options.emit_llvm_bc) {200 if (options.emit_llvm_ir or options.emit_llvm_bc) {
204 if (options.use_llvm == false)201 if (options.use_llvm == false)
...@@ -237,6 +234,13 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -237,6 +234,13 @@ pub fn resolve(options: Options) ResolveError!Config {
237 break :b !target_util.selfHostedBackendIsAsRobustAsLlvm(target);234 break :b !target_util.selfHostedBackendIsAsRobustAsLlvm(target);
238 };235 };
239236
237 const use_llvm = b: {
238 // If we have no zig code to compile, no need for LLVM.
239 if (!options.have_zcu) break :b false;
240
241 break :b can_use_llvm;
242 };
243
240 if (options.emit_bin and options.have_zcu) {244 if (options.emit_bin and options.have_zcu) {
241 if (!use_lib_llvm and use_llvm) {245 if (!use_lib_llvm and use_llvm) {
242 // Explicit request to use LLVM to produce an object file, but without246 // Explicit request to use LLVM to produce an object file, but without
...@@ -273,7 +277,7 @@ pub fn resolve(options: Options) ResolveError!Config {...@@ -273,7 +277,7 @@ pub fn resolve(options: Options) ResolveError!Config {
273 }277 }
274278
275 if (options.use_lld) |x| break :b x;279 if (options.use_lld) |x| break :b x;
276 break :b true;280 break :b can_use_llvm;
277 };281 };
278282
279 // Make a decision on whether to use Clang or Aro for translate-c and compiling C files.283 // Make a decision on whether to use Clang or Aro for translate-c and compiling C files.
src/arch/x86_64/Emit.zig+5-5
...@@ -378,9 +378,9 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -378,9 +378,9 @@ pub fn emitMir(emit: *Emit) Error!void {
378 };378 };
379 break :stack_value &loc_buf[0];379 break :stack_value &loc_buf[0];
380 } } },380 } } },
381 .pseudo_dbg_local_as => .{ mir_inst.data.as.air_inst, .{ .addr = .{381 .pseudo_dbg_local_as => .{ mir_inst.data.as.air_inst, .{
382 .sym = mir_inst.data.as.sym_index,382 .addr_reloc = mir_inst.data.as.sym_index,
383 } } },383 } },
384 .pseudo_dbg_local_aso => loc: {384 .pseudo_dbg_local_aso => loc: {
385 const sym_off = emit.lower.mir.extraData(385 const sym_off = emit.lower.mir.extraData(
386 bits.SymbolOffset,386 bits.SymbolOffset,
...@@ -388,7 +388,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -388,7 +388,7 @@ pub fn emitMir(emit: *Emit) Error!void {
388 ).data;388 ).data;
389 break :loc .{ mir_inst.data.ax.air_inst, .{ .plus = .{389 break :loc .{ mir_inst.data.ax.air_inst, .{ .plus = .{
390 sym: {390 sym: {
391 loc_buf[0] = .{ .addr = .{ .sym = sym_off.sym_index } };391 loc_buf[0] = .{ .addr_reloc = sym_off.sym_index };
392 break :sym &loc_buf[0];392 break :sym &loc_buf[0];
393 },393 },
394 off: {394 off: {
...@@ -437,7 +437,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -437,7 +437,7 @@ pub fn emitMir(emit: *Emit) Error!void {
437 .none => .{ .constu = 0 },437 .none => .{ .constu = 0 },
438 .reg => |reg| .{ .breg = reg.dwarfNum() },438 .reg => |reg| .{ .breg = reg.dwarfNum() },
439 .frame, .table, .rip_inst => unreachable,439 .frame, .table, .rip_inst => unreachable,
440 .reloc => |sym_index| .{ .addr = .{ .sym = sym_index } },440 .reloc => |sym_index| .{ .addr_reloc = sym_index },
441 };441 };
442 break :base &loc_buf[0];442 break :base &loc_buf[0];
443 },443 },
src/libs/libcxx.zig+2-2
...@@ -308,7 +308,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!...@@ -308,7 +308,7 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
308 assert(comp.libcxx_static_lib == null);308 assert(comp.libcxx_static_lib == null);
309 const crt_file = try sub_compilation.toCrtFile();309 const crt_file = try sub_compilation.toCrtFile();
310 comp.libcxx_static_lib = crt_file;310 comp.libcxx_static_lib = crt_file;
311 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);311 comp.queueLinkTaskMode(crt_file.full_object_path, &config);
312}312}
313313
314pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {314pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildError!void {
...@@ -504,7 +504,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr...@@ -504,7 +504,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
504 assert(comp.libcxxabi_static_lib == null);504 assert(comp.libcxxabi_static_lib == null);
505 const crt_file = try sub_compilation.toCrtFile();505 const crt_file = try sub_compilation.toCrtFile();
506 comp.libcxxabi_static_lib = crt_file;506 comp.libcxxabi_static_lib = crt_file;
507 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);507 comp.queueLinkTaskMode(crt_file.full_object_path, &config);
508}508}
509509
510pub fn addCxxArgs(510pub fn addCxxArgs(
src/libs/libtsan.zig+1-1
...@@ -325,7 +325,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo...@@ -325,7 +325,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
325 };325 };
326326
327 const crt_file = try sub_compilation.toCrtFile();327 const crt_file = try sub_compilation.toCrtFile();
328 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);328 comp.queueLinkTaskMode(crt_file.full_object_path, &config);
329 assert(comp.tsan_lib == null);329 assert(comp.tsan_lib == null);
330 comp.tsan_lib = crt_file;330 comp.tsan_lib = crt_file;
331}331}
src/libs/libunwind.zig+1-1
...@@ -195,7 +195,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr...@@ -195,7 +195,7 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
195 };195 };
196196
197 const crt_file = try sub_compilation.toCrtFile();197 const crt_file = try sub_compilation.toCrtFile();
198 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);198 comp.queueLinkTaskMode(crt_file.full_object_path, &config);
199 assert(comp.libunwind_static_lib == null);199 assert(comp.libunwind_static_lib == null);
200 comp.libunwind_static_lib = crt_file;200 comp.libunwind_static_lib = crt_file;
201}201}
src/libs/musl.zig+1-1
...@@ -278,7 +278,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro...@@ -278,7 +278,7 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
278 errdefer comp.gpa.free(basename);278 errdefer comp.gpa.free(basename);
279279
280 const crt_file = try sub_compilation.toCrtFile();280 const crt_file = try sub_compilation.toCrtFile();
281 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);281 comp.queueLinkTaskMode(crt_file.full_object_path, &config);
282 {282 {
283 comp.mutex.lock();283 comp.mutex.lock();
284 defer comp.mutex.unlock();284 defer comp.mutex.unlock();
src/link/Dwarf.zig+169-69
...@@ -785,6 +785,7 @@ const Entry = struct {...@@ -785,6 +785,7 @@ const Entry = struct {
785 }785 }
786786
787 const Index = enum(u32) {787 const Index = enum(u32) {
788 //got_proc,
788 _,789 _,
789790
790 const Optional = enum(u32) {791 const Optional = enum(u32) {
...@@ -1040,7 +1041,7 @@ const Entry = struct {...@@ -1040,7 +1041,7 @@ const Entry = struct {
1040 const symbol = zo.symbol(reloc.target_sym);1041 const symbol = zo.symbol(reloc.target_sym);
1041 try dwarf.resolveReloc(1042 try dwarf.resolveReloc(
1042 entry_off + reloc.source_off,1043 entry_off + reloc.source_off,
1043 @bitCast(symbol.address(.{}, elf_file) + @as(i64, @intCast(reloc.target_off)) -1044 @bitCast(symbol.address(.{}, elf_file) + @as(i64, @intCast(@intFromEnum(reloc.target_off))) -
1044 if (symbol.flags.is_tls) elf_file.dtpAddress() else 0),1045 if (symbol.flags.is_tls) elf_file.dtpAddress() else 0),
1045 @intFromEnum(dwarf.address_size),1046 @intFromEnum(dwarf.address_size),
1046 );1047 );
...@@ -1051,7 +1052,7 @@ const Entry = struct {...@@ -1051,7 +1052,7 @@ const Entry = struct {
1051 const ref = zo.getSymbolRef(reloc.target_sym, macho_file);1052 const ref = zo.getSymbolRef(reloc.target_sym, macho_file);
1052 try dwarf.resolveReloc(1053 try dwarf.resolveReloc(
1053 entry_off + reloc.source_off,1054 entry_off + reloc.source_off,
1054 ref.getSymbol(macho_file).?.getAddress(.{}, macho_file),1055 ref.getSymbol(macho_file).?.getAddress(.{}, macho_file) + @as(i64, @intCast(@intFromEnum(reloc.target_off))),
1055 @intFromEnum(dwarf.address_size),1056 @intFromEnum(dwarf.address_size),
1056 );1057 );
1057 }1058 }
...@@ -1080,18 +1081,39 @@ const CrossSectionReloc = struct {...@@ -1080,18 +1081,39 @@ const CrossSectionReloc = struct {
1080const ExternalReloc = struct {1081const ExternalReloc = struct {
1081 source_off: u32 = 0,1082 source_off: u32 = 0,
1082 target_sym: u32,1083 target_sym: u32,
1083 target_off: u64 = 0,1084 target_off: enum(u64) {
1085 none = 0,
1086 got = std.math.maxInt(i64) + 1,
1087 _,
1088
1089 pub fn rel(off: u64) @This() {
1090 const res: @This() = @enumFromInt(off);
1091 switch (res) {
1092 .none => {},
1093 _ => {},
1094 .got => unreachable, // assertion failure
1095 }
1096 return res;
1097 }
1098 } = .none,
1084};1099};
10851100
1086pub const Loc = union(enum) {1101pub const Loc = union(enum) {
1087 empty,1102 empty,
1088 addr: union(enum) { sym: u32 },1103 addr_reloc: u32,
1104 got_reloc: u32,
1105 deref: *const Loc,
1089 constu: u64,1106 constu: u64,
1090 consts: i64,1107 consts: i64,
1091 plus: Bin,1108 plus: Bin,
1092 reg: u32,1109 reg: u32,
1093 breg: u32,1110 breg: u32,
1094 push_object_address,1111 push_object_address,
1112 call: struct {
1113 args: []const Loc = &.{},
1114 unit: Unit.Index,
1115 entry: Entry.Index,
1116 },
1095 form_tls_address: *const Loc,1117 form_tls_address: *const Loc,
1096 implicit_value: []const u8,1118 implicit_value: []const u8,
1097 stack_value: *const Loc,1119 stack_value: *const Loc,
...@@ -1136,11 +1158,17 @@ pub const Loc = union(enum) {...@@ -1136,11 +1158,17 @@ pub const Loc = union(enum) {
1136 const writer = adapter.writer();1158 const writer = adapter.writer();
1137 switch (loc) {1159 switch (loc) {
1138 .empty => {},1160 .empty => {},
1139 .addr => |addr| {1161 .addr_reloc => |sym_index| {
1140 try writer.writeByte(DW.OP.addr);1162 try writer.writeByte(DW.OP.addr);
1141 switch (addr) {1163 try adapter.addrSym(sym_index);
1142 .sym => |sym_index| try adapter.addrSym(sym_index),1164 },
1143 }1165 .deref => |addr| {
1166 try addr.write(adapter);
1167 try writer.writeByte(DW.OP.deref);
1168 },
1169 .got_reloc => |sym_index| {
1170 try writer.writeByte(DW.OP.const4s);
1171 try adapter.gotSym(sym_index);
1144 },1172 },
1145 .constu => |constu| if (std.math.cast(u5, constu)) |lit| {1173 .constu => |constu| if (std.math.cast(u5, constu)) |lit| {
1146 try writer.writeByte(@as(u8, DW.OP.lit0) + lit);1174 try writer.writeByte(@as(u8, DW.OP.lit0) + lit);
...@@ -1225,6 +1253,11 @@ pub const Loc = union(enum) {...@@ -1225,6 +1253,11 @@ pub const Loc = union(enum) {
1225 try sleb128(writer, 0);1253 try sleb128(writer, 0);
1226 },1254 },
1227 .push_object_address => try writer.writeByte(DW.OP.push_object_address),1255 .push_object_address => try writer.writeByte(DW.OP.push_object_address),
1256 .call => |call| {
1257 for (call.args) |arg| try arg.write(adapter);
1258 try writer.writeByte(DW.OP.call_ref);
1259 try adapter.infoEntry(call.unit, call.entry);
1260 },
1228 .form_tls_address => |addr| {1261 .form_tls_address => |addr| {
1229 try addr.write(adapter);1262 try addr.write(adapter);
1230 try writer.writeByte(DW.OP.form_tls_address);1263 try writer.writeByte(DW.OP.form_tls_address);
...@@ -1385,12 +1418,12 @@ pub const Cfa = union(enum) {...@@ -1385,12 +1418,12 @@ pub const Cfa = union(enum) {
1385 },1418 },
1386 .def_cfa_expression => |expr| {1419 .def_cfa_expression => |expr| {
1387 try writer.writeByte(DW.CFA.def_cfa_expression);1420 try writer.writeByte(DW.CFA.def_cfa_expression);
1388 try wip_nav.frameExprloc(expr);1421 try wip_nav.frameExprLoc(expr);
1389 },1422 },
1390 .expression => |reg_expr| {1423 .expression => |reg_expr| {
1391 try writer.writeByte(DW.CFA.expression);1424 try writer.writeByte(DW.CFA.expression);
1392 try uleb128(writer, reg_expr.reg);1425 try uleb128(writer, reg_expr.reg);
1393 try wip_nav.frameExprloc(reg_expr.expr);1426 try wip_nav.frameExprLoc(reg_expr.expr);
1394 },1427 },
1395 .val_offset => |reg_off| {1428 .val_offset => |reg_off| {
1396 const factored_off = @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor);1429 const factored_off = @divExact(reg_off.off, wip_nav.dwarf.debug_frame.header.data_alignment_factor);
...@@ -1407,7 +1440,7 @@ pub const Cfa = union(enum) {...@@ -1407,7 +1440,7 @@ pub const Cfa = union(enum) {
1407 .val_expression => |reg_expr| {1440 .val_expression => |reg_expr| {
1408 try writer.writeByte(DW.CFA.val_expression);1441 try writer.writeByte(DW.CFA.val_expression);
1409 try uleb128(writer, reg_expr.reg);1442 try uleb128(writer, reg_expr.reg);
1410 try wip_nav.frameExprloc(reg_expr.expr);1443 try wip_nav.frameExprLoc(reg_expr.expr);
1411 },1444 },
1412 .escape => |bytes| try writer.writeAll(bytes),1445 .escape => |bytes| try writer.writeAll(bytes),
1413 }1446 }
...@@ -1471,7 +1504,7 @@ pub const WipNav = struct {...@@ -1471,7 +1504,7 @@ pub const WipNav = struct {
1471 });1504 });
1472 try wip_nav.strp(name);1505 try wip_nav.strp(name);
1473 try wip_nav.refType(ty);1506 try wip_nav.refType(ty);
1474 try wip_nav.infoExprloc(loc);1507 try wip_nav.infoExprLoc(loc);
1475 wip_nav.any_children = true;1508 wip_nav.any_children = true;
1476 }1509 }
14771510
...@@ -1733,6 +1766,9 @@ pub const WipNav = struct {...@@ -1733,6 +1766,9 @@ pub const WipNav = struct {
1733 fn endian(_: ExprLocCounter) std.builtin.Endian {1766 fn endian(_: ExprLocCounter) std.builtin.Endian {
1734 return @import("builtin").cpu.arch.endian();1767 return @import("builtin").cpu.arch.endian();
1735 }1768 }
1769 fn gotSym(counter: *ExprLocCounter, _: u32) error{}!void {
1770 counter.stream.bytes_written += 4;
1771 }
1736 fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void {1772 fn addrSym(counter: *ExprLocCounter, _: u32) error{}!void {
1737 counter.stream.bytes_written += @intFromEnum(counter.address_size);1773 counter.stream.bytes_written += @intFromEnum(counter.address_size);
1738 }1774 }
...@@ -1741,7 +1777,7 @@ pub const WipNav = struct {...@@ -1741,7 +1777,7 @@ pub const WipNav = struct {
1741 }1777 }
1742 };1778 };
17431779
1744 fn infoExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {1780 fn infoExprLoc(wip_nav: *WipNav, loc: Loc) UpdateError!void {
1745 var counter: ExprLocCounter = .init(wip_nav.dwarf);1781 var counter: ExprLocCounter = .init(wip_nav.dwarf);
1746 try loc.write(&counter);1782 try loc.write(&counter);
17471783
...@@ -1753,6 +1789,14 @@ pub const WipNav = struct {...@@ -1753,6 +1789,14 @@ pub const WipNav = struct {
1753 fn endian(ctx: @This()) std.builtin.Endian {1789 fn endian(ctx: @This()) std.builtin.Endian {
1754 return ctx.wip_nav.dwarf.endian;1790 return ctx.wip_nav.dwarf.endian;
1755 }1791 }
1792 fn gotSym(ctx: @This(), sym_index: u32) UpdateError!void {
1793 try ctx.wip_nav.infoExternalReloc(.{
1794 .source_off = @intCast(ctx.wip_nav.debug_info.items.len),
1795 .target_sym = sym_index,
1796 .target_off = .got,
1797 });
1798 try ctx.wip_nav.debug_info.appendNTimes(ctx.wip_nav.dwarf.gpa, 0, 4);
1799 }
1756 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {1800 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {
1757 try ctx.wip_nav.infoAddrSym(sym_index, 0);1801 try ctx.wip_nav.infoAddrSym(sym_index, 0);
1758 }1802 }
...@@ -1768,12 +1812,12 @@ pub const WipNav = struct {...@@ -1768,12 +1812,12 @@ pub const WipNav = struct {
1768 try wip_nav.infoExternalReloc(.{1812 try wip_nav.infoExternalReloc(.{
1769 .source_off = @intCast(wip_nav.debug_info.items.len),1813 .source_off = @intCast(wip_nav.debug_info.items.len),
1770 .target_sym = sym_index,1814 .target_sym = sym_index,
1771 .target_off = sym_off,1815 .target_off = .rel(sym_off),
1772 });1816 });
1773 try wip_nav.debug_info.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));1817 try wip_nav.debug_info.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));
1774 }1818 }
17751819
1776 fn frameExprloc(wip_nav: *WipNav, loc: Loc) UpdateError!void {1820 fn frameExprLoc(wip_nav: *WipNav, loc: Loc) UpdateError!void {
1777 var counter: ExprLocCounter = .init(wip_nav.dwarf);1821 var counter: ExprLocCounter = .init(wip_nav.dwarf);
1778 try loc.write(&counter);1822 try loc.write(&counter);
17791823
...@@ -1785,6 +1829,14 @@ pub const WipNav = struct {...@@ -1785,6 +1829,14 @@ pub const WipNav = struct {
1785 fn endian(ctx: @This()) std.builtin.Endian {1829 fn endian(ctx: @This()) std.builtin.Endian {
1786 return ctx.wip_nav.dwarf.endian;1830 return ctx.wip_nav.dwarf.endian;
1787 }1831 }
1832 fn gotSym(ctx: @This(), sym_index: u32) UpdateError!void {
1833 try ctx.wip_nav.frameExternalReloc(.{
1834 .source_off = @intCast(ctx.wip_nav.debug_frame.items.len),
1835 .target_sym = sym_index,
1836 .target_off = .got,
1837 });
1838 try ctx.wip_nav.debug_frame.appendNTimes(ctx.wip_nav.dwarf.gpa, 0, 4);
1839 }
1788 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {1840 fn addrSym(ctx: @This(), sym_index: u32) UpdateError!void {
1789 try ctx.wip_nav.frameAddrSym(sym_index, 0);1841 try ctx.wip_nav.frameAddrSym(sym_index, 0);
1790 }1842 }
...@@ -1800,7 +1852,7 @@ pub const WipNav = struct {...@@ -1800,7 +1852,7 @@ pub const WipNav = struct {
1800 try wip_nav.frameExternalReloc(.{1852 try wip_nav.frameExternalReloc(.{
1801 .source_off = @intCast(wip_nav.debug_frame.items.len),1853 .source_off = @intCast(wip_nav.debug_frame.items.len),
1802 .target_sym = sym_index,1854 .target_sym = sym_index,
1803 .target_off = sym_off,1855 .target_off = .rel(sym_off),
1804 });1856 });
1805 try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));1857 try wip_nav.debug_frame.appendNTimes(wip_nav.dwarf.gpa, 0, @intFromEnum(wip_nav.dwarf.address_size));
1806 }1858 }
...@@ -2286,50 +2338,81 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) !Unit.Index {...@@ -2286,50 +2338,81 @@ fn getUnit(dwarf: *Dwarf, mod: *Module) !Unit.Index {
2286 const mod_gop = try dwarf.mods.getOrPut(dwarf.gpa, mod);2338 const mod_gop = try dwarf.mods.getOrPut(dwarf.gpa, mod);
2287 const unit: Unit.Index = @enumFromInt(mod_gop.index);2339 const unit: Unit.Index = @enumFromInt(mod_gop.index);
2288 if (!mod_gop.found_existing) {2340 if (!mod_gop.found_existing) {
2289 errdefer _ = dwarf.mods.pop();2341 {
2290 mod_gop.value_ptr.* = .{2342 errdefer _ = dwarf.mods.pop();
2291 .root_dir_path = undefined,2343 mod_gop.value_ptr.* = .{
2292 .dirs = .empty,2344 .root_dir_path = undefined,
2293 .files = .empty,2345 .dirs = .empty,
2294 };2346 .files = .empty,
2295 errdefer mod_gop.value_ptr.dirs.deinit(dwarf.gpa);2347 };
2296 try mod_gop.value_ptr.dirs.putNoClobber(dwarf.gpa, unit, {});2348 errdefer mod_gop.value_ptr.dirs.deinit(dwarf.gpa);
2297 assert(try dwarf.debug_aranges.section.addUnit(2349 try mod_gop.value_ptr.dirs.putNoClobber(dwarf.gpa, unit, {});
2298 DebugAranges.headerBytes(dwarf),2350 assert(try dwarf.debug_aranges.section.addUnit(
2299 DebugAranges.trailerBytes(dwarf),2351 DebugAranges.headerBytes(dwarf),
2300 dwarf,2352 DebugAranges.trailerBytes(dwarf),
2301 ) == unit);2353 dwarf,
2302 errdefer dwarf.debug_aranges.section.popUnit(dwarf.gpa);2354 ) == unit);
2303 assert(try dwarf.debug_frame.section.addUnit(2355 errdefer dwarf.debug_aranges.section.popUnit(dwarf.gpa);
2304 DebugFrame.headerBytes(dwarf),2356 assert(try dwarf.debug_frame.section.addUnit(
2305 DebugFrame.trailerBytes(dwarf),2357 DebugFrame.headerBytes(dwarf),
2306 dwarf,2358 DebugFrame.trailerBytes(dwarf),
2307 ) == unit);2359 dwarf,
2308 errdefer dwarf.debug_frame.section.popUnit(dwarf.gpa);2360 ) == unit);
2309 assert(try dwarf.debug_info.section.addUnit(2361 errdefer dwarf.debug_frame.section.popUnit(dwarf.gpa);
2310 DebugInfo.headerBytes(dwarf),2362 assert(try dwarf.debug_info.section.addUnit(
2311 DebugInfo.trailer_bytes,2363 DebugInfo.headerBytes(dwarf),
2312 dwarf,2364 DebugInfo.trailer_bytes,
2313 ) == unit);2365 dwarf,
2314 errdefer dwarf.debug_info.section.popUnit(dwarf.gpa);2366 ) == unit);
2315 assert(try dwarf.debug_line.section.addUnit(2367 errdefer dwarf.debug_info.section.popUnit(dwarf.gpa);
2316 DebugLine.headerBytes(dwarf, 5, 25),2368 assert(try dwarf.debug_line.section.addUnit(
2317 DebugLine.trailer_bytes,2369 DebugLine.headerBytes(dwarf, 5, 25),
2318 dwarf,2370 DebugLine.trailer_bytes,
2319 ) == unit);2371 dwarf,
2320 errdefer dwarf.debug_line.section.popUnit(dwarf.gpa);2372 ) == unit);
2321 assert(try dwarf.debug_loclists.section.addUnit(2373 errdefer dwarf.debug_line.section.popUnit(dwarf.gpa);
2322 DebugLocLists.headerBytes(dwarf),2374 assert(try dwarf.debug_loclists.section.addUnit(
2323 DebugLocLists.trailer_bytes,2375 DebugLocLists.headerBytes(dwarf),
2324 dwarf,2376 DebugLocLists.trailer_bytes,
2325 ) == unit);2377 dwarf,
2326 errdefer dwarf.debug_loclists.section.popUnit(dwarf.gpa);2378 ) == unit);
2327 assert(try dwarf.debug_rnglists.section.addUnit(2379 errdefer dwarf.debug_loclists.section.popUnit(dwarf.gpa);
2328 DebugRngLists.headerBytes(dwarf),2380 assert(try dwarf.debug_rnglists.section.addUnit(
2329 DebugRngLists.trailer_bytes,2381 DebugRngLists.headerBytes(dwarf),
2330 dwarf,2382 DebugRngLists.trailer_bytes,
2331 ) == unit);2383 dwarf,
2332 errdefer dwarf.debug_rnglists.section.popUnit(dwarf.gpa);2384 ) == unit);
2385 errdefer dwarf.debug_rnglists.section.popUnit(dwarf.gpa);
2386 }
2387 //if (dwarf.bin_file.cast(.elf)) |elf_file| {
2388 // if (unit == .main) assert(try dwarf.addCommonEntry(unit) == .got_proc);
2389 // if (mod.pic and dwarf.debug_info.section.getUnit(.main).getEntry(.got_proc).len == 0) {
2390 // var wip_nav: WipNav = .{
2391 // .dwarf = dwarf,
2392 // .pt = undefined,
2393 // .unit = .main,
2394 // .entry = .got_proc,
2395 // .any_children = false,
2396 // .func = .none,
2397 // .func_sym_index = undefined,
2398 // .func_high_pc = undefined,
2399 // .blocks = undefined,
2400 // .cfi = undefined,
2401 // .debug_frame = .empty,
2402 // .debug_info = .empty,
2403 // .debug_line = .empty,
2404 // .debug_loclists = .empty,
2405 // .pending_lazy = .empty,
2406 // };
2407 // defer wip_nav.deinit();
2408 // try wip_nav.abbrevCode(.proc);
2409 // try wip_nav.infoExprLoc(.{ .deref = &.{ .plus = .{
2410 // &.empty,
2411 // &.{ .addr_reloc = try elf_file.zigObjectPtr().?.getGlobalSymbol(elf_file, "_GLOBAL_OFFSET_TABLE_", null) },
2412 // } } });
2413 // try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.items);
2414 // }
2415 //}
2333 }2416 }
2334 return unit;2417 return unit;
2335}2418}
...@@ -2384,7 +2467,8 @@ fn initWipNavInner(...@@ -2384,7 +2467,8 @@ fn initWipNavInner(
2384 else => {},2467 else => {},
2385 }2468 }
23862469
2387 const unit = try dwarf.getUnit(file.mod.?);2470 const mod = file.mod.?;
2471 const unit = try dwarf.getUnit(mod);
2388 const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index);2472 const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index);
2389 errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop();2473 errdefer _ = if (!nav_gop.found_existing) dwarf.navs.pop();
2390 if (nav_gop.found_existing) {2474 if (nav_gop.found_existing) {
...@@ -2425,13 +2509,22 @@ fn initWipNavInner(...@@ -2425,13 +2509,22 @@ fn initWipNavInner(
2425 }, &nav, inst_info.file, &decl);2509 }, &nav, inst_info.file, &decl);
2426 try wip_nav.strp(nav.fqn.toSlice(ip));2510 try wip_nav.strp(nav.fqn.toSlice(ip));
2427 const ty: Type = nav_val.typeOf(zcu);2511 const ty: Type = nav_val.typeOf(zcu);
2428 const addr: Loc = .{ .addr = .{ .sym = sym_index } };2512 const addr: Loc = .{ .addr_reloc = sym_index };
2429 const loc: Loc = if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr;2513 const loc: Loc = loc: {
2514 if (dwarf.bin_file.cast(.elf)) |elf_file| if (decl.linkage == .@"extern" and mod.pic)
2515 // TODO: lldb doesn't support call :(
2516 //.{ .call = .{ .args = &.{.{ .got_reloc = sym_index }}, .unit = .main, .entry = .got_proc } }
2517 break :loc .{ .deref = &.{ .plus = .{
2518 &.{ .addr_reloc = try elf_file.zigObjectPtr().?.getGlobalSymbol(elf_file, "_GLOBAL_OFFSET_TABLE_", null) },
2519 &.{ .got_reloc = sym_index },
2520 } } };
2521 break :loc if (decl.is_threadlocal) .{ .form_tls_address = &addr } else addr;
2522 };
2430 switch (decl.kind) {2523 switch (decl.kind) {
2431 .unnamed_test, .@"test", .decltest, .@"comptime", .@"usingnamespace" => unreachable,2524 .unnamed_test, .@"test", .decltest, .@"comptime", .@"usingnamespace" => unreachable,
2432 .@"const" => {2525 .@"const" => {
2433 const const_ty_reloc_index = try wip_nav.refForward();2526 const const_ty_reloc_index = try wip_nav.refForward();
2434 try wip_nav.infoExprloc(loc);2527 try wip_nav.infoExprLoc(loc);
2435 try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse2528 try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse
2436 ty.abiAlignment(zcu).toByteUnits().?);2529 ty.abiAlignment(zcu).toByteUnits().?);
2437 try diw.writeByte(@intFromBool(decl.linkage != .normal));2530 try diw.writeByte(@intFromBool(decl.linkage != .normal));
...@@ -2441,7 +2534,7 @@ fn initWipNavInner(...@@ -2441,7 +2534,7 @@ fn initWipNavInner(
2441 },2534 },
2442 .@"var" => {2535 .@"var" => {
2443 try wip_nav.refType(ty);2536 try wip_nav.refType(ty);
2444 try wip_nav.infoExprloc(loc);2537 try wip_nav.infoExprLoc(loc);
2445 try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse2538 try uleb128(diw, nav.status.fully_resolved.alignment.toByteUnits() orelse
2446 ty.abiAlignment(zcu).toByteUnits().?);2539 ty.abiAlignment(zcu).toByteUnits().?);
2447 try diw.writeByte(@intFromBool(decl.linkage != .normal));2540 try diw.writeByte(@intFromBool(decl.linkage != .normal));
...@@ -2649,7 +2742,7 @@ pub fn finishWipNavFunc(...@@ -2649,7 +2742,7 @@ pub fn finishWipNavFunc(
2649 .{2742 .{
2650 .source_off = 1 + @intFromEnum(dwarf.address_size),2743 .source_off = 1 + @intFromEnum(dwarf.address_size),
2651 .target_sym = wip_nav.func_sym_index,2744 .target_sym = wip_nav.func_sym_index,
2652 .target_off = code_size,2745 .target_off = .rel(code_size),
2653 },2746 },
2654 });2747 });
2655 try dwarf.debug_rnglists.section.replaceEntry(2748 try dwarf.debug_rnglists.section.replaceEntry(
...@@ -3838,7 +3931,7 @@ fn updateLazyValue(...@@ -3838,7 +3931,7 @@ fn updateLazyValue(
3838 byte_offset += base_ptr.byte_offset;3931 byte_offset += base_ptr.byte_offset;
3839 };3932 };
3840 try wip_nav.abbrevCode(.location_comptime_value);3933 try wip_nav.abbrevCode(.location_comptime_value);
3841 try wip_nav.infoExprloc(.{ .implicit_pointer = .{3934 try wip_nav.infoExprLoc(.{ .implicit_pointer = .{
3842 .unit = base_unit,3935 .unit = base_unit,
3843 .entry = base_entry,3936 .entry = base_entry,
3844 .offset = byte_offset,3937 .offset = byte_offset,
...@@ -4360,7 +4453,7 @@ fn refAbbrevCode(dwarf: *Dwarf, abbrev_code: AbbrevCode) UpdateError!@typeInfo(A...@@ -4360,7 +4453,7 @@ fn refAbbrevCode(dwarf: *Dwarf, abbrev_code: AbbrevCode) UpdateError!@typeInfo(A
4360 assert(abbrev_code != .null);4453 assert(abbrev_code != .null);
4361 const entry: Entry.Index = @enumFromInt(@intFromEnum(abbrev_code));4454 const entry: Entry.Index = @enumFromInt(@intFromEnum(abbrev_code));
4362 if (dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).getEntry(entry).len > 0) return @intFromEnum(abbrev_code);4455 if (dwarf.debug_abbrev.section.getUnit(DebugAbbrev.unit).getEntry(entry).len > 0) return @intFromEnum(abbrev_code);
4363 var debug_abbrev = std.ArrayList(u8).init(dwarf.gpa);4456 var debug_abbrev: std.ArrayList(u8) = .init(dwarf.gpa);
4364 defer debug_abbrev.deinit();4457 defer debug_abbrev.deinit();
4365 const daw = debug_abbrev.writer();4458 const daw = debug_abbrev.writer();
4366 const abbrev = AbbrevCode.abbrevs.get(abbrev_code);4459 const abbrev = AbbrevCode.abbrevs.get(abbrev_code);
...@@ -4422,7 +4515,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {...@@ -4422,7 +4515,7 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void {
4422 mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path);4515 mod_info.root_dir_path = try dwarf.debug_line_str.addString(dwarf, root_dir_path);
4423 }4516 }
44244517
4425 var header = std.ArrayList(u8).init(dwarf.gpa);4518 var header: std.ArrayList(u8) = .init(dwarf.gpa);
4426 defer header.deinit();4519 defer header.deinit();
4427 if (dwarf.debug_aranges.section.dirty) {4520 if (dwarf.debug_aranges.section.dirty) {
4428 for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| {4521 for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| {
...@@ -4888,6 +4981,7 @@ const AbbrevCode = enum {...@@ -4888,6 +4981,7 @@ const AbbrevCode = enum {
4888 comptime_value_field_comptime_state,4981 comptime_value_field_comptime_state,
4889 comptime_value_elem_runtime_bits,4982 comptime_value_elem_runtime_bits,
4890 comptime_value_elem_comptime_state,4983 comptime_value_elem_comptime_state,
4984 //proc,
48914985
4892 const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_instance_func_generic));4986 const decl_bytes = uleb128Bytes(@intFromEnum(AbbrevCode.decl_instance_func_generic));
4893 comptime {4987 comptime {
...@@ -5757,6 +5851,12 @@ const AbbrevCode = enum {...@@ -5757,6 +5851,12 @@ const AbbrevCode = enum {
5757 .{ .ZIG_comptime_value, .ref_addr },5851 .{ .ZIG_comptime_value, .ref_addr },
5758 },5852 },
5759 },5853 },
5854 //.proc = .{
5855 // .tag = .dwarf_procedure,
5856 // .attrs = &.{
5857 // .{ .location, .exprloc },
5858 // },
5859 //},
5760 .null = undefined,5860 .null = undefined,
5761 });5861 });
5762};5862};
src/link/Elf/ZigObject.zig+7-4
...@@ -463,8 +463,11 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {...@@ -463,8 +463,11 @@ pub fn flush(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !void {
463 for (entry.external_relocs.items) |reloc| {463 for (entry.external_relocs.items) |reloc| {
464 const target_sym = self.symbol(reloc.target_sym);464 const target_sym = self.symbol(reloc.target_sym);
465 const r_offset = entry_off + reloc.source_off;465 const r_offset = entry_off + reloc.source_off;
466 const r_addend: i64 = @intCast(reloc.target_off);466 const r_addend: i64 = switch (reloc.target_off) {
467 const r_type = relocation.dwarf.externalRelocType(target_sym.*, sect_index, dwarf.address_size, cpu_arch);467 .none, .got => 0,
468 else => |off| @intCast(@intFromEnum(off)),
469 };
470 const r_type = relocation.dwarf.externalRelocType(target_sym.*, reloc.target_off == .got, sect_index, dwarf.address_size, cpu_arch);
468 atom_ptr.addRelocAssumeCapacity(.{471 atom_ptr.addRelocAssumeCapacity(.{
469 .r_offset = r_offset,472 .r_offset = r_offset,
470 .r_addend = r_addend,473 .r_addend = r_addend,
...@@ -947,7 +950,7 @@ pub fn getNavVAddr(...@@ -947,7 +950,7 @@ pub fn getNavVAddr(
947 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{950 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
948 .source_off = @intCast(reloc_info.offset),951 .source_off = @intCast(reloc_info.offset),
949 .target_sym = this_sym_index,952 .target_sym = this_sym_index,
950 .target_off = reloc_info.addend,953 .target_off = .rel(reloc_info.addend),
951 }),954 }),
952 .plan9 => unreachable,955 .plan9 => unreachable,
953 .none => unreachable,956 .none => unreachable,
...@@ -980,7 +983,7 @@ pub fn getUavVAddr(...@@ -980,7 +983,7 @@ pub fn getUavVAddr(
980 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{983 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
981 .source_off = @intCast(reloc_info.offset),984 .source_off = @intCast(reloc_info.offset),
982 .target_sym = sym_index,985 .target_sym = sym_index,
983 .target_off = reloc_info.addend,986 .target_off = .rel(reloc_info.addend),
984 }),987 }),
985 .plan9 => unreachable,988 .plan9 => unreachable,
986 .none => unreachable,989 .none => unreachable,
src/link/Elf/relocation.zig+2-1
...@@ -108,12 +108,13 @@ pub const dwarf = struct {...@@ -108,12 +108,13 @@ pub const dwarf = struct {
108108
109 pub fn externalRelocType(109 pub fn externalRelocType(
110 target: Symbol,110 target: Symbol,
111 is_got: bool,
111 source_section: Dwarf.Section.Index,112 source_section: Dwarf.Section.Index,
112 address_size: Dwarf.AddressSize,113 address_size: Dwarf.AddressSize,
113 cpu_arch: std.Target.Cpu.Arch,114 cpu_arch: std.Target.Cpu.Arch,
114 ) u32 {115 ) u32 {
115 return switch (cpu_arch) {116 return switch (cpu_arch) {
116 .x86_64 => @intFromEnum(@as(elf.R_X86_64, switch (source_section) {117 .x86_64 => @intFromEnum(@as(elf.R_X86_64, if (is_got) .GOT32 else switch (source_section) {
117 else => switch (address_size) {118 else => switch (address_size) {
118 .@"32" => if (target.flags.is_tls) .DTPOFF32 else .@"32",119 .@"32" => if (target.flags.is_tls) .DTPOFF32 else .@"32",
119 .@"64" => if (target.flags.is_tls) .DTPOFF64 else .@"64",120 .@"64" => if (target.flags.is_tls) .DTPOFF64 else .@"64",
src/link/MachO/ZigObject.zig+2-2
...@@ -648,7 +648,7 @@ pub fn getNavVAddr(...@@ -648,7 +648,7 @@ pub fn getNavVAddr(
648 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{648 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
649 .source_off = @intCast(reloc_info.offset),649 .source_off = @intCast(reloc_info.offset),
650 .target_sym = sym_index,650 .target_sym = sym_index,
651 .target_off = reloc_info.addend,651 .target_off = .rel(reloc_info.addend),
652 }),652 }),
653 .plan9 => unreachable,653 .plan9 => unreachable,
654 .none => unreachable,654 .none => unreachable,
...@@ -688,7 +688,7 @@ pub fn getUavVAddr(...@@ -688,7 +688,7 @@ pub fn getUavVAddr(
688 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{688 .dwarf => |wip_nav| try wip_nav.infoExternalReloc(.{
689 .source_off = @intCast(reloc_info.offset),689 .source_off = @intCast(reloc_info.offset),
690 .target_sym = sym_index,690 .target_sym = sym_index,
691 .target_off = reloc_info.addend,691 .target_off = .rel(reloc_info.addend),
692 }),692 }),
693 .plan9 => unreachable,693 .plan9 => unreachable,
694 .none => unreachable,694 .none => unreachable,
src/target.zig+4
...@@ -223,6 +223,10 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {...@@ -223,6 +223,10 @@ pub fn hasLldSupport(ofmt: std.Target.ObjectFormat) bool {
223/// than or equal to the number of behavior tests as the respective LLVM backend.223/// than or equal to the number of behavior tests as the respective LLVM backend.
224pub fn selfHostedBackendIsAsRobustAsLlvm(target: std.Target) bool {224pub fn selfHostedBackendIsAsRobustAsLlvm(target: std.Target) bool {
225 if (target.cpu.arch.isSpirV()) return true;225 if (target.cpu.arch.isSpirV()) return true;
226 if (target.cpu.arch == .x86_64 and target.ptrBitWidth() == 64) return switch (target.ofmt) {
227 .elf, .macho => true,
228 else => false,
229 };
226 return false;230 return false;
227}231}
228232
test/behavior/math.zig+1
...@@ -1722,6 +1722,7 @@ test "signed zeros are represented properly" {...@@ -1722,6 +1722,7 @@ test "signed zeros are represented properly" {
1722 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1722 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1723 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1723 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1724 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;1724 if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest;
1725 if (builtin.zig_backend == .stage2_x86_64 and builtin.target.ofmt != .elf and builtin.target.ofmt != .macho) return error.SkipZigTest;
17251726
1726 const S = struct {1727 const S = struct {
1727 fn doTheTest() !void {1728 fn doTheTest() !void {
test/tests.zig+2-6
...@@ -1113,8 +1113,6 @@ const test_targets = blk: {...@@ -1113,8 +1113,6 @@ const test_targets = blk: {
1113 .os_tag = .linux,1113 .os_tag = .linux,
1114 .abi = .none,1114 .abi = .none,
1115 },1115 },
1116 .use_llvm = false,
1117 .use_lld = false,
1118 },1116 },
1119 .{1117 .{
1120 .target = .{1118 .target = .{
...@@ -1123,8 +1121,6 @@ const test_targets = blk: {...@@ -1123,8 +1121,6 @@ const test_targets = blk: {
1123 .os_tag = .linux,1121 .os_tag = .linux,
1124 .abi = .none,1122 .abi = .none,
1125 },1123 },
1126 .use_llvm = false,
1127 .use_lld = false,
1128 .pic = true,1124 .pic = true,
1129 },1125 },
1130 .{1126 .{
...@@ -1134,8 +1130,6 @@ const test_targets = blk: {...@@ -1134,8 +1130,6 @@ const test_targets = blk: {
1134 .os_tag = .linux,1130 .os_tag = .linux,
1135 .abi = .none,1131 .abi = .none,
1136 },1132 },
1137 .use_llvm = false,
1138 .use_lld = false,
1139 .strip = true,1133 .strip = true,
1140 },1134 },
1141 .{1135 .{
...@@ -1144,6 +1138,8 @@ const test_targets = blk: {...@@ -1144,6 +1138,8 @@ const test_targets = blk: {
1144 .os_tag = .linux,1138 .os_tag = .linux,
1145 .abi = .none,1139 .abi = .none,
1146 },1140 },
1141 .use_llvm = true,
1142 .use_lld = true,
1147 },1143 },
1148 .{1144 .{
1149 .target = .{1145 .target = .{