This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] libdwelf: Add dwelf_elf_e_machine_string and use it in readelf.


To print eh human readable description of the ELF e_machine header field
we used the ebl name. But this is not set for most EM constants. Introduce
a new function dwelf_elf_e_machine_string that does work for all known
EM values. Use that in eu-readelf to print a string representation of the
e_machine value.

Since this was the only usage of ebl->name, remove that from struct ebl.

Also add a testcase that makes sure dwelf_elf_e_machine_string works for
all EM values in the libelf/elf.h header so we will immediately notice
when a new value appears.

Signed-off-by: Mark Wielaard <mark@klomp.org>
---
 backends/ChangeLog                      |  18 ++
 backends/aarch64_init.c                 |   1 -
 backends/alpha_init.c                   |   1 -
 backends/arm_init.c                     |   1 -
 backends/bpf_init.c                     |   1 -
 backends/i386_init.c                    |   1 -
 backends/ia64_init.c                    |   1 -
 backends/m68k_init.c                    |   1 -
 backends/ppc64_init.c                   |   1 -
 backends/ppc_init.c                     |   1 -
 backends/riscv_init.c                   |   1 -
 backends/s390_init.c                    |   1 -
 backends/sh_init.c                      |   1 -
 backends/sparc_init.c                   |   6 -
 backends/tilegx_init.c                  |   1 -
 backends/x86_64_init.c                  |   1 -
 libdw/ChangeLog                         |   5 +
 libdw/libdw.map                         |   7 +-
 libdwelf/ChangeLog                      |   6 +
 libdwelf/Makefile.am                    |   3 +-
 libdwelf/dwelf_elf_e_machine_string.c   | 406 ++++++++++++++++++++++++++++++++
 libdwelf/libdwelf.h                     |   4 +
 libebl/ChangeLog                        |   6 +
 libebl/eblopenbackend.c                 |   3 -
 libebl/libeblP.h                        |   3 -
 src/ChangeLog                           |   5 +
 src/readelf.c                           |   7 +-
 tests/ChangeLog                         |   9 +
 tests/Makefile.am                       |  11 +-
 tests/dwelf_elf_e_machine_string.c      |  64 +++++
 tests/run-dwelf_elf_e_machine_string.sh |  31 +++
 31 files changed, 576 insertions(+), 32 deletions(-)
 create mode 100644 libdwelf/dwelf_elf_e_machine_string.c
 create mode 100644 tests/dwelf_elf_e_machine_string.c
 create mode 100755 tests/run-dwelf_elf_e_machine_string.sh

diff --git a/backends/ChangeLog b/backends/ChangeLog
index 6c2b47a..af1a40e 100644
--- a/backends/ChangeLog
+++ b/backends/ChangeLog
@@ -1,3 +1,21 @@
+2019-06-28  Mark Wielaard  <mark@klomp.org>
+
+	* aarch64_init.c (aarch64_init.c): Remove eh->name;
+	* alpha_init.c (alpha_init.c): Remove eh->name;
+	* arm_init.c (arm_init.c): Remove eh->name;
+	* bpf_init.c (bpf_init.c): Remove eh->name;
+	* i386_init.c (i386_init.c): Remove eh->name;
+	* ia64_init.c (ia64_init.c): Remove eh->name;
+	* m68k_init.c (m68k_init.c): Remove eh->name;
+	* ppc64_init.c (ppc64_init.c): Remove eh->name;
+	* ppc_init.c (ppc_init.c): Remove eh->name;
+	* riscv_init.c (riscv_init.c): Remove eh->name;
+	* s390_init.c (s390_init.c): Remove eh->name;
+	* sh_init.c (sh_init.c): Remove eh->name;
+	* sparc_init.c (sparc_init.c): Remove eh->name;
+	* tilegx_init.c (tilegx_init.c): Remove eh->name;
+	* x86_64_init.c (x86_64_init.c): Remove eh->name;
+
 2019-04-14  Mark Wielaard  <mark@klomp.org>
 
 	* riscv_cfi.c: Fix BACKEND define.
diff --git a/backends/aarch64_init.c b/backends/aarch64_init.c
index fad923f..95268ae 100644
--- a/backends/aarch64_init.c
+++ b/backends/aarch64_init.c
@@ -49,7 +49,6 @@ aarch64_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "AARCH64";
   aarch64_init_reloc (eh);
   HOOK (eh, register_info);
   HOOK (eh, core_note);
