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
This commit is contained in:
Elliott Hughes 2017-04-19 17:44:57 -07:00
parent 0fc84517ab
commit 72007ee68f

View file

@ -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;
}