From a8971514264996e7ab3dc69acecbc332afbef6f5 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Wed, 27 Jun 2018 14:39:06 -0700 Subject: [PATCH] linker: improve "bad ELF magic" error. Include what we actually saw. Bug: http://b/79463184 Test: ran tests Change-Id: Id5f8aa3ab94b411ea839b0a1ada9beda9053a10f --- linker/linker_phdr.cpp | 3 ++- tests/dlext_test.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/linker/linker_phdr.cpp b/linker/linker_phdr.cpp index b24be9212..54354a826 100644 --- a/linker/linker_phdr.cpp +++ b/linker/linker_phdr.cpp @@ -213,7 +213,8 @@ static const char* EM_to_string(int em) { bool ElfReader::VerifyElfHeader() { if (memcmp(header_.e_ident, ELFMAG, SELFMAG) != 0) { - DL_ERR("\"%s\" has bad ELF magic", name_.c_str()); + DL_ERR("\"%s\" has bad ELF magic: %02x%02x%02x%02x", name_.c_str(), + header_.e_ident[0], header_.e_ident[1], header_.e_ident[2], header_.e_ident[3]); return false; } diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp index ec2793298..1e3d9c867 100644 --- a/tests/dlext_test.cpp +++ b/tests/dlext_test.cpp @@ -173,7 +173,7 @@ TEST_F(DlExtTest, ExtInfoUseFdWithInvalidOffset) { extinfo.library_fd_offset = 0; handle_ = android_dlopen_ext("libname_ignored", RTLD_NOW, &extinfo); ASSERT_TRUE(handle_ == nullptr); - ASSERT_EQ("dlopen failed: \"" + lib_path + "\" has bad ELF magic", dlerror()); + ASSERT_EQ("dlopen failed: \"" + lib_path + "\" has bad ELF magic: 504b0304", dlerror()); // Check if dlsym works after unsuccessful dlopen(). // Supply non-exiting one to make linker visit every soinfo.