From f5b0f2cef8554efaa90adc6a1ae04c2b533970ed Mon Sep 17 00:00:00 2001 From: Brian Carlstrom Date: Fri, 14 Oct 2016 01:04:26 -0700 Subject: [PATCH] Ensure OpenDexFilesFromImage closes file to prevent file descriptor leak (cherry picked from commit 645e477c2ce7a59ac98bc86463826cf082a13ad8) Test: m -j32 test-art-host Bug: 32095919 Change-Id: I44541edeb403a508e1b9794ee09fb1f55e3f42bf --- compiler/elf_writer_test.cc | 2 +- patchoat/patchoat.cc | 9 +- runtime/elf_file.cc | 277 +++++++++++++++++++++++--------------------- runtime/elf_file.h | 4 +- runtime/elf_file_impl.h | 16 +-- runtime/oat_file.cc | 2 +- runtime/runtime.cc | 2 +- 7 files changed, 162 insertions(+), 150 deletions(-) diff --git a/compiler/elf_writer_test.cc b/compiler/elf_writer_test.cc index d5f16637b..1339da44b 100644 --- a/compiler/elf_writer_test.cc +++ b/compiler/elf_writer_test.cc @@ -94,7 +94,7 @@ TEST_F(ElfWriterTest, dlsym) { /*low_4gb*/false, &error_msg)); CHECK(ef.get() != nullptr) << error_msg; - CHECK(ef->Load(false, /*low_4gb*/false, &error_msg)) << error_msg; + CHECK(ef->Load(file.get(), false, /*low_4gb*/false, &error_msg)) << error_msg; EXPECT_EQ(dl_oatdata, ef->FindDynamicSymbolAddress("oatdata")); EXPECT_EQ(dl_oatexec, ef->FindDynamicSymbolAddress("oatexec")); EXPECT_EQ(dl_oatlastword, ef->FindDynamicSymbolAddress("oatlastword")); diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc index f3eb663cb..c79bf9286 100644 --- a/patchoat/patchoat.cc +++ b/patchoat/patchoat.cc @@ -442,7 +442,7 @@ PatchOat::MaybePic PatchOat::IsOatPic(const ElfFile* oat_in) { return ERROR_OAT_FILE; } - const std::string& file_path = oat_in->GetFile().GetPath(); + const std::string& file_path = oat_in->GetFilePath(); const OatHeader* oat_header = GetOatHeader(oat_in); if (oat_header == nullptr) { @@ -846,7 +846,7 @@ bool PatchOat::PatchOatHeader(ElfFileImpl* oat_file) { } OatHeader* oat_header = reinterpret_cast(oat_file->Begin() + rodata_sec->sh_offset); if (!oat_header->IsValid()) { - LOG(ERROR) << "Elf file " << oat_file->GetFile().GetPath() << " has an invalid oat header"; + LOG(ERROR) << "Elf file " << oat_file->GetFilePath() << " has an invalid oat header"; return false; } oat_header->RelocateOat(delta_); @@ -854,10 +854,11 @@ bool PatchOat::PatchOatHeader(ElfFileImpl* oat_file) { } bool PatchOat::PatchElf() { - if (oat_file_->Is64Bit()) + if (oat_file_->Is64Bit()) { return PatchElf(oat_file_->GetImpl64()); - else + } else { return PatchElf(oat_file_->GetImpl32()); + } } template diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc index 096f003de..2ea7bb677 100644 --- a/runtime/elf_file.cc +++ b/runtime/elf_file.cc @@ -36,8 +36,7 @@ template ElfFileImpl::ElfFileImpl(File* file, bool writable, bool program_header_only, uint8_t* requested_base) - : file_(file), - writable_(writable), + : writable_(writable), program_header_only_(program_header_only), header_(nullptr), base_address_(nullptr), @@ -74,7 +73,7 @@ ElfFileImpl* ElfFileImpl::Open(File* file, prot = PROT_READ; flags = MAP_PRIVATE; } - if (!elf_file->Setup(prot, flags, low_4gb, error_msg)) { + if (!elf_file->Setup(file, prot, flags, low_4gb, error_msg)) { return nullptr; } return elf_file.release(); @@ -89,39 +88,44 @@ ElfFileImpl* ElfFileImpl::Open(File* file, std::unique_ptr> elf_file(new ElfFileImpl (file, (prot & PROT_WRITE) == PROT_WRITE, /*program_header_only*/false, /*requested_base*/nullptr)); - if (!elf_file->Setup(prot, flags, low_4gb, error_msg)) { + if (!elf_file->Setup(file, prot, flags, low_4gb, error_msg)) { return nullptr; } return elf_file.release(); } template -bool ElfFileImpl::Setup(int prot, int flags, bool low_4gb, std::string* error_msg) { - int64_t temp_file_length = file_->GetLength(); +bool ElfFileImpl::Setup(File* file, + int prot, + int flags, + bool low_4gb, + std::string* error_msg) { + int64_t temp_file_length = file->GetLength(); if (temp_file_length < 0) { errno = -temp_file_length; *error_msg = StringPrintf("Failed to get length of file: '%s' fd=%d: %s", - file_->GetPath().c_str(), file_->Fd(), strerror(errno)); + file->GetPath().c_str(), file->Fd(), strerror(errno)); return false; } size_t file_length = static_cast(temp_file_length); if (file_length < sizeof(Elf_Ehdr)) { *error_msg = StringPrintf("File size of %zd bytes not large enough to contain ELF header of " "%zd bytes: '%s'", file_length, sizeof(Elf_Ehdr), - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (program_header_only_) { // first just map ELF header to get program header size information size_t elf_header_size = sizeof(Elf_Ehdr); - if (!SetMap(MemMap::MapFile(elf_header_size, + if (!SetMap(file, + MemMap::MapFile(elf_header_size, prot, flags, - file_->Fd(), + file->Fd(), 0, low_4gb, - file_->GetPath().c_str(), + file->GetPath().c_str(), error_msg), error_msg)) { return false; @@ -131,16 +135,17 @@ bool ElfFileImpl::Setup(int prot, int flags, bool low_4gb, std::string if (file_length < program_header_size) { *error_msg = StringPrintf("File size of %zd bytes not large enough to contain ELF program " "header of %zd bytes: '%s'", file_length, - sizeof(Elf_Ehdr), file_->GetPath().c_str()); + sizeof(Elf_Ehdr), file->GetPath().c_str()); return false; } - if (!SetMap(MemMap::MapFile(program_header_size, + if (!SetMap(file, + MemMap::MapFile(program_header_size, prot, flags, - file_->Fd(), + file->Fd(), 0, low_4gb, - file_->GetPath().c_str(), + file->GetPath().c_str(), error_msg), error_msg)) { *error_msg = StringPrintf("Failed to map ELF program headers: %s", error_msg->c_str()); @@ -148,13 +153,14 @@ bool ElfFileImpl::Setup(int prot, int flags, bool low_4gb, std::string } } else { // otherwise map entire file - if (!SetMap(MemMap::MapFile(file_->GetLength(), + if (!SetMap(file, + MemMap::MapFile(file->GetLength(), prot, flags, - file_->Fd(), + file->Fd(), 0, low_4gb, - file_->GetPath().c_str(), + file->GetPath().c_str(), error_msg), error_msg)) { *error_msg = StringPrintf("Failed to map ELF file: %s", error_msg->c_str()); @@ -178,7 +184,7 @@ bool ElfFileImpl::Setup(int prot, int flags, bool low_4gb, std::string Elf_Shdr* shstrtab_section_header = GetSectionNameStringSection(); if (shstrtab_section_header == nullptr) { *error_msg = StringPrintf("Failed to find shstrtab section header in ELF file: '%s'", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } @@ -186,7 +192,7 @@ bool ElfFileImpl::Setup(int prot, int flags, bool low_4gb, std::string dynamic_program_header_ = FindProgamHeaderByType(PT_DYNAMIC); if (dynamic_program_header_ == nullptr) { *error_msg = StringPrintf("Failed to find PT_DYNAMIC program header in ELF file: '%s'", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } @@ -200,7 +206,7 @@ bool ElfFileImpl::Setup(int prot, int flags, bool low_4gb, std::string Elf_Shdr* section_header = GetSectionHeader(i); if (section_header == nullptr) { *error_msg = StringPrintf("Failed to find section header for section %d in ELF file: '%s'", - i, file_->GetPath().c_str()); + i, file->GetPath().c_str()); return false; } switch (section_header->sh_type) { @@ -245,7 +251,7 @@ bool ElfFileImpl::Setup(int prot, int flags, bool low_4gb, std::string if (reinterpret_cast(dynamic_section_start_) != Begin() + section_header->sh_offset) { LOG(WARNING) << "Failed to find matching SHT_DYNAMIC for PT_DYNAMIC in " - << file_->GetPath() << ": " << std::hex + << file->GetPath() << ": " << std::hex << reinterpret_cast(dynamic_section_start_) << " != " << reinterpret_cast(Begin() + section_header->sh_offset); return false; @@ -263,7 +269,7 @@ bool ElfFileImpl::Setup(int prot, int flags, bool low_4gb, std::string } // Check for the existence of some sections. - if (!CheckSectionsExist(error_msg)) { + if (!CheckSectionsExist(file, error_msg)) { return false; } } @@ -283,7 +289,7 @@ bool ElfFileImpl::CheckAndSet(Elf32_Off offset, const char* label, uint8_t** target, std::string* error_msg) { if (Begin() + offset >= End()) { *error_msg = StringPrintf("Offset %d is out of range for %s in ELF file: '%s'", offset, label, - file_->GetPath().c_str()); + file_path_.c_str()); return false; } *target = Begin() + offset; @@ -324,11 +330,11 @@ bool ElfFileImpl::CheckSectionsLinked(const uint8_t* source, } template -bool ElfFileImpl::CheckSectionsExist(std::string* error_msg) const { + bool ElfFileImpl::CheckSectionsExist(File* file, std::string* error_msg) const { if (!program_header_only_) { // If in full mode, need section headers. if (section_headers_start_ == nullptr) { - *error_msg = StringPrintf("No section headers in ELF file: '%s'", file_->GetPath().c_str()); + *error_msg = StringPrintf("No section headers in ELF file: '%s'", file->GetPath().c_str()); return false; } } @@ -336,14 +342,14 @@ bool ElfFileImpl::CheckSectionsExist(std::string* error_msg) const { // This is redundant, but defensive. if (dynamic_program_header_ == nullptr) { *error_msg = StringPrintf("Failed to find PT_DYNAMIC program header in ELF file: '%s'", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } // Need a dynamic section. This is redundant, but defensive. if (dynamic_section_start_ == nullptr) { *error_msg = StringPrintf("Failed to find dynamic section in ELF file: '%s'", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } @@ -352,7 +358,7 @@ bool ElfFileImpl::CheckSectionsExist(std::string* error_msg) const { if (symtab_section_start_ != nullptr) { // When there's a symtab, there should be a strtab. if (strtab_section_start_ == nullptr) { - *error_msg = StringPrintf("No strtab for symtab in ELF file: '%s'", file_->GetPath().c_str()); + *error_msg = StringPrintf("No strtab for symtab in ELF file: '%s'", file->GetPath().c_str()); return false; } @@ -360,25 +366,25 @@ bool ElfFileImpl::CheckSectionsExist(std::string* error_msg) const { if (!CheckSectionsLinked(reinterpret_cast(symtab_section_start_), reinterpret_cast(strtab_section_start_))) { *error_msg = StringPrintf("Symtab is not linked to the strtab in ELF file: '%s'", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } } // We always need a dynstr & dynsym. if (dynstr_section_start_ == nullptr) { - *error_msg = StringPrintf("No dynstr in ELF file: '%s'", file_->GetPath().c_str()); + *error_msg = StringPrintf("No dynstr in ELF file: '%s'", file->GetPath().c_str()); return false; } if (dynsym_section_start_ == nullptr) { - *error_msg = StringPrintf("No dynsym in ELF file: '%s'", file_->GetPath().c_str()); + *error_msg = StringPrintf("No dynsym in ELF file: '%s'", file->GetPath().c_str()); return false; } // Need a hash section for dynamic symbol lookup. if (hash_section_start_ == nullptr) { *error_msg = StringPrintf("Failed to find hash section in ELF file: '%s'", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } @@ -386,7 +392,7 @@ bool ElfFileImpl::CheckSectionsExist(std::string* error_msg) const { if (!CheckSectionsLinked(reinterpret_cast(hash_section_start_), reinterpret_cast(dynsym_section_start_))) { *error_msg = StringPrintf("Hash section is not linked to the dynstr in ELF file: '%s'", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } @@ -397,9 +403,9 @@ bool ElfFileImpl::CheckSectionsExist(std::string* error_msg) const { // It might not be mapped, but we can compare against the file size. int64_t offset = static_cast(GetHeader().e_shoff + (GetHeader().e_shstrndx * GetHeader().e_shentsize)); - if (offset >= file_->GetLength()) { + if (offset >= file->GetLength()) { *error_msg = StringPrintf("Shstrtab is not in the mapped ELF file: '%s'", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } } @@ -408,15 +414,15 @@ bool ElfFileImpl::CheckSectionsExist(std::string* error_msg) const { } template -bool ElfFileImpl::SetMap(MemMap* map, std::string* error_msg) { +bool ElfFileImpl::SetMap(File* file, MemMap* map, std::string* error_msg) { if (map == nullptr) { // MemMap::Open should have already set an error. DCHECK(!error_msg->empty()); return false; } map_.reset(map); - CHECK(map_.get() != nullptr) << file_->GetPath(); - CHECK(map_->Begin() != nullptr) << file_->GetPath(); + CHECK(map_.get() != nullptr) << file->GetPath(); + CHECK(map_->Begin() != nullptr) << file->GetPath(); header_ = reinterpret_cast(map_->Begin()); if ((ELFMAG0 != header_->e_ident[EI_MAG0]) @@ -425,7 +431,7 @@ bool ElfFileImpl::SetMap(MemMap* map, std::string* error_msg) { || (ELFMAG3 != header_->e_ident[EI_MAG3])) { *error_msg = StringPrintf("Failed to find ELF magic value %d %d %d %d in %s, found %d %d %d %d", ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, - file_->GetPath().c_str(), + file->GetPath().c_str(), header_->e_ident[EI_MAG0], header_->e_ident[EI_MAG1], header_->e_ident[EI_MAG2], @@ -436,90 +442,90 @@ bool ElfFileImpl::SetMap(MemMap* map, std::string* error_msg) { if (elf_class != header_->e_ident[EI_CLASS]) { *error_msg = StringPrintf("Failed to find expected EI_CLASS value %d in %s, found %d", elf_class, - file_->GetPath().c_str(), + file->GetPath().c_str(), header_->e_ident[EI_CLASS]); return false; } if (ELFDATA2LSB != header_->e_ident[EI_DATA]) { *error_msg = StringPrintf("Failed to find expected EI_DATA value %d in %s, found %d", ELFDATA2LSB, - file_->GetPath().c_str(), + file->GetPath().c_str(), header_->e_ident[EI_CLASS]); return false; } if (EV_CURRENT != header_->e_ident[EI_VERSION]) { *error_msg = StringPrintf("Failed to find expected EI_VERSION value %d in %s, found %d", EV_CURRENT, - file_->GetPath().c_str(), + file->GetPath().c_str(), header_->e_ident[EI_CLASS]); return false; } if (ET_DYN != header_->e_type) { *error_msg = StringPrintf("Failed to find expected e_type value %d in %s, found %d", ET_DYN, - file_->GetPath().c_str(), + file->GetPath().c_str(), header_->e_type); return false; } if (EV_CURRENT != header_->e_version) { *error_msg = StringPrintf("Failed to find expected e_version value %d in %s, found %d", EV_CURRENT, - file_->GetPath().c_str(), + file->GetPath().c_str(), header_->e_version); return false; } if (0 != header_->e_entry) { *error_msg = StringPrintf("Failed to find expected e_entry value %d in %s, found %d", 0, - file_->GetPath().c_str(), + file->GetPath().c_str(), static_cast(header_->e_entry)); return false; } if (0 == header_->e_phoff) { *error_msg = StringPrintf("Failed to find non-zero e_phoff value in %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (0 == header_->e_shoff) { *error_msg = StringPrintf("Failed to find non-zero e_shoff value in %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (0 == header_->e_ehsize) { *error_msg = StringPrintf("Failed to find non-zero e_ehsize value in %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (0 == header_->e_phentsize) { *error_msg = StringPrintf("Failed to find non-zero e_phentsize value in %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (0 == header_->e_phnum) { *error_msg = StringPrintf("Failed to find non-zero e_phnum value in %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (0 == header_->e_shentsize) { *error_msg = StringPrintf("Failed to find non-zero e_shentsize value in %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (0 == header_->e_shnum) { *error_msg = StringPrintf("Failed to find non-zero e_shnum value in %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (0 == header_->e_shstrndx) { *error_msg = StringPrintf("Failed to find non-zero e_shstrndx value in %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (header_->e_shstrndx >= header_->e_shnum) { *error_msg = StringPrintf("Failed to find e_shnum value %d less than %d in %s", header_->e_shstrndx, header_->e_shnum, - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } @@ -528,14 +534,14 @@ bool ElfFileImpl::SetMap(MemMap* map, std::string* error_msg) { *error_msg = StringPrintf("Failed to find e_phoff value %" PRIu64 " less than %zd in %s", static_cast(header_->e_phoff), Size(), - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (header_->e_shoff >= Size()) { *error_msg = StringPrintf("Failed to find e_shoff value %" PRIu64 " less than %zd in %s", static_cast(header_->e_shoff), Size(), - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } } @@ -577,7 +583,7 @@ typename ElfTypes::Dyn* ElfFileImpl::GetDynamicSectionStart() const { template typename ElfTypes::Sym* ElfFileImpl::GetSymbolSectionStart( Elf_Word section_type) const { - CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type; + CHECK(IsSymbolSectionType(section_type)) << file_path_ << " " << section_type; switch (section_type) { case SHT_SYMTAB: { return symtab_section_start_; @@ -597,7 +603,7 @@ typename ElfTypes::Sym* ElfFileImpl::GetSymbolSectionStart( template const char* ElfFileImpl::GetStringSectionStart( Elf_Word section_type) const { - CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type; + CHECK(IsSymbolSectionType(section_type)) << file_path_ << " " << section_type; switch (section_type) { case SHT_SYMTAB: { return strtab_section_start_; @@ -615,7 +621,7 @@ const char* ElfFileImpl::GetStringSectionStart( template const char* ElfFileImpl::GetString(Elf_Word section_type, Elf_Word i) const { - CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type; + CHECK(IsSymbolSectionType(section_type)) << file_path_ << " " << section_type; if (i == 0) { return nullptr; } @@ -673,7 +679,7 @@ typename ElfTypes::Word ElfFileImpl::GetProgramHeaderNum() const { template typename ElfTypes::Phdr* ElfFileImpl::GetProgramHeader(Elf_Word i) const { - CHECK_LT(i, GetProgramHeaderNum()) << file_->GetPath(); // Sanity check for caller. + CHECK_LT(i, GetProgramHeaderNum()) << file_path_; // Sanity check for caller. uint8_t* program_header = GetProgramHeadersStart() + (i * GetHeader().e_phentsize); if (program_header >= End()) { return nullptr; // Failure condition. @@ -701,7 +707,7 @@ template typename ElfTypes::Shdr* ElfFileImpl::GetSectionHeader(Elf_Word i) const { // Can only access arbitrary sections when we have the whole file, not just program header. // Even if we Load(), it doesn't bring in all the sections. - CHECK(!program_header_only_) << file_->GetPath(); + CHECK(!program_header_only_) << file_path_; if (i >= GetSectionHeaderNum()) { return nullptr; // Failure condition. } @@ -716,7 +722,7 @@ template typename ElfTypes::Shdr* ElfFileImpl::FindSectionByType(Elf_Word type) const { // Can only access arbitrary sections when we have the whole file, not just program header. // We could change this to switch on known types if they were detected during loading. - CHECK(!program_header_only_) << file_->GetPath(); + CHECK(!program_header_only_) << file_path_; for (Elf_Word i = 0; i < GetSectionHeaderNum(); i++) { Elf_Shdr* section_header = GetSectionHeader(i); if (section_header->sh_type == type) { @@ -802,8 +808,8 @@ bool ElfFileImpl::IsSymbolSectionType(Elf_Word section_type) { template typename ElfTypes::Word ElfFileImpl::GetSymbolNum(Elf_Shdr& section_header) const { CHECK(IsSymbolSectionType(section_header.sh_type)) - << file_->GetPath() << " " << section_header.sh_type; - CHECK_NE(0U, section_header.sh_entsize) << file_->GetPath(); + << file_path_ << " " << section_header.sh_type; + CHECK_NE(0U, section_header.sh_entsize) << file_path_; return section_header.sh_size / section_header.sh_entsize; } @@ -819,7 +825,7 @@ typename ElfTypes::Sym* ElfFileImpl::GetSymbol(Elf_Word section_type, template typename ElfFileImpl::SymbolTable** ElfFileImpl::GetSymbolTable(Elf_Word section_type) { - CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type; + CHECK(IsSymbolSectionType(section_type)) << file_path_ << " " << section_type; switch (section_type) { case SHT_SYMTAB: { return &symtab_symbol_table_; @@ -837,8 +843,8 @@ ElfFileImpl::GetSymbolTable(Elf_Word section_type) { template typename ElfTypes::Sym* ElfFileImpl::FindSymbolByName( Elf_Word section_type, const std::string& symbol_name, bool build_map) { - CHECK(!program_header_only_) << file_->GetPath(); - CHECK(IsSymbolSectionType(section_type)) << file_->GetPath() << " " << section_type; + CHECK(!program_header_only_) << file_path_; + CHECK(IsSymbolSectionType(section_type)) << file_path_ << " " << section_type; SymbolTable** symbol_table = GetSymbolTable(section_type); if (*symbol_table != nullptr || build_map) { @@ -928,7 +934,7 @@ typename ElfTypes::Addr ElfFileImpl::FindSymbolAddress( template const char* ElfFileImpl::GetString(Elf_Shdr& string_section, Elf_Word i) const { - CHECK(!program_header_only_) << file_->GetPath(); + CHECK(!program_header_only_) << file_path_; // TODO: remove this static_cast from enum when using -std=gnu++0x if (static_cast(SHT_STRTAB) != string_section.sh_type) { return nullptr; // Failure condition. @@ -954,7 +960,7 @@ typename ElfTypes::Word ElfFileImpl::GetDynamicNum() const { template typename ElfTypes::Dyn& ElfFileImpl::GetDynamic(Elf_Word i) const { - CHECK_LT(i, GetDynamicNum()) << file_->GetPath(); + CHECK_LT(i, GetDynamicNum()) << file_path_; return *(GetDynamicSectionStart() + i); } @@ -981,40 +987,40 @@ typename ElfTypes::Word ElfFileImpl::FindDynamicValueByType(Elf_Sword template typename ElfTypes::Rel* ElfFileImpl::GetRelSectionStart(Elf_Shdr& section_header) const { - CHECK(SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type; + CHECK(SHT_REL == section_header.sh_type) << file_path_ << " " << section_header.sh_type; return reinterpret_cast(Begin() + section_header.sh_offset); } template typename ElfTypes::Word ElfFileImpl::GetRelNum(Elf_Shdr& section_header) const { - CHECK(SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type; - CHECK_NE(0U, section_header.sh_entsize) << file_->GetPath(); + CHECK(SHT_REL == section_header.sh_type) << file_path_ << " " << section_header.sh_type; + CHECK_NE(0U, section_header.sh_entsize) << file_path_; return section_header.sh_size / section_header.sh_entsize; } template typename ElfTypes::Rel& ElfFileImpl::GetRel(Elf_Shdr& section_header, Elf_Word i) const { - CHECK(SHT_REL == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type; - CHECK_LT(i, GetRelNum(section_header)) << file_->GetPath(); + CHECK(SHT_REL == section_header.sh_type) << file_path_ << " " << section_header.sh_type; + CHECK_LT(i, GetRelNum(section_header)) << file_path_; return *(GetRelSectionStart(section_header) + i); } template typename ElfTypes::Rela* ElfFileImpl::GetRelaSectionStart(Elf_Shdr& section_header) const { - CHECK(SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type; + CHECK(SHT_RELA == section_header.sh_type) << file_path_ << " " << section_header.sh_type; return reinterpret_cast(Begin() + section_header.sh_offset); } template typename ElfTypes::Word ElfFileImpl::GetRelaNum(Elf_Shdr& section_header) const { - CHECK(SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type; + CHECK(SHT_RELA == section_header.sh_type) << file_path_ << " " << section_header.sh_type; return section_header.sh_size / section_header.sh_entsize; } template typename ElfTypes::Rela& ElfFileImpl::GetRela(Elf_Shdr& section_header, Elf_Word i) const { - CHECK(SHT_RELA == section_header.sh_type) << file_->GetPath() << " " << section_header.sh_type; - CHECK_LT(i, GetRelaNum(section_header)) << file_->GetPath(); + CHECK(SHT_RELA == section_header.sh_type) << file_path_ << " " << section_header.sh_type; + CHECK_LT(i, GetRelaNum(section_header)) << file_path_; return *(GetRelaSectionStart(section_header) + i); } @@ -1037,7 +1043,7 @@ bool ElfFileImpl::GetLoadedSize(size_t* size, std::string* error_msg) std::ostringstream oss; oss << "Program header #" << i << " has overflow in p_vaddr+p_memsz: 0x" << std::hex << program_header->p_vaddr << "+0x" << program_header->p_memsz << "=0x" << end_vaddr - << " in ELF file \"" << file_->GetPath() << "\""; + << " in ELF file \"" << file_path_ << "\""; *error_msg = oss.str(); *size = static_cast(-1); return false; @@ -1048,13 +1054,13 @@ bool ElfFileImpl::GetLoadedSize(size_t* size, std::string* error_msg) } min_vaddr = RoundDown(min_vaddr, kPageSize); max_vaddr = RoundUp(max_vaddr, kPageSize); - CHECK_LT(min_vaddr, max_vaddr) << file_->GetPath(); + CHECK_LT(min_vaddr, max_vaddr) << file_path_; Elf_Addr loaded_size = max_vaddr - min_vaddr; // Check that the loaded_size fits in size_t. if (UNLIKELY(loaded_size > std::numeric_limits::max())) { std::ostringstream oss; oss << "Loaded size is 0x" << std::hex << loaded_size << " but maximum size_t is 0x" - << std::numeric_limits::max() << " for ELF file \"" << file_->GetPath() << "\""; + << std::numeric_limits::max() << " for ELF file \"" << file_path_ << "\""; *error_msg = oss.str(); *size = static_cast(-1); return false; @@ -1064,8 +1070,11 @@ bool ElfFileImpl::GetLoadedSize(size_t* size, std::string* error_msg) } template -bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* error_msg) { - CHECK(program_header_only_) << file_->GetPath(); +bool ElfFileImpl::Load(File* file, + bool executable, + bool low_4gb, + std::string* error_msg) { + CHECK(program_header_only_) << file->GetPath(); if (executable) { InstructionSet elf_ISA = GetInstructionSetFromELF(GetHeader().e_machine, GetHeader().e_flags); @@ -1082,7 +1091,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err Elf_Phdr* program_header = GetProgramHeader(i); if (program_header == nullptr) { *error_msg = StringPrintf("No program header for entry %d in ELF file %s.", - i, file_->GetPath().c_str()); + i, file->GetPath().c_str()); return false; } @@ -1106,11 +1115,11 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err // non-zero, the segments require the specific address specified, // which either was specified in the file because we already set // base_address_ after the first zero segment). - int64_t temp_file_length = file_->GetLength(); + int64_t temp_file_length = file->GetLength(); if (temp_file_length < 0) { errno = -temp_file_length; *error_msg = StringPrintf("Failed to get length of file: '%s' fd=%d: %s", - file_->GetPath().c_str(), file_->Fd(), strerror(errno)); + file->GetPath().c_str(), file->Fd(), strerror(errno)); return false; } size_t file_length = static_cast(temp_file_length); @@ -1122,7 +1131,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err reserve_base_override = requested_base_; } std::string reservation_name("ElfFile reservation for "); - reservation_name += file_->GetPath(); + reservation_name += file->GetPath(); size_t loaded_size; if (!GetLoadedSize(&loaded_size, error_msg)) { DCHECK(!error_msg->empty()); @@ -1178,7 +1187,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err *error_msg = StringPrintf("Invalid p_filesz > p_memsz (%" PRIu64 " > %" PRIu64 "): %s", static_cast(program_header->p_filesz), static_cast(program_header->p_memsz), - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (program_header->p_filesz < program_header->p_memsz && @@ -1187,14 +1196,14 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err " < %" PRIu64 "): %s", static_cast(program_header->p_filesz), static_cast(program_header->p_memsz), - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (file_length < (program_header->p_offset + program_header->p_filesz)) { *error_msg = StringPrintf("File size of %zd bytes not large enough to contain ELF segment " "%d of %" PRIu64 " bytes: '%s'", file_length, i, static_cast(program_header->p_offset + program_header->p_filesz), - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } if (program_header->p_filesz != 0u) { @@ -1203,28 +1212,28 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err program_header->p_filesz, prot, flags, - file_->Fd(), + file->Fd(), program_header->p_offset, /*low4_gb*/false, /*reuse*/true, // implies MAP_FIXED - file_->GetPath().c_str(), + file->GetPath().c_str(), error_msg)); if (segment.get() == nullptr) { *error_msg = StringPrintf("Failed to map ELF file segment %d from %s: %s", - i, file_->GetPath().c_str(), error_msg->c_str()); + i, file->GetPath().c_str(), error_msg->c_str()); return false; } if (segment->Begin() != p_vaddr) { *error_msg = StringPrintf("Failed to map ELF file segment %d from %s at expected address %p, " "instead mapped to %p", - i, file_->GetPath().c_str(), p_vaddr, segment->Begin()); + i, file->GetPath().c_str(), p_vaddr, segment->Begin()); return false; } segments_.push_back(segment.release()); } if (program_header->p_filesz < program_header->p_memsz) { std::string name = StringPrintf("Zero-initialized segment %" PRIu64 " of ELF file %s", - static_cast(i), file_->GetPath().c_str()); + static_cast(i), file->GetPath().c_str()); std::unique_ptr segment( MemMap::MapAnonymous(name.c_str(), p_vaddr + program_header->p_filesz, @@ -1232,13 +1241,13 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err prot, false, true /* reuse */, error_msg)); if (segment == nullptr) { *error_msg = StringPrintf("Failed to map zero-initialized ELF file segment %d from %s: %s", - i, file_->GetPath().c_str(), error_msg->c_str()); + i, file->GetPath().c_str(), error_msg->c_str()); return false; } if (segment->Begin() != p_vaddr) { *error_msg = StringPrintf("Failed to map zero-initialized ELF file segment %d from %s " "at expected address %p, instead mapped to %p", - i, file_->GetPath().c_str(), p_vaddr, segment->Begin()); + i, file->GetPath().c_str(), p_vaddr, segment->Begin()); return false; } segments_.push_back(segment.release()); @@ -1249,7 +1258,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err uint8_t* dsptr = base_address_ + GetDynamicProgramHeader().p_vaddr; if ((dsptr < Begin() || dsptr >= End()) && !ValidPointer(dsptr)) { *error_msg = StringPrintf("dynamic section address invalid in ELF file %s", - file_->GetPath().c_str()); + file->GetPath().c_str()); return false; } dynamic_section_start_ = reinterpret_cast(dsptr); @@ -1261,7 +1270,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err case DT_HASH: { if (!ValidPointer(d_ptr)) { *error_msg = StringPrintf("DT_HASH value %p does not refer to a loaded ELF segment of %s", - d_ptr, file_->GetPath().c_str()); + d_ptr, file->GetPath().c_str()); return false; } hash_section_start_ = reinterpret_cast(d_ptr); @@ -1270,7 +1279,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err case DT_STRTAB: { if (!ValidPointer(d_ptr)) { *error_msg = StringPrintf("DT_HASH value %p does not refer to a loaded ELF segment of %s", - d_ptr, file_->GetPath().c_str()); + d_ptr, file->GetPath().c_str()); return false; } dynstr_section_start_ = reinterpret_cast(d_ptr); @@ -1279,7 +1288,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err case DT_SYMTAB: { if (!ValidPointer(d_ptr)) { *error_msg = StringPrintf("DT_HASH value %p does not refer to a loaded ELF segment of %s", - d_ptr, file_->GetPath().c_str()); + d_ptr, file->GetPath().c_str()); return false; } dynsym_section_start_ = reinterpret_cast(d_ptr); @@ -1289,7 +1298,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err if (GetDynamicNum() != i+1) { *error_msg = StringPrintf("DT_NULL found after %d .dynamic entries, " "expected %d as implied by size of PT_DYNAMIC segment in %s", - i + 1, GetDynamicNum(), file_->GetPath().c_str()); + i + 1, GetDynamicNum(), file->GetPath().c_str()); return false; } break; @@ -1298,7 +1307,7 @@ bool ElfFileImpl::Load(bool executable, bool low_4gb, std::string* err } // Check for the existence of some sections. - if (!CheckSectionsExist(error_msg)) { + if (!CheckSectionsExist(file, error_msg)) { return false; } @@ -1392,7 +1401,7 @@ void ElfFileImpl::ApplyOatPatches( } template -bool ElfFileImpl::Strip(std::string* error_msg) { +bool ElfFileImpl::Strip(File* file, std::string* error_msg) { // ELF files produced by MCLinker look roughly like this // // +------------+ @@ -1484,10 +1493,10 @@ bool ElfFileImpl::Strip(std::string* error_msg) { GetHeader().e_shnum = section_headers.size(); GetHeader().e_shoff = shoff; - int result = ftruncate(file_->Fd(), offset); + int result = ftruncate(file->Fd(), offset); if (result != 0) { *error_msg = StringPrintf("Failed to truncate while stripping ELF file: '%s': %s", - file_->GetPath().c_str(), strerror(errno)); + file->GetPath().c_str(), strerror(errno)); return false; } return true; @@ -1498,32 +1507,32 @@ static const bool DEBUG_FIXUP = false; template bool ElfFileImpl::Fixup(Elf_Addr base_address) { if (!FixupDynamic(base_address)) { - LOG(WARNING) << "Failed to fixup .dynamic in " << file_->GetPath(); + LOG(WARNING) << "Failed to fixup .dynamic in " << file_path_; return false; } if (!FixupSectionHeaders(base_address)) { - LOG(WARNING) << "Failed to fixup section headers in " << file_->GetPath(); + LOG(WARNING) << "Failed to fixup section headers in " << file_path_; return false; } if (!FixupProgramHeaders(base_address)) { - LOG(WARNING) << "Failed to fixup program headers in " << file_->GetPath(); + LOG(WARNING) << "Failed to fixup program headers in " << file_path_; return false; } if (!FixupSymbols(base_address, true)) { - LOG(WARNING) << "Failed to fixup .dynsym in " << file_->GetPath(); + LOG(WARNING) << "Failed to fixup .dynsym in " << file_path_; return false; } if (!FixupSymbols(base_address, false)) { - LOG(WARNING) << "Failed to fixup .symtab in " << file_->GetPath(); + LOG(WARNING) << "Failed to fixup .symtab in " << file_path_; return false; } if (!FixupRelocations(base_address)) { - LOG(WARNING) << "Failed to fixup .rel.dyn in " << file_->GetPath(); + LOG(WARNING) << "Failed to fixup .rel.dyn in " << file_path_; return false; } static_assert(sizeof(Elf_Off) >= sizeof(base_address), "Potentially losing precision."); if (!FixupDebugSections(static_cast(base_address))) { - LOG(WARNING) << "Failed to fixup debug sections in " << file_->GetPath(); + LOG(WARNING) << "Failed to fixup debug sections in " << file_path_; return false; } return true; @@ -1538,7 +1547,7 @@ bool ElfFileImpl::FixupDynamic(Elf_Addr base_address) { Elf_Addr d_ptr = elf_dyn.d_un.d_ptr; if (DEBUG_FIXUP) { LOG(INFO) << StringPrintf("In %s moving Elf_Dyn[%d] from 0x%" PRIx64 " to 0x%" PRIx64, - GetFile().GetPath().c_str(), i, + file_path_.c_str(), i, static_cast(d_ptr), static_cast(d_ptr + base_address)); } @@ -1560,7 +1569,7 @@ bool ElfFileImpl::FixupSectionHeaders(Elf_Addr base_address) { } if (DEBUG_FIXUP) { LOG(INFO) << StringPrintf("In %s moving Elf_Shdr[%d] from 0x%" PRIx64 " to 0x%" PRIx64, - GetFile().GetPath().c_str(), i, + file_path_.c_str(), i, static_cast(sh->sh_addr), static_cast(sh->sh_addr + base_address)); } @@ -1575,19 +1584,19 @@ bool ElfFileImpl::FixupProgramHeaders(Elf_Addr base_address) { for (Elf_Word i = 0; i < GetProgramHeaderNum(); i++) { Elf_Phdr* ph = GetProgramHeader(i); CHECK(ph != nullptr); - CHECK_EQ(ph->p_vaddr, ph->p_paddr) << GetFile().GetPath() << " i=" << i; + CHECK_EQ(ph->p_vaddr, ph->p_paddr) << file_path_ << " i=" << i; CHECK((ph->p_align == 0) || (0 == ((ph->p_vaddr - ph->p_offset) & (ph->p_align - 1)))) - << GetFile().GetPath() << " i=" << i; + << file_path_ << " i=" << i; if (DEBUG_FIXUP) { LOG(INFO) << StringPrintf("In %s moving Elf_Phdr[%d] from 0x%" PRIx64 " to 0x%" PRIx64, - GetFile().GetPath().c_str(), i, + file_path_.c_str(), i, static_cast(ph->p_vaddr), static_cast(ph->p_vaddr + base_address)); } ph->p_vaddr += base_address; ph->p_paddr += base_address; CHECK((ph->p_align == 0) || (0 == ((ph->p_vaddr - ph->p_offset) & (ph->p_align - 1)))) - << GetFile().GetPath() << " i=" << i; + << file_path_ << " i=" << i; } return true; } @@ -1599,7 +1608,7 @@ bool ElfFileImpl::FixupSymbols(Elf_Addr base_address, bool dynamic) { Elf_Shdr* symbol_section = FindSectionByType(section_type); if (symbol_section == nullptr) { // file is missing optional .symtab - CHECK(!dynamic) << GetFile().GetPath(); + CHECK(!dynamic) << file_path_; return true; } for (uint32_t i = 0; i < GetSymbolNum(*symbol_section); i++) { @@ -1608,7 +1617,7 @@ bool ElfFileImpl::FixupSymbols(Elf_Addr base_address, bool dynamic) { if (symbol->st_value != 0) { if (DEBUG_FIXUP) { LOG(INFO) << StringPrintf("In %s moving Elf_Sym[%d] from 0x%" PRIx64 " to 0x%" PRIx64, - GetFile().GetPath().c_str(), i, + file_path_.c_str(), i, static_cast(symbol->st_value), static_cast(symbol->st_value + base_address)); } @@ -1628,7 +1637,7 @@ bool ElfFileImpl::FixupRelocations(Elf_Addr base_address) { Elf_Rel& rel = GetRel(*sh, j); if (DEBUG_FIXUP) { LOG(INFO) << StringPrintf("In %s moving Elf_Rel[%d] from 0x%" PRIx64 " to 0x%" PRIx64, - GetFile().GetPath().c_str(), j, + file_path_.c_str(), j, static_cast(rel.r_offset), static_cast(rel.r_offset + base_address)); } @@ -1639,7 +1648,7 @@ bool ElfFileImpl::FixupRelocations(Elf_Addr base_address) { Elf_Rela& rela = GetRela(*sh, j); if (DEBUG_FIXUP) { LOG(INFO) << StringPrintf("In %s moving Elf_Rela[%d] from 0x%" PRIx64 " to 0x%" PRIx64, - GetFile().GetPath().c_str(), j, + file_path_.c_str(), j, static_cast(rela.r_offset), static_cast(rela.r_offset + base_address)); } @@ -1695,8 +1704,9 @@ ElfFile* ElfFile::Open(File* file, low_4gb, error_msg, requested_base); - if (elf_file_impl == nullptr) + if (elf_file_impl == nullptr) { return nullptr; + } return new ElfFile(elf_file_impl); } else if (header[EI_CLASS] == ELFCLASS32) { ElfFileImpl32* elf_file_impl = ElfFileImpl32::Open(file, @@ -1775,8 +1785,8 @@ ElfFile* ElfFile::Open(File* file, int mmap_prot, int mmap_flags, std::string* e return elf32_->func(__VA_ARGS__); \ } -bool ElfFile::Load(bool executable, bool low_4gb, std::string* error_msg) { - DELEGATE_TO_IMPL(Load, executable, low_4gb, error_msg); +bool ElfFile::Load(File* file, bool executable, bool low_4gb, std::string* error_msg) { + DELEGATE_TO_IMPL(Load, file, executable, low_4gb, error_msg); } const uint8_t* ElfFile::FindDynamicSymbolAddress(const std::string& symbol_name) const { @@ -1795,8 +1805,8 @@ uint8_t* ElfFile::End() const { DELEGATE_TO_IMPL(End); } -const File& ElfFile::GetFile() const { - DELEGATE_TO_IMPL(GetFile); +const std::string& ElfFile::GetFilePath() const { + DELEGATE_TO_IMPL(GetFilePath); } bool ElfFile::GetSectionOffsetAndSize(const char* section_name, uint64_t* offset, @@ -1854,10 +1864,11 @@ bool ElfFile::Strip(File* file, std::string* error_msg) { return false; } - if (elf_file->elf64_.get() != nullptr) - return elf_file->elf64_->Strip(error_msg); - else - return elf_file->elf32_->Strip(error_msg); + if (elf_file->elf64_.get() != nullptr) { + return elf_file->elf64_->Strip(file, error_msg); + } else { + return elf_file->elf32_->Strip(file, error_msg); + } } bool ElfFile::Fixup(uint64_t base_address) { diff --git a/runtime/elf_file.h b/runtime/elf_file.h index c3616f729..b1c9395fb 100644 --- a/runtime/elf_file.h +++ b/runtime/elf_file.h @@ -53,7 +53,7 @@ class ElfFile { ~ElfFile(); // Load segments into memory based on PT_LOAD program headers - bool Load(bool executable, bool low_4gb, std::string* error_msg); + bool Load(File* file, bool executable, bool low_4gb, std::string* error_msg); const uint8_t* FindDynamicSymbolAddress(const std::string& symbol_name) const; @@ -65,7 +65,7 @@ class ElfFile { // The end of the memory map address range for this ELF file. uint8_t* End() const; - const File& GetFile() const; + const std::string& GetFilePath() const; bool GetSectionOffsetAndSize(const char* section_name, uint64_t* offset, uint64_t* size) const; diff --git a/runtime/elf_file_impl.h b/runtime/elf_file_impl.h index 1cdbedc05..04c224387 100644 --- a/runtime/elf_file_impl.h +++ b/runtime/elf_file_impl.h @@ -61,8 +61,8 @@ class ElfFileImpl { std::string* error_msg); ~ElfFileImpl(); - const File& GetFile() const { - return *file_; + const std::string& GetFilePath() const { + return file_path_; } uint8_t* Begin() const { @@ -119,7 +119,7 @@ class ElfFileImpl { // Load segments into memory based on PT_LOAD program headers. // executable is true at run time, false at compile time. - bool Load(bool executable, bool low_4gb, std::string* error_msg); + bool Load(File* file, bool executable, bool low_4gb, std::string* error_msg); bool Fixup(Elf_Addr base_address); bool FixupDynamic(Elf_Addr base_address); @@ -132,14 +132,14 @@ class ElfFileImpl { static void ApplyOatPatches(const uint8_t* patches, const uint8_t* patches_end, Elf_Addr delta, uint8_t* to_patch, const uint8_t* to_patch_end); - bool Strip(std::string* error_msg); + bool Strip(File* file, std::string* error_msg); private: ElfFileImpl(File* file, bool writable, bool program_header_only, uint8_t* requested_base); - bool Setup(int prot, int flags, bool low_4gb, std::string* error_msg); + bool Setup(File* file, int prot, int flags, bool low_4gb, std::string* error_msg); - bool SetMap(MemMap* map, std::string* error_msg); + bool SetMap(File* file, MemMap* map, std::string* error_msg); uint8_t* GetProgramHeadersStart() const; uint8_t* GetSectionHeadersStart() const; @@ -163,7 +163,7 @@ class ElfFileImpl { const Elf_Sym* FindDynamicSymbol(const std::string& symbol_name) const; // Check that certain sections and their dependencies exist. - bool CheckSectionsExist(std::string* error_msg) const; + bool CheckSectionsExist(File* file, std::string* error_msg) const; // Check that the link of the first section links to the second section. bool CheckSectionsLinked(const uint8_t* source, const uint8_t* target) const; @@ -191,7 +191,7 @@ class ElfFileImpl { // Lookup a string by section type. Returns null for special 0 offset. const char* GetString(Elf_Word section_type, Elf_Word) const; - const File* const file_; + const std::string file_path_; const bool writable_; const bool program_header_only_; diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc index f164a92c9..c14b6169f 100644 --- a/runtime/oat_file.cc +++ b/runtime/oat_file.cc @@ -959,7 +959,7 @@ bool ElfOatFile::ElfFileOpen(File* file, DCHECK(!error_msg->empty()); return false; } - bool loaded = elf_file_->Load(executable, low_4gb, error_msg); + bool loaded = elf_file_->Load(file, executable, low_4gb, error_msg); DCHECK(loaded || !error_msg->empty()); return loaded; } diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 9c0d2db87..9024aaac9 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -829,7 +829,7 @@ static bool OpenDexFilesFromImage(const std::string& image_location, if (file.get() == nullptr) { return false; } - std::unique_ptr elf_file(ElfFile::Open(file.release(), + std::unique_ptr elf_file(ElfFile::Open(file.get(), false /* writable */, false /* program_header_only */, false /* low_4gb */, -- 2.11.0