authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-06-04 06:04:34+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-06-04 19:24:08+02:00
log2add31bfde7c261c433b61328a88953892fb1b41
tree99069fd702d097d5e319fda5608eaa5b16080068
parent100b76e17a7523edc04aa7fa97806c183c2b5a88

valgrind: Add riscv64-linux support.

This appeared in Valgrind 3.25.0.

4 files changed, 37 insertions(+), 6 deletions(-)

lib/std/valgrind.zig+14
...@@ -66,6 +66,20 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:...@@ -66,6 +66,20 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
66 [_] "{r3}" (default),66 [_] "{r3}" (default),
67 : "cc", "memory"67 : "cc", "memory"
68 ),68 ),
69 .riscv64 => asm volatile (
70 \\ .option push
71 \\ .option norvc
72 \\ srli zero, zero, 3
73 \\ srli zero, zero, 13
74 \\ srli zero, zero, 51
75 \\ srli zero, zero, 61
76 \\ or a0, a0, a0
77 \\ .option pop
78 : [_] "={a3}" (-> usize),
79 : [_] "{a4}" (args),
80 [_] "{a3}" (default),
81 : "cc", "memory"
82 ),
69 .s390x => asm volatile (83 .s390x => asm volatile (
70 \\ lr %%r15, %%r1584 \\ lr %%r15, %%r15
71 \\ lr %%r1, %%r185 \\ lr %%r1, %%r1
src/Package/Module.zig+3-3
...@@ -113,8 +113,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -113,8 +113,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
113 break :b options.global.root_strip;113 break :b options.global.root_strip;
114 };114 };
115115
116 const zig_backend = target_util.zigBackend(target, options.global.use_llvm);
117
116 const valgrind = b: {118 const valgrind = b: {
117 if (!target_util.hasValgrindSupport(target)) {119 if (!target_util.hasValgrindSupport(target, zig_backend)) {
118 if (options.inherited.valgrind == true)120 if (options.inherited.valgrind == true)
119 return error.ValgrindUnsupportedOnTarget;121 return error.ValgrindUnsupportedOnTarget;
120 break :b false;122 break :b false;
...@@ -125,8 +127,6 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -125,8 +127,6 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
125 break :b optimize_mode == .Debug;127 break :b optimize_mode == .Debug;
126 };128 };
127129
128 const zig_backend = target_util.zigBackend(target, options.global.use_llvm);
129
130 const single_threaded = b: {130 const single_threaded = b: {
131 if (target_util.alwaysSingleThreaded(target)) {131 if (target_util.alwaysSingleThreaded(target)) {
132 if (options.inherited.single_threaded == false)132 if (options.inherited.single_threaded == false)
src/codegen/llvm.zig+14-1
...@@ -11604,7 +11604,7 @@ pub const FuncGen = struct {...@@ -11604,7 +11604,7 @@ pub const FuncGen = struct {
11604 const pt = o.pt;11604 const pt = o.pt;
11605 const zcu = pt.zcu;11605 const zcu = pt.zcu;
11606 const target = zcu.getTarget();11606 const target = zcu.getTarget();
11607 if (!target_util.hasValgrindSupport(target)) return default_value;11607 if (!target_util.hasValgrindSupport(target, .stage2_llvm)) return default_value;
1160811608
11609 const llvm_usize = try o.lowerType(Type.usize);11609 const llvm_usize = try o.lowerType(Type.usize);
11610 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();11610 const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();
...@@ -11678,6 +11678,19 @@ pub const FuncGen = struct {...@@ -11678,6 +11678,19 @@ pub const FuncGen = struct {
11678 ,11678 ,
11679 .constraints = "={r3},{r4},{r3},~{cc},~{memory}",11679 .constraints = "={r3},{r4},{r3},~{cc},~{memory}",
11680 },11680 },
11681 .riscv64 => .{
11682 .template =
11683 \\ .option push
11684 \\ .option norvc
11685 \\ srli zero, zero, 3
11686 \\ srli zero, zero, 13
11687 \\ srli zero, zero, 51
11688 \\ srli zero, zero, 61
11689 \\ or a0, a0, a0
11690 \\ .option pop
11691 ,
11692 .constraints = "={a3},{a4},{a3},~{cc},~{memory}",
11693 },
11681 .s390x => .{11694 .s390x => .{
11682 .template =11695 .template =
11683 \\ lr %r15, %r1511696 \\ lr %r15, %r15
src/target.zig+6-2
...@@ -84,7 +84,7 @@ pub fn defaultSingleThreaded(target: std.Target) bool {...@@ -84,7 +84,7 @@ pub fn defaultSingleThreaded(target: std.Target) bool {
84 return false;84 return false;
85}85}
8686
87pub fn hasValgrindSupport(target: std.Target) bool {87pub fn hasValgrindSupport(target: std.Target, backend: std.builtin.CompilerBackend) bool {
88 // We can't currently output the necessary Valgrind client request assembly when using the C88 // We can't currently output the necessary Valgrind client request assembly when using the C
89 // backend and compiling with an MSVC-like compiler.89 // backend and compiling with an MSVC-like compiler.
90 const ofmt_c_msvc = (target.abi == .msvc or target.abi == .itanium) and target.ofmt == .c;90 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 {...@@ -103,7 +103,11 @@ pub fn hasValgrindSupport(target: std.Target) bool {
103 else => false,103 else => false,
104 },104 },
105 .powerpc, .powerpcle, .powerpc64, .powerpc64le => switch (target.os.tag) {105 .powerpc, .powerpcle, .powerpc64, .powerpc64le => switch (target.os.tag) {
106 .linux => true,106 .linux => backend != .stage2_powerpc, // Insufficient inline assembly support in self-hosted.
107 else => false,
108 },
109 .riscv64 => switch (target.os.tag) {
110 .linux => backend != .stage2_riscv64, // Insufficient inline assembly support in self-hosted.
107 else => false,111 else => false,
108 },112 },
109 .s390x => switch (target.os.tag) {113 .s390x => switch (target.os.tag) {