From 4965d191806c9a28bffbb157228bf42270b0008e Mon Sep 17 00:00:00 2001
From: Khem Raj <raj.khem@gmail.com>
Date: Mon, 16 Nov 2020 11:03:31 -0800
Subject: [PATCH] perf: Alias SYS_futex with SYS_futex_time64 on 32-bit arches
 with 64bit time_t

glibc does not define SYS_futex for 32bit architectures using 64bit
time_t e.g. riscv32, therefore perf fails to compile as it does not find
SYS_futex in C library headers, define it to SYS_futex_time64 when it
exists

Upstream-Status: Pending
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 tools/perf/bench/futex.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tools/perf/bench/futex.h b/tools/perf/bench/futex.h
index 31b53cc7d5bc..33f3f3230ae1 100644
--- a/tools/perf/bench/futex.h
+++ b/tools/perf/bench/futex.h
@@ -13,6 +13,19 @@
 #include <sys/types.h>
 #include <linux/futex.h>
 
+/**
+ * SYS_futex is expected from system C library,
+ * in glibc (/usr/include/bits/syscall.h defines it in terms of of NR_futex)
+ * some newer 32bit architectures e.g. RISCV32 is using 64bit time_t from
+ * get go unlike other 32bit architectures in glibc, therefore it wont have
+ * NR_futex defined but just NR_futex_time64 this aliases it to NR_futex
+ * so that SYS_futex is then defined for rv32
+*/
+
+#if !defined(SYS_futex) && defined(SYS_futex_time64)
+#define SYS_futex SYS_futex_time64
+#endif
+
 /**
  * futex() - SYS_futex syscall wrapper
  * @uaddr:	address of first futex
-- 
2.29.2

