From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 4FC04138A1A for ; Tue, 6 Jan 2015 17:26:16 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2DC1FE07EA; Tue, 6 Jan 2015 17:26:14 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A5ED5E07EA for ; Tue, 6 Jan 2015 17:26:13 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4DC8234067D for ; Tue, 6 Jan 2015 17:26:12 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id EB378F010 for ; Tue, 6 Jan 2015 17:26:10 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <1420565232.51e620eef945c3af2c2d8c92fedbacb99ba55d3d.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: misc/elf-abi/ X-VCS-Repository: proj/elfix X-VCS-Files: misc/elf-abi/elf-abi.c X-VCS-Directories: misc/elf-abi/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 51e620eef945c3af2c2d8c92fedbacb99ba55d3d X-VCS-Branch: master Date: Tue, 6 Jan 2015 17:26:10 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: f808633a-21e9-4e12-884b-a3d67cb987a6 X-Archives-Hash: 68f33c2033e629933351fb0a64da692d commit: 51e620eef945c3af2c2d8c92fedbacb99ba55d3d Author: Anthony G. Basile gentoo org> AuthorDate: Tue Jan 6 17:27:12 2015 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Tue Jan 6 17:27:12 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=51e620ee misc/elf-abi: sort out EM numbers for gentoo -- except mips --- misc/elf-abi/elf-abi.c | 116 +++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 61 deletions(-) diff --git a/misc/elf-abi/elf-abi.c b/misc/elf-abi/elf-abi.c index fb53391..13ec542 100644 --- a/misc/elf-abi/elf-abi.c +++ b/misc/elf-abi/elf-abi.c @@ -58,50 +58,38 @@ #include #include -/* We steal this from but don't include it so as to not increase our dependancies. */ +/* We reorder the big endian EM_ numbers to avoid also reading endian information from + * the Elf file. For a mapping between common macine names and EM_ see . For a + * more complete mapping, see elfutil's machines[] defined in libebl/eblopenbackend.c. + */ #define ELFMAG "\177ELF" #define ELFCLASS32 1 /* 32-bit objects */ #define ELFCLASS64 2 /* 64-bit objects */ -#define EM_SPARC 2 /* SUN SPARC */ -#define EM_386 3 /* Intel 80386 */ -#define EM_68K 4 /* Motorola m68k family */ +#define EM_ALPHA 0x9026 /* alpha */ +#define EM_ARM 40 /* arm */ +#define EM_AARCH64 183 /* arm64 */ +#define EM_PARISC_BE 0x0F00 /* hppa - big endian reordering of EM_PARISC = 15 */ +#define EM_IA_64 50 /* ia64 */ +#define EM_68K_BE 0x0400 /* m68k - big endian reordering of EM_68K = 4 */ + #define EM_MIPS 8 /* MIPS R3000 big-endian */ #define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ -#define EM_PARISC 15 /* HPPA */ -#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ -#define EM_PPC 20 /* PowerPC */ -#define EM_PPC64 21 /* PowerPC 64-bit */ -#define EM_S390 22 /* IBM S390 */ -#define EM_ARM 40 /* ARM */ -#define EM_FAKE_ALPHA 41 /* Digital Alpha */ -#define EM_SH 42 /* Hitachi SH */ -#define EM_SPARCV9 43 /* SPARC v9 64-bit */ -#define EM_IA_64 50 /* Intel Merced */ -#define EM_X86_64 62 /* AMD x86-64 architecture */ -#define EM_AARCH64 183 /* ARM AARCH64 */ -#define EM_ALPHA 0x9026 /* Unofficial, but needed in Gentoo */ -#define EM_HPPA 0x0F00 /* Unofficial, but needed in Gentoo */ -#define EF_MIPS_ABI 0x0000F000 -#define E_MIPS_ABI_O32 0x00001000 +#define EM_PPC_BE 0x1400 /* ppc - big endian reordering of EM_PPC = 20 */ +#define EM_PPC64_BE 0x1500 /* ppc64 - bit endian reordering of EM_PPC64 = 21 */ +#define EM_S390_BE 0x1600 /* s390 - big endian reordering of EM_S390 */ +#define EM_SH 42 /* Hitachi SH */ +#define EM_SPARC32_BE 0x1200 /* sparc - big endian reordering of EM_SPARC32PLUS = 18 */ +#define EM_SPARC64_BE 0x2B00 /* sparc - big endian reordinger of EM_SPARCV9 = 43 */ +#define EM_386 3 /* x86 */ +#define EM_X86_64 62 /* amd64 */ -#define EF_ARM_EABIMASK 0XFF000000 - - -int -get_wordsize(uint8_t ei_class) -{ - switch (ei_class) { - case ELFCLASS32: - return 32; - case ELFCLASS64: - return 64; - default: - return 0; - } -} +/* The arm and mips ABI flags housed in e_flags */ +#define EF_MIPS_ABI 0x0000F000 /* Mask for mips ABI */ +#define E_MIPS_ABI_O32 0x00001000 /* Value for o32 */ +#define EF_ARM_EABIMASK 0XFF000000 /* Mask for arm EABI - we dont' destinguish versions */ char * @@ -115,21 +103,8 @@ get_abi(uint16_t e_machine, int width, uint32_t e_flags) /* alpha: We support only one 64-bit ABI. */ case EM_ALPHA: - case EM_FAKE_ALPHA: return "alpha_64"; - /* amd64 + x86: We support X86-64, X86-X32, and X86-32 ABI. The first - * two are 64-bit ABIs and the third is 32-bit. All three will run on - * amd64 architecture, but only the 32-bit will run on the x86 family. - */ - case EM_X86_64: - if (width == 64) - return "x86_64"; - else - return "x86_x32"; - case EM_386: - return "x86_32"; - /* arm: We support two 32-bit ABIs, eabi and oabi. */ case EM_ARM: if (e_flags & EF_ARM_EABIMASK) @@ -142,7 +117,7 @@ get_abi(uint16_t e_machine, int width, uint32_t e_flags) return "arm_64"; /* m68k: We support only one 32-bit ABI. */ - case EM_68K: + case EM_68K_BE: return "m68k_32"; /* mips: We support o32, n32 and n64. The first is 32-bits and the @@ -163,20 +138,19 @@ get_abi(uint16_t e_machine, int width, uint32_t e_flags) return "ia_64"; /* hppa: We support only one 32-bit ABI. */ - case EM_PARISC: - case EM_HPPA: + case EM_PARISC_BE: return "hppa_32"; /* ppc: We support only one 32-bit ABI. */ - case EM_PPC: + case EM_PPC_BE: return "ppc_32"; /* ppc64: We support only one 64-bit ABI. */ - case EM_PPC64: + case EM_PPC64_BE: return "ppc_64"; /* s390: We support one 32-bit and one 64-bit ABI. */ - case EM_S390: + case EM_S390_BE: if (width == 64) return "s390_64"; else @@ -187,13 +161,22 @@ get_abi(uint16_t e_machine, int width, uint32_t e_flags) return "sh_32"; /* sparc: We support one 32-bit and one 64-bit ABI. */ - case EM_SPARC32PLUS: - case EM_SPARCV9: - case EM_SPARC: + case EM_SPARC32_BE: + return "sparc_32"; + case EM_SPARC64_BE: + return "sparc_64"; + + /* amd64 + x86: We support X86-64, X86-X32, and X86-32 ABI. The first + * two are 64-bit ABIs and the third is 32-bit. All three will run on + * amd64 architecture, but only the 32-bit will run on the x86 family. + */ + case EM_386: + return "x86_32"; + case EM_X86_64: if (width == 64) - return "sparc_64"; + return "x86_64"; else - return "sparc_32"; + return "x86_x32"; default: return "unknown"; @@ -231,10 +214,19 @@ main(int argc, char* argv[]) if (strncmp(magic, ELFMAG, 4) != 0) errx(1, "%s is not an ELF object", argv[1]); - /* 32 or 64 bits? */ + /* 32 or 64 bits machine word size? */ if (read(fd, &ei_class, 1) == -1) err(1, "read() ei_class failed"); - width = get_wordsize(ei_class); + switch (ei_class) { + case ELFCLASS32: + width = 32; + break; + case ELFCLASS64: + width = 64; + break; + default: + errx(1, "Unknown machine word size."); + } /* All Elf files begin with the following Elf header: @@ -261,6 +253,8 @@ main(int argc, char* argv[]) err(1, "lseek() e_machine failed"); if (read(fd, &e_machine, 2) == -1) err(1, "read() e_machine failed"); + printf("%x\n", e_machine); + printf("%d\n", e_machine); if (lseek(fd, e_flags_offset, SEEK_SET) == -1) err(1, "lseek() e_flags failed");