Add ElfImage to hold ELF image address and size.
(cherry picked from commit 578763dc6630156b163933720a85f8d34cbab652)
Change-Id: I76d03130eabb100869ea941c9e4fd92cc9244eeb
diff --git a/src/compiler_llvm/compilation_unit.h b/src/compiler_llvm/compilation_unit.h
index 4a23095..659bc64 100644
--- a/src/compiler_llvm/compilation_unit.h
+++ b/src/compiler_llvm/compilation_unit.h
@@ -18,6 +18,7 @@
#define ART_SRC_COMPILER_LLVM_COMPILATION_UNIT_H_
#include "constants.h"
+#include "elf_image.h"
#include "globals.h"
#include "logging.h"
@@ -76,12 +77,8 @@
bitcode_filename_ = filename;
}
- const byte* GetElfImage() const {
- return reinterpret_cast<const byte*>(&*elf_image_.begin());
- }
-
- size_t GetElfSize() const {
- return elf_image_.size();
+ ElfImage GetElfImage() const {
+ return ElfImage(elf_image_);
}
bool WriteBitcodeToFile();
diff --git a/src/compiler_llvm/compiler_llvm.cc b/src/compiler_llvm/compiler_llvm.cc
index 1d878c9..65d53b9 100644
--- a/src/compiler_llvm/compiler_llvm.cc
+++ b/src/compiler_llvm/compiler_llvm.cc
@@ -21,6 +21,7 @@
#include "compiled_method.h"
#include "compiler.h"
#include "dex_cache.h"
+#include "elf_image.h"
#include "elf_loader.h"
#include "ir_builder.h"
#include "jni_compiler.h"
@@ -205,9 +206,7 @@
compiler_lock_.AssertHeld();
DCHECK(cunit->IsMaterialized()) << cunit->GetElfIndex();
- if (!elf_loader_->LoadElfAt(cunit->GetElfIndex(),
- cunit->GetElfImage(),
- cunit->GetElfSize())) {
+ if (!elf_loader_->LoadElfAt(cunit->GetElfIndex(), cunit->GetElfImage())) {
LOG(ERROR) << "Failed to load ELF from compilation unit "
<< cunit->GetElfIndex();
}
diff --git a/src/compiler_llvm/compiler_llvm.h b/src/compiler_llvm/compiler_llvm.h
index 626c13d..f5a282a 100644
--- a/src/compiler_llvm/compiler_llvm.h
+++ b/src/compiler_llvm/compiler_llvm.h
@@ -19,6 +19,7 @@
#include "constants.h"
#include "dex_file.h"
+#include "elf_image.h"
#include "macros.h"
#include "object.h"
diff --git a/src/compiler_llvm/elf_loader.cc b/src/compiler_llvm/elf_loader.cc
index f309b82..ccb02ad 100644
--- a/src/compiler_llvm/elf_loader.cc
+++ b/src/compiler_llvm/elf_loader.cc
@@ -17,6 +17,7 @@
#include "elf_loader.h"
#include "compiled_method.h"
+#include "elf_image.h"
#include "logging.h"
#include "object.h"
#include "runtime_support_llvm.h"
@@ -36,7 +37,7 @@
}
-bool ElfLoader::LoadElfAt(size_t elf_idx, const byte* image, size_t size) {
+bool ElfLoader::LoadElfAt(size_t elf_idx, const ElfImage& elf_image) {
if (elf_idx < executables_.size() && executables_[elf_idx] != NULL) {
return false;
}
@@ -46,11 +47,13 @@
}
RSExecRef executable =
- rsloaderCreateExec(reinterpret_cast<const unsigned char*>(image),
- size, art_find_runtime_support_func, NULL);
+ rsloaderCreateExec(elf_image.begin(), elf_image.size(),
+ art_find_runtime_support_func, NULL);
if (executable == NULL) {
- LOG(WARNING) << "Failed to load ELF image: " << image << " size: " << size;
+ LOG(WARNING) << "Failed to load ELF"
+ << " image: " << elf_image.begin()
+ << " size: " << elf_image.size();
return false;
}
diff --git a/src/compiler_llvm/elf_loader.h b/src/compiler_llvm/elf_loader.h
index 5f7ab86..5c8063a 100644
--- a/src/compiler_llvm/elf_loader.h
+++ b/src/compiler_llvm/elf_loader.h
@@ -17,6 +17,7 @@
#ifndef ART_SRC_COMPILER_LLVM_ELF_LOADER_H_
#define ART_SRC_COMPILER_LLVM_ELF_LOADER_H_
+#include "elf_image.h"
#include "globals.h"
#include "object.h"
@@ -34,7 +35,7 @@
public:
~ElfLoader();
- bool LoadElfAt(size_t elf_idx, const byte* addr, size_t size);
+ bool LoadElfAt(size_t elf_idx, const ElfImage& elf_image);
const void* GetMethodCodeAddr(size_t elf_idx, const Method* method) const;
diff --git a/src/elf_image.h b/src/elf_image.h
new file mode 100644
index 0000000..79f54c2
--- /dev/null
+++ b/src/elf_image.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_SRC_ELF_IMAGE_H_
+#define ART_SRC_ELF_IMAGE_H_
+
+#include "globals.h"
+#include <string>
+
+namespace art {
+
+class ElfImage {
+ public:
+ explicit ElfImage(const std::string& str)
+ : begin_(reinterpret_cast<const byte*>(str.data())), size_(str.size()) {
+ }
+
+ explicit ElfImage(const byte* begin, size_t size)
+ : begin_(begin), size_(size) {
+ }
+
+ const byte* begin() const {
+ return begin_;
+ }
+
+ const byte* end() const {
+ return (begin_ + size_);
+ }
+
+ size_t size() const {
+ return size_;
+ }
+
+ private:
+ const byte* begin_;
+ size_t size_;
+};
+
+} // namespace art
+
+#endif // ART_SRC_ELF_IMAGE_H_