Link lzma and lz4 compression libs statically into libartbase and use that
instead.

All targets using these compression libs already use libartbase. This grows
libartbase VM size by 240K (219%) on 64 bit, but only these targets pack on
extra bloat: dexanalyze, dexdump2, dexlayout(d), dexlist.

Test: art/tools/buildbot-build.sh {--host,--target}
Test: art/test/testrunner/run_build_test_target.py art-asan
Bug: 118374951
Change-Id: I16d67d99897ec0a35e1467ab561bb82ee2449983
diff --git a/compiler/Android.bp b/compiler/Android.bp
index c2f8e3c..8e4e383 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -180,7 +180,6 @@
     shared_libs: [
         "libbase",
         "libcutils",  // for atrace.
-        "liblzma",
     ],
     include_dirs: ["art/disassembler"],
     header_libs: [
@@ -196,7 +195,6 @@
     static_libs: [
         "libbase",
         "libcutils",
-        "liblzma",
     ],
 }
 
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index 666db42..897dbfb 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -71,11 +71,8 @@
     generated_sources: ["art_dex2oat_operator_srcs"],
     shared_libs: [
         "libbase",
-        "liblz4",
-        "liblzma",
     ],
     include_dirs: [
-        "external/lz4/lib",
         "external/zlib",
     ],
     export_include_dirs: ["."],
@@ -98,8 +95,6 @@
     },
     static_libs: [
         "libbase",
-        "liblz4",
-        "liblzma",
     ],
 }
 
@@ -247,7 +242,6 @@
         "libdexfile",
         "libartbase",
         "libbase",
-        "liblz4",
         "libsigchain",
     ],
     static_libs: [
@@ -285,7 +279,6 @@
         "libdexfiled",
         "libartbased",
         "libbase",
-        "liblz4",
         "libsigchain",
     ],
     static_libs: [
@@ -315,7 +308,6 @@
     ],
     static_libs: [
         "libbase",
-        "liblz4",
         "libsigchain_dummy",
     ],
 }
@@ -411,11 +403,11 @@
         "external/zlib",
     ],
     shared_libs: [
-        "libprofiled",
+        "libartbased",
         "libartd-compiler",
         "libartd-dexlayout",
         "libbase",
-        "liblz4",
+        "libprofiled",
         "libsigchain",
         "libziparchive",
     ],
diff --git a/libartbase/Android.bp b/libartbase/Android.bp
index 5010f68..1e776ae8 100644
--- a/libartbase/Android.bp
+++ b/libartbase/Android.bp
@@ -71,6 +71,16 @@
         // For common macros.
         "libbase",
     ],
+
+    // Utilities used by various ART libs and tools are linked in statically
+    // here to avoid shared lib dependencies outside the ART APEX. No target
+    // there should depend on these separately.
+    whole_static_libs: [
+        "liblz4",
+        "liblzma",
+    ],
+    version_script: "libartbase.map",
+
     export_include_dirs: ["."],
     // ART's macros.h depends on libbase's macros.h.
     // Note: runtime_options.h depends on cmdline. But we don't really want to export this
diff --git a/libartbase/libartbase.map b/libartbase/libartbase.map
new file mode 100644
index 0000000..6249930
--- /dev/null
+++ b/libartbase/libartbase.map
@@ -0,0 +1,15 @@
+# This is used only to hide data symbols that get imported through
+# whole_static_libs, or else they might trigger the ASan odr-violation check.
+# Before adding symbols here, please make sure that it doesn't give rise to a
+# real ODR problem. All these symbols are either in .rodata or .data.rel.ro
+# sections.
+LIBARTBASE {
+  local:
+    PPMD7_kExpEscape;
+    XZ_SIG;
+    g_AlignedAlloc;
+    g_Alloc;
+    g_BigAlloc;
+    g_MidAlloc;
+    k7zSignature;
+};
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 86ee952..4c1b288 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -377,7 +377,6 @@
     include_dirs: [
         "art/sigchainlib",
         "external/icu/icu4c/source/common",
-        "external/lz4/lib",
         "external/zlib",
     ],
     header_libs: [
@@ -390,7 +389,6 @@
         "libnativebridge",
         "libnativeloader",
         "libbacktrace",
-        "liblz4",
         "liblog",
         // For atrace, properties, ashmem, set_sched_policy.
         "libcutils",
@@ -422,8 +420,6 @@
         "libbase",
         "libcutils",
         "liblog",
-        "liblz4",
-        "liblzma",
         "libnativebridge",
         "libnativeloader",
         "libunwindstack",