Link libart-disassembler statically into static libart-compiler.

Necessary to avoid runtime dlopen of non-existing
libart(d)-disassembler.so in host dex2oat. This increases the stripped
dex2oat binary size by 4.8% or ~800 KB.

Test: art/tools/buildbot-build.sh --host && \
  art/test/testrunner/testrunner.py --optimizing --host --ndebug -t 465
  with and without HOST_PREFER_32_BIT=true
Bug: 145934348
Change-Id: I623019132175bd0430d30a421655484bdcb71857
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 332754e..3ec2a38 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -157,6 +157,9 @@
             ],
         },
     },
+    static: {
+        cflags: ["-DART_STATIC_LIBART_COMPILER"],
+    },
     generated_sources: ["art_compiler_operator_srcs"],
     shared_libs: [
         "libbase",
@@ -266,6 +269,7 @@
     name: "libart-compiler_static_defaults",
     defaults: [
         "libart-compiler_static_base_defaults",
+        "libart-disassembler_static_defaults",
         "libart_static_defaults",
         "libartbase_static_defaults",
         "libdexfile_static_defaults",
@@ -339,8 +343,9 @@
     name: "libartd-compiler_static_defaults",
     defaults: [
         "libart-compiler_static_base_defaults",
-        "libartd_static_defaults",
         "libartbased_static_defaults",
+        "libartd-disassembler_static_defaults",
+        "libartd_static_defaults",
         "libdexfiled_static_defaults",
         "libprofiled_static_defaults",
     ],
diff --git a/compiler/optimizing/graph_visualizer.cc b/compiler/optimizing/graph_visualizer.cc
index 3f6215a..f9c63c4 100644
--- a/compiler/optimizing/graph_visualizer.cc
+++ b/compiler/optimizing/graph_visualizer.cc
@@ -110,13 +110,17 @@
   }
 }
 
+#ifndef ART_STATIC_LIBART_COMPILER
 using create_disasm_prototype = Disassembler*(InstructionSet, DisassemblerOptions*);
+#endif
+
 class HGraphVisualizerDisassembler {
  public:
   HGraphVisualizerDisassembler(InstructionSet instruction_set,
                                const uint8_t* base_address,
                                const uint8_t* end_address)
       : instruction_set_(instruction_set), disassembler_(nullptr) {
+#ifndef ART_STATIC_LIBART_COMPILER
     constexpr const char* libart_disassembler_so_name =
         kIsDebugBuild ? "libartd-disassembler.so" : "libart-disassembler.so";
     libart_disassembler_handle_ = dlopen(libart_disassembler_so_name, RTLD_NOW);
@@ -132,10 +136,11 @@
                  << libart_disassembler_so_name << ": " << dlerror();
       return;
     }
+#endif
     // Reading the disassembly from 0x0 is easier, so we print relative
     // addresses. We will only disassemble the code once everything has
     // been generated, so we can read data in literal pools.
-    disassembler_ = std::unique_ptr<Disassembler>((*create_disassembler)(
+    disassembler_ = std::unique_ptr<Disassembler>(create_disassembler(
             instruction_set,
             new DisassemblerOptions(/* absolute_addresses= */ false,
                                     base_address,
@@ -149,9 +154,11 @@
   ~HGraphVisualizerDisassembler() {
     // We need to call ~Disassembler() before we close the library.
     disassembler_.reset();
+#ifndef ART_STATIC_LIBART_COMPILER
     if (libart_disassembler_handle_ != nullptr) {
       dlclose(libart_disassembler_handle_);
     }
+#endif
   }
 
   void Disassemble(std::ostream& output, size_t start, size_t end) const {
@@ -172,7 +179,9 @@
   InstructionSet instruction_set_;
   std::unique_ptr<Disassembler> disassembler_;
 
+#ifndef ART_STATIC_LIBART_COMPILER
   void* libart_disassembler_handle_;
+#endif
 };
 
 
diff --git a/disassembler/Android.bp b/disassembler/Android.bp
index 064aaea..452e883 100644
--- a/disassembler/Android.bp
+++ b/disassembler/Android.bp
@@ -58,6 +58,14 @@
     ],
 }
 
+cc_defaults {
+    name: "libart-disassembler_static_defaults",
+    whole_static_libs: [
+        "libart-disassembler",
+        "libvixl",
+    ],
+}
+
 art_cc_library {
     name: "libartd-disassembler",
     defaults: [
@@ -75,6 +83,14 @@
     ],
 }
 
+cc_defaults {
+    name: "libartd-disassembler_static_defaults",
+    whole_static_libs: [
+        "libartd-disassembler",
+        "libvixld",
+    ],
+}
+
 cc_library_headers {
     name: "art_disassembler_headers",
     host_supported: true,