| author | |
| committer | |
| log | cc381d56a6461c2aa8df8eae3d9f3ad206204ecf |
| tree | 43651f1f1cc852c6ec5b474e2d5b021ae72fa858 |
| parent | 8e79fc64cddf6832e4446b20d282084ae69f93ae |
| parent | 9bd8f8ed56c1e74e184be022f7e60b49dfd841a2 |
| signature |
Compilation: don't build compiler_rt or ubsan_rt for amdgcn and ptx4 files changed, 61 insertions(+), 36 deletions(-)
src/Compilation.zig+4-21| ... | ... | @@ -1352,8 +1352,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1352 | 1352 | // approach, since the ubsan runtime uses quite a lot of the standard library |
| 1353 | 1353 | // and this reduces unnecessary bloat. |
| 1354 | 1354 | const ubsan_rt_strat: RtStrat = s: { |
| 1355 | const is_spirv = options.root_mod.resolved_target.result.cpu.arch.isSpirV(); | |
| 1356 | const want_ubsan_rt = options.want_ubsan_rt orelse (!is_spirv and any_sanitize_c == .full and is_exe_or_dyn_lib); | |
| 1355 | const can_build_ubsan_rt = target_util.canBuildLibUbsanRt(options.root_mod.resolved_target.result); | |
| 1356 | const want_ubsan_rt = options.want_ubsan_rt orelse (can_build_ubsan_rt and any_sanitize_c == .full and is_exe_or_dyn_lib); | |
| 1357 | 1357 | if (!want_ubsan_rt) break :s .none; |
| 1358 | 1358 | if (options.skip_linker_dependencies) break :s .none; |
| 1359 | 1359 | if (have_zcu) break :s .zcu; |
| ... | ... | @@ -1768,8 +1768,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1768 | 1768 | errdefer comp.destroy(); |
| 1769 | 1769 | |
| 1770 | 1770 | const target = comp.root_mod.resolved_target.result; |
| 1771 | ||
| 1772 | const capable_of_building_compiler_rt = canBuildLibCompilerRt(target, comp.config.use_llvm); | |
| 1771 | const can_build_compiler_rt = target_util.canBuildLibCompilerRt(target, comp.config.use_llvm, build_options.have_llvm); | |
| 1773 | 1772 | |
| 1774 | 1773 | // Add a `CObject` for each `c_source_files`. |
| 1775 | 1774 | try comp.c_object_table.ensureTotalCapacity(gpa, options.c_source_files.len); |
| ... | ... | @@ -1939,7 +1938,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1939 | 1938 | comp.remaining_prelink_tasks += 1; |
| 1940 | 1939 | } |
| 1941 | 1940 | |
| 1942 | if (capable_of_building_compiler_rt) { | |
| 1941 | if (can_build_compiler_rt) { | |
| 1943 | 1942 | if (comp.compiler_rt_strat == .lib) { |
| 1944 | 1943 | log.debug("queuing a job to build compiler_rt_lib", .{}); |
| 1945 | 1944 | comp.queued_jobs.compiler_rt_lib = true; |
| ... | ... | @@ -6558,22 +6557,6 @@ pub fn dump_argv(argv: []const []const u8) void { |
| 6558 | 6557 | nosuspend stderr.print("{s}\n", .{argv[argv.len - 1]}) catch {}; |
| 6559 | 6558 | } |
| 6560 | 6559 | |
| 6561 | fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool) bool { | |
| 6562 | switch (target.os.tag) { | |
| 6563 | .plan9 => return false, | |
| 6564 | else => {}, | |
| 6565 | } | |
| 6566 | switch (target.cpu.arch) { | |
| 6567 | .spirv, .spirv32, .spirv64 => return false, | |
| 6568 | else => {}, | |
| 6569 | } | |
| 6570 | return switch (target_util.zigBackend(target, use_llvm)) { | |
| 6571 | .stage2_llvm => true, | |
| 6572 | .stage2_x86_64 => if (target.ofmt == .elf or target.ofmt == .macho) true else build_options.have_llvm, | |
| 6573 | else => build_options.have_llvm, | |
| 6574 | }; | |
| 6575 | } | |
| 6576 | ||
| 6577 | 6560 | pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend { |
| 6578 | 6561 | const target = comp.root_mod.resolved_target.result; |
| 6579 | 6562 | return target_util.zigBackend(target, comp.config.use_llvm); |
src/codegen/spirv.zig+29-15| ... | ... | @@ -1065,6 +1065,7 @@ const NavGen = struct { |
| 1065 | 1065 | |
| 1066 | 1066 | fn derivePtr(self: *NavGen, derivation: Value.PointerDeriveStep) Error!IdRef { |
| 1067 | 1067 | const pt = self.pt; |
| 1068 | const zcu = pt.zcu; | |
| 1068 | 1069 | switch (derivation) { |
| 1069 | 1070 | .comptime_alloc_ptr, .comptime_field_ptr => unreachable, |
| 1070 | 1071 | .int => |int| { |
| ... | ... | @@ -1104,23 +1105,36 @@ const NavGen = struct { |
| 1104 | 1105 | .offset_and_cast => |oac| { |
| 1105 | 1106 | const parent_ptr_id = try self.derivePtr(oac.parent.*); |
| 1106 | 1107 | const parent_ptr_ty = try oac.parent.ptrType(pt); |
| 1107 | disallow: { | |
| 1108 | if (oac.byte_offset != 0) break :disallow; | |
| 1109 | // Allow changing the pointer type child only to restructure arrays. | |
| 1110 | // e.g. [3][2]T to T is fine, as is [2]T -> [2][1]T. | |
| 1111 | const result_ty_id = try self.resolveType(oac.new_ptr_ty, .direct); | |
| 1112 | const result_ptr_id = self.spv.allocId(); | |
| 1113 | try self.func.body.emit(self.spv.gpa, .OpBitcast, .{ | |
| 1114 | .id_result_type = result_ty_id, | |
| 1115 | .id_result = result_ptr_id, | |
| 1116 | .operand = parent_ptr_id, | |
| 1117 | }); | |
| 1118 | return result_ptr_id; | |
| 1108 | const result_ty_id = try self.resolveType(oac.new_ptr_ty, .direct); | |
| 1109 | ||
| 1110 | if (oac.byte_offset != 0) { | |
| 1111 | const child_size = oac.new_ptr_ty.childType(zcu).abiSize(zcu); | |
| 1112 | if (oac.byte_offset % child_size != 0) { | |
| 1113 | return self.fail("cannot perform pointer cast: '{}' to '{}'", .{ | |
| 1114 | parent_ptr_ty.fmt(pt), | |
| 1115 | oac.new_ptr_ty.fmt(pt), | |
| 1116 | }); | |
| 1117 | } | |
| 1118 | ||
| 1119 | // Vector element ptr accesses are derived as offset_and_cast. | |
| 1120 | // We can just use OpAccessChain. | |
| 1121 | assert(parent_ptr_ty.childType(zcu).zigTypeTag(zcu) == .vector); | |
| 1122 | return self.accessChain( | |
| 1123 | result_ty_id, | |
| 1124 | parent_ptr_id, | |
| 1125 | &.{@intCast(@divExact(oac.byte_offset, child_size))}, | |
| 1126 | ); | |
| 1119 | 1127 | } |
| 1120 | return self.fail("cannot perform pointer cast: '{}' to '{}'", .{ | |
| 1121 | parent_ptr_ty.fmt(pt), | |
| 1122 | oac.new_ptr_ty.fmt(pt), | |
| 1128 | ||
| 1129 | // Allow changing the pointer type child only to restructure arrays. | |
| 1130 | // e.g. [3][2]T to T is fine, as is [2]T -> [2][1]T. | |
| 1131 | const result_ptr_id = self.spv.allocId(); | |
| 1132 | try self.func.body.emit(self.spv.gpa, .OpBitcast, .{ | |
| 1133 | .id_result_type = result_ty_id, | |
| 1134 | .id_result = result_ptr_id, | |
| 1135 | .operand = parent_ptr_id, | |
| 1123 | 1136 | }); |
| 1137 | return result_ptr_id; | |
| 1124 | 1138 | }, |
| 1125 | 1139 | } |
| 1126 | 1140 | } |
src/target.zig+27| ... | ... | @@ -313,6 +313,33 @@ pub fn defaultCompilerRtOptimizeMode(target: std.Target) std.builtin.OptimizeMod |
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | pub fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool, have_llvm: bool) bool { | |
| 317 | switch (target.os.tag) { | |
| 318 | .plan9 => return false, | |
| 319 | else => {}, | |
| 320 | } | |
| 321 | switch (target.cpu.arch) { | |
| 322 | .spirv, .spirv32, .spirv64 => return false, | |
| 323 | // Remove this once https://github.com/ziglang/zig/issues/23714 is fixed | |
| 324 | .amdgcn => return false, | |
| 325 | else => {}, | |
| 326 | } | |
| 327 | return switch (zigBackend(target, use_llvm)) { | |
| 328 | .stage2_llvm => true, | |
| 329 | .stage2_x86_64 => if (target.ofmt == .elf or target.ofmt == .macho) true else have_llvm, | |
| 330 | else => have_llvm, | |
| 331 | }; | |
| 332 | } | |
| 333 | ||
| 334 | pub fn canBuildLibUbsanRt(target: std.Target) bool { | |
| 335 | switch (target.cpu.arch) { | |
| 336 | .spirv, .spirv32, .spirv64 => return false, | |
| 337 | // Remove this once https://github.com/ziglang/zig/issues/23715 is fixed | |
| 338 | .nvptx, .nvptx64 => return false, | |
| 339 | else => return true, | |
| 340 | } | |
| 341 | } | |
| 342 | ||
| 316 | 343 | pub fn hasRedZone(target: std.Target) bool { |
| 317 | 344 | return switch (target.cpu.arch) { |
| 318 | 345 | .aarch64, |
test/behavior/struct.zig+1| ... | ... | @@ -1524,6 +1524,7 @@ test "optional generic function label struct field" { |
| 1524 | 1524 | } |
| 1525 | 1525 | |
| 1526 | 1526 | test "struct fields get automatically reordered" { |
| 1527 | if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; | |
| 1527 | 1528 | if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; |
| 1528 | 1529 | |
| 1529 | 1530 | const S1 = struct { |