]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
libdwelf: Add dwelf_elf_e_machine_string and use it in readelf.
authorMark Wielaard <mark@klomp.org>
Fri, 28 Jun 2019 17:21:59 +0000 (19:21 +0200)
committerMark Wielaard <mark@klomp.org>
Wed, 10 Jul 2019 12:08:33 +0000 (14:08 +0200)
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>
31 files changed:
backends/ChangeLog
backends/aarch64_init.c
backends/alpha_init.c
backends/arm_init.c
backends/bpf_init.c
backends/i386_init.c
backends/ia64_init.c
backends/m68k_init.c
backends/ppc64_init.c
backends/ppc_init.c
backends/riscv_init.c
backends/s390_init.c
backends/sh_init.c
backends/sparc_init.c
backends/tilegx_init.c
backends/x86_64_init.c
libdw/ChangeLog
libdw/libdw.map
libdwelf/ChangeLog
libdwelf/Makefile.am
libdwelf/dwelf_elf_e_machine_string.c [new file with mode: 0644]
libdwelf/libdwelf.h
libebl/ChangeLog
libebl/eblopenbackend.c
libebl/libeblP.h
src/ChangeLog
src/readelf.c
tests/ChangeLog
tests/Makefile.am
tests/dwelf_elf_e_machine_string.c [new file with mode: 0644]
tests/run-dwelf_elf_e_machine_string.sh [new file with mode: 0755]

index 6c2b47a94646558183b02521b32127dce046076f..af1a40e2d2cb4886bd617995c1bddd28133040ba 100644 (file)
@@ -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.
index fad923faa6112d0ac386c5a1ca1a5aaa09b27d44..95268ae036fb6b210fe679174804ddd98e351672 100644 (file)
@@ -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);
index 25c5b32f4bb3c095953c835c9a46bcd553b7fbb3..f66f40c51013554464c32c5305651d24731a24a9 100644 (file)
@@ -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);
index f2b1b11ea5bbff33c2aea5c7405d48fd11bb3d5e..af023f02ed2b7c36803879abb15b9076ff244650 100644 (file)
@@ -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);
index a046e06929c695279f99f3f5e9afc0ca875785ed..d407d378bd9ae23d12be8012f7f87d3a5158c0c5 100644 (file)
@@ -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);
index fc1587a9ea1134e80b59199730ce4cb18f701008..67428b53739e4673b5c354633f48c1dd3e2cad2d 100644 (file)
@@ -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);
index 7241d7b8247998a55e3e7620b6b2fde4ad5ab977..2d1f43f211665ed2b42dc5efc8513fb502852f36 100644 (file)
@@ -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);
index 8cae710bf89d12c4efed7de6e995241f6d556fed..05d544c10e078f252764a970d2b3ffd94216cbb5 100644 (file)
@@ -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);
index 3db5e7666ff9045baf1c230a39257f7056c9da54..c2e7043bcfbad3cb05bc54f9ec74e99749c57ed3 100644 (file)
@@ -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);
index aea9f2d7404b1d4dc2581fe9d5a3227924e64a68..eb286c2569925368178e03bc1ab051628caebab4 100644 (file)
@@ -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);
index 3398c1045881deb8a4ea0c1638ee5595c6359e05..9aaec9ce98683fde41442682b49b1d047d1a5c9d 100644 (file)
@@ -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);
index 0004aeeac6ae6219ed9ff9b05ff7e4f95dfed6d2..b4f3e7f88befc73b3a54342ce5a2eda2a3a5170e 100644 (file)
@@ -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);
index 5526aca1ae15c03ef74cc368afb6c1aa2ba920f4..24f4d4a4bee5ec4b4514a27b37a858fa59d8ec02 100644 (file)
@@ -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);
index 8e946fb2a05cbd306a11c1d0ab9a36a289af806e..6daff114a3b1d937b10b4a52445481a66172b943 100644 (file)
@@ -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);
index 162ed3624b87397c1d0c9a7b0dd721c62b3027a0..66df9318a79c3ad324a2247aed5fa3a3e0cd94f8 100644 (file)
@@ -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);
index 49f6c6c7a063eba86bd193b891f71569e4823be3..8abafb7f118646f25301ef4b87ec8c211d406995 100644 (file)
@@ -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);
index 4760f9deda7db4e6704324e9f4de15b9ce6a8609..6b779e7778621929bf71d7ad0f852aff39aa9ee6 100644 (file)
@@ -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
index 55482d58792eba8bceb34ef48284e51a01081ee8..2e1c0e9eedfd9b2a6a130936250e47c06c7d0bff 100644 (file)
@@ -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;
index 88be3421e13f4aaaeff3886e1ad97f7dc07b695d..29f9a509e13003b19ec454ae7f9c562468982ce1 100644 (file)
@@ -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.
index a7933fda0d950e44799558068e7a86bc1992033a..a35a2873cdf2de4ff5315ce67cb51e9c47263069 100644 (file)
@@ -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 (file)
index 0000000..de07b01
--- /dev/null
@@ -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;
+    }
+}
index 6d491847114fa8fe037c0fff07eb456222e2b70b..cb7ea091d32e42834e0968de87f7b70ddd04fa7a 100644 (file)
@@ -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
index 8a7d177ff183d55177362c30c7027ccab3d56c48..e42cd34b45199cc1a883f9190de05fc787438f7d 100644 (file)
@@ -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
index 36a2492103e715d38bee989ef1f33187112d2be8..9dd519505efbe63a052b5369bba1266a449ab5ea 100644 (file)
@@ -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;
index 5b339b31dfc7e1210cff3e4080d95074aee85eff..a58696852e85fa646ae9b1be8927809a16fb3c58 100644 (file)
@@ -38,9 +38,6 @@
 /* Backend handle.  */
 struct ebl
 {
-  /* Machine name.  */
-  const char *name;
-
   /* Emulation name.  */
   const char *emulation;
 
index c78e6fa18b399e780816e07157bf5ac562f89030..27812b05c23385edc9b072c28281c3db48e3988f 100644 (file)
@@ -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.
index 062168bb9fcf6119bbf58940942939acab8a6d1e..cda7c93a18781ac3094b0707828e7a1f87e728eb 100644 (file)
@@ -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,
index 400588f4360bcf3336b4daf5a79b109677d3512b..81621851d676a0e5496a0791ec0374a040f2252e 100644 (file)
@@ -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-07-01  Mark Wielaard  <mark@klomp.org>
 
        * run-large-elf-file.sh: Add 2GB to mem_needed when running under
index 3d95cf685fc38ec86e3bef9ab333a24b02105f57..a605d0800199e872c8ce49bd195f01ba771d2650 100644 (file)
@@ -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
@@ -162,7 +163,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
@@ -431,7 +433,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'
@@ -603,6 +607,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 (file)
index 0000000..1df2b23
--- /dev/null
@@ -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 (executable)
index 0000000..ba6d0e6
--- /dev/null
@@ -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