Move ArtDexFileLoader to libdexfile

Adds a dependency from libdexfile on libartbase, but allows the use of
MemMap loaders, etc.

Bug: 78652467
Test: make -j 40 checkbuild
Change-Id: I15cf33893ca9192050762f8350a3cc1e39f88dc5
diff --git a/adbconnection/Android.bp b/adbconnection/Android.bp
index 441b706..95fc274 100644
--- a/adbconnection/Android.bp
+++ b/adbconnection/Android.bp
@@ -65,6 +65,7 @@
     defaults: ["adbconnection-defaults"],
     shared_libs: [
         "libart",
+        "libartbase",
     ],
 }
 
@@ -76,5 +77,6 @@
     ],
     shared_libs: [
         "libartd",
+        "libartbased",
     ],
 }
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 5884a54..be963fb 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -246,6 +246,7 @@
         "libart",
         "libprofile",
         "libdexfile",
+        "libartbase",
     ],
 
     target: {
@@ -295,6 +296,7 @@
         "libartd",
         "libprofiled",
         "libdexfiled",
+        "libartbased",
     ],
 }
 
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index 18548ba..e74947a 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -202,6 +202,7 @@
         "libart-dexlayout",
         "libart",
         "libdexfile",
+        "libartbase",
         "libbase",
         "liblz4",
         "libsigchain",
@@ -239,6 +240,7 @@
         "libartd-dexlayout",
         "libartd",
         "libdexfiled",
+        "libartbased",
         "libbase",
         "liblz4",
         "libsigchain",
@@ -267,12 +269,13 @@
         "-z muldefs",
     ],
     static_libs: [
-        "libprofile",
         "libart-dex2oat",
         "libart-compiler",
         "libart-dexlayout",
         "libart",
+        "libartbase",
         "libdexfile",
+        "libprofile",
         "libvixl-arm",
         "libvixl-arm64",
     ] + art_static_dependencies,
@@ -309,6 +312,7 @@
         "libartd-compiler",
         "libartd-dexlayout",
         "libartd",
+        "libartbased",
         "libprofiled",
         "libdexfiled",
         "libvixld-arm",
diff --git a/dexdump/Android.bp b/dexdump/Android.bp
index c63d6c3..2f0962c 100644
--- a/dexdump/Android.bp
+++ b/dexdump/Android.bp
@@ -35,6 +35,7 @@
     host_supported: true,
     shared_libs: [
         "libdexfile",
+        "libartbase",
         "libbase",
     ],
 }
@@ -46,6 +47,7 @@
     device_supported: false,
     static_libs: [
         "libdexfile",
+        "libartbase",
     ] + art_static_dependencies,
     target: {
         darwin: {
diff --git a/dexlayout/Android.bp b/dexlayout/Android.bp
index b009774..bf56239 100644
--- a/dexlayout/Android.bp
+++ b/dexlayout/Android.bp
@@ -41,6 +41,7 @@
     shared_libs: [
         "libart",
         "libdexfile",
+        "libartbase",
         "libprofile",
     ],
 
@@ -62,6 +63,7 @@
     shared_libs: [
         "libartd",
         "libdexfiled",
+        "libartbased",
         "libprofiled",
     ],
 }
@@ -82,6 +84,7 @@
     shared_libs: [
         "libprofile",
         "libart",
+        "libartbase",
         "libart-dexlayout",
     ],
 }
@@ -95,6 +98,7 @@
     shared_libs: [
         "libprofiled",
         "libartd",
+        "libartbased",
         "libartd-dexlayout",
     ],
 }
@@ -117,6 +121,7 @@
     cflags: ["-Wall"],
     shared_libs: [
         "libart",
+        "libartbase",
         "libart-dexlayout",
         "libbase",
     ],
