Build debug library libdexfiled

Add a debug version of libdexfile for use when CHECKs, etc., are
enabled.

Bug: 22322814
Test: make -j 50 checkbuild
Change-Id: I263138611bcdde9dbc8f619bcb2a0a6d3a09fbf6
diff --git a/Android.bp b/Android.bp
index ad42d3f..bb92e5f 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,7 +1,6 @@
 // TODO: These should be handled with transitive static library dependencies
 art_static_dependencies = [
     // Note: the order is important because of static linking resolution.
-    "libdexfile",
     "libziparchive",
     "libnativehelper",
     "libnativebridge",
diff --git a/compiler/Android.bp b/compiler/Android.bp
index 4539659..ba08d79 100644
--- a/compiler/Android.bp
+++ b/compiler/Android.bp
@@ -184,7 +184,6 @@
     },
     generated_sources: ["art_compiler_operator_srcs"],
     shared_libs: [
-        "libdexfile",
         "libbase",
         "libcutils",  // for atrace.
         "liblzma",
@@ -250,6 +249,7 @@
     },
     shared_libs: [
         "libart",
+        "libdexfile",
     ],
 
     pgo: {
@@ -295,6 +295,7 @@
     },
     shared_libs: [
         "libartd",
+        "libdexfiled",
     ],
 }
 
diff --git a/dex2oat/Android.bp b/dex2oat/Android.bp
index ab06ddd..dd16ba4 100644
--- a/dex2oat/Android.bp
+++ b/dex2oat/Android.bp
@@ -152,7 +152,7 @@
         "libartd-compiler",
         "libartd-dexlayout",
         "libartd",
-        "libdexfile",
+        "libdexfiled",
         "libbase",
         "liblz4",
         "libsigchain",
@@ -185,6 +185,7 @@
         "libart-compiler",
         "libart-dexlayout",
         "libart",
+        "libdexfile",
         "libvixl-arm",
         "libvixl-arm64",
     ] + art_static_dependencies,
@@ -216,6 +217,7 @@
         "libartd-compiler",
         "libartd-dexlayout",
         "libartd",
+        "libdexfiled",
         "libvixld-arm",
         "libvixld-arm64",
     ] + art_static_dependencies,
diff --git a/dexdump/Android.bp b/dexdump/Android.bp
index f6b7a6b..eca0844 100644
--- a/dexdump/Android.bp
+++ b/dexdump/Android.bp
@@ -45,6 +45,7 @@
     host_supported: true,
     device_supported: false,
     static_libs: [
+        "libdexfile",
         "libbase",
     ] + art_static_dependencies,
     target: {
diff --git a/dexlayout/Android.bp b/dexlayout/Android.bp
index 3ea7f4b..bea61d0 100644
--- a/dexlayout/Android.bp
+++ b/dexlayout/Android.bp
@@ -27,7 +27,6 @@
     ],
     export_include_dirs: ["."],
     shared_libs: [
-        "libdexfile",
         "libbase",
     ],
     static_libs: ["libz"],
@@ -36,7 +35,10 @@
 art_cc_library {
     name: "libart-dexlayout",
     defaults: ["libart-dexlayout-defaults"],
-    shared_libs: ["libart"],
+    shared_libs: [
+        "libart",
+        "libdexfile",
+    ],
 
     pgo: {
         instrumentation: true,
@@ -51,7 +53,10 @@
       "libart-dexlayout-defaults",
       "art_debug_defaults",
     ],
-    shared_libs: ["libartd"],
+    shared_libs: [
+        "libartd",
+        "libdexfiled",
+    ],
 }
 
 cc_defaults {
diff --git a/libdexfile/Android.bp b/libdexfile/Android.bp
index bcf2bdb..90c603f 100644
--- a/libdexfile/Android.bp
+++ b/libdexfile/Android.bp
@@ -93,6 +93,14 @@
     },
 }
 
+art_cc_library {
+    name: "libdexfiled",
+    defaults: [
+        "art_debug_defaults",
+        "libdexfile_defaults",
+    ],
+}
+
 art_cc_test {
     name: "art_libdexfile_tests",
     defaults: [
diff --git a/oatdump/Android.bp b/oatdump/Android.bp
index c93c172..012100d 100644
--- a/oatdump/Android.bp
+++ b/oatdump/Android.bp
@@ -51,7 +51,7 @@
         "libartd",
         "libartd-compiler",
         "libartd-disassembler",
-        "libdexfile",
+        "libdexfiled",
         "libbase",
     ],
 }
