Skip to content

Commit 2add31b

Browse files
committed
valgrind: Add riscv64-linux support.
This appeared in Valgrind 3.25.0.
1 parent 100b76e commit 2add31b

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

lib/std/valgrind.zig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3:
6666
[_] "{r3}" (default),
6767
: "cc", "memory"
6868
),
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+
),
6983
.s390x => asm volatile (
7084
\\ lr %%r15, %%r15
7185
\\ lr %%r1, %%r1

src/Package/Module.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,10 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
113113
break :b options.global.root_strip;
114114
};
115115

116+
const zig_backend = target_util.zigBackend(target, options.global.use_llvm);
117+
116118
const valgrind = b: {
117-
if (!target_util.hasValgrindSupport(target)) {
119+
if (!target_util.hasValgrindSupport(target, zig_backend)) {
118120
if (options.inherited.valgrind == true)
119121
return error.ValgrindUnsupportedOnTarget;
120122
break :b false;
@@ -125,8 +127,6 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
125127
break :b optimize_mode == .Debug;
126128
};
127129

128-
const zig_backend = target_util.zigBackend(target, options.global.use_llvm);
129-
130130
const single_threaded = b: {
131131
if (target_util.alwaysSingleThreaded(target)) {
132132
if (options.inherited.single_threaded == false)

src/codegen/llvm.zig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11604,7 +11604,7 @@ pub const FuncGen = struct {
1160411604
const pt = o.pt;
1160511605
const zcu = pt.zcu;
1160611606
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

1160911609
const llvm_usize = try o.lowerType(Type.usize);
1161011610
const usize_alignment = Type.usize.abiAlignment(zcu).toLlvm();
@@ -11678,6 +11678,19 @@ pub const FuncGen = struct {
1167811678
,
1167911679
.constraints = "={r3},{r4},{r3},~{cc},~{memory}",
1168011680
},
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+
},
1168111694
.s390x => .{
1168211695
.template =
1168311696
\\ lr %r15, %r15

src/target.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub fn defaultSingleThreaded(target: std.Target) bool {
8484
return false;
8585
}
8686

87-
pub fn hasValgrindSupport(target: std.Target) bool {
87+
pub fn hasValgrindSupport(target: std.Target, backend: std.builtin.CompilerBackend) bool {
8888
// We can't currently output the necessary Valgrind client request assembly when using the C
8989
// backend and compiling with an MSVC-like compiler.
9090
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 {
103103
else => false,
104104
},
105105
.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.
107111
else => false,
108112
},
109113
.s390x => switch (target.os.tag) {

0 commit comments

Comments
 (0)