diff --git a/dexlist/Android.bp b/dexlist/Android.bp
index 2703732..bd521ac 100644
--- a/dexlist/Android.bp
+++ b/dexlist/Android.bp
@@ -17,7 +17,11 @@
     host_supported: true,
     srcs: ["dexlist.cc"],
     cflags: ["-Wall", "-Werror"],
-    shared_libs: ["libdexfile", "libbase"],
+    shared_libs: [
+        "libdexfile",
+        "libartbase",
+        "libbase"
+    ],
     // TODO: fix b/72216369 and remove the need for this.
     include_dirs: [
         "art/runtime"  // dex utils.
diff --git a/dexoptanalyzer/Android.bp b/dexoptanalyzer/Android.bp
index 33366ad..99a11cd 100644
--- a/dexoptanalyzer/Android.bp
+++ b/dexoptanalyzer/Android.bp
@@ -38,6 +38,7 @@
     defaults: ["dexoptanalyzer-defaults"],
     shared_libs: [
         "libart",
+        "libartbase",
     ],
 }
 
@@ -49,6 +50,7 @@
     ],
     shared_libs: [
         "libartd",
+        "libartbased",
     ],
 }
 
diff --git a/imgdiag/Android.bp b/imgdiag/Android.bp
index 2b89497..972c8f7 100644
--- a/imgdiag/Android.bp
+++ b/imgdiag/Android.bp
@@ -57,6 +57,7 @@
     defaults: ["imgdiag-defaults"],
     shared_libs: [
         "libart",
+        "libartbase",
         "libart-compiler",
     ],
 }
@@ -69,6 +70,7 @@
     ],
     shared_libs: [
         "libartd",
+        "libartbased",
         "libartd-compiler",
     ],
 }
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
index 9d49f37..3818624 100644
--- a/libdexfile/Android.bp
+++ b/libdexfile/Android.bp
@@ -19,6 +19,7 @@
     defaults: ["art_defaults"],
     host_supported: true,
     srcs: [
+        "dex/art_dex_file_loader.cc",
         "dex/compact_dex_file.cc",
         "dex/compact_offset_table.cc",
         "dex/descriptors_names.cc",
@@ -55,25 +56,20 @@
     },
     generated_sources: ["dexfile_operator_srcs"],
     shared_libs: [
+        // For MemMap.
         "libartbase",
-        // Important note: relying on libartbase's header_lib is perfectly acceptable.
-        // However, relying on the libartbase shared library introduces further, possibly cyclic,
-	// dependencies for clients outside of ART.
         "liblog",
+        // For atrace.
+        "libcutils",
         // For common macros.
         "libbase",
         "libz",
     ],
-    header_libs: [
-        "art_libartbase_headers",
-    ],
     export_include_dirs: ["."],
     export_shared_lib_headers: [
+        "libartbase",
         "libbase",
     ],
-    export_header_lib_headers: [
-        "art_libartbase_headers",
-    ],
 }
 
 gensrcs {
@@ -115,6 +111,7 @@
         "art_gtest_defaults",
     ],
     srcs: [
+        "dex/art_dex_file_loader_test.cc",
         "dex/code_item_accessors_test.cc",
         "dex/compact_dex_file_test.cc",
         "dex/compact_offset_table_test.cc",
diff --git a/runtime/dex/art_dex_file_loader.cc b/libdexfile/dex/art_dex_file_loader.cc
similarity index 100%
rename from runtime/dex/art_dex_file_loader.cc
rename to libdexfile/dex/art_dex_file_loader.cc
diff --git a/runtime/dex/art_dex_file_loader.h b/libdexfile/dex/art_dex_file_loader.h
similarity index 97%
rename from runtime/dex/art_dex_file_loader.h
rename to libdexfile/dex/art_dex_file_loader.h
index 7577945..a460aee 100644
--- a/runtime/dex/art_dex_file_loader.h
+++ b/libdexfile/dex/art_dex_file_loader.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef ART_RUNTIME_DEX_ART_DEX_FILE_LOADER_H_
-#define ART_RUNTIME_DEX_ART_DEX_FILE_LOADER_H_
+#ifndef ART_LIBDEXFILE_DEX_ART_DEX_FILE_LOADER_H_
+#define ART_LIBDEXFILE_DEX_ART_DEX_FILE_LOADER_H_
 
 #include <cstdint>
 #include <memory>
@@ -137,4 +137,4 @@
 
 }  // namespace art
 