@@ -76,6 +76,7 @@
     ],
     static_libs: [
         "libart",
+        "libdexfile",
         "libart-compiler",
         "libart-disassembler",
         "libvixl-arm",
@@ -106,6 +107,7 @@
     ],
     static_libs: [
         "libartd",
+        "libdexfiled",
         "libartd-compiler",
         "libartd-disassembler",
         "libvixld-arm",
diff --git a/openjdkjvmti/Android.bp b/openjdkjvmti/Android.bp
index 1500bca..1553b78 100644
--- a/openjdkjvmti/Android.bp
+++ b/openjdkjvmti/Android.bp
@@ -58,7 +58,6 @@
         "libopenjdkjvmti_headers",
     ],
     shared_libs: [
-        "libdexfile",
         "libbase",
     ],
 }
@@ -70,6 +69,7 @@
         "libart",
         "libart-compiler",
         "libart-dexlayout",
+        "libdexfile",
     ],
 }
 
@@ -83,5 +83,6 @@
         "libartd",
         "libartd-compiler",
         "libartd-dexlayout",
+        "libdexfiled",
     ],
 }
diff --git a/profman/Android.bp b/profman/Android.bp
index 6592b9d..163be2b 100644
--- a/profman/Android.bp
+++ b/profman/Android.bp
@@ -31,7 +31,6 @@
     },
 
     shared_libs: [
-        "libdexfile",
         "libbase",
     ],
 }
@@ -41,6 +40,7 @@
     defaults: ["profman-defaults"],
     shared_libs: [
         "libart",
+        "libdexfile",
     ],
 }
 
@@ -52,6 +52,7 @@
     ],
     shared_libs: [
         "libartd",
+        "libdexfiled",
     ],
 }
 
diff --git a/runtime/Android.bp b/runtime/Android.bp
index 110b04f..1ac770f 100644
--- a/runtime/Android.bp
+++ b/runtime/Android.bp
@@ -409,7 +409,6 @@
         "jni_platform_headers",
     ],
     shared_libs: [
-        "libdexfile",
         "libnativebridge",
         "libnativeloader",
         "libbacktrace",
@@ -430,10 +429,7 @@
     // 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
     //       generically. dex2oat takes care of it itself.
-    export_shared_lib_headers: [
-        "libbase",
-        "libdexfile",
-    ],
+    export_shared_lib_headers: ["libbase"],
 }
 
 gensrcs {
@@ -490,6 +486,8 @@
     strip: {
         keep_symbols: true,
     },
+    shared_libs: ["libdexfile"],
+    export_shared_lib_headers: ["libdexfile"],
 }
 
 art_cc_library {
@@ -498,6 +496,8 @@
         "art_debug_defaults",
         "libart_defaults",
     ],
