summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2014-10-16 20:31:53 -0700
committerIan Rogers <irogers@google.com>2014-10-16 21:30:37 -0700
commitd4c4d953035d4418126d36517e402f411d6a87f3 (patch)
tree735aacf812bbac7c1ae7c0788c1ca6f58cfa82ee
parent6f3dbbadf4ce66982eb3d400e0a74cb73eb034f3 (diff)
downloadart-d4c4d953035d4418126d36517e402f411d6a87f3.tar.gz
art-d4c4d953035d4418126d36517e402f411d6a87f3.tar.bz2
art-d4c4d953035d4418126d36517e402f411d6a87f3.zip
Some code clean-up.
Change-Id: I4b745fd5298cd61c793e3b57514b48347bd66c0e
-rw-r--r--compiler/common_compiler_test.cc5
-rw-r--r--compiler/driver/compiler_driver.cc2
-rw-r--r--compiler/driver/compiler_driver.h2
-rw-r--r--compiler/elf_writer_test.cc1
-rw-r--r--compiler/oat_test.cc22
-rw-r--r--compiler/trampolines/trampoline_compiler.cc4
-rw-r--r--patchoat/patchoat.cc14
-rw-r--r--patchoat/patchoat.h20
-rw-r--r--runtime/elf_file.cc119
-rw-r--r--runtime/elf_file.h40
-rw-r--r--runtime/elf_file_impl.h14
-rw-r--r--runtime/elf_utils.h4
-rw-r--r--runtime/memory_region.h5
-rw-r--r--runtime/runtime.cc1
14 files changed, 131 insertions, 122 deletions
diff --git a/compiler/common_compiler_test.cc b/compiler/common_compiler_test.cc
index 9a5f74db91..359d6af57d 100644
--- a/compiler/common_compiler_test.cc
+++ b/compiler/common_compiler_test.cc
@@ -150,8 +150,7 @@ void CommonCompilerTest::SetUp() {
}
// TODO: make selectable
- Compiler::Kind compiler_kind
- = (kUsePortableCompiler) ? Compiler::kPortable : Compiler::kQuick;
+ Compiler::Kind compiler_kind = kUsePortableCompiler ? Compiler::kPortable : Compiler::kQuick;
timer_.reset(new CumulativeLogger("Compilation times"));
compiler_driver_.reset(new CompilerDriver(compiler_options_.get(),
verification_results_.get(),
@@ -159,7 +158,7 @@ void CommonCompilerTest::SetUp() {
compiler_kind, instruction_set,
instruction_set_features_.get(),
true, new std::set<std::string>,
- 2, true, true, timer_.get()));
+ 2, true, true, timer_.get(), ""));
}
// We typically don't generate an image in unit tests, disable this optimization by default.
compiler_driver_->SetSupportBootImageFixup(false);
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index aac33d289f..4b1063f37b 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -332,7 +332,7 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options,
const InstructionSetFeatures* instruction_set_features,
bool image, std::set<std::string>* image_classes, size_t thread_count,
bool dump_stats, bool dump_passes, CumulativeLogger* timer,
- std::string profile_file)
+ const std::string& profile_file)
: profile_present_(false), compiler_options_(compiler_options),
verification_results_(verification_results),
method_inliner_map_(method_inliner_map),
diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h
index 0425d272dd..74f6835750 100644
--- a/compiler/driver/compiler_driver.h
+++ b/compiler/driver/compiler_driver.h
@@ -91,7 +91,7 @@ class CompilerDriver {
const InstructionSetFeatures* instruction_set_features,
bool image, std::set<std::string>* image_classes,
size_t thread_count, bool dump_stats, bool dump_passes,
- CumulativeLogger* timer, std::string profile_file = "");
+ CumulativeLogger* timer, const std::string& profile_file);
~CompilerDriver();
diff --git a/compiler/elf_writer_test.cc b/compiler/elf_writer_test.cc
index e479322238..2ffbd10eab 100644
--- a/compiler/elf_writer_test.cc
+++ b/compiler/elf_writer_test.cc
@@ -17,6 +17,7 @@
#include "elf_file.h"
#include "base/stringprintf.h"
+#include "base/unix_file/fd_file.h"
#include "common_compiler_test.h"
#include "oat.h"
#include "utils.h"
diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc
index a9d30b65f9..847fa0d08f 100644
--- a/compiler/oat_test.cc
+++ b/compiler/oat_test.cc
@@ -44,11 +44,11 @@ class OatTest : public CommonCompilerTest {
compiler_driver_->GetCompiledMethod(MethodReference(dex_file,
method->GetDexMethodIndex()));
- if (compiled_method == NULL) {
- EXPECT_TRUE(oat_method.GetQuickCode() == NULL) << PrettyMethod(method) << " "
- << oat_method.GetQuickCode();
- EXPECT_TRUE(oat_method.GetPortableCode() == NULL) << PrettyMethod(method) << " "
- << oat_method.GetPortableCode();
+ if (compiled_method == nullptr) {
+ EXPECT_TRUE(oat_method.GetQuickCode() == nullptr) << PrettyMethod(method) << " "
+ << oat_method.GetQuickCode();
+ EXPECT_TRUE(oat_method.GetPortableCode() == nullptr) << PrettyMethod(method) << " "
+ << oat_method.GetPortableCode();
EXPECT_EQ(oat_method.GetFrameSizeInBytes(), 0U);
EXPECT_EQ(oat_method.GetCoreSpillMask(), 0U);
EXPECT_EQ(oat_method.GetFpSpillMask(), 0U);
@@ -109,9 +109,9 @@ TEST_F(OatTest, WriteRead) {
verification_results_.get(),
method_inliner_map_.get(),
compiler_kind, insn_set,
- insn_features.get(), false, NULL, 2, true, true,
- timer_.get()));
- jobject class_loader = NULL;
+ insn_features.get(), false, nullptr, 2, true, true,
+ timer_.get(), ""));
+ jobject class_loader = nullptr;
if (kCompile) {
TimingLogger timings("OatTest::WriteRead", false, false);
compiler_driver_->CompileAll(class_loader, class_linker->GetBootClassPath(), &timings);
@@ -138,8 +138,8 @@ TEST_F(OatTest, WriteRead) {
if (kCompile) { // OatWriter strips the code, regenerate to compare
compiler_driver_->CompileAll(class_loader, class_linker->GetBootClassPath(), &timings);
}
- std::unique_ptr<OatFile> oat_file(OatFile::Open(tmp.GetFilename(), tmp.GetFilename(), NULL, false,
- &error_msg));
+ std::unique_ptr<OatFile> oat_file(OatFile::Open(tmp.GetFilename(), tmp.GetFilename(), nullptr,
+ false, &error_msg));
ASSERT_TRUE(oat_file.get() != nullptr) << error_msg;
const OatHeader& oat_header = oat_file->GetOatHeader();
ASSERT_TRUE(oat_header.IsValid());
@@ -159,7 +159,7 @@ TEST_F(OatTest, WriteRead) {
const DexFile::ClassDef& class_def = dex_file->GetClassDef(i);
const uint8_t* class_data = dex_file->GetClassData(class_def);
size_t num_virtual_methods = 0;
- if (class_data != NULL) {
+ if (class_data != nullptr) {
ClassDataItemIterator it(*dex_file, class_data);
num_virtual_methods = it.NumVirtualMethods();
}
diff --git a/compiler/trampolines/trampoline_compiler.cc b/compiler/trampolines/trampoline_compiler.cc
index 6da375aef0..e793c6b12c 100644
--- a/compiler/trampolines/trampoline_compiler.cc
+++ b/compiler/trampolines/trampoline_compiler.cc
@@ -166,7 +166,7 @@ const std::vector<uint8_t>* CreateTrampoline64(InstructionSet isa, EntryPointCal
return x86_64::CreateTrampoline(offset);
default:
LOG(FATAL) << "Unexpected InstructionSet: " << isa;
- return nullptr;
+ UNREACHABLE();
}
}
@@ -182,7 +182,7 @@ const std::vector<uint8_t>* CreateTrampoline32(InstructionSet isa, EntryPointCal
return x86::CreateTrampoline(offset);
default:
LOG(FATAL) << "Unexpected InstructionSet: " << isa;
- return nullptr;
+ UNREACHABLE();
}
}
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc
index 504addc054..c0c96e5ac3 100644
--- a/patchoat/patchoat.cc
+++ b/patchoat/patchoat.cc
@@ -27,6 +27,7 @@
#include "base/scoped_flock.h"
#include "base/stringpiece.h"
#include "base/stringprintf.h"
+#include "base/unix_file/fd_file.h"
#include "elf_utils.h"
#include "elf_file.h"
#include "elf_file_impl.h"
@@ -513,7 +514,7 @@ bool PatchOat::PatchOatHeader(ElfFileImpl* oat_file) {
}
bool PatchOat::PatchElf() {
- if (oat_file_->is_elf64_)
+ if (oat_file_->Is64Bit())
return PatchElf<ElfFileImpl64>(oat_file_->GetImpl64());
else
return PatchElf<ElfFileImpl32>(oat_file_->GetImpl32());
@@ -531,13 +532,12 @@ bool PatchOat::PatchElf(ElfFileImpl* oat_file) {
}
bool need_fixup = false;
- for (unsigned int i = 0; i < oat_file->GetProgramHeaderNum(); i++) {
+ for (unsigned int i = 0; i < oat_file->GetProgramHeaderNum(); ++i) {
auto hdr = oat_file->GetProgramHeader(i);
- if (hdr->p_vaddr != 0 && hdr->p_vaddr != hdr->p_offset) {
- need_fixup = true;
- }
- if (hdr->p_paddr != 0 && hdr->p_paddr != hdr->p_offset) {
+ if ((hdr->p_vaddr != 0 && hdr->p_vaddr != hdr->p_offset) ||
+ (hdr->p_paddr != 0 && hdr->p_paddr != hdr->p_offset)) {
need_fixup = true;
+ break;
}
}
if (!need_fixup) {
@@ -801,7 +801,7 @@ static int patchoat(int argc, char **argv) {
bool dump_timings = kIsDebugBuild;
bool lock_output = true;
- for (int i = 0; i < argc; i++) {
+ for (int i = 0; i < argc; ++i) {
const StringPiece option(argv[i]);
const bool log_options = false;
if (log_options) {
diff --git a/patchoat/patchoat.h b/patchoat/patchoat.h
index 7dd95f5d6b..fd36ad59a3 100644
--- a/patchoat/patchoat.h
+++ b/patchoat/patchoat.h
@@ -52,7 +52,8 @@ class PatchOat {
private:
// Takes ownership only of the ElfFile. All other pointers are only borrowed.
PatchOat(ElfFile* oat_file, off_t delta, TimingLogger* timings)
- : oat_file_(oat_file), delta_(delta), timings_(timings) {}
+ : oat_file_(oat_file), image_(nullptr), bitmap_(nullptr), heap_(nullptr), delta_(delta),
+ timings_(timings) {}
PatchOat(MemMap* image, gc::accounting::ContinuousSpaceBitmap* bitmap,
MemMap* heap, off_t delta, TimingLogger* timings)
: image_(image), bitmap_(bitmap), heap_(heap),
@@ -106,21 +107,22 @@ class PatchOat {
void operator() (mirror::Class* cls, mirror::Reference* ref) const
EXCLUSIVE_LOCKS_REQUIRED(Locks::mutator_lock_, Locks::heap_bitmap_lock_);
private:
- PatchOat* patcher_;
- mirror::Object* copy_;
+ PatchOat* const patcher_;
+ mirror::Object* const copy_;
};
// The elf file we are patching.
std::unique_ptr<ElfFile> oat_file_;
// A mmap of the image we are patching. This is modified.
- const MemMap* image_;
+ const MemMap* const image_;
+ // The bitmap over the image within the heap we are patching. This is not modified.
+ gc::accounting::ContinuousSpaceBitmap* const bitmap_;
// The heap we are patching. This is not modified.
- gc::accounting::ContinuousSpaceBitmap* bitmap_;
- // The heap we are patching. This is not modified.
- const MemMap* heap_;
+ const MemMap* const heap_;
// The amount we are changing the offset by.
- off_t delta_;
- TimingLogger* timings_;
+ const off_t delta_;
+ // Timing splits.
+ TimingLogger* const timings_;
DISALLOW_IMPLICIT_CONSTRUCTORS(PatchOat);
};
diff --git a/runtime/elf_file.cc b/runtime/elf_file.cc
index c3a25595cd..18053c3fb9 100644
--- a/runtime/elf_file.cc
+++ b/runtime/elf_file.cc
@@ -23,7 +23,10 @@
#include "base/logging.h"
#include "base/stringprintf.h"
#include "base/stl_util.h"
+#include "base/unix_file/fd_file.h"
#include "dwarf.h"
+#include "elf_file_impl.h"
+#include "elf_utils.h"
#include "leb128.h"
#include "utils.h"
#include "instruction_set.h"
@@ -1661,7 +1664,7 @@ struct PACKED(1) DebugLineHeader {
}
};
-class DebugLineInstructionIterator {
+class DebugLineInstructionIterator FINAL {
public:
static DebugLineInstructionIterator* Create(DebugLineHeader* header, size_t section_size) {
std::unique_ptr<DebugLineInstructionIterator> line_iter(
@@ -1688,11 +1691,11 @@ class DebugLineInstructionIterator {
}
}
- uint8_t* GetInstruction() {
+ uint8_t* GetInstruction() const {
return current_instruction_;
}
- bool IsExtendedOpcode() {
+ bool IsExtendedOpcode() const {
return header_->IsExtendedOpcode(current_instruction_);
}
@@ -1719,8 +1722,8 @@ class DebugLineInstructionIterator {
: header_(header), last_instruction_(reinterpret_cast<uint8_t*>(header) + size),
current_instruction_(header->GetDebugLineData()) {}
- DebugLineHeader* header_;
- uint8_t* last_instruction_;
+ DebugLineHeader* const header_;
+ uint8_t* const last_instruction_;
uint8_t* current_instruction_;
};
@@ -1781,9 +1784,8 @@ static int32_t FormLength(uint32_t att) {
}
}
-class DebugTag {
+class DebugTag FINAL {
public:
- const uint32_t index_;
~DebugTag() {}
// Creates a new tag and moves data pointer up to the start of the next one.
// nullptr means error.
@@ -1820,14 +1822,18 @@ class DebugTag {
return size_;
}
- bool HasChild() {
+ bool HasChild() const {
return has_child_;
}
- uint32_t GetTagNumber() {
+ uint32_t GetTagNumber() const {
return tag_;
}
+ uint32_t GetIndex() const {
+ return index_;
+ }
+
// Gets the offset of a particular attribute in this tag structure.
// Interpretation of the data is left to the consumer. 0 is returned if the
// tag does not contain the attribute.
@@ -1857,6 +1863,8 @@ class DebugTag {
size_map_.insert(std::pair<uint32_t, uint32_t>(type, attr_size));
size_ += attr_size;
}
+
+ const uint32_t index_;
std::map<uint32_t, uint32_t> off_map_;
std::map<uint32_t, uint32_t> size_map_;
uint32_t size_;
@@ -1884,7 +1892,7 @@ class DebugAbbrev {
if (tag.get() == nullptr) {
return false;
} else {
- tags_.insert(std::pair<uint32_t, uint32_t>(tag->index_, tag_list_.size()));
+ tags_.insert(std::pair<uint32_t, uint32_t>(tag->GetIndex(), tag_list_.size()));
tag_list_.push_back(std::move(tag));
}
}
@@ -1904,8 +1912,8 @@ class DebugAbbrev {
private:
DebugAbbrev(const uint8_t* begin, const uint8_t* end) : begin_(begin), end_(end) {}
- const uint8_t* begin_;
- const uint8_t* end_;
+ const uint8_t* const begin_;
+ const uint8_t* const end_;
std::map<uint32_t, uint32_t> tags_;
std::vector<std::unique_ptr<DebugTag>> tag_list_;
};
@@ -1983,10 +1991,10 @@ class DebugInfoIterator {
last_entry_(reinterpret_cast<uint8_t*>(header) + frame_size),
current_entry_(reinterpret_cast<uint8_t*>(header) + sizeof(DebugInfoHeader)),
current_tag_(abbrev_->ReadTag(current_entry_)) {}
- DebugAbbrev* abbrev_;
+ DebugAbbrev* const abbrev_;
DebugInfoHeader* current_cu_;
DebugInfoHeader* next_cu_;
- uint8_t* last_entry_;
+ uint8_t* const last_entry_;
uint8_t* current_entry_;
DebugTag* current_tag_;
};
@@ -2406,24 +2414,15 @@ template class ElfFileImpl<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Word,
template class ElfFileImpl<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Word,
Elf64_Sword, Elf64_Addr, Elf64_Sym, Elf64_Rel, Elf64_Rela, Elf64_Dyn, Elf64_Off>;
-ElfFile::ElfFile(ElfFileImpl32* elf32) : is_elf64_(false) {
- CHECK_NE(elf32, static_cast<ElfFileImpl32*>(nullptr));
- elf_.elf32_ = elf32;
+ElfFile::ElfFile(ElfFileImpl32* elf32) : elf32_(elf32), elf64_(nullptr) {
}
-ElfFile::ElfFile(ElfFileImpl64* elf64) : is_elf64_(true) {
- CHECK_NE(elf64, static_cast<ElfFileImpl64*>(nullptr));
- elf_.elf64_ = elf64;
+ElfFile::ElfFile(ElfFileImpl64* elf64) : elf32_(nullptr), elf64_(elf64) {
}
ElfFile::~ElfFile() {
- if (is_elf64_) {
- CHECK_NE(elf_.elf64_, static_cast<ElfFileImpl64*>(nullptr));
- delete elf_.elf64_;
- } else {
- CHECK_NE(elf_.elf32_, static_cast<ElfFileImpl32*>(nullptr));
- delete elf_.elf32_;
- }
+ // Should never have 32 and 64-bit impls.
+ CHECK_NE(elf32_.get() == nullptr, elf64_.get() == nullptr);
}
ElfFile* ElfFile::Open(File* file, bool writable, bool program_header_only, std::string* error_msg) {
@@ -2445,8 +2444,9 @@ ElfFile* ElfFile::Open(File* file, bool writable, bool program_header_only, std:
return new ElfFile(elf_file_impl);
} else if (header[EI_CLASS] == ELFCLASS32) {
ElfFileImpl32* elf_file_impl = ElfFileImpl32::Open(file, writable, program_header_only, error_msg);
- if (elf_file_impl == nullptr)
+ if (elf_file_impl == nullptr) {
return nullptr;
+ }
return new ElfFile(elf_file_impl);
} else {
*error_msg = StringPrintf("Failed to find expected EI_CLASS value %d or %d in %s, found %d",
@@ -2471,13 +2471,15 @@ ElfFile* ElfFile::Open(File* file, int mmap_prot, int mmap_flags, std::string* e
uint8_t* header = map->Begin();
if (header[EI_CLASS] == ELFCLASS64) {
ElfFileImpl64* elf_file_impl = ElfFileImpl64::Open(file, mmap_prot, mmap_flags, error_msg);
- 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, mmap_prot, mmap_flags, error_msg);
- if (elf_file_impl == nullptr)
+ if (elf_file_impl == nullptr) {
return nullptr;
+ }
return new ElfFile(elf_file_impl);
} else {
*error_msg = StringPrintf("Failed to find expected EI_CLASS value %d or %d in %s, found %d",
@@ -2489,12 +2491,11 @@ ElfFile* ElfFile::Open(File* file, int mmap_prot, int mmap_flags, std::string* e
}
#define DELEGATE_TO_IMPL(func, ...) \
- if (is_elf64_) { \
- CHECK_NE(elf_.elf64_, static_cast<ElfFileImpl64*>(nullptr)); \
- return elf_.elf64_->func(__VA_ARGS__); \
+ if (elf64_.get() != nullptr) { \
+ return elf64_->func(__VA_ARGS__); \
} else { \
- CHECK_NE(elf_.elf32_, static_cast<ElfFileImpl32*>(nullptr)); \
- return elf_.elf32_->func(__VA_ARGS__); \
+ DCHECK(elf32_.get() != nullptr); \
+ return elf32_->func(__VA_ARGS__); \
}
bool ElfFile::Load(bool executable, std::string* error_msg) {
@@ -2522,29 +2523,31 @@ const File& ElfFile::GetFile() const {
}
bool ElfFile::GetSectionOffsetAndSize(const char* section_name, uint64_t* offset, uint64_t* size) {
- if (is_elf64_) {
- CHECK_NE(elf_.elf64_, static_cast<ElfFileImpl64*>(nullptr));
+ if (elf32_.get() == nullptr) {
+ CHECK(elf64_.get() != nullptr);
- Elf64_Shdr *shdr = elf_.elf64_->FindSectionByName(section_name);
- if (shdr == nullptr)
+ Elf64_Shdr *shdr = elf64_->FindSectionByName(section_name);
+ if (shdr == nullptr) {
return false;
-
- if (offset != nullptr)
+ }
+ if (offset != nullptr) {
*offset = shdr->sh_offset;
- if (size != nullptr)
+ }
+ if (size != nullptr) {
*size = shdr->sh_size;
+ }
return true;
} else {
- CHECK_NE(elf_.elf32_, static_cast<ElfFileImpl32*>(nullptr));
-
- Elf32_Shdr *shdr = elf_.elf32_->FindSectionByName(section_name);
- if (shdr == nullptr)
+ Elf32_Shdr *shdr = elf32_->FindSectionByName(section_name);
+ if (shdr == nullptr) {
return false;
-
- if (offset != nullptr)
+ }
+ if (offset != nullptr) {
*offset = shdr->sh_offset;
- if (size != nullptr)
+ }
+ if (size != nullptr) {
*size = shdr->sh_size;
+ }
return true;
}
}
@@ -2565,26 +2568,14 @@ bool ElfFile::Strip(File* file, std::string* error_msg) {
return false;
}
- if (elf_file->is_elf64_)
- return elf_file->elf_.elf64_->Strip(error_msg);
+ if (elf_file->elf64_.get() != nullptr)
+ return elf_file->elf64_->Strip(error_msg);
else
- return elf_file->elf_.elf32_->Strip(error_msg);
+ return elf_file->elf32_->Strip(error_msg);
}
bool ElfFile::Fixup(uintptr_t base_address) {
DELEGATE_TO_IMPL(Fixup, base_address);
}
-ElfFileImpl32* ElfFile::GetImpl32() const {
- CHECK(!is_elf64_);
- CHECK_NE(elf_.elf32_, static_cast<ElfFileImpl32*>(nullptr));
- return elf_.elf32_;
-}
-
-ElfFileImpl64* ElfFile::GetImpl64() const {
- CHECK(is_elf64_);
- CHECK_NE(elf_.elf64_, static_cast<ElfFileImpl64*>(nullptr));
- return elf_.elf64_;
-}
-
} // namespace art
diff --git a/runtime/elf_file.h b/runtime/elf_file.h
index a7f3056cae..10d6360fcc 100644
--- a/runtime/elf_file.h
+++ b/runtime/elf_file.h
@@ -17,12 +17,25 @@
#ifndef ART_RUNTIME_ELF_FILE_H_
#define ART_RUNTIME_ELF_FILE_H_
+#include <memory>
#include <string>
-#include "base/unix_file/fd_file.h"
-#include "elf_file_impl.h"
+#include "base/macros.h"
+// Explicitly include our own elf.h to avoid Linux and other dependencies.
+#include "./elf.h"
+#include "os.h"
namespace art {
+template <typename Elf_Ehdr, typename Elf_Phdr, typename Elf_Shdr, typename Elf_Word,
+ typename Elf_Sword, typename Elf_Addr, typename Elf_Sym, typename Elf_Rel,
+ typename Elf_Rela, typename Elf_Dyn, typename Elf_Off>
+class ElfFileImpl;
+
+// Explicitly instantiated in elf_file.cc
+typedef ElfFileImpl<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Word, Elf32_Sword,
+ Elf32_Addr, Elf32_Sym, Elf32_Rel, Elf32_Rela, Elf32_Dyn, Elf32_Off> ElfFileImpl32;
+typedef ElfFileImpl<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Word, Elf64_Sword,
+ Elf64_Addr, Elf64_Sym, Elf64_Rel, Elf64_Rela, Elf64_Dyn, Elf64_Off> ElfFileImpl64;
// Used for compile time and runtime for ElfFile access. Because of
// the need for use at runtime, cannot directly use LLVM classes such as
@@ -35,8 +48,6 @@ class ElfFile {
static ElfFile* Open(File* file, int mmap_prot, int mmap_flags, std::string* error_msg);
~ElfFile();
- const bool is_elf64_;
-
// Load segments into memory based on PT_LOAD program headers
bool Load(bool executable, std::string* error_msg);
@@ -68,17 +79,26 @@ class ElfFile {
bool Fixup(uintptr_t base_address);
- ElfFileImpl32* GetImpl32() const;
- ElfFileImpl64* GetImpl64() const;
+ bool Is64Bit() const {
+ return elf64_.get() != nullptr;
+ }
+
+ ElfFileImpl32* GetImpl32() const {
+ return elf32_.get();
+ }
+
+ ElfFileImpl64* GetImpl64() const {
+ return elf64_.get();
+ }
private:
explicit ElfFile(ElfFileImpl32* elf32);
explicit ElfFile(ElfFileImpl64* elf64);
- union ElfFileContainer {
- ElfFileImpl32* elf32_;
- ElfFileImpl64* elf64_;
- } elf_;
+ const std::unique_ptr<ElfFileImpl32> elf32_;
+ const std::unique_ptr<ElfFileImpl64> elf64_;
+
+ DISALLOW_COPY_AND_ASSIGN(ElfFile);
};
} // namespace art
diff --git a/runtime/elf_file_impl.h b/runtime/elf_file_impl.h
index a2fc422cea..a8bb465817 100644
--- a/runtime/elf_file_impl.h
+++ b/runtime/elf_file_impl.h
@@ -21,11 +21,9 @@
#include <memory>
#include <vector>
-#include "base/unix_file/fd_file.h"
-#include "globals.h"
-#include "elf_utils.h"
+// Explicitly include our own elf.h to avoid Linux and other dependencies.
+#include "./elf.h"
#include "mem_map.h"
-#include "os.h"
namespace art {
@@ -207,13 +205,9 @@ class ElfFileImpl {
Elf_Sword, Elf_Addr, Elf_Sym, Elf_Rel,
Elf_Rela, Elf_Dyn, Elf_Off>> gdb_file_mapping_;
void GdbJITSupport();
-};
-// Explicitly instantiated in elf_file.cc
-typedef ElfFileImpl<Elf32_Ehdr, Elf32_Phdr, Elf32_Shdr, Elf32_Word, Elf32_Sword,
- Elf32_Addr, Elf32_Sym, Elf32_Rel, Elf32_Rela, Elf32_Dyn, Elf32_Off> ElfFileImpl32;
-typedef ElfFileImpl<Elf64_Ehdr, Elf64_Phdr, Elf64_Shdr, Elf64_Word, Elf64_Sword,
- Elf64_Addr, Elf64_Sym, Elf64_Rel, Elf64_Rela, Elf64_Dyn, Elf64_Off> ElfFileImpl64;
+ DISALLOW_COPY_AND_ASSIGN(ElfFileImpl);
+};
} // namespace art
diff --git a/runtime/elf_utils.h b/runtime/elf_utils.h
index 5966d05996..676cd522e6 100644
--- a/runtime/elf_utils.h
+++ b/runtime/elf_utils.h
@@ -67,11 +67,11 @@
// Patching section type
#define SHT_OAT_PATCH SHT_LOUSER
-inline void SetBindingAndType(Elf32_Sym* sym, unsigned char b, unsigned char t) {
+static inline void SetBindingAndType(Elf32_Sym* sym, unsigned char b, unsigned char t) {
sym->st_info = (b << 4) + (t & 0x0f);
}
-inline bool IsDynamicSectionPointer(Elf32_Word d_tag, Elf32_Word e_machine) {
+static inline bool IsDynamicSectionPointer(Elf32_Word d_tag, Elf32_Word e_machine) {
switch (d_tag) {
// case 1: well known d_tag values that imply Elf32_Dyn.d_un contains an address in d_ptr
case DT_PLTGOT:
diff --git a/runtime/memory_region.h b/runtime/memory_region.h
index 645996366b..4eb6d47537 100644
--- a/runtime/memory_region.h
+++ b/runtime/memory_region.h
@@ -21,6 +21,7 @@
#include "base/logging.h"
#include "base/macros.h"
+#include "base/value_object.h"
#include "globals.h"
namespace art {
@@ -28,9 +29,9 @@ namespace art {
// Memory regions are useful for accessing memory with bounds check in
// debug mode. They can be safely passed by value and do not assume ownership
// of the region.
-class MemoryRegion {
+class MemoryRegion FINAL : public ValueObject {
public:
- MemoryRegion() : pointer_(NULL), size_(0) {}
+ MemoryRegion() : pointer_(nullptr), size_(0) {}
MemoryRegion(void* pointer, uintptr_t size) : pointer_(pointer), size_(size) {}
void* pointer() const { return pointer_; }
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index e366084e4b..9c4a61eea1 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -43,6 +43,7 @@
#include "arch/x86/registers_x86.h"
#include "arch/x86_64/quick_method_frame_info_x86_64.h"
#include "arch/x86_64/registers_x86_64.h"
+#include "base/unix_file/fd_file.h"
#include "atomic.h"
#include "class_linker.h"
#include "debugger.h"