diff --git a/lib/std/valgrind.zig b/lib/std/valgrind.zig index 30170aa6ed..7b095a8997 100644 --- a/lib/std/valgrind.zig +++ b/lib/std/valgrind.zig @@ -66,6 +66,20 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: [_] "{r3}" (default), : "cc", "memory" ), + .riscv64 => asm volatile ( + \\ .option push + \\ .option norvc + \\ srli zero, zero, 3 + \\ srli zero, zero, 13 + \\ srli zero, zero, 51 + \\ srli zero, zero, 61 + \\ or a0, a0, a0 + \\ .option pop + : [_] "={a3}" (-> usize), + : [_] "{a4}" (args), + [_] "{a3}" (default), + : "cc", "memory" + ), .s390x => asm volatile ( \\ lr %%r15, %%r15 \\ lr %%r1, %%r1 diff --git a/src/Package/Module.zig b/src/Package/Module.zig index 207c233898..bcab39415f 100644 --- a/src/Package/Module.zig +++ b/src/Package/Module.zig @@ -113,8 +113,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { break :b options.global.root_strip; }; + const zig_backend = target_util.zigBackend(target, options.global.use_llvm); + const valgrind = b: { - if (!target_util.hasValgrindSupport(target)) { + if (!target_util.hasValgrindSupport(target, zig_backend)) { if (options.inherited.valgrind == true) return error.ValgrindUnsupportedOnTarget; break :b false; @@ -125,8 +127,6 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { break :b optimize_mode == .Debug; }; - const zig_backend = target_util.zigBackend(target, options.global.use_llvm); - const single_threaded = b: { if (target_util.alwaysSingleThreaded(target)) { if (options.inherited.single_threaded == false) diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 268a57417b..3b26c9674d 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -11604,7 +11604,7 @@ pub const FuncGen = struct { const pt = o.pt; const zcu = pt.zcu; const target = zcu.getTarget(); - if (!target_util.hasValgrindSupport(target)) return default_value; + if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value; const llvm_usize = try o.lowerType(Type.usize); const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm(); @@ -11678,6 +11678,19 @@ pub const FuncGen = struct { , .constraints = "={r3},{r4},{r3},~{cc},~{memory}", }, + .riscv64 => .{ + .template = + \\ .option push + \\ .option norvc + \\ srli zero, zero, 3 + \\ srli zero, zero, 13 + \\ srli zero, zero, 51 + \\ srli zero, zero, 61 + \\ or a0, a0, a0 + \\ .option pop + , + .constraints = "={a3},{a4},{a3},~{cc},~{memory}", + }, .s390x => .{ .template = \\ lr %r15, %r15 diff --git a/src/target.zig b/src/target.zig index 4b0cc20bda..71a58369fc 100644 --- a/src/target.zig +++ b/src/target.zig @@ -84,7 +84,7 @@ pub fn defaultSingleThreaded(target: std.Target) bool { return false; } -pub fn hasValgrindSupport(target: std.Target) bool { +pub fn hasValgrindSupport(target: std.Target, backend: std.builtin.CompilerBackend) bool { // We can't currently output the necessary Valgrind client request assembly when using the C // backend and compiling with an MSVC-like compiler. const ofmt_c_msvc = (target.abi == .msvc or target.abi == .itanium) and target.ofmt == .c; @@ -103,7 +103,11 @@ pub fn hasValgrindSupport(target: std.Target) bool { else => false, }, .powerpc, .powerpcle, .powerpc64, .powerpc64le => switch (target.os.tag) { - .linux => true, + .linux => backend != .stage2_powerpc, // Insufficient inline assembly support in self-hosted. + else => false, + }, + .riscv64 => switch (target.os.tag) { + .linux => backend != .stage2_riscv64, // Insufficient inline assembly support in self-hosted. else => false, }, .s390x => switch (target.os.tag) {