diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/dex/arena_allocator.cc | 4 | ||||
-rw-r--r-- | compiler/elf_fixup.cc | 5 | ||||
-rw-r--r-- | compiler/elf_stripper.cc | 11 | ||||
-rw-r--r-- | compiler/elf_stripper.h | 4 | ||||
-rw-r--r-- | compiler/elf_writer.cc | 5 | ||||
-rw-r--r-- | compiler/elf_writer_test.cc | 17 | ||||
-rw-r--r-- | compiler/image_test.cc | 7 | ||||
-rw-r--r-- | compiler/image_writer.cc | 17 | ||||
-rw-r--r-- | compiler/oat_test.cc | 9 |
9 files changed, 50 insertions, 29 deletions
diff --git a/compiler/dex/arena_allocator.cc b/compiler/dex/arena_allocator.cc index 2da8064..95e44b3 100644 --- a/compiler/dex/arena_allocator.cc +++ b/compiler/dex/arena_allocator.cc @@ -50,7 +50,9 @@ Arena::Arena(size_t size) map_(nullptr), next_(nullptr) { if (kUseMemMap) { - map_ = MemMap::MapAnonymous("dalvik-arena", NULL, size, PROT_READ | PROT_WRITE); + std::string error_msg; + map_ = MemMap::MapAnonymous("dalvik-arena", NULL, size, PROT_READ | PROT_WRITE, &error_msg); + CHECK(map_ != nullptr) << error_msg; memory_ = map_->Begin(); size_ = map_->Size(); } else { diff --git a/compiler/elf_fixup.cc b/compiler/elf_fixup.cc index 359c493..c571288 100644 --- a/compiler/elf_fixup.cc +++ b/compiler/elf_fixup.cc @@ -27,8 +27,9 @@ namespace art { static const bool DEBUG_FIXUP = false; bool ElfFixup::Fixup(File* file, uintptr_t oat_data_begin) { - UniquePtr<ElfFile> elf_file(ElfFile::Open(file, true, false)); - CHECK(elf_file.get() != NULL); + std::string error_msg; + UniquePtr<ElfFile> elf_file(ElfFile::Open(file, true, false, &error_msg)); + CHECK(elf_file.get() != nullptr) << error_msg; // Lookup "oatdata" symbol address. ::llvm::ELF::Elf32_Addr oatdata_address = ElfWriter::GetOatDataAddress(elf_file.get()); diff --git a/compiler/elf_stripper.cc b/compiler/elf_stripper.cc index 7fc662c..7ee8d3c 100644 --- a/compiler/elf_stripper.cc +++ b/compiler/elf_stripper.cc @@ -27,9 +27,11 @@ namespace art { -bool ElfStripper::Strip(File* file) { - UniquePtr<ElfFile> elf_file(ElfFile::Open(file, true, false)); - CHECK(elf_file.get() != NULL); +bool ElfStripper::Strip(File* file, std::string* error_msg) { + UniquePtr<ElfFile> elf_file(ElfFile::Open(file, true, false, error_msg)); + if (elf_file.get() == nullptr) { + return false; + } // ELF files produced by MCLinker look roughly like this // @@ -120,7 +122,8 @@ bool ElfStripper::Strip(File* file) { elf_file->GetHeader().e_shoff = shoff; int result = ftruncate(file->Fd(), offset); if (result != 0) { - PLOG(ERROR) << "Failed to truncate while stripping ELF file: " << file->GetPath(); + *error_msg = StringPrintf("Failed to truncate while stripping ELF file: '%s': %s", + file->GetPath().c_str(), strerror(errno)); return false; } return true; diff --git a/compiler/elf_stripper.h b/compiler/elf_stripper.h index 6015b30..f1a1d46 100644 --- a/compiler/elf_stripper.h +++ b/compiler/elf_stripper.h @@ -17,6 +17,8 @@ #ifndef ART_COMPILER_ELF_STRIPPER_H_ #define ART_COMPILER_ELF_STRIPPER_H_ +#include <string> + #include "base/macros.h" #include "os.h" @@ -26,7 +28,7 @@ class ElfStripper { public: // Strip an ELF file of unneeded debugging information. // Returns true on success, false on failure. - static bool Strip(File* file); + static bool Strip(File* file, std::string* error_msg); private: DISALLOW_IMPLICIT_CONSTRUCTORS(ElfStripper); diff --git a/compiler/elf_writer.cc b/compiler/elf_writer.cc index d3c13dd..0bfe4a4 100644 --- a/compiler/elf_writer.cc +++ b/compiler/elf_writer.cc @@ -47,8 +47,9 @@ llvm::ELF::Elf32_Addr ElfWriter::GetOatDataAddress(ElfFile* elf_file) { void ElfWriter::GetOatElfInformation(File* file, size_t& oat_loaded_size, size_t& oat_data_offset) { - UniquePtr<ElfFile> elf_file(ElfFile::Open(file, false, false)); - CHECK(elf_file.get() != NULL); + std::string error_msg; + UniquePtr<ElfFile> elf_file(ElfFile::Open(file, false, false, &error_msg)); + CHECK(elf_file.get() != NULL) << error_msg; oat_loaded_size = elf_file->GetLoadedSize(); CHECK_NE(0U, oat_loaded_size); diff --git a/compiler/elf_writer_test.cc b/compiler/elf_writer_test.cc index ffe1f72..eca67a8 100644 --- a/compiler/elf_writer_test.cc +++ b/compiler/elf_writer_test.cc @@ -65,23 +65,26 @@ TEST_F(ElfWriterTest, dlsym) { UniquePtr<File> file(OS::OpenFileForReading(elf_filename.c_str())); ASSERT_TRUE(file.get() != NULL); { - UniquePtr<ElfFile> ef(ElfFile::Open(file.get(), false, false)); - CHECK(ef.get() != NULL); + std::string error_msg; + UniquePtr<ElfFile> ef(ElfFile::Open(file.get(), false, false, &error_msg)); + CHECK(ef.get() != nullptr) << error_msg; EXPECT_ELF_FILE_ADDRESS(ef, dl_oatdata, "oatdata", false); EXPECT_ELF_FILE_ADDRESS(ef, dl_oatexec, "oatexec", false); EXPECT_ELF_FILE_ADDRESS(ef, dl_oatlastword, "oatlastword", false); } { - UniquePtr<ElfFile> ef(ElfFile::Open(file.get(), false, false)); - CHECK(ef.get() != NULL); + std::string error_msg; + UniquePtr<ElfFile> ef(ElfFile::Open(file.get(), false, false, &error_msg)); + CHECK(ef.get() != nullptr) << error_msg; EXPECT_ELF_FILE_ADDRESS(ef, dl_oatdata, "oatdata", true); EXPECT_ELF_FILE_ADDRESS(ef, dl_oatexec, "oatexec", true); EXPECT_ELF_FILE_ADDRESS(ef, dl_oatlastword, "oatlastword", true); } { - UniquePtr<ElfFile> ef(ElfFile::Open(file.get(), false, true)); - CHECK(ef.get() != NULL); - ef->Load(false); + std::string error_msg; + UniquePtr<ElfFile> ef(ElfFile::Open(file.get(), false, true, &error_msg)); + CHECK(ef.get() != nullptr) << error_msg; + CHECK(ef->Load(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/compiler/image_test.cc b/compiler/image_test.cc index d4be7c0..a8b7c88 100644 --- a/compiler/image_test.cc +++ b/compiler/image_test.cc @@ -112,8 +112,11 @@ TEST_F(ImageTest, WriteRead) { runtime_.reset(); java_lang_dex_file_ = NULL; - UniquePtr<const DexFile> dex(DexFile::Open(GetLibCoreDexFileName(), GetLibCoreDexFileName())); - ASSERT_TRUE(dex.get() != NULL); + std::string error_msg; + UniquePtr<const DexFile> dex(DexFile::Open(GetLibCoreDexFileName().c_str(), + GetLibCoreDexFileName().c_str(), + &error_msg)); + ASSERT_TRUE(dex.get() != nullptr) << error_msg; // Remove the reservation of the memory for use to load the image. UnreserveImageSpace(); diff --git a/compiler/image_writer.cc b/compiler/image_writer.cc index bcdc1c1..871cfd5 100644 --- a/compiler/image_writer.cc +++ b/compiler/image_writer.cc @@ -82,12 +82,14 @@ bool ImageWriter::Write(const std::string& image_filename, LOG(ERROR) << "Failed to open oat file " << oat_filename << " for " << oat_location; return false; } - oat_file_ = OatFile::OpenWritable(oat_file.get(), oat_location); - if (oat_file_ == NULL) { - LOG(ERROR) << "Failed to open writable oat file " << oat_filename << " for " << oat_location; + std::string error_msg; + oat_file_ = OatFile::OpenWritable(oat_file.get(), oat_location, &error_msg); + if (oat_file_ == nullptr) { + LOG(ERROR) << "Failed to open writable oat file " << oat_filename << " for " << oat_location + << ": " << error_msg; return false; } - class_linker->RegisterOatFile(*oat_file_); + CHECK_EQ(class_linker->RegisterOatFile(oat_file_), oat_file_); interpreter_to_interpreter_bridge_offset_ = oat_file_->GetOatHeader().GetInterpreterToInterpreterBridgeOffset(); @@ -192,9 +194,10 @@ bool ImageWriter::AllocMemory() { int prot = PROT_READ | PROT_WRITE; size_t length = RoundUp(size, kPageSize); - image_.reset(MemMap::MapAnonymous("image writer image", NULL, length, prot)); - if (image_.get() == NULL) { - LOG(ERROR) << "Failed to allocate memory for image file generation"; + std::string error_msg; + image_.reset(MemMap::MapAnonymous("image writer image", NULL, length, prot, &error_msg)); + if (UNLIKELY(image_.get() == nullptr)) { + LOG(ERROR) << "Failed to allocate memory for image file generation: " << error_msg; return false; } return true; diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc index 6ac5d6a..634a160 100644 --- a/compiler/oat_test.cc +++ b/compiler/oat_test.cc @@ -100,8 +100,10 @@ TEST_F(OatTest, WriteRead) { base::TimingLogger timings("CommonTest::WriteRead", false, false); compiler_driver_->CompileAll(class_loader, class_linker->GetBootClassPath(), timings); } - UniquePtr<OatFile> oat_file(OatFile::Open(tmp.GetFilename(), tmp.GetFilename(), NULL, false)); - ASSERT_TRUE(oat_file.get() != NULL); + std::string error_msg; + UniquePtr<OatFile> oat_file(OatFile::Open(tmp.GetFilename(), tmp.GetFilename(), NULL, false, + &error_msg)); + ASSERT_TRUE(oat_file.get() != nullptr) << error_msg; const OatHeader& oat_header = oat_file->GetOatHeader(); ASSERT_TRUE(oat_header.IsValid()); ASSERT_EQ(1U, oat_header.GetDexFileCount()); // core @@ -111,8 +113,9 @@ TEST_F(OatTest, WriteRead) { const DexFile* dex_file = java_lang_dex_file_; uint32_t dex_file_checksum = dex_file->GetLocationChecksum(); - const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_file->GetLocation(), + const OatFile::OatDexFile* oat_dex_file = oat_file->GetOatDexFile(dex_file->GetLocation().c_str(), &dex_file_checksum); + ASSERT_TRUE(oat_dex_file != nullptr); CHECK_EQ(dex_file->GetLocationChecksum(), oat_dex_file->GetDexFileLocationChecksum()); for (size_t i = 0; i < dex_file->NumClassDefs(); i++) { const DexFile::ClassDef& class_def = dex_file->GetClassDef(i); |