Skip to content

Commit

Permalink
Use ElfFile instead of dlopen for Quick
Browse files Browse the repository at this point in the history
Bug: 10614658
Change-Id: I6a7e2cb0960a5d468a55d220c3fafa80bc239fa9
  • Loading branch information
bdcgoogle committed Oct 4, 2013
1 parent 7c3d13a commit eeb9888
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions runtime/elf_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,17 @@ bool ElfFile::Setup(File* file, bool writable, bool program_header_only) {
return false;
}
if (file_length < sizeof(llvm::ELF::Elf32_Ehdr)) {
LOG(WARNING) << "File not large enough to contain ELF header: " << file_->GetPath();
if (writable) {
LOG(WARNING) << "File size " << file_length
<< " not large enough to contain ELF header: " << file_->GetPath();
}
return false;
}

if (program_header_only) {
// first just map ELF header to get program header size information
size_t elf_header_size = sizeof(llvm::ELF::Elf32_Ehdr);
if (!SetMap(MemMap::MapFile(elf_header_size, prot, flags, file_->Fd(), 0))) {
LOG(WARNING) << "Failed to map ELF header: " << file_->GetPath();
return false;
}
// then remap to cover program header
Expand Down
12 changes: 10 additions & 2 deletions runtime/oat_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ OatFile* OatFile::Open(const std::string& filename,
bool executable) {
CHECK(!filename.empty()) << location;
CheckLocation(filename);
// If we are trying to execute, we need to use dlopen.
#ifdef ART_USE_PORTABLE_COMPILER
// If we are using PORTABLE, use dlopen to deal with relocations.
//
// We use our own ELF loader for Quick to deal with legacy apps that
// open a generated dex file by name, remove the file, then open
// another generated dex file with the same name. http://b/10614658
if (executable) {
return OpenDlopen(filename, location, requested_base);
}
#endif
// If we aren't trying to execute, we just use our own ElfFile loader for a couple reasons:
//
// On target, dlopen may fail when compiling due to selinux restrictions on installd.
Expand Down Expand Up @@ -160,7 +166,9 @@ bool OatFile::Dlopen(const std::string& elf_filename, byte* requested_base) {
bool OatFile::ElfFileOpen(File* file, byte* requested_base, bool writable, bool executable) {
elf_file_.reset(ElfFile::Open(file, writable, true));
if (elf_file_.get() == NULL) {
PLOG(WARNING) << "Failed to create ELF file for " << file->GetPath();
if (writable) {
PLOG(WARNING) << "Failed to open ELF file for " << file->GetPath();
}
return false;
}
bool loaded = elf_file_->Load(executable);
Expand Down

0 comments on commit eeb9888

Please sign in to comment.