-#endif  // ART_RUNTIME_DEX_ART_DEX_FILE_LOADER_H_
+#endif  // ART_LIBDEXFILE_DEX_ART_DEX_FILE_LOADER_H_
diff --git a/runtime/dex/art_dex_file_loader_test.cc b/libdexfile/dex/art_dex_file_loader_test.cc
similarity index 100%
rename from runtime/dex/art_dex_file_loader_test.cc
rename to libdexfile/dex/art_dex_file_loader_test.cc
diff --git a/libprofile/Android.bp b/libprofile/Android.bp
index bcb90cb..b9883f6 100644
--- a/libprofile/Android.bp
+++ b/libprofile/Android.bp
@@ -45,6 +45,7 @@
     shared_libs: [
         "libartbase",
         "libdexfile",
+        "libartbase",
 	// For atrace.
         "libcutils",
     ],
@@ -97,6 +98,7 @@
     shared_libs: [
         "libartbased",
         "libdexfiled",
+        "libartbased",
         "libziparchive",
     ],
 }
diff --git a/oatdump/Android.bp b/oatdump/Android.bp
index 535acdf..77dede3 100644
--- a/oatdump/Android.bp
+++ b/oatdump/Android.bp
@@ -39,6 +39,7 @@
         "libart-compiler",
         "libart-disassembler",
         "libdexfile",
+        "libartbase",
         "libprofile",
         "libbase",
     ],
@@ -55,6 +56,7 @@
         "libartd-compiler",
         "libartd-disassembler",
         "libdexfiled",
+        "libartbased",
         "libprofiled",
         "libbase",
     ],
@@ -82,6 +84,7 @@
         "libart",
         "libdexfile",
         "libprofile",
+        "libartbase",
         "libart-compiler",
         "libart-disassembler",
         "libvixl-arm",
@@ -117,6 +120,7 @@
         "libartd",
         "libdexfiled",
         "libprofiled",
+        "libartbased",
         "libartd-compiler",
         "libartd-disassembler",
         "libvixld-arm",
diff --git a/openjdkjvm/Android.bp b/openjdkjvm/Android.bp
index a178993..907315e 100644
--- a/openjdkjvm/Android.bp
+++ b/openjdkjvm/Android.bp
@@ -29,7 +29,10 @@
 art_cc_library {
     name: "libopenjdkjvm",
     defaults: ["libopenjdkjvm_defaults"],
-    shared_libs: ["libart"],
+    shared_libs: [
+        "libart",
+        "libartbase",
+    ],
 }
 
 art_cc_library {
@@ -38,5 +41,8 @@
         "art_debug_defaults",
         "libopenjdkjvm_defaults",
     ],
-    shared_libs: ["libartd"],
+    shared_libs: [
+        "libartd",
+        "libartbased",
+    ],
 }
diff --git a/openjdkjvmti/Android.bp b/openjdkjvmti/Android.bp
index 81b69e8..d8902d6 100644
--- a/openjdkjvmti/Android.bp
+++ b/openjdkjvmti/Android.bp
@@ -71,6 +71,7 @@
         "libart-compiler",
         "libart-dexlayout",
         "libdexfile",
+        "libartbase",
     ],
 }
 
@@ -85,5 +86,6 @@
         "libartd-compiler",
         "libartd-dexlayout",
         "libdexfiled",
+        "libartbased",
     ],
 }
