authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-13 14:03:11 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-13 14:03:11 -07:00
log12e0765577d2e0d4c26267f3b8fd781aed84d365
treee6f8ac8251de4799f09399a39a111caee6edc029
parente5f2387fe6d71d4c0a965348125e9e612680decd
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

fix a commit from the linux kernel


3 files changed, 254 insertions(+), 30 deletions(-)

git.zig+39-29
...@@ -6,8 +6,7 @@ const extras = @import("extras");...@@ -6,8 +6,7 @@ const extras = @import("extras");
6const tracer = @import("tracer");6const tracer = @import("tracer");
7const nfs = @import("nfs");7const nfs = @import("nfs");
88
9// 40 is length of sha1 hash9pub const Id = []const u8;
10pub const Id = *const [40]u8;
1110
12pub const TreeId = struct {11pub const TreeId = struct {
13 id: Id,12 id: Id,
...@@ -96,9 +95,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId {...@@ -96,9 +95,10 @@ pub fn getHEAD(alloc: std.mem.Allocator, dir: nfs.Dir) !?CommitId {
96 return ensureObjId(CommitId, h);95 return ensureObjId(CommitId, h);
97}96}
9897
98// 40 is length of sha1 hash
99pub fn ensureObjId(comptime T: type, input: string) T {99pub fn ensureObjId(comptime T: type, input: string) T {
100 extras.assertLog(input.len == 40, "ensureObjId: {s}", .{input});100 extras.assertLog(input.len == 40, "ensureObjId: {s}", .{input});
101 return .{ .id = input[0..40] };101 return .{ .id = input };
102}102}
103103
104// TODO make this inspect .git/objects104// TODO make this inspect .git/objects
...@@ -450,7 +450,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p...@@ -450,7 +450,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p
450 .cwd_dir = dir.to_std(),450 .cwd_dir = dir.to_std(),
451 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1451 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
452 // result of `printf | git hash-object -t tree --stdin`452 // result of `printf | git hash-object -t tree --stdin`
453 .argv = &.{ "git", "diff-tree", "-p", "--raw", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id },453 .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id },
454 .max_output_bytes = 1024 * 1024 * 1024,454 .max_output_bytes = 1024 * 1024 * 1024,
455 });455 });
456 std.debug.assert(result.term == .Exited and result.term.Exited == 0);456 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
...@@ -459,7 +459,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p...@@ -459,7 +459,7 @@ pub fn getTreeDiff(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitId, p
459 const result = try std.process.Child.run(.{459 const result = try std.process.Child.run(.{
460 .allocator = alloc,460 .allocator = alloc,
461 .cwd_dir = dir.to_std(),461 .cwd_dir = dir.to_std(),
462 .argv = &.{ "git", "diff-tree", "-p", "--raw", parentid.?.id, commitid.id },462 .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", parentid.?.id, commitid.id },
463 .max_output_bytes = 1024 * 1024 * 1024,463 .max_output_bytes = 1024 * 1024 * 1024,
464 });464 });
465 std.debug.assert(result.term == .Exited and result.term.Exited == 0);465 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
...@@ -478,7 +478,7 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI...@@ -478,7 +478,7 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI
478 .cwd_dir = dir.to_std(),478 .cwd_dir = dir.to_std(),
479 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1479 // 4b825dc642cb6eb9a060e54bf8d69288fbee4904 is a hardcode for the empty tree in git sha1
480 // result of `printf | git hash-object -t tree --stdin`480 // result of `printf | git hash-object -t tree --stdin`
481 .argv = &.{ "git", "diff-tree", "-p", "--raw", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id, "--", path },481 .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", "4b825dc642cb6eb9a060e54bf8d69288fbee4904", commitid.id, "--", path },
482 .max_output_bytes = 1024 * 1024 * 1024,482 .max_output_bytes = 1024 * 1024 * 1024,
483 });483 });
484 std.debug.assert(result.term == .Exited and result.term.Exited == 0);484 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
...@@ -487,7 +487,7 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI...@@ -487,7 +487,7 @@ pub fn getTreeDiffPath(alloc: std.mem.Allocator, dir: nfs.Dir, commitid: CommitI
487 const result = try std.process.Child.run(.{487 const result = try std.process.Child.run(.{
488 .allocator = alloc,488 .allocator = alloc,
489 .cwd_dir = dir.to_std(),489 .cwd_dir = dir.to_std(),
490 .argv = &.{ "git", "diff-tree", "-p", "--raw", parentid.?.id, commitid.id, "--", path },490 .argv = &.{ "git", "diff-tree", "-p", "--raw", "--full-index", parentid.?.id, commitid.id, "--", path },
491 .max_output_bytes = 1024 * 1024 * 1024,491 .max_output_bytes = 1024 * 1024 * 1024,
492 });492 });
493 std.debug.assert(result.term == .Exited and result.term.Exited == 0);493 std.debug.assert(result.term == .Exited and result.term.Exited == 0);
...@@ -602,22 +602,9 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -602,22 +602,9 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
602 },602 },
603 .action = std.meta.stringToEnum(TreeDiff.Action, action_s).?,603 .action = std.meta.stringToEnum(TreeDiff.Action, action_s).?,
604 .sub_path = kter.rest(),604 .sub_path = kter.rest(),
605 .adds = 0,
606 .subs = 0,
607 });605 });
608 }606 }
609607
610 const S = struct {
611 fn eql(comptime a: u8) fn (u8) bool {
612 const SS = struct {
613 fn actual(b: u8) bool {
614 return a == b;
615 }
616 };
617 return SS.actual;
618 }
619 };
620
621 // diff --git a/notes/all_packages.txt b/notes/all_packages.txt608 // diff --git a/notes/all_packages.txt b/notes/all_packages.txt
622 // index c06b41d..e8f91cf 100644609 // index c06b41d..e8f91cf 100644
623 // --- a/notes/all_packages.txt610 // --- a/notes/all_packages.txt
...@@ -630,10 +617,17 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -630,10 +617,17 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
630 blk: while (true) {617 blk: while (true) {
631 const first_line = lineiter.next().?;618 const first_line = lineiter.next().?;
632 std.debug.assert(std.mem.startsWith(u8, first_line, "diff --git"));619 std.debug.assert(std.mem.startsWith(u8, first_line, "diff --git"));
633 const i = diffs.items.len;620 var i = diffs.items.len;
634 try diffs.append(.{ .before_path = overview.items[i].sub_path, .after_path = overview.items[i].sub_path, .content = "" });621 for (overview.items[0..i]) |o| i -= @intFromBool(o.action == .T);
635 if (extras.matchesAll(u8, overview.items[i].before.blob.id, S.eql('0'))) diffs.items[i].before_path = "/dev/null";622 try diffs.append(.{
636 if (extras.matchesAll(u8, overview.items[i].after.blob.id, S.eql('0'))) diffs.items[i].after_path = "/dev/null";623 .index = .{ "", "" },
624 .before_path = overview.items[i].sub_path,
625 .after_path = overview.items[i].sub_path,
626 .subs = 0,
627 .adds = 0,
628 .content = "",
629 });
630 const diff = &diffs.items[diffs.items.len - 1];
637631
638 while (true) {632 while (true) {
639 if (lineiter.index.? >= input.len) {633 if (lineiter.index.? >= input.len) {
...@@ -641,6 +635,13 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -641,6 +635,13 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
641 }635 }
642 if (lineiter.peek()) |lin| {636 if (lineiter.peek()) |lin| {
643 if (std.mem.startsWith(u8, lin, "index")) {637 if (std.mem.startsWith(u8, lin, "index")) {
638 const index = lin[6..];
639 var iiter = std.mem.splitSequence(u8, index, "..");
640 diff.index[0] = iiter.next().?;
641 diff.index[1] = iiter.next().?;
642 std.debug.assert(iiter.next() == null);
643 if (std.mem.indexOfScalar(u8, diff.index[1], ' ')) |j| diff.index[1] = diff.index[1][0..j];
644
644 lineiter.index.? += lin.len + 1;645 lineiter.index.? += lin.len + 1;
645 break;646 break;
646 }647 }
...@@ -676,10 +677,12 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -676,10 +677,12 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
676 }677 }
677 if (lineiter.peek()) |lin| {678 if (lineiter.peek()) |lin| {
678 if (std.mem.startsWith(u8, lin, "--- ")) {679 if (std.mem.startsWith(u8, lin, "--- ")) {
680 diff.before_path = extras.trimPrefix(lin[4..], "a/");
679 lineiter.index.? += lin.len + 1;681 lineiter.index.? += lin.len + 1;
680 continue;682 continue;
681 }683 }
682 if (std.mem.startsWith(u8, lin, "+++ ")) {684 if (std.mem.startsWith(u8, lin, "+++ ")) {
685 diff.after_path = extras.trimPrefix(lin[4..], "b/");
683 lineiter.index.? += lin.len + 1;686 lineiter.index.? += lin.len + 1;
684 continue;687 continue;
685 }688 }
...@@ -701,7 +704,7 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -701,7 +704,7 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
701 }704 }
702 }705 }
703 if (lineiter.index.? >= input.len) {706 if (lineiter.index.? >= input.len) {
704 diffs.items[diffs.items.len - 1].content = input[content_start..];707 diff.content = input[content_start..];
705 break :blk;708 break :blk;
706 }709 }
707710
...@@ -709,13 +712,19 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {...@@ -709,13 +712,19 @@ pub fn parseTreeDiff(alloc: std.mem.Allocator, input: string) !TreeDiff {
709 if (lineiter.peek()) |lin| {712 if (lineiter.peek()) |lin| {
710 if (std.mem.startsWith(u8, lin, "diff --git")) {713 if (std.mem.startsWith(u8, lin, "diff --git")) {
711 const content_end = lineiter.index.? - 1;714 const content_end = lineiter.index.? - 1;
712 diffs.items[diffs.items.len - 1].content = input[content_start..content_end];715 diff.content = input[content_start..content_end];
713 continue :blk;716 continue :blk;
714 }717 }
718 if (lin[0] == '-') {
719 diff.subs += 1;
720 }
721 if (lin[0] == '+') {
722 diff.adds += 1;
723 }
715 lineiter.index.? += lin.len + 1;724 lineiter.index.? += lin.len + 1;
716725
717 if (lineiter.index.? >= input.len) {726 if (lineiter.index.? >= input.len) {
718 diffs.items[diffs.items.len - 1].content = input[content_start..];727 diff.content = input[content_start..];
719 break :blk;728 break :blk;
720 }729 }
721 }730 }
...@@ -737,8 +746,6 @@ pub const TreeDiff = struct {...@@ -737,8 +746,6 @@ pub const TreeDiff = struct {
737 after: State,746 after: State,
738 action: Action,747 action: Action,
739 sub_path: string,748 sub_path: string,
740 adds: u32,
741 subs: u32,
742 };749 };
743750
744 pub const State = struct {751 pub const State = struct {
...@@ -764,8 +771,11 @@ pub const TreeDiff = struct {...@@ -764,8 +771,11 @@ pub const TreeDiff = struct {
764 };771 };
765772
766 pub const Diff = struct {773 pub const Diff = struct {
774 index: [2][]const u8,
767 before_path: string,775 before_path: string,
768 after_path: string,776 after_path: string,
777 adds: u32,
778 subs: u32,
769 content: string,779 content: string,
770 };780 };
771};781};
test.zig+7-1
...@@ -145,7 +145,7 @@ test {...@@ -145,7 +145,7 @@ test {
145 ":100644 100644 73c7032166db0eb23c4be11a4ff8ff26ec47c582 b229eadbd5d6655c2dfbaca5a5f68f2f8f3c5454 M\tgit.zig\n" ++145 ":100644 100644 73c7032166db0eb23c4be11a4ff8ff26ec47c582 b229eadbd5d6655c2dfbaca5a5f68f2f8f3c5454 M\tgit.zig\n" ++
146 "\n" ++146 "\n" ++
147 "diff --git a/git.zig b/git.zig\n" ++147 "diff --git a/git.zig b/git.zig\n" ++
148 "index 73c7032..b229ead 100644\n" ++148 "index 73c7032166db0eb23c4be11a4ff8ff26ec47c582..b229eadbd5d6655c2dfbaca5a5f68f2f8f3c5454 100644\n" ++
149 "--- a/git.zig\n" ++149 "--- a/git.zig\n" ++
150 "+++ b/git.zig\n" ++150 "+++ b/git.zig\n" ++
151 "@@ -251,10 +251,10 @@ pub fn parseTree(alloc: std.mem.Allocator, treefile: string) !Tree {\n" ++151 "@@ -251,10 +251,10 @@ pub fn parseTree(alloc: std.mem.Allocator, treefile: string) !Tree {\n" ++
...@@ -250,3 +250,9 @@ test {...@@ -250,3 +250,9 @@ test {
250 const alloc = arena.allocator();250 const alloc = arena.allocator();
251 _ = try git.parseTreeDiff(alloc, @embedFile("./testdata/diff-1f7390f3999e80f775dbc0e62f1dcb071c3bed77")); // zig251 _ = try git.parseTreeDiff(alloc, @embedFile("./testdata/diff-1f7390f3999e80f775dbc0e62f1dcb071c3bed77")); // zig
252}252}
253test {
254 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
255 defer arena.deinit();
256 const alloc = arena.allocator();
257 _ = try git.parseTreeDiff(alloc, @embedFile("./testdata/diff-a0482e3446cea426bf16571e0000423ed5b25af0")); // linux
258}
testdata/diff-a0482e3446cea426bf16571e0000423ed5b25af0 created+208
...@@ -0,0 +1,208 @@
1:100644 100644 12a0614b9fd4983deffe5d6a7cfa06ba8d92a516 918a2caa070ebc681a9525f0518afffcf10f5ae3 M tools/testing/selftests/vDSO/Makefile
2:100644 100644 722260f9756198956f0dfccced907284b6851e76 5fdd0f36233742bc47ae79f23d2cfae5a0f56dee M tools/testing/selftests/vDSO/vdso_config.h
3:100644 120000 9ce795b806f0992b83cef78c7e16fac0e54750da 4d3d96f1e440c965474681a6f35375a60b3921be T tools/testing/selftests/vDSO/vdso_standalone_test_x86.c
4:100644 100644 8757f738b0b1a76a48c83c5e5df79925a30c1bc7 0aad682b12c8836efabb49a65a47cf87466891a3 M tools/testing/selftests/vDSO/vdso_test_chacha.c
5:100644 100644 38d46a8bf7cba7a9b4a9b13b5eb17aa207972bd0 b5d5f59f725a703c357dfca91bfe170aaaeb42fa M tools/testing/selftests/vDSO/vdso_test_clock_getres.c
6:100644 100644 5fb97ad67eeaf17b6cfa4f82783c57894f03e5c5 da651cf53c6ca4242085de109c7fc57bd807297c M tools/testing/selftests/vDSO/vdso_test_correctness.c
7:100644 100644 95057f7567db22226d9cb09a667a56e387a33a46 dd1132508a0db29a32ec977b30f64b20aa43e03d M tools/testing/selftests/vDSO/vdso_test_getrandom.c
8
9diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile
10index 12a0614b9fd4..918a2caa070e 100644
11--- a/tools/testing/selftests/vDSO/Makefile
12+++ b/tools/testing/selftests/vDSO/Makefile
13@@ -12,7 +12,7 @@ TEST_GEN_PROGS += vdso_test_correctness
14 TEST_GEN_PROGS += vdso_test_getrandom
15 TEST_GEN_PROGS += vdso_test_chacha
16
17-CFLAGS := -std=gnu99 -O2
18+CFLAGS := -std=gnu99 -O2 -Wall -Wstrict-prototypes
19
20 ifeq ($(CONFIG_X86_32),y)
21 LDLIBS += -lgcc_s
22diff --git a/tools/testing/selftests/vDSO/vdso_config.h b/tools/testing/selftests/vDSO/vdso_config.h
23index 722260f97561..5fdd0f362337 100644
24--- a/tools/testing/selftests/vDSO/vdso_config.h
25+++ b/tools/testing/selftests/vDSO/vdso_config.h
26@@ -58,6 +58,7 @@
27 #define VDSO_NAMES 1
28 #endif
29
30+__attribute__((unused))
31 static const char *versions[7] = {
32 "LINUX_2.6",
33 "LINUX_2.6.15",
34@@ -68,6 +69,7 @@ static const char *versions[7] = {
35 "LINUX_5.10"
36 };
37
38+__attribute__((unused))
39 static const char *names[2][7] = {
40 {
41 "__kernel_gettimeofday",
42diff --git a/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c b/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c
43deleted file mode 100644
44index 9ce795b806f0..000000000000
45--- a/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c
46+++ /dev/null
47@@ -1,58 +0,0 @@
48-// SPDX-License-Identifier: GPL-2.0-only
49-/*
50- * vdso_test_gettimeofday.c: Sample code to test parse_vdso.c and
51- * vDSO gettimeofday()
52- * Copyright (c) 2014 Andy Lutomirski
53- *
54- * Compile with:
55- * gcc -std=gnu99 vdso_test_gettimeofday.c parse_vdso_gettimeofday.c
56- *
57- * Tested on x86, 32-bit and 64-bit. It may work on other architectures, too.
58- */
59-
60-#include <stdio.h>
61-#ifndef NOLIBC
62-#include <sys/auxv.h>
63-#include <sys/time.h>
64-#endif
65-
66-#include "../kselftest.h"
67-#include "parse_vdso.h"
68-#include "vdso_config.h"
69-#include "vdso_call.h"
70-
71-int main(int argc, char **argv)
72-{
73- const char *version = versions[VDSO_VERSION];
74- const char **name = (const char **)&names[VDSO_NAMES];
75-
76- unsigned long sysinfo_ehdr = getauxval(AT_SYSINFO_EHDR);
77- if (!sysinfo_ehdr) {
78- printf("AT_SYSINFO_EHDR is not present!\n");
79- return KSFT_SKIP;
80- }
81-
82- vdso_init_from_sysinfo_ehdr(getauxval(AT_SYSINFO_EHDR));
83-
84- /* Find gettimeofday. */
85- typedef long (*gtod_t)(struct timeval *tv, struct timezone *tz);
86- gtod_t gtod = (gtod_t)vdso_sym(version, name[0]);
87-
88- if (!gtod) {
89- printf("Could not find %s\n", name[0]);
90- return KSFT_SKIP;
91- }
92-
93- struct timeval tv;
94- long ret = VDSO_CALL(gtod, 2, &tv, 0);
95-
96- if (ret == 0) {
97- printf("The time is %lld.%06lld\n",
98- (long long)tv.tv_sec, (long long)tv.tv_usec);
99- } else {
100- printf("%s failed\n", name[0]);
101- return KSFT_FAIL;
102- }
103-
104- return 0;
105-}
106diff --git a/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c b/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c
107new file mode 120000
108index 000000000000..4d3d96f1e440
109--- /dev/null
110+++ b/tools/testing/selftests/vDSO/vdso_standalone_test_x86.c
111@@ -0,0 +1 @@
112+vdso_test_gettimeofday.c
113\ No newline at end of file
114diff --git a/tools/testing/selftests/vDSO/vdso_test_chacha.c b/tools/testing/selftests/vDSO/vdso_test_chacha.c
115index 8757f738b0b1..0aad682b12c8 100644
116--- a/tools/testing/selftests/vDSO/vdso_test_chacha.c
117+++ b/tools/testing/selftests/vDSO/vdso_test_chacha.c
118@@ -76,7 +76,8 @@ static void reference_chacha20_blocks(uint8_t *dst_bytes, const uint32_t *key, u
119
120 void __weak __arch_chacha20_blocks_nostack(uint8_t *dst_bytes, const uint32_t *key, uint32_t *counter, size_t nblocks)
121 {
122- ksft_exit_skip("Not implemented on architecture\n");
123+ ksft_test_result_skip("Not implemented on architecture\n");
124+ ksft_finished();
125 }
126
127 int main(int argc, char *argv[])
128diff --git a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
129index 38d46a8bf7cb..b5d5f59f725a 100644
130--- a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
131+++ b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
132@@ -13,7 +13,6 @@
133
134 #define _GNU_SOURCE
135 #include <elf.h>
136-#include <err.h>
137 #include <fcntl.h>
138 #include <stdint.h>
139 #include <stdio.h>
140diff --git a/tools/testing/selftests/vDSO/vdso_test_correctness.c b/tools/testing/selftests/vDSO/vdso_test_correctness.c
141index 5fb97ad67eea..da651cf53c6c 100644
142--- a/tools/testing/selftests/vDSO/vdso_test_correctness.c
143+++ b/tools/testing/selftests/vDSO/vdso_test_correctness.c
144@@ -108,7 +108,7 @@ static void *vsyscall_getcpu(void)
145 }
146
147
148-static void fill_function_pointers()
149+static void fill_function_pointers(void)
150 {
151 void *vdso = dlopen("linux-vdso.so.1",
152 RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD);
153diff --git a/tools/testing/selftests/vDSO/vdso_test_getrandom.c b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
154index 95057f7567db..dd1132508a0d 100644
155--- a/tools/testing/selftests/vDSO/vdso_test_getrandom.c
156+++ b/tools/testing/selftests/vDSO/vdso_test_getrandom.c
157@@ -21,7 +21,6 @@
158 #include <sys/wait.h>
159 #include <sys/types.h>
160 #include <linux/random.h>
161-#include <linux/compiler.h>
162 #include <linux/ptrace.h>
163
164 #include "../kselftest.h"
165@@ -101,6 +100,7 @@ static void *vgetrandom_get_state(void)
166 return state;
167 }
168
169+__attribute__((unused)) /* Example for libc implementors */
170 static void vgetrandom_put_state(void *state)
171 {
172 if (!state)
173@@ -242,6 +242,7 @@ static void kselftest(void)
174 pid_t child;
175
176 ksft_print_header();
177+ vgetrandom_init();
178 ksft_set_plan(2);
179
180 for (size_t i = 0; i < 1000; ++i) {
181@@ -265,7 +266,7 @@ static void kselftest(void)
182 }
183 for (;;) {
184 struct ptrace_syscall_info info = { 0 };
185- int status, ret;
186+ int status;
187 ksft_assert(waitpid(child, &status, 0) >= 0);
188 if (WIFEXITED(status)) {
189 ksft_assert(WEXITSTATUS(status) == 0);
190@@ -295,8 +296,6 @@ static void usage(const char *argv0)
191
192 int main(int argc, char *argv[])
193 {
194- vgetrandom_init();
195-
196 if (argc == 1) {
197 kselftest();
198 return 0;
199@@ -306,6 +305,9 @@ int main(int argc, char *argv[])
200 usage(argv[0]);
201 return 1;
202 }
203+
204+ vgetrandom_init();
205+
206 if (!strcmp(argv[1], "bench-single"))
207 bench_single();
208 else if (!strcmp(argv[1], "bench-multi"))