diff --git a/backends/alpha_init.c b/backends/alpha_init.c
index 25c5b32..f66f40c 100644
--- a/backends/alpha_init.c
+++ b/backends/alpha_init.c
@@ -50,7 +50,6 @@ alpha_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "Alpha";
   alpha_init_reloc (eh);
   HOOK (eh, dynamic_tag_name);
   HOOK (eh, dynamic_tag_check);
diff --git a/backends/arm_init.c b/backends/arm_init.c
index f2b1b11..af023f0 100644
--- a/backends/arm_init.c
+++ b/backends/arm_init.c
@@ -50,7 +50,6 @@ arm_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "ARM";
   arm_init_reloc (eh);
   HOOK (eh, segment_type_name);
   HOOK (eh, section_type_name);
diff --git a/backends/bpf_init.c b/backends/bpf_init.c
index a046e06..d407d37 100644
--- a/backends/bpf_init.c
+++ b/backends/bpf_init.c
@@ -49,7 +49,6 @@ bpf_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "BPF";
   bpf_init_reloc (eh);
   HOOK (eh, register_info);
   HOOK (eh, disasm);
diff --git a/backends/i386_init.c b/backends/i386_init.c
index fc1587a..67428b5 100644
--- a/backends/i386_init.c
+++ b/backends/i386_init.c
@@ -49,7 +49,6 @@ i386_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "Intel 80386";
   i386_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, gotpc_reloc_check);
diff --git a/backends/ia64_init.c b/backends/ia64_init.c
index 7241d7b..2d1f43f 100644
--- a/backends/ia64_init.c
+++ b/backends/ia64_init.c
@@ -49,7 +49,6 @@ ia64_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "Intel IA-64";
   ia64_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, segment_type_name);
diff --git a/backends/m68k_init.c b/backends/m68k_init.c
index 8cae710..05d544c 100644
--- a/backends/m68k_init.c
+++ b/backends/m68k_init.c
@@ -48,7 +48,6 @@ m68k_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "M68K";
   m68k_init_reloc (eh);
   HOOK (eh, gotpc_reloc_check);
   HOOK (eh, reloc_simple_type);
diff --git a/backends/ppc64_init.c b/backends/ppc64_init.c
index 3db5e76..c2e7043 100644
--- a/backends/ppc64_init.c
+++ b/backends/ppc64_init.c
@@ -52,7 +52,6 @@ ppc64_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "PowerPC 64-bit";
   ppc64_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, dynamic_tag_name);
diff --git a/backends/ppc_init.c b/backends/ppc_init.c
index aea9f2d..eb286c2 100644
--- a/backends/ppc_init.c
+++ b/backends/ppc_init.c
@@ -50,7 +50,6 @@ ppc_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "PowerPC";
   ppc_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, machine_flag_check);
diff --git a/backends/riscv_init.c b/backends/riscv_init.c
index 3398c10..9aaec9c 100644
--- a/backends/riscv_init.c
+++ b/backends/riscv_init.c
@@ -54,7 +54,6 @@ riscv_init (Elf *elf,
     return NULL;
 
   /* We handle it.  */
-  eh->name = "RISC-V";
   riscv_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, register_info);
diff --git a/backends/s390_init.c b/backends/s390_init.c
index 0004aee..b4f3e7f 100644
--- a/backends/s390_init.c
+++ b/backends/s390_init.c
@@ -51,7 +51,6 @@ s390_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "IBM S/390";
   s390_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, check_special_symbol);
diff --git a/backends/sh_init.c b/backends/sh_init.c
index 5526aca..24f4d4a 100644
--- a/backends/sh_init.c
+++ b/backends/sh_init.c
@@ -50,7 +50,6 @@ sh_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "Hitachi SH";
   sh_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, gotpc_reloc_check);
diff --git a/backends/sparc_init.c b/backends/sparc_init.c
index 8e946fb..6daff11 100644
--- a/backends/sparc_init.c
+++ b/backends/sparc_init.c
@@ -55,12 +55,6 @@ sparc_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  if (machine == EM_SPARCV9)
-    eh->name = "SPARC v9";
-  else if (machine == EM_SPARC32PLUS)
-    eh->name = "SPARC v8+";
-  else
-    eh->name = "SPARC";
   sparc_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, machine_flag_check);
