summaryrefslogtreecommitdiff
path: root/libdwelf
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2019-06-28 19:21:59 +0200
committerMark Wielaard <mark@klomp.org>2019-07-10 14:08:33 +0200
commitb3233914074cb7eb19ea2fc3c70257679f867f68 (patch)
treeaad365893d911393052714723f050388197170d7 /libdwelf
parent31c8b3f098b0654db8f573b2a15d5b6d07d4d3b0 (diff)
downloadelfutils-b3233914074cb7eb19ea2fc3c70257679f867f68.tar.gz
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>
Diffstat (limited to 'libdwelf')
-rw-r--r--libdwelf/ChangeLog6
-rw-r--r--libdwelf/Makefile.am3
-rw-r--r--libdwelf/dwelf_elf_e_machine_string.c406
-rw-r--r--libdwelf/libdwelf.h4
4 files changed, 418 insertions, 1 deletions
diff --git a/libdwelf/ChangeLog b/libdwelf/ChangeLog
index 88be3421..29f9a509 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 a7933fda..a35a2873 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 00000000..de07b01e
--- /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 6d491847..cb7ea091 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