Allow for sig chain to be disabled.
Tools like dex2oat or patchoat don't need the sig chain or the fault
manager. This also enables building a statically link version of
dex2oat.
Change-Id: I9897728cac48acade854bb027bfde860628ebf84
diff --git a/build/Android.executable.mk b/build/Android.executable.mk
index 7b03682..5ed94d5 100644
--- a/build/Android.executable.mk
+++ b/build/Android.executable.mk
@@ -55,7 +55,6 @@
LOCAL_SRC_FILES := $$(art_source)
LOCAL_C_INCLUDES += $(ART_C_INCLUDES) art/runtime art/cmdline $$(art_c_includes)
LOCAL_SHARED_LIBRARIES += $$(art_shared_libraries)
- LOCAL_WHOLE_STATIC_LIBRARIES += libsigchain
ifeq ($$(art_ndebug_or_debug),ndebug)
LOCAL_MODULE := $$(art_executable)
diff --git a/cmdline/cmdline.h b/cmdline/cmdline.h
index 2967e27..2e9f208 100644
--- a/cmdline/cmdline.h
+++ b/cmdline/cmdline.h
@@ -104,7 +104,9 @@
options.push_back(
std::make_pair("imageinstructionset",
reinterpret_cast<const void*>(GetInstructionSetString(instruction_set))));
-
+ // None of the command line tools need sig chain. If this changes we'll need
+ // to upgrade this option to a proper parameter.
+ options.push_back(std::make_pair("-Xno-sig-chain", nullptr));
if (!Runtime::Create(options, false)) {
fprintf(stderr, "Failed to create runtime\n");
return nullptr;
diff --git a/dex2oat/Android.mk b/dex2oat/Android.mk
index 321cd75..b4d2343 100644
--- a/dex2oat/Android.mk
+++ b/dex2oat/Android.mk
@@ -38,16 +38,16 @@
endif
ifeq ($(ART_BUILD_TARGET_NDEBUG),true)
- $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libart-compiler,art/compiler,target,ndebug,$(dex2oat_target_arch)))
+ $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libart-compiler libsigchain,art/compiler,target,ndebug,$(dex2oat_target_arch)))
endif
ifeq ($(ART_BUILD_TARGET_DEBUG),true)
- $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libartd-compiler,art/compiler,target,debug,$(dex2oat_target_arch)))
+ $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libartd-compiler libsigchain,art/compiler,target,debug,$(dex2oat_target_arch)))
endif
# We always build dex2oat and dependencies, even if the host build is otherwise disabled, since they are used to cross compile for the target.
ifeq ($(ART_BUILD_HOST_NDEBUG),true)
- $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libart-compiler libziparchive-host,art/compiler,host,ndebug,$(dex2oat_host_arch)))
+ $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libart-compiler libsigchain libziparchive-host,art/compiler,host,ndebug,$(dex2oat_host_arch)))
endif
ifeq ($(ART_BUILD_HOST_DEBUG),true)
- $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libartd-compiler libziparchive-host,art/compiler,host,debug,$(dex2oat_host_arch)))
+ $(eval $(call build-art-executable,dex2oat,$(DEX2OAT_SRC_FILES),libcutils libartd-compiler libsigchain libziparchive-host,art/compiler,host,debug,$(dex2oat_host_arch)))
endif
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 74d5c0c..b4520e9 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1129,6 +1129,9 @@
if (!image_) {
runtime_options.push_back(std::make_pair("-Xno-dex-file-fallback", nullptr));
}
+ // Disable libsigchain. We don't don't need it during compilation and it prevents us
+ // from getting a statically linked version of dex2oat (because of dlsym and RTLD_NEXT).
+ runtime_options.push_back(std::make_pair("-Xno-sig-chain", nullptr));
if (!CreateRuntime(runtime_options)) {
return false;
diff --git a/patchoat/Android.mk b/patchoat/Android.mk
index 68ca923..8f9ffca 100644
--- a/patchoat/Android.mk
+++ b/patchoat/Android.mk
@@ -30,16 +30,16 @@
endif
ifeq ($(ART_BUILD_TARGET_NDEBUG),true)
- $(eval $(call build-art-executable,patchoat,$(PATCHOAT_SRC_FILES),libcutils,art/compiler,target,ndebug,$(patchoat_arch)))
+ $(eval $(call build-art-executable,patchoat,$(PATCHOAT_SRC_FILES),libcutils libsigchain,art/compiler,target,ndebug,$(patchoat_arch)))
endif
ifeq ($(ART_BUILD_TARGET_DEBUG),true)
- $(eval $(call build-art-executable,patchoat,$(PATCHOAT_SRC_FILES),libcutils,art/compiler,target,debug,$(patchoat_arch)))
+ $(eval $(call build-art-executable,patchoat,$(PATCHOAT_SRC_FILES),libcutils libsigchain,art/compiler,target,debug,$(patchoat_arch)))
endif
# We always build patchoat and dependencies, even if the host build is otherwise disabled, since they are used to cross compile for the target.
ifeq ($(ART_BUILD_HOST_NDEBUG),true)
- $(eval $(call build-art-executable,patchoat,$(PATCHOAT_SRC_FILES),libcutils,art/compiler,host,ndebug))
+ $(eval $(call build-art-executable,patchoat,$(PATCHOAT_SRC_FILES),libcutils libsigchain,art/compiler,host,ndebug))
endif
ifeq ($(ART_BUILD_HOST_DEBUG),true)
- $(eval $(call build-art-executable,patchoat,$(PATCHOAT_SRC_FILES),libcutils,art/compiler,host,debug))
+ $(eval $(call build-art-executable,patchoat,$(PATCHOAT_SRC_FILES),libcutils libsigchain,art/compiler,host,debug))
endif
diff --git a/patchoat/patchoat.cc b/patchoat/patchoat.cc
index 0401727..3a155be 100644
--- a/patchoat/patchoat.cc
+++ b/patchoat/patchoat.cc
@@ -138,6 +138,7 @@
std::string img = "-Ximage:" + image_location;
options.push_back(std::make_pair(img.c_str(), nullptr));
options.push_back(std::make_pair("imageinstructionset", reinterpret_cast<const void*>(isa_name)));
+ options.push_back(std::make_pair("-Xno-sig-chain", nullptr));
if (!Runtime::Create(options, false)) {
LOG(ERROR) << "Unable to initialize runtime";
return false;
@@ -233,6 +234,7 @@
std::string img = "-Ximage:" + image_location;
options.push_back(std::make_pair(img.c_str(), nullptr));
options.push_back(std::make_pair("imageinstructionset", reinterpret_cast<const void*>(isa_name)));
+ options.push_back(std::make_pair("-Xno-sig-chain", nullptr));
if (!Runtime::Create(options, false)) {
LOG(ERROR) << "Unable to initialize runtime";
return false;
diff --git a/runtime/parsed_options.cc b/runtime/parsed_options.cc
index 5e84df5..d08af71 100644
--- a/runtime/parsed_options.cc
+++ b/runtime/parsed_options.cc
@@ -257,6 +257,8 @@
.IntoKey(M::ZygoteMaxFailedBoots)
.Define("-Xno-dex-file-fallback")
.IntoKey(M::NoDexFileFallback)
+ .Define("-Xno-sig-chain")
+ .IntoKey(M::NoSigChain)
.Define("--cpu-abilist=_")
.WithType<std::string>()
.IntoKey(M::CpuAbiList)
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 96c15ea..5fef8ae 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -191,6 +191,7 @@
implicit_null_checks_(false),
implicit_so_checks_(false),
implicit_suspend_checks_(false),
+ no_sig_chain_(false),
is_native_bridge_loaded_(false),
zygote_max_failed_boots_(0),
experimental_lambdas_(false) {
@@ -487,6 +488,8 @@
bool Runtime::Start() {
VLOG(startup) << "Runtime::Start entering";
+ CHECK(!no_sig_chain_) << "A started runtime should have sig chain enabled";
+
// Restore main thread state to kNative as expected by native code.
Thread* self = Thread::Current();
@@ -838,6 +841,8 @@
verify_ = runtime_options.GetOrDefault(Opt::Verify);
allow_dex_file_fallback_ = !runtime_options.Exists(Opt::NoDexFileFallback);
+ no_sig_chain_ = runtime_options.Exists(Opt::NoSigChain);
+
Split(runtime_options.GetOrDefault(Opt::CpuAbiList), ',', &cpu_abilist_);
if (runtime_options.GetOrDefault(Opt::Interpret)) {
@@ -933,33 +938,37 @@
break;
}
- // Always initialize the signal chain so that any calls to sigaction get
- // correctly routed to the next in the chain regardless of whether we
- // have claimed the signal or not.
- InitializeSignalChain();
+ if (!no_sig_chain_) {
+ // Dex2Oat's Runtime does not need the signal chain or the fault handler.
- if (implicit_null_checks_ || implicit_so_checks_ || implicit_suspend_checks_) {
- fault_manager.Init();
+ // Initialize the signal chain so that any calls to sigaction get
+ // correctly routed to the next in the chain regardless of whether we
+ // have claimed the signal or not.
+ InitializeSignalChain();
- // These need to be in a specific order. The null point check handler must be
- // after the suspend check and stack overflow check handlers.
- //
- // Note: the instances attach themselves to the fault manager and are handled by it. The manager
- // will delete the instance on Shutdown().
- if (implicit_suspend_checks_) {
- new SuspensionHandler(&fault_manager);
- }
+ if (implicit_null_checks_ || implicit_so_checks_ || implicit_suspend_checks_) {
+ fault_manager.Init();
- if (implicit_so_checks_) {
- new StackOverflowHandler(&fault_manager);
- }
+ // These need to be in a specific order. The null point check handler must be
+ // after the suspend check and stack overflow check handlers.
+ //
+ // Note: the instances attach themselves to the fault manager and are handled by it. The manager
+ // will delete the instance on Shutdown().
+ if (implicit_suspend_checks_) {
+ new SuspensionHandler(&fault_manager);
+ }
- if (implicit_null_checks_) {
- new NullPointerHandler(&fault_manager);
- }
+ if (implicit_so_checks_) {
+ new StackOverflowHandler(&fault_manager);
+ }
- if (kEnableJavaStackTraceHandler) {
- new JavaStackTraceHandler(&fault_manager);
+ if (implicit_null_checks_) {
+ new NullPointerHandler(&fault_manager);
+ }
+
+ if (kEnableJavaStackTraceHandler) {
+ new JavaStackTraceHandler(&fault_manager);
+ }
}
}
diff --git a/runtime/runtime.h b/runtime/runtime.h
index 3cd7404..bcc7118 100644
--- a/runtime/runtime.h
+++ b/runtime/runtime.h
@@ -715,6 +715,11 @@
bool implicit_so_checks_; // StackOverflow checks are implicit.
bool implicit_suspend_checks_; // Thread suspension checks are implicit.
+ // Whether or not the sig chain (and implicitly the fault handler) should be
+ // disabled. Tools like dex2oat or patchoat don't need them. This enables
+ // building a statically link version of dex2oat.
+ bool no_sig_chain_;
+
// Whether or not a native bridge has been loaded.
//
// The native bridge allows running native code compiled for a foreign ISA. The way it works is,
diff --git a/runtime/runtime_options.def b/runtime/runtime_options.def
index fc527b5..d5f7f97 100644
--- a/runtime/runtime_options.def
+++ b/runtime/runtime_options.def
@@ -91,6 +91,7 @@
RUNTIME_OPTIONS_KEY (BackgroundGcOption, BackgroundGc)
RUNTIME_OPTIONS_KEY (Unit, DisableExplicitGC)
+RUNTIME_OPTIONS_KEY (Unit, NoSigChain)
RUNTIME_OPTIONS_KEY (LogVerbosity, Verbose)
RUNTIME_OPTIONS_KEY (unsigned int, LockProfThreshold)
RUNTIME_OPTIONS_KEY (std::string, StackTraceFile)