Skip to content

Commit bc8ace2

Browse files
committed
compiler-rt: Issue VALGRIND_DISCARD_TRANSLATIONS request in __clear_cache().
Closes #24030.
1 parent 3b2bef8 commit bc8ace2

File tree

2 files changed

+78
-15
lines changed

2 files changed

+78
-15
lines changed

lib/compiler_rt/clear_cache.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ fn clear_cache(start: usize, end: usize) callconv(.c) void {
173173
);
174174
exportIt();
175175
}
176+
177+
std.valgrind.discardTranslations(@as([*]u8, @ptrFromInt(start))[0 .. end - start]);
176178
}
177179

178180
fn exportIt() void {

src/Compilation.zig

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4206,23 +4206,78 @@ fn performAllTheWorkInner(
42064206
// compiler-rt due to LLD bugs as well, e.g.:
42074207
//
42084208
// https://github.com/llvm/llvm-project/issues/43698#issuecomment-2542660611
4209-
comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", "compiler_rt", .compiler_rt, .Lib, false, &comp.compiler_rt_lib, main_progress_node });
4209+
comp.link_task_wait_group.spawnManager(buildRt, .{
4210+
comp,
4211+
"compiler_rt.zig",
4212+
"compiler_rt",
4213+
.Lib,
4214+
.compiler_rt,
4215+
main_progress_node,
4216+
RtOptions{
4217+
.checks_valgrind = true,
4218+
.allow_lto = false,
4219+
},
4220+
&comp.compiler_rt_lib,
4221+
});
42104222
}
42114223

42124224
if (comp.queued_jobs.compiler_rt_obj and comp.compiler_rt_obj == null) {
4213-
comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "compiler_rt.zig", "compiler_rt", .compiler_rt, .Obj, false, &comp.compiler_rt_obj, main_progress_node });
4225+
comp.link_task_wait_group.spawnManager(buildRt, .{
4226+
comp,
4227+
"compiler_rt.zig",
4228+
"compiler_rt",
4229+
.Obj,
4230+
.compiler_rt,
4231+
main_progress_node,
4232+
RtOptions{
4233+
.checks_valgrind = true,
4234+
.allow_lto = false,
4235+
},
4236+
&comp.compiler_rt_obj,
4237+
});
42144238
}
42154239

42164240
if (comp.queued_jobs.fuzzer_lib and comp.fuzzer_lib == null) {
4217-
comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "fuzzer.zig", "fuzzer", .libfuzzer, .Lib, true, &comp.fuzzer_lib, main_progress_node });
4241+
comp.link_task_wait_group.spawnManager(buildRt, .{
4242+
comp,
4243+
"fuzzer.zig",
4244+
"fuzzer",
4245+
.Lib,
4246+
.libfuzzer,
4247+
main_progress_node,
4248+
RtOptions{},
4249+
&comp.fuzzer_lib,
4250+
});
42184251
}
42194252

42204253
if (comp.queued_jobs.ubsan_rt_lib and comp.ubsan_rt_lib == null) {
4221-
comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "ubsan_rt.zig", "ubsan_rt", .libubsan, .Lib, false, &comp.ubsan_rt_lib, main_progress_node });
4254+
comp.link_task_wait_group.spawnManager(buildRt, .{
4255+
comp,
4256+
"ubsan_rt.zig",
4257+
"ubsan_rt",
4258+
.Lib,
4259+
.libubsan,
4260+
main_progress_node,
4261+
RtOptions{
4262+
.allow_lto = false,
4263+
},
4264+
&comp.ubsan_rt_lib,
4265+
});
42224266
}
42234267

