aboutsummaryrefslogtreecommitdiff
path: root/src/libtsan.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-01-02 14:11:27 -0800
committerGitHub <noreply@github.com>2024-01-02 14:11:27 -0800
commit289ae45c1b58e952867c4fa1e246d0ef7bc2ff64 (patch)
tree5dd034143a2354b7b44496e684f1c764e2f9664c /src/libtsan.zig
parentc89bb3e141ee215add0b52930d48bffd8dae8342 (diff)
parentc546ddb3edc557fae4b932e5239b9dcb66117832 (diff)
downloadzig-289ae45c1b58e952867c4fa1e246d0ef7bc2ff64.tar.gz
zig-289ae45c1b58e952867c4fa1e246d0ef7bc2ff64.zip
Merge pull request #18160 from ziglang/std-build-module
Move many settings from being per-Compilation to being per-Module
Diffstat (limited to 'src/libtsan.zig')
-rw-r--r--src/libtsan.zig98
1 files changed, 64 insertions, 34 deletions
diff --git a/src/libtsan.zig b/src/libtsan.zig
index 2489eb21af..14a7db0888 100644
--- a/src/libtsan.zig
+++ b/src/libtsan.zig
@@ -4,6 +4,7 @@ const assert = std.debug.assert;
const Compilation = @import("Compilation.zig");
const build_options = @import("build_options");
const trace = @import("tracy.zig").trace;
+const Module = @import("Package/Module.zig");
pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
if (!build_options.have_llvm) {
@@ -33,6 +34,52 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
.basename = basename,
};
+ const optimize_mode = comp.compilerRtOptMode();
+ const strip = comp.compilerRtStrip();
+
+ const config = try Compilation.Config.resolve(.{
+ .output_mode = output_mode,
+ .link_mode = link_mode,
+ .resolved_target = comp.root_mod.resolved_target,
+ .is_test = false,
+ .have_zcu = false,
+ .emit_bin = true,
+ .root_optimize_mode = optimize_mode,
+ .root_strip = strip,
+ .link_libc = true,
+ });
+
+ const common_flags = [_][]const u8{
+ "-DTSAN_CONTAINS_UBSAN=0",
+ };
+
+ const root_mod = try Module.create(arena, .{
+ .global_cache_directory = comp.global_cache_directory,
+ .paths = .{
+ .root = .{ .root_dir = comp.zig_lib_directory },
+ .root_src_path = "",
+ },
+ .fully_qualified_name = "root",
+ .inherited = .{
+ .resolved_target = comp.root_mod.resolved_target,
+ .strip = strip,
+ .stack_check = false,
+ .stack_protector = 0,
+ .sanitize_c = false,
+ .sanitize_thread = false,
+ .red_zone = comp.root_mod.red_zone,
+ .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
+ .valgrind = false,
+ .optimize_mode = optimize_mode,
+ .structured_cfg = comp.root_mod.structured_cfg,
+ .pic = true,
+ },
+ .global = config,
+ .cc_argv = &common_flags,
+ .parent = null,
+ .builtin_mod = null,
+ });
+
var c_source_files = std.ArrayList(Compilation.CSourceFile).init(arena);
try c_source_files.ensureUnusedCapacity(tsan_sources.len);
@@ -49,8 +96,9 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
try cflags.append("-fno-rtti");
c_source_files.appendAssumeCapacity(.{
- .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", tsan_src }),
+ .src_path = try comp.zig_lib_directory.join(arena, &.{ "tsan", tsan_src }),
.extra_flags = cflags.items,
+ .owner = root_mod,
});
}
@@ -73,6 +121,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", tsan_src }),
.extra_flags = cflags.items,
+ .owner = root_mod,
});
}
{
@@ -93,6 +142,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
c_source_files.appendAssumeCapacity(.{
.src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ "tsan", asm_source }),
.extra_flags = cflags.items,
+ .owner = root_mod,
});
}
@@ -116,10 +166,11 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
"tsan", "sanitizer_common", common_src,
}),
.extra_flags = cflags.items,
+ .owner = root_mod,
});
}
- const to_c_or_not_to_c_sources = if (comp.bin_file.options.link_libc)
+ const to_c_or_not_to_c_sources = if (comp.config.link_libc)
&sanitizer_libcdep_sources
else
&sanitizer_nolibc_sources;
@@ -140,6 +191,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
"tsan", "sanitizer_common", c_src,
}),
.extra_flags = cflags.items,
+ .owner = root_mod,
});
}
@@ -160,6 +212,7 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
"tsan", "sanitizer_common", c_src,
}),
.extra_flags = cflags.items,
+ .owner = root_mod,
});
}
@@ -188,63 +241,40 @@ pub fn buildTsan(comp: *Compilation, prog_node: *std.Progress.Node) !void {
"tsan", "interception", c_src,
}),
.extra_flags = cflags.items,
+ .owner = root_mod,
});
}
- const common_flags = [_][]const u8{
- "-DTSAN_CONTAINS_UBSAN=0",
- };
-
- const sub_compilation = try Compilation.create(comp.gpa, .{
+ const sub_compilation = try Compilation.create(comp.gpa, arena, .{
.local_cache_directory = comp.global_cache_directory,
.global_cache_directory = comp.global_cache_directory,
.zig_lib_directory = comp.zig_lib_directory,
+ .thread_pool = comp.thread_pool,
+ .self_exe_path = comp.self_exe_path,
.cache_mode = .whole,
- .target = target,
+ .config = config,
+ .root_mod = root_mod,
.root_name = root_name,
- .main_mod = null,
- .output_mode = output_mode,
- .thread_pool = comp.thread_pool,
- .libc_installation = comp.bin_file.options.libc_installation,
+ .libc_installation = comp.libc_installation,
.emit_bin = emit_bin,
- .optimize_mode = comp.compilerRtOptMode(),
- .link_mode = link_mode,
- .want_sanitize_c = false,
- .want_stack_check = false,
- .want_stack_protector = 0,
- .want_valgrind = false,
- .want_tsan = false,
- .want_pic = true,
- .want_pie = null,
.emit_h = null,
- .strip = comp.compilerRtStrip(),
- .is_native_os = comp.bin_file.options.is_native_os,
- .is_native_abi = comp.bin_file.options.is_native_abi,
- .self_exe_path = comp.self_exe_path,
.c_source_files = c_source_files.items,
.verbose_cc = comp.verbose_cc,
- .verbose_link = comp.bin_file.options.verbose_link,
+ .verbose_link = comp.verbose_link,
.verbose_air = comp.verbose_air,
.verbose_llvm_ir = comp.verbose_llvm_ir,
.verbose_llvm_bc = comp.verbose_llvm_bc,
.verbose_cimport = comp.verbose_cimport,
.verbose_llvm_cpu_features = comp.verbose_llvm_cpu_features,
.clang_passthrough_mode = comp.clang_passthrough_mode,
- .link_libc = true,
.skip_linker_dependencies = true,
- .clang_argv = &common_flags,
});
defer sub_compilation.destroy();
try comp.updateSubCompilation(sub_compilation, .libtsan, prog_node);
assert(comp.tsan_static_lib == null);
- comp.tsan_static_lib = Compilation.CRTFile{
- .full_object_path = try sub_compilation.bin_file.options.emit.?.directory.join(comp.gpa, &[_][]const u8{
- sub_compilation.bin_file.options.emit.?.sub_path,
- }),
- .lock = sub_compilation.bin_file.toOwnedLock(),
- };
+ comp.tsan_static_lib = try sub_compilation.toCrtFile();
}
const tsan_sources = [_][]const u8{