+    shared_libs: ["libdexfiled"],
+    export_shared_lib_headers: ["libdexfiled"],
 }
 
 art_cc_library {
diff --git a/runtime/base/stringpiece.cc b/runtime/base/stringpiece.cc
index 672431c..aea4e74 100644
--- a/runtime/base/stringpiece.cc
+++ b/runtime/base/stringpiece.cc
@@ -23,13 +23,6 @@
 
 namespace art {
 
-#if !defined(NDEBUG)
-char StringPiece::operator[](size_type i) const {
-  CHECK_LT(i, length_);
-  return ptr_[i];
-}
-#endif
-
 void StringPiece::CopyToString(std::string* target) const {
   target->assign(ptr_, length_);
 }
diff --git a/runtime/base/stringpiece.h b/runtime/base/stringpiece.h
index 46743e9..e7109dc 100644
--- a/runtime/base/stringpiece.h
+++ b/runtime/base/stringpiece.h
@@ -20,6 +20,8 @@
 #include <string.h>
 #include <string>
 
+#include <android-base/logging.h>
+
 namespace art {
 
 // A string-like object that points to a sized piece of memory.
@@ -84,13 +86,10 @@
     length_ = len;
   }
 
-#if defined(NDEBUG)
   char operator[](size_type i) const {
+    DCHECK_LT(i, length_);
     return ptr_[i];
   }
-#else
-  char operator[](size_type i) const;
-#endif
 
   void remove_prefix(size_type n) {
     ptr_ += n;
diff --git a/test/Android.bp b/test/Android.bp
index 5f39ffe..d8d90a4 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -62,7 +62,7 @@
         "libvixld-arm",
         "libvixld-arm64",
         "libart-gtest",
-        "libdexfile",
+        "libdexfiled",
 
         "libbase",
         "libicuuc",
@@ -114,7 +114,7 @@
     shared_libs: [
         "libartd",
         "libartd-compiler",
-        "libdexfile",
+        "libdexfiled",
     ],
     static_libs: [
         "libgtest",
@@ -151,7 +151,7 @@
     shared_libs: [
         "libartd",
         "libartd-compiler",
-        "libdexfile",
+        "libdexfiled",
         "libbase",
         "libbacktrace",
     ],
@@ -294,14 +294,16 @@
     ],
     shared_libs: [
         "libbase",
-        "libdexfile",
     ],
 }
 
 art_cc_test_library {
     name: "libtiagent",
     defaults: ["libtiagent-defaults"],
-    shared_libs: ["libart"],
+    shared_libs: [
+        "libart",
+        "libdexfile",
+    ],
 }
 
 art_cc_test_library {
@@ -310,7 +312,10 @@
         "art_debug_defaults",
         "libtiagent-defaults",
     ],
-    shared_libs: ["libartd"],
+    shared_libs: [
+        "libartd",
+        "libdexfiled",
+    ],
 }
 
 art_cc_test_library {
@@ -413,7 +418,6 @@
         "708-jit-cache-churn/jit.cc",
     ],
     shared_libs: [
-        "libdexfile",
         "libbacktrace",
         "libbase",
         "libnativehelper",
@@ -423,7 +427,10 @@
 art_cc_test_library {
     name: "libarttest",
     defaults: ["libarttest-defaults"],
-    shared_libs: ["libart"],
+    shared_libs: [
+        "libart",
+        "libdexfile",
+    ],
 }
 
 art_cc_test_library {
@@ -432,7 +439,10 @@
         "art_debug_defaults",
         "libarttest-defaults",
     ],
-    shared_libs: ["libartd"],
+    shared_libs: [
+        "libartd",
+        "libdexfiled",
+    ],
 }
 
 art_cc_test_library {
diff --git a/test/etc/run-test-jar b/test/etc/run-test-jar
index bb6ace1..b8427f4 100755
--- a/test/etc/run-test-jar
+++ b/test/etc/run-test-jar
@@ -850,7 +850,7 @@
     fi
 
     # System libraries needed by libarttestd.so
-    PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libdexfile.so:libbase.so:libnativehelper.so
+    PUBLIC_LIBS=libart.so:libartd.so:libc++.so:libbacktrace.so:libdexfile.so:libdexfiled.so:libbase.so:libnativehelper.so
 
     # Create a script with the command. The command can get longer than the longest
     # allowed adb command and there is no way to get the exit status from a adb shell
diff --git a/tools/hiddenapi/Android.bp b/tools/hiddenapi/Android.bp
index f9824f1..af87d31 100644
--- a/tools/hiddenapi/Android.bp
+++ b/tools/hiddenapi/Android.bp
@@ -30,7 +30,6 @@
     },
 
     shared_libs: [
-        "libdexfile",
         "libbase",
     ],
 }
@@ -40,6 +39,7 @@
     defaults: ["hiddenapi-defaults"],
     shared_libs: [
         "libart",
+        "libdexfile",
     ],
 }
 
@@ -51,6 +51,7 @@
     ],
     shared_libs: [
         "libartd",
+        "libdexfiled",
     ],
 }
 
diff --git a/tools/public.libraries.buildbot.txt b/tools/public.libraries.buildbot.txt
index 734fd1e..de636a8 100644
--- a/tools/public.libraries.buildbot.txt
+++ b/tools/public.libraries.buildbot.txt
@@ -1,6 +1,7 @@
 libart.so
 libartd.so
 libdexfile.so
+libdexfiled.so
 libbacktrace.so
 libc.so
 libc++.so