diff options
| -rw-r--r-- | runtime/class_linker.cc | 10 | ||||
| -rw-r--r-- | runtime/elf_file.cc | 14 |
2 files changed, 23 insertions, 1 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 1f4cf8fcfc..a225f60291 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -21,6 +21,7 @@ #include <memory> #include <queue> #include <string> +#include <unistd.h> #include <utility> #include <vector> @@ -704,7 +705,14 @@ bool ClassLinker::GenerateOatFile(const char* dex_filename, argv.push_back(compiler_options[i].c_str()); } - return Exec(argv, error_msg); + if (!Exec(argv, error_msg)) { + // Manually delete the file. Ensures there is no garbage left over if the process unexpectedly + // died. Ignore unlink failure, propagate the original error. + TEMP_FAILURE_RETRY(unlink(oat_cache_filename)); + return false; + } + + return true; } const OatFile* ClassLinker::RegisterOatFile(const OatFile* oat_file) { diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc index 65972359e8..4198905e23 100644 --- a/runtime/elf_file.cc +++ b/runtime/elf_file.cc @@ -488,6 +488,20 @@ bool ElfFileImpl<Elf_Ehdr, Elf_Phdr, Elf_Shdr, Elf_Word, return false; } + // We'd also like to confirm a shstrtab in program_header_only_ mode (else Open() does this for + // us). This is usually the last in an oat file, and a good indicator of whether writing was + // successful (or the process crashed and left garbage). + if (program_header_only_) { + // It might not be mapped, but we can compare against the file size. + int64_t offset = static_cast<int64_t>(GetHeader().e_shoff + + (GetHeader().e_shstrndx * GetHeader().e_shentsize)); + if (offset >= file_->GetLength()) { + *error_msg = StringPrintf("Shstrtab is not in the mapped ELF file: '%s'", + file_->GetPath().c_str()); + return false; + } + } + return true; } |