[1/2] Recognize EM_RISCV in e_machine_to_string

Message ID 20231229004051.540340-2-mark@klomp.org
State New
Headers
Series [1/2] Recognize EM_RISCV in e_machine_to_string |

Commit Message

Mark Wielaard Dec. 29, 2023, 12:40 a.m. UTC
  Check that EM_RISCV is defined in elf.h and if it is then recognize
it in e_machine_to_string, producing "elf-riscv".

	* configure.ac: Defining HAVE_EM_RISCV_MACRO if EM_RISCV
	is defined in elf.h.
	* src/abg-dwarf-reader.cc (e_machine_to_string): Handle
	EM_RISCV if HAVE_EM_RISCV_MACRO is defined.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 configure.ac           | 12 ++++++++++++
 src/abg-elf-helpers.cc |  5 +++++
 2 files changed, 17 insertions(+)
  

Patch

diff --git a/configure.ac b/configure.ac
index 65b738d8..788b5620 100644
--- a/configure.ac
+++ b/configure.ac
@@ -947,6 +947,18 @@  if test x$HAS_EM_TILEGX = xyes; then
             [Defined to 1 if elf.h has EM_TILEGX macro defined])
 fi
 
+HAS_EM_RISCV=no
+AC_CHECK_DECL([EM_RISCV],
+              [HAS_EM_RISCV=yes],
+              [HAS_EM_RISCV=no],
+              [[#include <elf.h>]])
+
+if test x$HAS_EM_RISCV = xyes; then
+  AC_DEFINE([HAVE_EM_RISCV_MACRO],
+                 1,
+            [Defined to 1 if elf.h has EM_RISCV macro defined])
+fi
+
 HAS_R_AARCH64_ABS64=no
 AC_CHECK_DECL([R_AARCH64_ABS64],
 	      [HAS_R_AARCH64_ABS64=yes],
diff --git a/src/abg-elf-helpers.cc b/src/abg-elf-helpers.cc
index e05dccdc..87feb905 100644
--- a/src/abg-elf-helpers.cc
+++ b/src/abg-elf-helpers.cc
@@ -287,6 +287,11 @@  e_machine_to_string(GElf_Half e_machine)
       return "elf-tilera-tilegx";
 #endif
 
+#ifdef HAVE_EM_RISCV_MACRO
+    case EM_RISCV:
+      return "elf-riscv";
+#endif
+
     case EM_NUM:
       return "elf-last-arch-number";
     case EM_ALPHA: