summaryrefslogtreecommitdiff
path: root/oatdump/oatdump.cc
diff options
context:
space:
mode:
Diffstat (limited to 'oatdump/oatdump.cc')
-rw-r--r--oatdump/oatdump.cc98
1 files changed, 48 insertions, 50 deletions
diff --git a/oatdump/oatdump.cc b/oatdump/oatdump.cc
index ea61b43627..94eb82b054 100644
--- a/oatdump/oatdump.cc
+++ b/oatdump/oatdump.cc
@@ -98,33 +98,6 @@ const DexFile* OpenDexFile(const OatFile::OatDexFile* oat_dex_file, std::string*
class OatSymbolizer FINAL {
public:
- class RodataWriter FINAL : public CodeOutput {
- public:
- explicit RodataWriter(const OatFile* oat_file) : oat_file_(oat_file) {}
-
- bool Write(OutputStream* out) OVERRIDE {
- const size_t rodata_size = oat_file_->GetOatHeader().GetExecutableOffset();
- return out->WriteFully(oat_file_->Begin(), rodata_size);
- }
-
- private:
- const OatFile* oat_file_;
- };
-
- class TextWriter FINAL : public CodeOutput {
- public:
- explicit TextWriter(const OatFile* oat_file) : oat_file_(oat_file) {}
-
- bool Write(OutputStream* out) OVERRIDE {
- const size_t rodata_size = oat_file_->GetOatHeader().GetExecutableOffset();
- const uint8_t* text_begin = oat_file_->Begin() + rodata_size;
- return out->WriteFully(text_begin, oat_file_->End() - text_begin);
- }
-
- private:
- const OatFile* oat_file_;
- };
-
OatSymbolizer(const OatFile* oat_file, const std::string& output_name) :
oat_file_(oat_file), builder_(nullptr),
output_name_(output_name.empty() ? "symbolized.oat" : output_name) {
@@ -139,31 +112,57 @@ class OatSymbolizer FINAL {
uint32_t);
bool Symbolize() {
- Elf32_Word rodata_size = oat_file_->GetOatHeader().GetExecutableOffset();
- uint32_t size = static_cast<uint32_t>(oat_file_->End() - oat_file_->Begin());
- uint32_t text_size = size - rodata_size;
- uint32_t bss_size = oat_file_->BssSize();
- RodataWriter rodata_writer(oat_file_);
- TextWriter text_writer(oat_file_);
- builder_.reset(new ElfBuilder<ElfTypes32>(
- oat_file_->GetOatHeader().GetInstructionSet(),
- rodata_size, &rodata_writer,
- text_size, &text_writer,
- bss_size));
+ const InstructionSet isa = oat_file_->GetOatHeader().GetInstructionSet();
+
+ File* elf_file = OS::CreateEmptyFile(output_name_.c_str());
+ std::unique_ptr<BufferedOutputStream> output_stream(
+ new BufferedOutputStream(new FileOutputStream(elf_file)));
+ builder_.reset(new ElfBuilder<ElfTypes32>(isa, output_stream.get()));
+
+ builder_->Start();
+
+ auto* rodata = builder_->GetRoData();
+ auto* text = builder_->GetText();
+ auto* bss = builder_->GetBss();
+ auto* strtab = builder_->GetStrTab();
+ auto* symtab = builder_->GetSymTab();
+
+ rodata->Start();
+ const uint8_t* rodata_begin = oat_file_->Begin();
+ const size_t rodata_size = oat_file_->GetOatHeader().GetExecutableOffset();
+ rodata->WriteFully(rodata_begin, rodata_size);
+ rodata->End();
+
+ text->Start();
+ const uint8_t* text_begin = oat_file_->Begin() + rodata_size;
+ const size_t text_size = oat_file_->End() - text_begin;
+ text->WriteFully(text_begin, text_size);
+ text->End();
+
+ if (oat_file_->BssSize() != 0) {
+ bss->Start();
+ bss->SetSize(oat_file_->BssSize());
+ bss->End();
+ }
+
+ builder_->WriteDynamicSection(elf_file->GetPath());
Walk(&art::OatSymbolizer::RegisterForDedup);
NormalizeState();
+ strtab->Start();
+ strtab->Write(""); // strtab should start with empty string.
Walk(&art::OatSymbolizer::AddSymbol);
+ strtab->End();
- File* elf_output = OS::CreateEmptyFile(output_name_.c_str());
- bool result = builder_->Write(elf_output);
+ symtab->Start();
+ symtab->Write();
+ symtab->End();
- // Ignore I/O errors.
- UNUSED(elf_output->FlushClose());
+ builder_->End();
- return result;
+ return builder_->Good() && output_stream->Flush();
}
void Walk(Callback callback) {
@@ -295,9 +294,8 @@ class OatSymbolizer FINAL {
pretty_name = "[Dedup]" + pretty_name;
}
- auto* symtab = builder_->GetSymtab();
-
- symtab->AddSymbol(pretty_name, builder_->GetText(),
+ int name_offset = builder_->GetStrTab()->Write(pretty_name);
+ builder_->GetSymTab()->Add(name_offset, builder_->GetText(),
oat_method.GetCodeOffset() - oat_file_->GetOatHeader().GetExecutableOffset(),
true, oat_method.GetQuickCodeSize(), STB_GLOBAL, STT_FUNC);
}
@@ -1620,9 +1618,9 @@ class ImageDumper {
dex_caches_.clear();
{
ReaderMutexLock mu(self, *class_linker->DexLock());
- for (jobject weak_root : class_linker->GetDexCaches()) {
+ for (const ClassLinker::DexCacheData& data : class_linker->GetDexCachesData()) {
mirror::DexCache* dex_cache =
- down_cast<mirror::DexCache*>(self->DecodeJObject(weak_root));
+ down_cast<mirror::DexCache*>(self->DecodeJObject(data.weak_root));
if (dex_cache != nullptr) {
dex_caches_.insert(dex_cache);
}
@@ -2376,7 +2374,7 @@ static int DumpImage(Runtime* runtime, const char* image_location, OatDumperOpti
ScopedObjectAccess soa(Thread::Current());
gc::Heap* heap = runtime->GetHeap();
- gc::space::ImageSpace* image_space = heap->GetImageSpace();
+ gc::space::ImageSpace* image_space = heap->GetBootImageSpace();
CHECK(image_space != nullptr);
const ImageHeader& image_header = image_space->GetImageHeader();
if (!image_header.IsValid()) {
@@ -2414,7 +2412,7 @@ static int DumpOatWithRuntime(Runtime* runtime, OatFile* oat_file, OatDumperOpti
// Need a class loader.
// Fake that we're a compiler.
- jobject class_loader = class_linker->CreatePathClassLoader(self, class_path);
+ jobject class_loader = class_linker->CreatePathClassLoader(self, class_path, /*parent*/nullptr);
// Use the class loader while dumping.
StackHandleScope<1> scope(self);