dex2oat: Add a --compile-pic option
(cherry-picked from AOSP master
83c5612e69fa05610baf4f4d237fe0995a79cde5)
Bug: 18035729
Change-Id: I80e03613e3b6ac079bcbc7e068bbaae760c364c9
diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc
index fa2a560..9a44ade 100644
--- a/compiler/driver/compiler_driver.cc
+++ b/compiler/driver/compiler_driver.cc
@@ -934,6 +934,10 @@
if (resolved_class == nullptr) {
return false;
}
+ if (GetCompilerOptions().GetCompilePic()) {
+ // Do not allow a direct class pointer to be used when compiling for position-independent
+ return false;
+ }
*out_is_finalizable = resolved_class->IsFinalizable();
const bool compiling_boot = Runtime::Current()->GetHeap()->IsCompilingBoot();
const bool support_boot_image_fixup = GetSupportBootImageFixup();
@@ -1089,7 +1093,7 @@
void CompilerDriver::GetCodeAndMethodForDirectCall(InvokeType* type, InvokeType sharp_type,
bool no_guarantee_of_dex_cache_entry,
- mirror::Class* referrer_class,
+ const mirror::Class* referrer_class,
mirror::ArtMethod* method,
int* stats_flags,
MethodReference* target_method,
@@ -1101,7 +1105,7 @@
// invoked, so this can be passed to the out-of-line runtime support code.
*direct_code = 0;
*direct_method = 0;
- bool use_dex_cache = false;
+ bool use_dex_cache = GetCompilerOptions().GetCompilePic(); // Off by default
const bool compiling_boot = Runtime::Current()->GetHeap()->IsCompilingBoot();
// TODO This is somewhat hacky. We should refactor all of this invoke codepath.
const bool force_relocations = (compiling_boot ||
@@ -1116,7 +1120,7 @@
return;
}
// TODO: support patching on all architectures.
- use_dex_cache = force_relocations && !support_boot_image_fixup_;
+ use_dex_cache = use_dex_cache || (force_relocations && !support_boot_image_fixup_);
}
bool method_code_in_boot = (method->GetDeclaringClass()->GetClassLoader() == nullptr);
if (!use_dex_cache) {