diff --git a/patchoat/Android.bp b/patchoat/Android.bp
index 1e2f328..13c8f47 100644
--- a/patchoat/Android.bp
+++ b/patchoat/Android.bp
@@ -59,7 +59,6 @@
         "patchoat_test.cc",
     ],
     shared_libs: [
-        "libartd",
         "libcrypto", // For computing the digest of image file
     ],
 }
diff --git a/profman/Android.bp b/profman/Android.bp
index 3c8c72c..5aaccb0 100644
--- a/profman/Android.bp
+++ b/profman/Android.bp
@@ -42,6 +42,7 @@
         "libart",
         "libprofile",
         "libdexfile",
+        "libartbase",
     ],
 }
 
@@ -55,6 +56,7 @@
         "libartd",
         "libprofiled",
         "libdexfiled",
+        "libartbased",
     ],
 }
 
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 0540b20..92607f5 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -45,7 +45,6 @@
         "compiler_filter.cc",
         "debug_print.cc",
         "debugger.cc",
-        "dex/art_dex_file_loader.cc",
         "dex/dex_file_annotations.cc",
         "dex_to_dex_decompiler.cc",
         "elf_file.cc",
@@ -464,9 +463,9 @@
         keep_symbols: true,
     },
     whole_static_libs: [
-        "libartbase",
     ],
     shared_libs: [
+        "libartbase",
         "libdexfile",
         "libprofile",
     ],
@@ -489,9 +488,9 @@
         "libart_defaults",
     ],
     whole_static_libs: [
-        "libartbased",
     ],
     shared_libs: [
+        "libartbased",
         "libdexfiled",
         "libprofiled",
     ],
@@ -545,7 +544,6 @@
         "class_loader_context_test.cc",
         "class_table_test.cc",
         "compiler_filter_test.cc",
-        "dex/art_dex_file_loader_test.cc",
         "entrypoints/math_entrypoints_test.cc",
         "entrypoints/quick/quick_trampoline_entrypoints_test.cc",
         "entrypoints_order_test.cc",
diff --git a/simulator/Android.bp b/simulator/Android.bp
index 74b5a90..8690426 100644
--- a/simulator/Android.bp
+++ b/simulator/Android.bp
@@ -44,6 +44,7 @@
     defaults: ["libart_simulator_defaults"],
     shared_libs: [
         "libart",
+        "libartbase",
         "libvixl-arm64",
     ],
 }
@@ -56,6 +57,7 @@
     ],
     shared_libs: [
         "libartd",
+        "libartbased",
         "libvixld-arm64",
     ],
 }
@@ -80,6 +82,7 @@
     name: "libart-simulator-container",
     defaults: ["libart_simulator_container_defaults"],
     shared_libs: [
+        "libartbase",
         "libart",
     ],
 }
@@ -91,6 +94,7 @@
         "libart_simulator_container_defaults",
     ],
     shared_libs: [
+        "libartbased",
         "libartd",
     ],
 }
diff --git a/test/Android.bp b/test/Android.bp
index 84f2e22..7909bf8 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -64,6 +64,7 @@
         "libart-gtest",
         "libdexfiled",
         "libprofiled",
+        "libartbased",
 
         "libbase",
         "libicuuc",
@@ -117,6 +118,7 @@
         "libartd-compiler",
         "libdexfiled",
         "libprofiled",
+        "libartbased",
     ],
     static_libs: [
         "libgtest",
@@ -156,6 +158,7 @@
         "libartd-compiler",
         "libdexfiled",
         "libprofiled",
+        "libartbased",
         "libbase",
         "libbacktrace",
     ],
@@ -187,6 +190,7 @@
         "libart",
         "libdexfile",
         "libprofile",
+        "libartbase",
     ],
 }
 
@@ -201,6 +205,7 @@
         "libartd",
         "libdexfiled",
         "libprofiled",
+        "libartbased",
     ],
 }
 
