summaryrefslogtreecommitdiffstats
path: root/dex2oat
diff options
context:
space:
mode:
authorAlex Light <allight@google.com>2014-07-02 16:28:08 -0700
committerAndreas Gampe <agampe@google.com>2014-07-22 08:24:14 -0700
commita59dd80f9f48cb750d329d4d4af2d99d72b484d1 (patch)
tree36958b15842205addaf6d2a13e40823eab47c8bc /dex2oat
parent84568fdf08f8f476292996ad653b4453d2894d23 (diff)
downloadandroid_art-a59dd80f9f48cb750d329d4d4af2d99d72b484d1.tar.gz
android_art-a59dd80f9f48cb750d329d4d4af2d99d72b484d1.tar.bz2
android_art-a59dd80f9f48cb750d329d4d4af2d99d72b484d1.zip
Runtime can now be set to require relocation
Add a pair of runtime flags -Xrelocate and -Xnorelocate that can force the runtime to require that all files that are run are relocated, to prevent attacks based on the known art base address. Add support for running patchoat on oat files compiled without an image. Change run-test to have new --prebuild and --relocate flags. Bug: 15358152 Change-Id: I91166c62dd1ab80e5cbcb7883a2cd0d56afca32d
Diffstat (limited to 'dex2oat')
-rw-r--r--dex2oat/dex2oat.cc39
1 files changed, 35 insertions, 4 deletions
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 6d861d4bfe..d6501a162d 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -45,6 +45,7 @@
#include "driver/compiler_driver.h"
#include "driver/compiler_options.h"
#include "elf_fixup.h"
+#include "elf_patcher.h"
#include "elf_stripper.h"
#include "gc/space/image_space.h"
#include "gc/space/space-inl.h"
@@ -324,11 +325,28 @@ class Dex2Oat {
return ReadImageClasses(image_classes_stream);
}
+ bool PatchOatCode(const CompilerDriver* compiler_driver, File* oat_file,
+ const std::string& oat_location, std::string* error_msg) {
+ // We asked to include patch information but we are not making an image. We need to fix
+ // everything up manually.
+ std::unique_ptr<ElfFile> elf_file(ElfFile::Open(oat_file, PROT_READ|PROT_WRITE,
+ MAP_SHARED, error_msg));
+ if (elf_file.get() == NULL) {
+ LOG(ERROR) << error_msg;
+ return false;
+ }
+ {
+ ReaderMutexLock mu(Thread::Current(), *Locks::mutator_lock_);
+ return ElfPatcher::Patch(compiler_driver, elf_file.get(), oat_location, error_msg);
+ }
+ }
+
const CompilerDriver* CreateOatFile(const std::string& boot_image_option,
const std::string& android_root,
bool is_host,
const std::vector<const DexFile*>& dex_files,
File* oat_file,
+ const std::string& oat_location,
const std::string& bitcode_filename,
bool image,
std::unique_ptr<CompilerDriver::DescriptorSet>& image_classes,
@@ -380,6 +398,7 @@ class Dex2Oat {
std::string image_file_location;
uint32_t image_file_location_oat_checksum = 0;
uintptr_t image_file_location_oat_data_begin = 0;
+ int32_t image_patch_delta = 0;
if (!driver->IsImage()) {
TimingLogger::ScopedTiming t3("Loading image checksum", &timings);
gc::space::ImageSpace* image_space = Runtime::Current()->GetHeap()->GetImageSpace();
@@ -387,6 +406,7 @@ class Dex2Oat {
image_file_location_oat_data_begin =
reinterpret_cast<uintptr_t>(image_space->GetImageHeader().GetOatDataBegin());
image_file_location = image_space->GetImageFilename();
+ image_patch_delta = image_space->GetImageHeader().GetPatchDelta();
}
if (!image_file_location.empty()) {
@@ -395,6 +415,7 @@ class Dex2Oat {
OatWriter oat_writer(dex_files, image_file_location_oat_checksum,
image_file_location_oat_data_begin,
+ image_patch_delta,
driver.get(),
&timings,
key_value_store);
@@ -405,6 +426,16 @@ class Dex2Oat {
return nullptr;
}
+ if (!driver->IsImage() && driver->GetCompilerOptions().GetIncludePatchInformation()) {
+ t2.NewTiming("Patching ELF");
+ std::string error_msg;
+ if (!PatchOatCode(driver.get(), oat_file, oat_location, &error_msg)) {
+ LOG(ERROR) << "Failed to fixup ELF file " << oat_file->GetPath();
+ LOG(ERROR) << "Error was: " << error_msg;
+ return nullptr;
+ }
+ }
+
return driver.release();
}
@@ -1361,6 +1392,7 @@ static int dex2oat(int argc, char** argv) {
is_host,
dex_files,
oat_file.get(),
+ oat_location,
bitcode_filename,
image,
image_classes,
@@ -1370,7 +1402,6 @@ static int dex2oat(int argc, char** argv) {
compiler_phases_timings,
profile_file,
key_value_store.get()));
-
if (compiler.get() == nullptr) {
LOG(ERROR) << "Failed to create oat file: " << oat_location;
return EXIT_FAILURE;
@@ -1420,9 +1451,9 @@ static int dex2oat(int argc, char** argv) {
// memory mapped so we could predict where its contents were based
// on the file size. Now that it is an ELF file, we need to inspect
// the ELF file to understand the in memory segment layout including
- // where the oat header is located within. ImageWriter's
- // PatchOatCodeAndMethods uses the PatchInformation from the
- // Compiler to touch up absolute references in the oat file.
+ // where the oat header is located within. ElfPatcher's Patch method
+ // uses the PatchInformation from the Compiler to touch up absolute
+ // references in the oat file.
//
// 3. We fixup the ELF program headers so that dlopen will try to
// load the .so at the desired location at runtime by offsetting the