From 72007ee68f507c0ab952a0b98888fc19473ba6f0 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 19 Apr 2017 17:44:57 -0700 Subject: [PATCH] Decode the common EM_ values. We know what "3" and "40" are, but most folks not on our team don't. I don't think we need to support all the weird values, because only the supported architectures actually occur in practice. Bug: N/A Test: manually overwrote aarch64 libcrypto.so with an x86-64 .so and ran "date" Test: CANNOT LINK EXECUTABLE "date": "/system/lib64/libcrypto.so" has unexpected e_machine: 62 (EM_X86_64) Change-Id: Ic4c6325fe7968f0c96fc0bfe15a50ed922a5ba55 --- linker/linker_phdr.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp index 72549cc73..42c29c8c2 100644 --- a/linker/linker_phdr.cpp +++ b/linker/linker_phdr.cpp @@ -199,6 +199,15 @@ bool ElfReader::ReadElfHeader() { return true; } +static const char* EM_to_string(int em) { + if (em == EM_386) return "EM_386"; + if (em == EM_AARCH64) return "EM_AARCH64"; + if (em == EM_ARM) return "EM_ARM"; + if (em == EM_MIPS) return "EM_MIPS"; + if (em == EM_X86_64) return "EM_X86_64"; + return "EM_???"; +} + bool ElfReader::VerifyElfHeader() { if (memcmp(header_.e_ident, ELFMAG, SELFMAG) != 0) { DL_ERR("\"%s\" has bad ELF magic", name_.c_str()); @@ -244,7 +253,8 @@ bool ElfReader::VerifyElfHeader() { } if (header_.e_machine != GetTargetElfMachine()) { - DL_ERR("\"%s\" has unexpected e_machine: %d", name_.c_str(), header_.e_machine); + DL_ERR("\"%s\" has unexpected e_machine: %d (%s)", name_.c_str(), header_.e_machine, + EM_to_string(header_.e_machine)); return false; }