authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-15 14:22:24-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:19-07:00
loga1236b32f9a4114231312b1493dcbac308a2c055
tree6c5760b75396a392765f6c08755110c0df1065a5
parent2596f5d92593a5f7dad21d9a54f2d08f33639432

libcxx: update to new Compilation API


5 files changed, 114 insertions(+), 59 deletions(-)

src/Compilation/Config.zig+2
...@@ -13,6 +13,7 @@ any_non_single_threaded: bool,...@@ -13,6 +13,7 @@ any_non_single_threaded: bool,
13/// and function calling convention depend on this global value, however, other13/// and function calling convention depend on this global value, however, other
14/// kinds of error tracing are omitted depending on the per-Module setting.14/// kinds of error tracing are omitted depending on the per-Module setting.
15any_error_tracing: bool,15any_error_tracing: bool,
16any_sanitize_thread: bool,
16pie: bool,17pie: bool,
17/// If this is true then linker code is responsible for making an LLVM IR18/// If this is true then linker code is responsible for making an LLVM IR
18/// Module, outputting it to an object file, and then linking that together19/// Module, outputting it to an object file, and then linking that together
...@@ -427,6 +428,7 @@ pub fn resolve(options: Options) !Config {...@@ -427,6 +428,7 @@ pub fn resolve(options: Options) !Config {
427 .any_c_source_files = options.any_c_source_files,428 .any_c_source_files = options.any_c_source_files,
428 .any_non_single_threaded = options.any_non_single_threaded,429 .any_non_single_threaded = options.any_non_single_threaded,
429 .any_error_tracing = any_error_tracing,430 .any_error_tracing = any_error_tracing,
431 .any_sanitize_thread = options.any_sanitize_thread,
430 .root_error_tracing = root_error_tracing,432 .root_error_tracing = root_error_tracing,
431 .pie = pie,433 .pie = pie,
432 .lto = lto,434 .lto = lto,
src/Module.zig+3-3
...@@ -4566,7 +4566,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4566,7 +4566,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
45664566
4567 // If we don't get an error return trace from a caller, create our own.4567 // If we don't get an error return trace from a caller, create our own.
4568 if (func.analysis(ip).calls_or_awaits_errorable_fn and4568 if (func.analysis(ip).calls_or_awaits_errorable_fn and
4569 mod.comp.config.error_tracing and4569 mod.comp.config.any_error_tracing and
4570 !sema.fn_ret_ty.isError(mod))4570 !sema.fn_ret_ty.isError(mod))
4571 {4571 {
4572 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {4572 sema.setupErrorReturnTrace(&inner_block, last_arg_index) catch |err| switch (err) {
...@@ -5567,8 +5567,8 @@ pub const Feature = enum {...@@ -5567,8 +5567,8 @@ pub const Feature = enum {
5567};5567};
55685568
5569pub fn backendSupportsFeature(zcu: Module, feature: Feature) bool {5569pub fn backendSupportsFeature(zcu: Module, feature: Feature) bool {
5570 const cpu_arch = zcu.root_mod.resolved_target.cpu.arch;5570 const cpu_arch = zcu.root_mod.resolved_target.result.cpu.arch;
5571 const ofmt = zcu.root_mod.resolved_target.ofmt;5571 const ofmt = zcu.root_mod.resolved_target.result.ofmt;
5572 const use_llvm = zcu.comp.config.use_llvm;5572 const use_llvm = zcu.comp.config.use_llvm;
5573 return switch (feature) {5573 return switch (feature) {
5574 .panic_fn => ofmt == .c or use_llvm or cpu_arch == .x86_64,5574 .panic_fn => ofmt == .c or use_llvm or cpu_arch == .x86_64,
src/Package/Module.zig+5
...@@ -102,6 +102,11 @@ pub const ResolvedTarget = struct {...@@ -102,6 +102,11 @@ pub const ResolvedTarget = struct {
102102
103/// At least one of `parent` and `resolved_target` must be non-null.103/// At least one of `parent` and `resolved_target` must be non-null.
104pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {104pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
105 if (options.inherited.sanitize_thread == true) assert(options.global.any_sanitize_thread);
106 if (options.inherited.single_threaded == false) assert(options.global.any_non_single_threaded);
107 if (options.inherited.unwind_tables == true) assert(options.global.any_unwind_tables);
108 if (options.inherited.error_tracing == true) assert(options.global.any_error_tracing);
109
105 const resolved_target = options.inherited.resolved_target orelse options.parent.?.resolved_target;110 const resolved_target = options.inherited.resolved_target orelse options.parent.?.resolved_target;
106 const target = resolved_target.result;111 const target = resolved_target.result;
107112
src/libcxx.zig+104-53
...@@ -6,6 +6,7 @@ const target_util = @import("target.zig");...@@ -6,6 +6,7 @@ const target_util = @import("target.zig");
6const Compilation = @import("Compilation.zig");6const Compilation = @import("Compilation.zig");
7const build_options = @import("build_options");7const build_options = @import("build_options");
8const trace = @import("tracy.zig").trace;8const trace = @import("tracy.zig").trace;
9const Module = @import("Package/Module.zig");
910
10pub const AbiVersion = enum(u2) {11pub const AbiVersion = enum(u2) {
11 @"1" = 1,12 @"1" = 1,
...@@ -115,7 +116,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -115,7 +116,7 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
115 const root_name = "c++";116 const root_name = "c++";
116 const output_mode = .Lib;117 const output_mode = .Lib;
117 const link_mode = .Static;118 const link_mode = .Static;
118 const target = comp.getTarget();119 const target = comp.root_mod.resolved_target.result;
119 const basename = try std.zig.binNameAlloc(arena, .{120 const basename = try std.zig.binNameAlloc(arena, .{
120 .root_name = root_name,121 .root_name = root_name,
121 .target = target,122 .target = target,
...@@ -226,46 +227,70 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -226,46 +227,70 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
226 });227 });
227 }228 }
228229
230 const optimize_mode = comp.compilerRtOptMode();
231 const strip = comp.compilerRtStrip();
232
233 const config = try Compilation.Config.resolve(.{
234 .output_mode = output_mode,
235 .link_mode = link_mode,
236 .resolved_target = comp.root_mod.resolved_target,
237 .is_test = false,
238 .have_zcu = false,
239 .emit_bin = true,
240 .root_optimize_mode = optimize_mode,
241 .root_strip = strip,
242 .link_libc = true,
243 .lto = comp.config.lto,
244 });
245
246 const root_mod = try Module.create(arena, .{
247 .global_cache_directory = comp.global_cache_directory,
248 .paths = .{
249 .root = .{ .root_dir = comp.zig_lib_directory },
250 .root_src_path = "",
251 },
252 .fully_qualified_name = "root",
253 .inherited = .{
254 .strip = strip,
255 .stack_check = false,
256 .stack_protector = 0,
257 .sanitize_c = false,
258 .sanitize_thread = comp.config.any_sanitize_thread,
259 .red_zone = comp.root_mod.red_zone,
260 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
261 .valgrind = false,
262 .optimize_mode = optimize_mode,
263 .structured_cfg = comp.root_mod.structured_cfg,
264 .pic = comp.root_mod.pic,
265 },
266 .global = config,
267 .cc_argv = &.{},
268 .parent = null,
269 .builtin_mod = null,
270 });
271
229 const sub_compilation = try Compilation.create(comp.gpa, .{272 const sub_compilation = try Compilation.create(comp.gpa, .{
230 .local_cache_directory = comp.global_cache_directory,273 .local_cache_directory = comp.global_cache_directory,
231 .global_cache_directory = comp.global_cache_directory,274 .global_cache_directory = comp.global_cache_directory,
232 .zig_lib_directory = comp.zig_lib_directory,275 .zig_lib_directory = comp.zig_lib_directory,
276 .self_exe_path = comp.self_exe_path,
233 .cache_mode = .whole,277 .cache_mode = .whole,
234 .target = target,278 .config = config,
279 .root_mod = root_mod,
235 .root_name = root_name,280 .root_name = root_name,
236 .main_mod = null,
237 .output_mode = output_mode,
238 .thread_pool = comp.thread_pool,281 .thread_pool = comp.thread_pool,
239 .libc_installation = comp.bin_file.options.libc_installation,282 .libc_installation = comp.libc_installation,
240 .emit_bin = emit_bin,283 .emit_bin = emit_bin,
241 .optimize_mode = comp.compilerRtOptMode(),
242 .link_mode = link_mode,
243 .want_sanitize_c = false,
244 .want_stack_check = false,
245 .want_stack_protector = 0,
246 .want_red_zone = comp.bin_file.options.red_zone,
247 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
248 .want_valgrind = false,
249 .want_tsan = comp.bin_file.options.tsan,
250 .want_pic = comp.bin_file.options.pic,
251 .want_pie = null,
252 .want_lto = comp.bin_file.options.lto,
253 .function_sections = comp.bin_file.options.function_sections,
254 .emit_h = null,284 .emit_h = null,
255 .strip = comp.compilerRtStrip(),
256 .is_native_os = comp.bin_file.options.is_native_os,
257 .is_native_abi = comp.bin_file.options.is_native_abi,
258 .self_exe_path = comp.self_exe_path,
259 .c_source_files = c_source_files.items,285 .c_source_files = c_source_files.items,
260 .verbose_cc = comp.verbose_cc,286 .verbose_cc = comp.verbose_cc,
261 .verbose_link = comp.bin_file.options.verbose_link,287 .verbose_link = comp.verbose_link,
262 .verbose_air = comp.verbose_air,288 .verbose_air = comp.verbose_air,
263 .verbose_llvm_ir = comp.verbose_llvm_ir,289 .verbose_llvm_ir = comp.verbose_llvm_ir,
264 .verbose_llvm_bc = comp.verbose_llvm_bc,290 .verbose_llvm_bc = comp.verbose_llvm_bc,
265 .verbose_cimport = comp.verbose_cimport,291 .verbose_cimport = comp.verbose_cimport,
266 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,292 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
267 .clang_passthrough_mode = comp.clang_passthrough_mode,293 .clang_passthrough_mode = comp.clang_passthrough_mode,
268 .link_libc = true,
269 .skip_linker_dependencies = true,294 .skip_linker_dependencies = true,
270 });295 });
271 defer sub_compilation.destroy();296 defer sub_compilation.destroy();
...@@ -274,8 +299,8 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -274,8 +299,8 @@ pub fn buildLibCXX(comp: *Compilation, prog_node: *std.Progress.Node) !void {
274299
275 assert(comp.libcxx_static_lib == null);300 assert(comp.libcxx_static_lib == null);
276 comp.libcxx_static_lib = Compilation.CRTFile{301 comp.libcxx_static_lib = Compilation.CRTFile{
277 .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{302 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &.{
278 sub_compilation.bin_file.options.emit.?.sub_path,303 sub_compilation.bin_file.?.emit.sub_path,
279 }),304 }),
280 .lock = sub_compilation.bin_file.toOwnedLock(),305 .lock = sub_compilation.bin_file.toOwnedLock(),
281 };306 };
...@@ -296,7 +321,7 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -296,7 +321,7 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
296 const root_name = "c++abi";321 const root_name = "c++abi";
297 const output_mode = .Lib;322 const output_mode = .Lib;
298 const link_mode = .Static;323 const link_mode = .Static;
299 const target = comp.getTarget();324 const target = comp.root_mod.resolved_target.result;
300 const basename = try std.zig.binNameAlloc(arena, .{325 const basename = try std.zig.binNameAlloc(arena, .{
301 .root_name = root_name,326 .root_name = root_name,
302 .target = target,327 .target = target,
...@@ -365,7 +390,6 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -365,7 +390,6 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
365 }390 }
366 try cflags.append("-nostdinc++");391 try cflags.append("-nostdinc++");
367 try cflags.append("-fstrict-aliasing");392 try cflags.append("-fstrict-aliasing");
368 try cflags.append("-funwind-tables");
369 try cflags.append("-std=c++20");393 try cflags.append("-std=c++20");
370394
371 // These depend on only the zig lib directory file path, which is395 // These depend on only the zig lib directory file path, which is
...@@ -389,46 +413,73 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -389,46 +413,73 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
389 });413 });
390 }414 }
391415
416 const optimize_mode = comp.compilerRtOptMode();
417 const strip = comp.compilerRtStrip();
418 const unwind_tables = true;
419
420 const config = try Compilation.Config.resolve(.{
421 .output_mode = output_mode,
422 .link_mode = link_mode,
423 .resolved_target = comp.root_mod.resolved_target,
424 .is_test = false,
425 .have_zcu = false,
426 .emit_bin = true,
427 .root_optimize_mode = optimize_mode,
428 .root_strip = strip,
429 .link_libc = true,
430 .any_unwind_tables = unwind_tables,
431 .lto = comp.config.lto,
432 });
433
434 const root_mod = try Module.create(arena, .{
435 .global_cache_directory = comp.global_cache_directory,
436 .paths = .{
437 .root = .{ .root_dir = comp.zig_lib_directory },
438 .root_src_path = "",
439 },
440 .fully_qualified_name = "root",
441 .inherited = .{
442 .strip = strip,
443 .stack_check = false,
444 .stack_protector = 0,
445 .sanitize_c = false,
446 .sanitize_thread = comp.config.any_sanitize_thread,
447 .red_zone = comp.root_mod.red_zone,
448 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
449 .valgrind = false,
450 .optimize_mode = optimize_mode,
451 .structured_cfg = comp.root_mod.structured_cfg,
452 .unwind_tables = unwind_tables,
453 .pic = comp.root_mod.pic,
454 },
455 .global = config,
456 .cc_argv = &.{},
457 .parent = null,
458 .builtin_mod = null,
459 });
460
392 const sub_compilation = try Compilation.create(comp.gpa, .{461 const sub_compilation = try Compilation.create(comp.gpa, .{
393 .local_cache_directory = comp.global_cache_directory,462 .local_cache_directory = comp.global_cache_directory,
394 .global_cache_directory = comp.global_cache_directory,463 .global_cache_directory = comp.global_cache_directory,
395 .zig_lib_directory = comp.zig_lib_directory,464 .zig_lib_directory = comp.zig_lib_directory,
465 .self_exe_path = comp.self_exe_path,
396 .cache_mode = .whole,466 .cache_mode = .whole,
397 .target = target,467 .config = config,
468 .root_mod = root_mod,
398 .root_name = root_name,469 .root_name = root_name,
399 .main_mod = null,
400 .output_mode = output_mode,
401 .thread_pool = comp.thread_pool,470 .thread_pool = comp.thread_pool,
402 .libc_installation = comp.bin_file.options.libc_installation,471 .libc_installation = comp.libc_installation,
403 .emit_bin = emit_bin,472 .emit_bin = emit_bin,
404 .optimize_mode = comp.compilerRtOptMode(),
405 .link_mode = link_mode,
406 .want_sanitize_c = false,
407 .want_stack_check = false,
408 .want_stack_protector = 0,
409 .want_red_zone = comp.bin_file.options.red_zone,
410 .omit_frame_pointer = comp.bin_file.options.omit_frame_pointer,
411 .want_valgrind = false,
412 .want_tsan = comp.bin_file.options.tsan,
413 .want_pic = comp.bin_file.options.pic,
414 .want_pie = null,
415 .want_lto = comp.bin_file.options.lto,
416 .function_sections = comp.bin_file.options.function_sections,
417 .emit_h = null,473 .emit_h = null,
418 .strip = comp.compilerRtStrip(),
419 .is_native_os = comp.bin_file.options.is_native_os,
420 .is_native_abi = comp.bin_file.options.is_native_abi,
421 .self_exe_path = comp.self_exe_path,
422 .c_source_files = c_source_files.items,474 .c_source_files = c_source_files.items,
423 .verbose_cc = comp.verbose_cc,475 .verbose_cc = comp.verbose_cc,
424 .verbose_link = comp.bin_file.options.verbose_link,476 .verbose_link = comp.verbose_link,
425 .verbose_air = comp.verbose_air,477 .verbose_air = comp.verbose_air,
426 .verbose_llvm_ir = comp.verbose_llvm_ir,478 .verbose_llvm_ir = comp.verbose_llvm_ir,
427 .verbose_llvm_bc = comp.verbose_llvm_bc,479 .verbose_llvm_bc = comp.verbose_llvm_bc,
428 .verbose_cimport = comp.verbose_cimport,480 .verbose_cimport = comp.verbose_cimport,
429 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,481 .verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
430 .clang_passthrough_mode = comp.clang_passthrough_mode,482 .clang_passthrough_mode = comp.clang_passthrough_mode,
431 .link_libc = true,
432 .skip_linker_dependencies = true,483 .skip_linker_dependencies = true,
433 });484 });
434 defer sub_compilation.destroy();485 defer sub_compilation.destroy();
...@@ -437,8 +488,8 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {...@@ -437,8 +488,8 @@ pub fn buildLibCXXABI(comp: *Compilation, prog_node: *std.Progress.Node) !void {
437488
438 assert(comp.libcxxabi_static_lib == null);489 assert(comp.libcxxabi_static_lib == null);
439 comp.libcxxabi_static_lib = Compilation.CRTFile{490 comp.libcxxabi_static_lib = Compilation.CRTFile{
440 .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{491 .full_object_path = try sub_compilation.bin_file.?.emit.directory.join(comp.gpa, &[_][]const u8{
441 sub_compilation.bin_file.options.emit.?.sub_path,492 sub_compilation.bin_file.?.emit.sub_path,
442 }),493 }),
443 .lock = sub_compilation.bin_file.toOwnedLock(),494 .lock = sub_compilation.bin_file.toOwnedLock(),
444 };495 };
src/musl.zig-3
...@@ -191,7 +191,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -191,7 +191,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
191 return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items);191 return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items);
192 },192 },
193 .libc_so => {193 .libc_so => {
194 const unwind_tables = false;
195 const optimize_mode = comp.compilerRtOptMode();194 const optimize_mode = comp.compilerRtOptMode();
196 const strip = comp.compilerRtStrip();195 const strip = comp.compilerRtStrip();
197 const config = try Compilation.Config.resolve(.{196 const config = try Compilation.Config.resolve(.{
...@@ -204,7 +203,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -204,7 +203,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
204 .root_optimize_mode = optimize_mode,203 .root_optimize_mode = optimize_mode,
205 .root_strip = strip,204 .root_strip = strip,
206 .link_libc = false,205 .link_libc = false,
207 .any_unwind_tables = unwind_tables,
208 });206 });
209207
210 const target = comp.root_mod.resolved_target.result;208 const target = comp.root_mod.resolved_target.result;
...@@ -232,7 +230,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr...@@ -232,7 +230,6 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile, prog_node: *std.Progr
232 .red_zone = comp.root_mod.red_zone,230 .red_zone = comp.root_mod.red_zone,
233 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,231 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
234 .valgrind = false,232 .valgrind = false,
235 .unwind_tables = unwind_tables,
236 .optimize_mode = optimize_mode,233 .optimize_mode = optimize_mode,
237 .structured_cfg = comp.root_mod.structured_cfg,234 .structured_cfg = comp.root_mod.structured_cfg,
238 },235 },