diff --git a/backends/tilegx_init.c b/backends/tilegx_init.c
index 162ed36..66df931 100644
--- a/backends/tilegx_init.c
+++ b/backends/tilegx_init.c
@@ -48,7 +48,6 @@ tilegx_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "TILE-Gx";
   tilegx_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, return_value_location);
diff --git a/backends/x86_64_init.c b/backends/x86_64_init.c
index 49f6c6c..8abafb7 100644
--- a/backends/x86_64_init.c
+++ b/backends/x86_64_init.c
@@ -52,7 +52,6 @@ x86_64_init (Elf *elf __attribute__ ((unused)),
     return NULL;
 
   /* We handle it.  */
-  eh->name = "AMD x86-64";
   x86_64_init_reloc (eh);
   HOOK (eh, reloc_simple_type);
   HOOK (eh, section_type_name);
diff --git a/libdw/ChangeLog b/libdw/ChangeLog
index 4760f9d..6b779e7 100644
--- a/libdw/ChangeLog
+++ b/libdw/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-28  Mark Wielaard  <mark@klomp.org>
+
+	* libdw.map (ELFUTILS_0.177): New section. Add
+	dwelf_elf_e_machine_string.
+
 2019-05-16  Mark Wielaard  <mark@klomp.org>
 
 	* dwarf.h: Add DW_AT_GNU_numerator, DW_AT_GNU_denominator and
diff --git a/libdw/libdw.map b/libdw/libdw.map
index 55482d5..2e1c0e9 100644
--- a/libdw/libdw.map
+++ b/libdw/libdw.map
@@ -360,4 +360,9 @@ ELFUTILS_0.173 {
 ELFUTILS_0.175 {
   global:
     dwelf_elf_begin;
-} ELFUTILS_0.173;
\ No newline at end of file
+} ELFUTILS_0.173;
+
+ELFUTILS_0.177 {
+  global:
+    dwelf_elf_e_machine_string;
+} ELFUTILS_0.175;
diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
index 88be342..29f9a50 100644
--- a/libdwelf/ChangeLog
+++ b/libdwelf/ChangeLog
@@ -1,3 +1,9 @@
+2019-06-28  Mark Wielaard  <mark@klomp.org>
+
+	* Makefile.am (libdwelf_a_SOURCES): Add dwelf_elf_e_machine_string.c.
+	* libdwelf.h (dwelf_elf_e_machine_string): Define new function.
+	* dwelf_elf_e_machine_string.c: New file.
+
 2018-10-21  Mark Wielaard  <mark@klomp.org>
 
 	* libdwelf.h (dwelf_elf_begin): Add function declaration.
diff --git a/libdwelf/Makefile.am b/libdwelf/Makefile.am
index a7933fd..a35a287 100644
--- a/libdwelf/Makefile.am
+++ b/libdwelf/Makefile.am
@@ -41,7 +41,8 @@ noinst_HEADERS = libdwelfP.h
 
 libdwelf_a_SOURCES = dwelf_elf_gnu_debuglink.c dwelf_dwarf_gnu_debugaltlink.c \
 		     dwelf_elf_gnu_build_id.c dwelf_scn_gnu_compressed_size.c \
-		     dwelf_strtab.c dwelf_elf_begin.c
+		     dwelf_strtab.c dwelf_elf_begin.c \
+		     dwelf_elf_e_machine_string.c
 
 libdwelf = $(libdw)
 
diff --git a/libdwelf/dwelf_elf_e_machine_string.c b/libdwelf/dwelf_elf_e_machine_string.c
new file mode 100644
index 0000000..de07b01
--- /dev/null
+++ b/libdwelf/dwelf_elf_e_machine_string.c
@@ -0,0 +1,406 @@
+/* Returns a human readable description of an ELF header e_machine value.
+   Copyright (C) 2019 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "libdwelf.h"
+
+
+const char *
+dwelf_elf_e_machine_string (int machine)
+{
+  switch (machine)
+    {
+    case EM_NONE:
+      return "None";
+    case EM_M32:
+      return "WE32100";
+    case EM_SPARC:
+      return "SPARC";
+    case EM_386:
+      return "Intel 80386";
+    case EM_68K:
+      return "M68K";
+    case EM_88K:
+      return "M88K";
+    case EM_IAMCU:
+      return "Intel MCU";
+    case EM_860:
+      return "Intel 80860";
+    case EM_MIPS:
+      return "MIPS R3000";
+    case EM_S370:
+      return "IBM System/370";
+    case EM_MIPS_RS3_LE:
+      return "MIPS R3000";
+    case EM_PARISC:
+      return "HPPA";
+    case EM_VPP500:
+      return "Fujitsu VPP500";
+    case EM_SPARC32PLUS:
+      return "SPARC v8+";
+    case EM_960:
+      return "Intel 80960";
+    case EM_PPC:
+      return "PowerPC";
+    case EM_PPC64:
+      return "PowerPC64";
+    case EM_S390:
+      return "IBM S/390";
+    case EM_SPU:
+      return "IBM SPU/SPC";
+    case EM_V800:
+      return "NEC V800";
+    case EM_FR20:
+      return "Fujitsu FR20";
+    case EM_RH32:
+      return "TRW RH-32";
+    case EM_RCE:
+      return "Motorola RCE";
+    case EM_ARM:
+      return "ARM";
+    case EM_FAKE_ALPHA:
+      return "Digital Alpha";
+    case EM_SH:
+      return "SH";
+    case EM_SPARCV9:
+      return "SPARC v9";
+    case EM_TRICORE:
+      return "Siemens Tricore";
+    case EM_ARC:
+      return "ARC";
+    case EM_H8_300:
+      return "H8/300";
+    case EM_H8_300H:
+      return "H8/300H";
+    case EM_H8S:
+      return "H8S";
+    case EM_H8_500:
+      return "H8/500";
+    case EM_IA_64:
+      return "Intel IA-64";
+    case EM_MIPS_X:
+      return "Stanford MIPS-X";
+    case EM_COLDFIRE:
+      return "Motorola Coldfire";
+    case EM_68HC12:
+      return "Motorola M68HC12";
+    case EM_MMA:
+      return "Fujitsu MMA Multimedia Accelerator";
+    case EM_PCP:
+      return "Siemens PCP";
+    case EM_NCPU:
+      return "Sony nCPU embeded RISC";
+    case EM_NDR1:
+      return "Denso NDR1 microprocessor";
+    case EM_STARCORE:
+      return "Motorola Star*Core processor";
+    case EM_ME16:
+      return "Toyota ME16 processor";
+    case EM_ST100:
+      return "STMicroelectronic ST100";
+    case EM_TINYJ:
+      return "Advanced Logic Corporation Tinyj";
+    case EM_X86_64:
+      return "AMD x86-64";
+    case EM_PDSP:
+      return "Sony DSP Processor";
+    case EM_PDP10:
+      return "Digital PDP-10";
+    case EM_PDP11:
+      return "Digital PDP-11";
+    case EM_FX66:
+      return "Siemens FX66 microcontroller";
+    case EM_ST9PLUS:
+      return "STMicroelectronics ST9+";
+    case EM_ST7:
+      return "STMicroelectronics ST7";
+    case EM_68HC16:
+      return "Motorola MC68HC16 microcontroller";
+    case EM_68HC11:
+      return "Motorola MC68HC11 microcontroller";
+    case EM_68HC08:
+      return "Motorola MC68HC08 microcontroller";
+    case EM_68HC05:
+      return "Motorola MC68HC05 microcontroller";
+    case EM_SVX:
+      return "Silicon Graphics SVx";
+    case EM_ST19:
+      return "STMicroelectronics ST19";
+    case EM_VAX:
+      return "Digital VAX";
+    case EM_CRIS:
+      return "Axis Communications 32-bit embedded processor";
+    case EM_JAVELIN:
+      return "Infineon Technologies 32-bit embedded processor";
+    case EM_FIREPATH:
+      return "Element 14 64-bit DSP Processor";
+    case EM_ZSP:
+      return "LSI Logic 16-bit DSP Processor";
+    case EM_MMIX:
+      return "Donald Knuth's educational 64-bit processor";
+    case EM_HUANY:
+      return "Harvard University machine-independent object";
+    case EM_PRISM:
+      return "SiTera Prism";
+    case EM_AVR:
+      return "Atmel AVR 8-bit microcontroller";
+    case EM_FR30:
+      return "Fujitsu FR30";
+    case EM_D10V:
+      return "Mitsubishi D10V";
+    case EM_D30V:
+      return "Mitsubishi D30V";
+    case EM_V850:
+      return "NEC v850";
+    case EM_M32R:
+      return "Mitsubishi M32R";
+    case EM_MN10300:
+      return "Matsushita MN10300";
+    case EM_MN10200:
+      return "Matsushita MN10200";
+    case EM_PJ:
+      return "picoJava";
+    case EM_OPENRISC:
+      return "OpenRISC";
+    case EM_ARC_COMPACT:
+      return "ARC International ARCompact";
+    case EM_XTENSA:
+      return "Tensilica Xtensa Architecture";
+    case EM_VIDEOCORE:
+      return "Alphamosaic VideoCore";
+    case EM_TMM_GPP:
+      return "Thompson Multimedia General Purpose Processor";
+    case EM_NS32K:
+      return "National Semiconductor 32000";
+    case EM_TPC:
+      return "Tenor Network TPC";
+    case EM_SNP1K:
+      return "Trebia SNP 1000";
+    case EM_ST200:
+      return "STMicroelectronics ST200";
+    case EM_IP2K:
+      return "Ubicom IP2xxx";
+    case EM_MAX:
+      return "MAX processor";
+    case EM_CR:
+      return "National Semiconductor CompactRISC";
+    case EM_F2MC16:
+      return "Fujitsu F2MC16";
+    case EM_MSP430:
+      return "Texas Instruments msp430";
+    case EM_BLACKFIN:
+      return "Analog Devices Blackfin DSP";
+    case EM_SE_C33:
+      return "Seiko Epson S1C33";
+    case EM_SEP:
+      return "Sharp embedded microprocessor";
+    case EM_ARCA:
+      return "Arca RISC";
+    case EM_UNICORE:
+      return "Unicore";
+    case EM_EXCESS:
+      return "eXcess configurable CPU";
+    case EM_DXP:
+      return "Icera Semiconductor Deep Execution Processor";
+    case EM_ALTERA_NIOS2:
+      return "Altera Nios II";
+    case EM_CRX:
+      return "National Semiconductor CompactRISC CRX";
+    case EM_XGATE:
+      return "Motorola XGATE";
+    case EM_C166:
+      return "Infineon C16x/XC16x";
+    case EM_M16C:
+      return "Renesas M16C";
+    case EM_DSPIC30F:
+      return "Microchip Technology dsPIC30F";
+    case EM_CE:
+      return "Freescale Communication Engine RISC";
+    case EM_M32C:
+      return "Renesas M32C";
+    case EM_TSK3000:
+      return "Altium TSK3000";
+    case EM_RS08:
+      return "Freescale RS08";
+    case EM_SHARC:
+      return "Analog Devices SHARC";
+    case EM_ECOG2:
+      return "Cyan Technology eCOG2";
+    case EM_SCORE7:
+      return "Sunplus S+core7 RISC";
+    case EM_DSP24:
+      return "New Japan Radio (NJR) 24-bit DSP";
+    case EM_VIDEOCORE3:
+      return "Broadcom VideoCore III";
+    case EM_LATTICEMICO32:
+      return "RISC for Lattice FPGA";
+    case EM_SE_C17:
+      return "Seiko Epson C17";
+    case EM_TI_C6000:
+      return "Texas Instruments TMS320C6000 DSP";
+    case EM_TI_C2000:
+      return "Texas Instruments TMS320C2000 DSP";
+    case EM_TI_C5500:
+      return "Texas Instruments TMS320C55x DSP";
+    case EM_TI_ARP32:
+      return "Texas Instruments Application Specific RISC";
+    case EM_TI_PRU:
+      return "Texas Instruments Programmable Realtime Unit";
+    case EM_MMDSP_PLUS:
+      return "STMicroelectronics 64bit VLIW DSP";
+    case EM_CYPRESS_M8C:
+      return "Cypress M8C";
+    case EM_R32C:
+      return "Renesas R32C";
+    case EM_TRIMEDIA:
+      return "NXP Semiconductors TriMedia";
+    case EM_QDSP6:
+      return "QUALCOMM DSP6";
+    case EM_8051:
+      return "Intel 8051 and variants";
+    case EM_STXP7X:
+      return "STMicroelectronics STxP7x";
+    case EM_NDS32:
+      return "Andes Technology compact code size embeded RISC";
+    case EM_ECOG1X:
+      return "Cyan Technology eCOG1X";
+    case EM_MAXQ30:
+      return "Dallas Semicondutor MAXQ30";
+    case EM_XIMO16:
+      return "New Japan Radio (NJR) 16-bit DSP";
+    case EM_MANIK:
+      return "M2000 Reconfigurable RISC";
+    case EM_CRAYNV2:
+      return "Cray NV2 vector architecture";
+    case EM_RX:
+      return "Renesas RX";
+    case EM_METAG:
+      return "Imagination Technologies META";
+    case EM_MCST_ELBRUS:
+      return "MCST Elbrus";
+    case EM_ECOG16:
+      return "Cyan Technology eCOG16";
+    case EM_CR16:
+      return "National Semiconductor CompactRISC";
+    case EM_ETPU:
+      return "Freescale Extended Time Processing Unit";
+    case EM_SLE9X:
+      return "Infineon Technologies SLE9X";
+    case EM_L10M:
+      return "Intel L10M";
+    case EM_K10M:
+      return "Intel K10M";
+    case EM_AARCH64:
+      return "AARCH64";
+    case EM_AVR32:
+      return "Amtel AVR32";
+    case EM_STM8:
+      return "STMicroelectronics STM8";
+    case EM_TILE64:
+      return "Tilera TILE64";
+    case EM_TILEPRO:
+      return "Tilera TILEPro";
+    case EM_MICROBLAZE:
+      return "Xilinx MicroBlaze";
+    case EM_CUDA:
+      return "NVIDIA CUDA";
+    case EM_TILEGX:
+      return "Tilera TILE-Gx";
+    case EM_CLOUDSHIELD:
+      return "CloudShield";
+    case EM_COREA_1ST:
+      return "KIPO-KAIST Core-A 1st gen";
+    case EM_COREA_2ND:
+      return "KIPO-KAIST Core-A 2nd gen";
+    case EM_ARC_COMPACT2:
+      return "Synopsys ARCompact V2";
+    case EM_OPEN8:
+      return "Open8 RISC";
+    case EM_RL78:
+      return "Renesas RL78";
+    case EM_VIDEOCORE5:
+      return "Broadcom VideoCore V";
+    case EM_78KOR:
+      return "Renesas 78KOR";
+    case EM_56800EX:
+      return "Freescale 56800EX DSC";
+    case EM_BA1:
+      return "Beyond BA1";
+    case EM_BA2:
+      return "Beyond BA2";
+    case EM_XCORE:
+      return "XMOS xCORE";
+    case EM_MCHP_PIC:
+      return "Microchip 8-bit PIC";
+    case EM_KM32:
+      return "KM211 KM32";
+    case EM_KMX32:
+      return "KM211 KMX32";
+    case EM_EMX16:
+      return "KM211 KMX16";
+    case EM_EMX8:
+      return "KM211 KMX8";
+    case EM_KVARC:
+      return "KM211 KVARC";
+    case EM_CDP:
+      return "Paneve CDP";
+    case EM_COGE:
+      return "Cognitive Smart Memory Processor";
+    case EM_COOL:
+      return "Bluechip CoolEngine";
+    case EM_NORC:
+      return "Nanoradio Optimized RISC";
+    case EM_CSR_KALIMBA:
+      return "CSR Kalimba";
+    case EM_Z80:
+      return "Zilog Z80";
+    case EM_VISIUM:
+      return "CDS VISIUMcore";
+    case EM_FT32:
+      return "FTDI Chip FT32";
+    case EM_MOXIE:
+      return "Moxie";
+    case EM_AMDGPU:
+      return "AMD GPU";
+    case EM_RISCV:
+      return "RISC-V";
+    case EM_BPF:
+      return "BPF";
+    case EM_CSKY:
+      return "C-SKY";
+
+    case EM_ALPHA:
+      return "Alpha";
+
+    default:
+      return NULL;
+    }
+}
diff --git a/libdwelf/libdwelf.h b/libdwelf/libdwelf.h
index 6d49184..cb7ea09 100644
--- a/libdwelf/libdwelf.h
+++ b/libdwelf/libdwelf.h
@@ -133,6 +133,10 @@ extern void dwelf_strtab_free (Dwelf_Strtab *st)
    file handle will not be closed.  Does not return ELF_K_NONE handles.  */
 extern Elf *dwelf_elf_begin (int fd);
 
+/* Returns a human readable string for the given ELF header e_machine
+   value, or NULL if the given number isn't currently known.  */
+extern const char *dwelf_elf_e_machine_string (int machine);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/libebl/ChangeLog b/libebl/ChangeLog
index 8a7d177..e42cd34 100644
--- a/libebl/ChangeLog
+++ b/libebl/ChangeLog
@@ -1,3 +1,9 @@
+2019-06-28  Mark Wielaard  <mark@klomp.org>
+
+	* eblopenbackend.c (try_dlopen): Remove result->name check.
+	(openbackend): Remove result->name assignment.
+	(struct ebl): Remove name.
+
 2019-05-30  Mark Wielaard  <mark@klomp.org>
 
 	* eblopenbackend.c (try_dlopen): New function extracted from
diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
index 36a2492..9dd5195 100644
--- a/libebl/eblopenbackend.c
+++ b/libebl/eblopenbackend.c
@@ -283,7 +283,6 @@ try_dlopen (const char *dsoname, Elf *elf, GElf_Half machine, size_t cnt,
 	  result->elf = elf;
 
 	  /* A few entries are mandatory.  */
-	  assert (result->name != NULL);
 	  assert (result->destr != NULL);
 
 	  return result;
@@ -398,7 +397,6 @@ openbackend (Elf *elf, const char *emulation, GElf_Half machine)
 	   Return that information.  */
 	result->dlhandle = NULL;
 	result->elf = elf;
-	result->name = machines[cnt].prefix;
 	fill_defaults (result);
 
 	return result;
@@ -408,7 +406,6 @@ openbackend (Elf *elf, const char *emulation, GElf_Half machine)
   result->dlhandle = NULL;
   result->elf = elf;
   result->emulation = "<unknown>";
-  result->name = "<unknown>";
   fill_defaults (result);
 
   return result;
diff --git a/libebl/libeblP.h b/libebl/libeblP.h
index 5b339b3..a586968 100644
--- a/libebl/libeblP.h
+++ b/libebl/libeblP.h
@@ -38,9 +38,6 @@
 /* Backend handle.  */
 struct ebl
 {
-  /* Machine name.  */
-  const char *name;
-
   /* Emulation name.  */
   const char *emulation;
 
diff --git a/src/ChangeLog b/src/ChangeLog
index c78e6fa..27812b0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2019-06-28  Mark Wielaard  <mark@klomp.org>
+
+	* readelf.c (print_ehdr): Use dwelf_elf_e_machine_string instead of
+	ebl->name. If unknown print hex value.
+
 2019-06-25  Mark Wielaard  <mark@klomp.org>
 
 	* stack.c (parse_opt): Fix dwfl_core_file_attach error message.
diff --git a/src/readelf.c b/src/readelf.c
index 062168b..cda7c93 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1084,7 +1084,12 @@ print_ehdr (Ebl *ebl, GElf_Ehdr *ehdr)
   fputs_unlocked (gettext ("  Type:                              "), stdout);
   print_file_type (ehdr->e_type);
 
-  printf (gettext ("  Machine:                           %s\n"), ebl->name);
+  const char *machine = dwelf_elf_e_machine_string (ehdr->e_machine);
+  if (machine != NULL)
+    printf (gettext ("  Machine:                           %s\n"), machine);
+  else
+    printf (gettext ("  Machine:                           <unknown>: 0x%x\n"),
+	    ehdr->e_machine);
 
   printf (gettext ("  Version:                           %d %s\n"),
 	  ehdr->e_version,
diff --git a/tests/ChangeLog b/tests/ChangeLog
index e038793..29334bc 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,12 @@
+2019-06-28  Mark Wielaard  <mark@klomp.org>
+
+	* Makefile.am (check_PROGRAMS): Add dwelf_elf_e_machine_string.
+	(TESTS): Add run-dwelf_elf_e_machine_string.sh.
+	(EXTRA_DIST): Likewise.
+	(dwelf_elf_e_machine_string_LDADD): New variable.
+	* dwelf_elf_e_machine_string.c: New file.
+	* run-dwelf_elf_e_machine_string.sh: New test.
+
 2019-06-03  Mark Wielaard  <mark@klomp.org>
 
 	* elfcopy.c (copy_elf): When swapping the sh_offsets of two sections,
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 87428aa..639633d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -60,7 +60,8 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
 		  fillfile dwarf_default_lower_bound dwarf-die-addr-die \
 		  get-units-invalid get-units-split attr-integrate-skel \
 		  all-dwarf-ranges unit-info next_cfi \
-		  elfcopy addsections xlate_notes elfrdwrnop
+		  elfcopy addsections xlate_notes elfrdwrnop \
+		  dwelf_elf_e_machine_string
 
 asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
 	    asm-tst6 asm-tst7 asm-tst8 asm-tst9
@@ -161,7 +162,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
 	run-copyadd-sections.sh run-copymany-sections.sh \
 	run-typeiter-many.sh run-strip-test-many.sh \
 	run-strip-version.sh run-xlate-note.sh \
-	run-readelf-discr.sh
+	run-readelf-discr.sh \
+	run-dwelf_elf_e_machine_string.sh
 
 if !BIARCH
 export ELFUTILS_DISABLE_BIARCH = 1
@@ -429,7 +431,9 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
 	     run-strip-version.sh testfile-version.bz2 \
 	     run-xlate-note.sh \
 	     run-readelf-discr.sh \
-	     testfile-rng.debug.bz2 testfile-urng.debug.bz2
+	     testfile-rng.debug.bz2 testfile-urng.debug.bz2 \
+	     run-dwelf_elf_e_machine_string.sh
+
 
 if USE_VALGRIND
 valgrind_cmd='valgrind -q --leak-check=full --error-exitcode=1'
@@ -601,6 +605,7 @@ elfcopy_LDADD = $(libelf)
 addsections_LDADD = $(libelf)
 xlate_notes_LDADD = $(libelf)
 elfrdwrnop_LDADD = $(libelf)
+dwelf_elf_e_machine_string_LDADD = $(libelf) $(libdw)
 
 # We want to test the libelf header against the system elf.h header.
 # Don't include any -I CPPFLAGS. Except when we install our own elf.h.
diff --git a/tests/dwelf_elf_e_machine_string.c b/tests/dwelf_elf_e_machine_string.c
new file mode 100644
index 0000000..1df2b23
--- /dev/null
+++ b/tests/dwelf_elf_e_machine_string.c
@@ -0,0 +1,64 @@
+/* Test program for dwelf_elf_e_machine_string
+   Copyright (C) 2019 Red Hat, Inc.
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+#include <unistd.h>
+
+#include ELFUTILS_HEADER(dwelf)
+
+int
+main (int argc, char **argv)
+{
+  int i;
+  for (i = 1; i < argc; i++)
+    {
+      long val;
+      int em;
+      const char *machine;
+
+      if (strncmp ("0x", argv[i], 2) == 0)
+	val = strtol (&argv[i][2], NULL, 16);
+      else
+	val = strtol (argv[i], NULL, 10);
+
+      if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
+           || (errno != 0 && val == 0))
+	{
+          perror ("strtol");
+          exit (EXIT_FAILURE);
+	}
+
+      em = val;
+      assert (em == val);
+
+      machine = dwelf_elf_e_machine_string (em);
+      printf ("0x%x %s\n", em, machine);
+      assert (machine != NULL);
+    }
+
+  return 0;
+}
diff --git a/tests/run-dwelf_elf_e_machine_string.sh b/tests/run-dwelf_elf_e_machine_string.sh
new file mode 100755
index 0000000..ba6d0e6
--- /dev/null
+++ b/tests/run-dwelf_elf_e_machine_string.sh
@@ -0,0 +1,31 @@
+#! /bin/bash
+# Test to make sure all EM values in elf.h are recognized
+# Copyright (C) 2019 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Get all known EM values from elf.h and pass them through the
+# preprocessor to get the numbers. Call dwelf_elf_e_machine_string on
+# all of them.
+EM_VALUES=$(grep ^\#define\ EM_ ${abs_srcdir}/../libelf/elf.h \
+            | cut -f2 -d\  | cut -f1 | grep -v ^EM_NUM$ | xargs echo)
+# echo "EM_VALUES: $EM_VALUES"
+EM_NUMBERS=$((cat ${abs_srcdir}/../libelf/elf.h; echo "$EM_VALUES") \
+             | gcc -E - | tail -1)
+# echo "EM_NUMBERS: $EM_NUMBERS"
+
+testrun ${abs_top_builddir}/tests/dwelf_elf_e_machine_string $EM_NUMBERS
-- 
1.8.3.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]