Revert^4 "Add "linkage" test options""
This reverts commit 16c08ca97486f535698f1a1b17f0332bfe78e95a.
Reason for revert: Disabled on device testing
Change-Id: I8d5442e0ebb6383ebfbce98f1857b5e844e0d5e1
Bug: none
Test: make test-art-host-gtest-dex2oat_test
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index ec05939..8e8fa80 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -806,7 +806,9 @@
app_image_fd_(kInvalidFd),
profile_file_fd_(kInvalidFd),
timings_(timings),
- force_determinism_(false)
+ force_determinism_(false),
+ check_linkage_conditions_(false),
+ crash_on_linkage_violation_(false)
{}
~Dex2Oat() {
@@ -1106,6 +1108,9 @@
}
compiler_options_->force_determinism_ = force_determinism_;
+ compiler_options_->check_linkage_conditions_ = check_linkage_conditions_;
+ compiler_options_->crash_on_linkage_violation_ = crash_on_linkage_violation_;
+
if (passes_to_run_filename_ != nullptr) {
passes_to_run_ = ReadCommentedInputFromFile<std::vector<std::string>>(
passes_to_run_filename_,
@@ -1324,6 +1329,8 @@
AssignIfExists(args, M::DirtyImageObjects, &dirty_image_objects_filename_);
AssignIfExists(args, M::ImageFormat, &image_storage_mode_);
AssignIfExists(args, M::CompilationReason, &compilation_reason_);
+ AssignTrueIfExists(args, M::CheckLinkageConditions, &check_linkage_conditions_);
+ AssignTrueIfExists(args, M::CrashOnLinkageViolation, &crash_on_linkage_violation_);
AssignIfExists(args, M::Backend, &compiler_kind_);
parser_options->requested_specific_compiler = args.Exists(M::Backend);
@@ -3016,6 +3023,10 @@
// See CompilerOptions.force_determinism_.
bool force_determinism_;
+ // See CompilerOptions.crash_on_linkage_violation_.
+ bool check_linkage_conditions_;
+ // See CompilerOptions.crash_on_linkage_violation_.
+ bool crash_on_linkage_violation_;
// Directory of relative classpaths.
std::string classpath_dir_;
diff --git a/dex2oat/dex2oat_options.cc b/dex2oat/dex2oat_options.cc
index 58944ff..ea72d54 100644
--- a/dex2oat/dex2oat_options.cc
+++ b/dex2oat/dex2oat_options.cc
@@ -224,6 +224,10 @@
.IntoKey(M::VeryLargeAppThreshold)
.Define("--force-determinism")
.IntoKey(M::ForceDeterminism)
+ .Define("--check-linkage-conditions")
+ .IntoKey(M::CheckLinkageConditions)
+ .Define("--crash-on-linkage-violation")
+ .IntoKey(M::CrashOnLinkageViolation)
.Define("--copy-dex-files=_")
.WithType<linker::CopyOption>()
.WithValueMap({{"true", linker::CopyOption::kOnlyIfCompressed},
diff --git a/dex2oat/dex2oat_options.def b/dex2oat/dex2oat_options.def
index f48806c..e324e8b 100644
--- a/dex2oat/dex2oat_options.def
+++ b/dex2oat/dex2oat_options.def
@@ -91,5 +91,7 @@
DEX2OAT_OPTIONS_KEY (std::string, DirtyImageObjects)
DEX2OAT_OPTIONS_KEY (std::vector<std::string>, RuntimeOptions)
DEX2OAT_OPTIONS_KEY (std::string, CompilationReason)
+DEX2OAT_OPTIONS_KEY (Unit, CheckLinkageConditions)
+DEX2OAT_OPTIONS_KEY (Unit, CrashOnLinkageViolation)
#undef DEX2OAT_OPTIONS_KEY
diff --git a/dex2oat/dex2oat_test.cc b/dex2oat/dex2oat_test.cc
index 687e3ff..db0eb8a 100644
--- a/dex2oat/dex2oat_test.cc
+++ b/dex2oat/dex2oat_test.cc
@@ -2422,4 +2422,29 @@
RunTest();
}
+class LinkageTest : public Dex2oatTest {};
+
+TEST_F(LinkageTest, LinkageEnabled) {
+ TEST_DISABLED_FOR_TARGET();
+ std::unique_ptr<const DexFile> dex(OpenTestDexFile("LinkageTest"));
+ std::string out_dir = GetScratchDir();
+ const std::string base_oat_name = out_dir + "/base.oat";
+ std::string error_msg;
+ const int res_fail = GenerateOdexForTestWithStatus(
+ {dex->GetLocation()},
+ base_oat_name,
+ CompilerFilter::Filter::kQuicken,
+ &error_msg,
+ {"--check-linkage-conditions", "--crash-on-linkage-violation"});
+ EXPECT_NE(0, res_fail);
+
+ const int res_no_fail = GenerateOdexForTestWithStatus(
+ {dex->GetLocation()},
+ base_oat_name,
+ CompilerFilter::Filter::kQuicken,
+ &error_msg,
+ {"--check-linkage-conditions"});
+ EXPECT_EQ(0, res_no_fail);
+}
+
} // namespace art
diff --git a/dex2oat/driver/compiler_driver.cc b/dex2oat/driver/compiler_driver.cc
index 15c7c65..b97f1db 100644
--- a/dex2oat/driver/compiler_driver.cc
+++ b/dex2oat/driver/compiler_driver.cc
@@ -1596,7 +1596,7 @@
// generated code.
const dex::ClassDef& class_def = dex_file.GetClassDef(class_def_index);
ScopedObjectAccess soa(self);
- StackHandleScope<2> hs(soa.Self());
+ StackHandleScope<5> hs(soa.Self());
Handle<mirror::ClassLoader> class_loader(
hs.NewHandle(soa.Decode<mirror::ClassLoader>(jclass_loader)));
Handle<mirror::DexCache> dex_cache(hs.NewHandle(class_linker->FindDexCache(
@@ -1611,6 +1611,40 @@
CheckAndClearResolveException(soa.Self());
resolve_fields_and_methods = false;
} else {
+ Handle<mirror::Class> hklass(hs.NewHandle(klass));
+ if (manager_->GetCompiler()->GetCompilerOptions().IsCheckLinkageConditions() &&
+ !manager_->GetCompiler()->GetCompilerOptions().IsBootImage()) {
+ bool is_fatal = manager_->GetCompiler()->GetCompilerOptions().IsCrashOnLinkageViolation();
+ ObjPtr<mirror::ClassLoader> resolving_class_loader = hklass->GetClassLoader();
+ if (resolving_class_loader != soa.Decode<mirror::ClassLoader>(jclass_loader)) {
+ // Redefinition via different ClassLoaders.
+ // This OptStat stuff is to enable logging from the APK scanner.
+ if (is_fatal)
+ LOG(FATAL) << "OptStat#" << hklass->PrettyClassAndClassLoader() << ": 1";
+ else
+ LOG(ERROR)
+ << "LINKAGE VIOLATION: "
+ << hklass->PrettyClassAndClassLoader()
+ << " was redefined";
+ }
+ // Check that the current class is not a subclass of java.lang.ClassLoader.
+ if (!hklass->IsInterface() &&
+ hklass->IsSubClass(class_linker->FindClass(self,
+ "Ljava/lang/ClassLoader;",
+ hs.NewHandle(resolving_class_loader)))) {
+ // Subclassing of java.lang.ClassLoader.
+ // This OptStat stuff is to enable logging from the APK scanner.
+ if (is_fatal)
+ LOG(FATAL) << "OptStat#" << hklass->PrettyClassAndClassLoader() << ": 1";
+ else
+ LOG(ERROR)
+ << "LINKAGE VIOLATION: "
+ << hklass->PrettyClassAndClassLoader()
+ << " is a subclass of java.lang.ClassLoader";
+ }
+ CHECK(hklass->IsResolved()) << hklass->PrettyClass();
+ klass.Assign(hklass.Get());
+ }
// We successfully resolved a class, should we skip it?
if (SkipClass(jclass_loader, dex_file, klass)) {
return;