teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame rpm-4.13.x-rpmrc-Convert-uname.machine-riscv-to-riscv32-riscv64.patch

9c2066
From cf5679397f36710a942fcb83a63c690eb25d72af Mon Sep 17 00:00:00 2001
9c2066
From: "Richard W.M. Jones" <rjones@redhat.com>
9c2066
Date: Thu, 11 Aug 2016 11:38:18 +0100
9c2066
Subject: [PATCH 2/3] rpmrc: Convert uname.machine == "riscv" to
9c2066
 "riscv32"/"riscv64"/"riscv128".
9c2066
9c2066
On RISC-V, the kernel can return uname.machine == "riscv" (for all bit
9c2066
sizes).  I say "can" return, because that is the default, but it is
9c2066
also possible to compile the kernel specially so it returns "riscv64"
9c2066
etc.
9c2066
9c2066
GNU is using "riscv64".
9c2066
9c2066
This commit converts the kernel uname machine type "riscv" to a more
9c2066
suitable value.
9c2066
9c2066
This conversion is supposed to be done by the arch_canon table.
9c2066
However the arch_canon table is not populated until after the
9c2066
defaultMachine function is called for the first time, making it a bit
9c2066
useless.  In any case, arch_canon cannot take into account the bit
9c2066
size of the architecture, but the C code here can.
9c2066
9c2066
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
9c2066
---
9c2066
 lib/rpmrc.c | 11 +++++++++++
9c2066
 1 file changed, 11 insertions(+)
9c2066
9c2066
diff --git a/lib/rpmrc.c b/lib/rpmrc.c
9c2066
index f2e0f48..eb136d8 100644
9c2066
--- a/lib/rpmrc.c
9c2066
+++ b/lib/rpmrc.c
9c2066
@@ -1216,6 +1216,17 @@ static void defaultMachine(rpmrcCtx ctx, const char ** arch, const char ** os)
9c2066
 	}
9c2066
 #	endif	/* arm*-linux */
9c2066
 
9c2066
+#	if defined(__linux__) && defined(__riscv__)
9c2066
+	if (rstreq(un.machine, "riscv")) {
9c2066
+		if (sizeof(long) == 4)
9c2066
+			strcpy(un.machine, "riscv32");
9c2066
+		else if (sizeof(long) == 8)
9c2066
+			strcpy(un.machine, "riscv64");
9c2066
+		else if (sizeof(long) == 16)
9c2066
+			strcpy(un.machine, "riscv128");
9c2066
+	}
9c2066
+#	endif	/* riscv */
9c2066
+
9c2066
 #	if defined(__GNUC__) && defined(__alpha__)
9c2066
 	{
9c2066
 	    unsigned long amask, implver;
9c2066
-- 
9c2066
2.7.4
9c2066