| ... | ... | @@ -810,16 +810,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 810 | 810 | return error.ExportTableAndImportTableConflict; |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | | // The `have_llvm` condition is here only because native backends cannot yet build compiler-rt. |
| 814 | | // Once they are capable this condition could be removed. When removing this condition, |
| 815 | | // also test the use case of `build-obj -fcompiler-rt` with the native backends |
| 816 | | // and make sure the compiler-rt symbols are emitted. |
| 817 | | const is_p9 = options.target.os.tag == .plan9; |
| 818 | | const is_spv = options.target.cpu.arch.isSpirV(); |
| 819 | | const capable_of_building_compiler_rt = build_options.have_llvm and !is_p9 and !is_spv; |
| 820 | | const capable_of_building_zig_libc = build_options.have_llvm and !is_p9 and !is_spv; |
| 821 | | const capable_of_building_ssp = build_options.have_llvm and !is_p9 and !is_spv; |
| 822 | | |
| 823 | 813 | const comp: *Compilation = comp: { |
| 824 | 814 | // For allocations that have the same lifetime as Compilation. This arena is used only during this |
| 825 | 815 | // initialization and then is freed in deinit(). |
| ... | ... | @@ -1094,6 +1084,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1094 | 1084 | if (stack_check and !target_util.supportsStackProbing(options.target)) |
| 1095 | 1085 | return error.StackCheckUnsupportedByTarget; |
| 1096 | 1086 | |
| 1087 | const capable_of_building_ssp = canBuildLibSsp(options.target, use_llvm); |
| 1088 | |
| 1097 | 1089 | const stack_protector: u32 = options.want_stack_protector orelse b: { |
| 1098 | 1090 | if (!target_util.supportsStackProtector(options.target)) break :b @as(u32, 0); |
| 1099 | 1091 | |
| ... | ... | @@ -1752,6 +1744,9 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1752 | 1744 | |
| 1753 | 1745 | const target = comp.getTarget(); |
| 1754 | 1746 | |
| 1747 | const capable_of_building_compiler_rt = canBuildLibCompilerRt(target, comp.bin_file.options.use_llvm); |
| 1748 | const capable_of_building_zig_libc = canBuildZigLibC(target, comp.bin_file.options.use_llvm); |
| 1749 | |
| 1755 | 1750 | // Add a `CObject` for each `c_source_files`. |
| 1756 | 1751 | try comp.c_object_table.ensureTotalCapacity(gpa, options.c_source_files.len); |
| 1757 | 1752 | for (options.c_source_files) |c_source_file| { |
| ... | ... | @@ -6238,9 +6233,66 @@ pub fn dump_argv(argv: []const []const u8) void { |
| 6238 | 6233 | nosuspend stderr.print("{s}\n", .{argv[argv.len - 1]}) catch {}; |
| 6239 | 6234 | } |
| 6240 | 6235 | |
| 6236 | fn canBuildLibCompilerRt(target: std.Target, use_llvm: bool) bool { |
| 6237 | switch (target.os.tag) { |
| 6238 | .plan9 => return false, |
| 6239 | else => {}, |
| 6240 | } |
| 6241 | switch (target.cpu.arch) { |
| 6242 | .spirv32, .spirv64 => return false, |
| 6243 | else => {}, |
| 6244 | } |
| 6245 | return switch (zigBackend(target, use_llvm)) { |
| 6246 | .stage2_llvm, |
| 6247 | .stage2_x86_64, |
| 6248 | => true, |
| 6249 | |
| 6250 | else => false, |
| 6251 | }; |
| 6252 | } |
| 6253 | |
| 6254 | fn canBuildLibSsp(target: std.Target, use_llvm: bool) bool { |
| 6255 | switch (target.os.tag) { |
| 6256 | .plan9 => return false, |
| 6257 | else => {}, |
| 6258 | } |
| 6259 | switch (target.cpu.arch) { |
| 6260 | .spirv32, .spirv64 => return false, |
| 6261 | else => {}, |
| 6262 | } |
| 6263 | return switch (zigBackend(target, use_llvm)) { |
| 6264 | .stage2_llvm => true, |
| 6265 | else => false, |
| 6266 | }; |
| 6267 | } |
| 6268 | |
| 6269 | /// Not to be confused with canBuildLibC, which builds musl, glibc, and similar. |
| 6270 | /// This one builds lib/c.zig. |
| 6271 | fn canBuildZigLibC(target: std.Target, use_llvm: bool) bool { |
| 6272 | switch (target.os.tag) { |
| 6273 | .plan9 => return false, |
| 6274 | else => {}, |
| 6275 | } |
| 6276 | switch (target.cpu.arch) { |
| 6277 | .spirv32, .spirv64 => return false, |
| 6278 | else => {}, |
| 6279 | } |
| 6280 | return switch (zigBackend(target, use_llvm)) { |
| 6281 | .stage2_llvm, |
| 6282 | .stage2_x86_64, |
| 6283 | => true, |
| 6284 | |
| 6285 | else => false, |
| 6286 | }; |
| 6287 | } |
| 6288 | |
| 6241 | 6289 | pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend { |
| 6242 | | if (comp.bin_file.options.use_llvm) return .stage2_llvm; |
| 6243 | 6290 | const target = comp.bin_file.options.target; |
| 6291 | return zigBackend(target, comp.bin_file.options.use_llvm); |
| 6292 | } |
| 6293 | |
| 6294 | fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBackend { |
| 6295 | if (use_llvm) return .stage2_llvm; |
| 6244 | 6296 | if (target.ofmt == .c) return .stage2_c; |
| 6245 | 6297 | return switch (target.cpu.arch) { |
| 6246 | 6298 | .wasm32, .wasm64 => std.builtin.CompilerBackend.stage2_wasm, |