Link liblz4 and liblzma dynamically again.

This reverts https://r.android.com/821441 in spirit - it was an attempt
to avoid external shared lib dependencies before the APEX library
dependency logic was built. Now these shared libraries will simply be
added as internal libs in the APEX.

Soong doesn't propagate shared lib dependencies in static libs, so we
have to repeat them in some cases where libelffile and libart-dex2oat
are used.

Test: art/build/apex/runtests.sh
Test: art/tools/buildbot-build.sh
Bug: 118374951
Change-Id: I0a61b8388f12a749ab8ab5074866eebbad78548b
diff --git a/build/apex/art_apex_test.py b/build/apex/art_apex_test.py
index 5541e24..eb1dd78 100755
--- a/build/apex/art_apex_test.py
+++ b/build/apex/art_apex_test.py
@@ -578,6 +578,7 @@
     self._checker.check_native_library('libc++')
     self._checker.check_native_library('libdt_socket')
     self._checker.check_native_library('libjdwp')
+    self._checker.check_native_library('liblz4')
     self._checker.check_native_library('liblzma')
     self._checker.check_native_library('libnpt')
     self._checker.check_native_library('libunwindstack')
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 8896c84..a0118ca 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -160,6 +160,7 @@
     generated_sources: ["art_compiler_operator_srcs"],
     shared_libs: [
         "libbase",
+        "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib.
     ],
     header_libs: [
         "art_cmdlineparser_headers", // For compiler_options.
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index 3f83031..ef3ebb2 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -58,10 +58,8 @@
     generated_sources: ["art_dex2oat_operator_srcs"],
     shared_libs: [
         "libbase",
-
-        // For SHA-1 checksumming of build ID
-        "libcrypto",
-
+        "libcrypto", // For SHA-1 checksumming of build ID
+        "liblz4",
         "libz",
     ],
     export_include_dirs: ["."],
@@ -72,6 +70,7 @@
     static_libs: [
         "libbase",
         "libcrypto",
+        "liblz4",
         "libz",
     ],
 }
@@ -212,15 +211,16 @@
     // either dex2oat or dex2oatd in ART source builds.
     visibility: ["//visibility:public"],
     shared_libs: [
-        "libprofile",
+        "libart",
         "libart-compiler",
         "libart-dexlayout",
-        "libart",
-        "libcrypto",
-        "libdexfile",
         "libartbase",
         "libartpalette",
         "libbase",
+        "libcrypto",
+        "libdexfile",
+        "liblz4", // libart-dex2oat dependency; must be repeated here since it's a static lib.
+        "libprofile",
         "libsigchain",
         "libz",
     ],
@@ -279,15 +279,16 @@
     // either dex2oat or dex2oatd in ART source builds.
     visibility: ["//visibility:public"],
     shared_libs: [
-        "libprofiled",
+        "libartbased",
+        "libartd",
         "libartd-compiler",
         "libartd-dexlayout",
-        "libartd",
-        "libcrypto",
-        "libdexfiled",
-        "libartbased",
         "libartpalette",
         "libbase",
+        "libcrypto",
+        "libdexfiled",
+        "liblz4", // libartd-dex2oat dependency; must be repeated here since it's a static lib.
+        "libprofiled",
         "libsigchain",
         "libz",
     ],
@@ -389,11 +390,12 @@
         "common_compiler_driver_test.cc",
     ],
     shared_libs: [
-        "libartd-compiler",
-        "libartd-disassembler",
         "libart-compiler-gtest",
         "libart-runtime-gtest",
+        "libartd-compiler",
+        "libartd-disassembler",
         "libbase",
+        "liblz4", // libartd-dex2oat dependency; must be repeated here since it's a static lib.
     ],
     static_libs: [
         "libartd-dex2oat",
@@ -479,6 +481,7 @@
         "libartpalette",
         "libbase",
         "libcrypto",
+        "liblz4", // libartd-dex2oat dependency; must be repeated here since it's a static lib.
         "libprofiled",
         "libsigchain",
         "libziparchive",
diff --git a/libartbase/Android.bp b/libartbase/Android.bp
index 3efdba5..8f26196 100644
--- a/libartbase/Android.bp
+++ b/libartbase/Android.bp
@@ -72,10 +72,6 @@
                 "libbase",
             ],
             export_shared_lib_headers: ["libbase"],
-            // Exclude the version script from Darwin host since it's not
-            // supported by the linker there. That means ASan checks on Darwin
-            // might trigger ODR violations.
-            version_script: "libartbase.map",
         },
         not_windows: {
             srcs: [
@@ -93,11 +89,7 @@
             ],
             export_shared_lib_headers: ["libbase"],
         },
-        linux_glibc: {
-            version_script: "libartbase.map",
-        },
         windows: {
-            version_script: "libartbase.map",
             srcs: [
                 "base/mem_map_windows.cc",
             ],
@@ -120,14 +112,6 @@
     generated_sources: ["art_libartbase_operator_srcs"],
     cflags: ["-DBUILDING_LIBART=1"],
 
-    // 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",
-    ],
-
     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
deleted file mode 100644
index 6249930..0000000
--- a/libartbase/libartbase.map
+++ /dev/null
@@ -1,15 +0,0 @@
-# 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/libelffile/Android.bp b/libelffile/Android.bp
index de7fa96..6b2b34f 100644
--- a/libelffile/Android.bp
+++ b/libelffile/Android.bp
@@ -27,6 +27,7 @@
     ],
     shared_libs: [
         "libbase",
+        "liblzma",
     ],
 }
 
diff --git a/runtime/Android.bp b/runtime/Android.bp
index e8d95bd..cd3c812 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -416,14 +416,15 @@
     ],
     shared_libs: [
         "libartpalette",
+        "libbacktrace",
+        "libbase", // For common macros.
+        "liblog",
+        "liblz4",
+        "liblzma", // libelffile(d) dependency; must be repeated here since it's a static lib.
         "libnativebridge",
         "libnativeloader",
-        "libbacktrace",
-        "liblog",
-        // For common macros.
-        "libbase",
-        "libunwindstack",
         "libsigchain",
+        "libunwindstack",
     ],
     export_include_dirs: ["."],
     // ART's macros.h depends on libbase's macros.h.
@@ -469,6 +470,8 @@
         "libbacktrace",
         "libbase",
         "liblog",
+        "liblz4",
+        "liblzma", // libelffile dependency; must be repeated here since it's a static lib.
         "libnativebridge",
         "libnativeloader",
         "libsigchain_fake",