@@ -322,6 +327,7 @@
         "libart",
         "libdexfile",
         "libprofile",
+        "libartbase",
     ],
 }
 
@@ -335,6 +341,7 @@
         "libartd",
         "libdexfiled",
         "libprofiled",
+        "libartbased",
     ],
 }
 
@@ -496,6 +503,7 @@
         "libart",
         "libdexfile",
         "libprofile",
+        "libartbase",
     ],
 }
 
@@ -509,6 +517,7 @@
         "libartd",
         "libdexfiled",
         "libprofiled",
+        "libartbased",
     ],
 }
 
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index fad8011..1ba433e 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -861,9 +861,9 @@
     # System libraries needed by libarttestd.so
     PUBLIC_LIBS=libc++.so:libbacktrace.so:libbase.so:libnativehelper.so
     if [ "$TEST_IS_NDEBUG" = "y" ]; then
-      PUBLIC_LIBS=$PUBLIC_LIBS:libart.so:libdexfile.so:libprofile.so
+      PUBLIC_LIBS=$PUBLIC_LIBS:libart.so:libdexfile.so:libprofile.so:libartbase.so
     else
-      PUBLIC_LIBS=$PUBLIC_LIBS:libartd.so:libdexfiled.so:libprofiled.so
+      PUBLIC_LIBS=$PUBLIC_LIBS:libartd.so:libdexfiled.so:libprofiled.so:libartbased.so
     fi
 
     # Create a script with the command. The command can get longer than the longest
diff --git a/tools/cpp-define-generator/Android.bp b/tools/cpp-define-generator/Android.bp
index 39e57bd..23cc917 100644
--- a/tools/cpp-define-generator/Android.bp
+++ b/tools/cpp-define-generator/Android.bp
@@ -31,6 +31,7 @@
     include_dirs: [
         "art/libartbase",
         "art/libdexfile",
+        "art/libartbase",
         "art/runtime",
     ],
     srcs: ["main.cc"],
diff --git a/tools/dexanalyze/Android.bp b/tools/dexanalyze/Android.bp
index 2754e64..a229d73 100644
--- a/tools/dexanalyze/Android.bp
+++ b/tools/dexanalyze/Android.bp
@@ -37,6 +37,7 @@
     defaults: ["dexanalyze-defaults"],
     shared_libs: [
         "libdexfile",
+        "libartbase",
         "libbase",
     ],
 }
diff --git a/tools/hiddenapi/Android.bp b/tools/hiddenapi/Android.bp
index af87d31..3b364b6 100644
--- a/tools/hiddenapi/Android.bp
+++ b/tools/hiddenapi/Android.bp
@@ -40,6 +40,7 @@
     shared_libs: [
         "libart",
         "libdexfile",
+        "libartbase",
     ],
 }
 
@@ -52,6 +53,7 @@
     shared_libs: [
         "libartd",
         "libdexfiled",
+        "libartbased",
     ],
 }
 
diff --git a/tools/public.libraries.buildbot.txt b/tools/public.libraries.buildbot.txt
index 6c81145..9b171a2 100644
--- a/tools/public.libraries.buildbot.txt
+++ b/tools/public.libraries.buildbot.txt
@@ -1,5 +1,7 @@
 libart.so
 libartd.so
+libartbase.so
+libartbased.so
 libdexfile.so
 libdexfiled.so
 libbacktrace.so
diff --git a/tools/veridex/Android.bp b/tools/veridex/Android.bp
index 570960c..5186c43 100644
--- a/tools/veridex/Android.bp
+++ b/tools/veridex/Android.bp
@@ -24,7 +24,11 @@
         "veridex.cc",
     ],
     cflags: ["-Wall", "-Werror"],
-    shared_libs: ["libdexfile", "libbase"],
+    shared_libs: [
+        "libdexfile",
+        "libartbase",
+        "libbase",
+    ],
     header_libs: [
         "art_libartbase_headers",
     ],