42244268
if (comp.queued_jobs.ubsan_rt_obj and comp.ubsan_rt_obj == null) {
4225-
comp.link_task_wait_group.spawnManager(buildRt, .{ comp, "ubsan_rt.zig", "ubsan_rt", .libubsan, .Obj, false, &comp.ubsan_rt_obj, main_progress_node });
4269+
comp.link_task_wait_group.spawnManager(buildRt, .{
4270+
comp,
4271+
"ubsan_rt.zig",
4272+
"ubsan_rt",
4273+
.Obj,
4274+
.libubsan,
4275+
main_progress_node,
4276+
RtOptions{
4277+
.allow_lto = false,
4278+
},
4279+
&comp.ubsan_rt_obj,
4280+
});
42264281
}
42274282

42284283
if (comp.queued_jobs.glibc_shared_objects) {
@@ -5201,24 +5256,29 @@ fn workerUpdateWin32Resource(
52015256
};
52025257
}
52035258

5259+
pub const RtOptions = struct {
5260+
checks_valgrind: bool = false,
5261+
allow_lto: bool = true,
5262+
};
5263+
52045264
fn buildRt(
52055265
comp: *Compilation,
52065266
root_source_name: []const u8,
52075267
root_name: []const u8,
5208-
misc_task: MiscTask,
52095268
output_mode: std.builtin.OutputMode,
5210-
allow_lto: bool,
5211-
out: *?CrtFile,
5269+
misc_task: MiscTask,
52125270
prog_node: std.Progress.Node,
5271+
options: RtOptions,
5272+
out: *?CrtFile,
52135273
) void {
52145274
comp.buildOutputFromZig(
52155275
root_source_name,
52165276
root_name,
52175277
output_mode,
5218-
allow_lto,
5219-
out,
52205278
misc_task,
52215279
prog_node,
5280+
options,
5281+
out,
52225282
) catch |err| switch (err) {
52235283
error.SubCompilationFailed => return, // error reported already
52245284
else => comp.lockAndSetMiscFailure(misc_task, "unable to build {s}: {s}", .{
@@ -5370,10 +5430,10 @@ fn buildLibZigC(comp: *Compilation, prog_node: std.Progress.Node) void {
53705430
"c.zig",
53715431
"zigc",
53725432
.Lib,
5373-
true,
5374-
&comp.zigc_static_lib,
53755433
.libzigc,
53765434
prog_node,
5435+
.{},
5436+
&comp.zigc_static_lib,
53775437
) catch |err| switch (err) {
53785438
error.SubCompilationFailed => return, // error reported already
53795439
else => comp.lockAndSetMiscFailure(.libzigc, "unable to build libzigc: {s}", .{@errorName(err)}),
@@ -7044,10 +7104,10 @@ fn buildOutputFromZig(
70447104
src_basename: []const u8,
70457105
root_name: []const u8,
70467106
output_mode: std.builtin.OutputMode,
7047-
allow_lto: bool,
7048-
out: *?CrtFile,
70497107
misc_task_tag: MiscTask,
70507108
prog_node: std.Progress.Node,
7109+
options: RtOptions,
7110+
out: *?CrtFile,
70517111
) !void {
70527112
const tracy_trace = trace(@src());
70537113
defer tracy_trace.end();
@@ -7075,7 +7135,7 @@ fn buildOutputFromZig(
70757135
.any_unwind_tables = comp.root_mod.unwind_tables != .none,
70767136
.any_error_tracing = false,
70777137
.root_error_tracing = false,
7078-
.lto = if (allow_lto) comp.config.lto else .none,
7138+
.lto = if (options.allow_lto) comp.config.lto else .none,
70797139
});
70807140

70817141
const root_mod = try Package.Module.create(arena, .{
@@ -7098,6 +7158,7 @@ fn buildOutputFromZig(
70987158
.no_builtin = true,
70997159
.code_model = comp.root_mod.code_model,
71007160
.error_tracing = false,
7161+
.valgrind = if (options.checks_valgrind) comp.root_mod.valgrind else null,
71017162
},
71027163
.global = config,
71037164
.cc_argv = &.{},

0 commit comments

Comments
 (0)