Snap for 8513021 from 927e93bcf2e178b5a0b7f00bb2ef16601eb88437 to main-cg-testing-release

Change-Id: I6c84d9d6fc21111c68b5beb5f0ea05662c84e0e4
diff --git a/Android.bp b/Android.bp
index d6d7c64..7b7e22e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -307,19 +307,6 @@
     ],
 }
 
-// Musl sources for the dynamic linker when used in the sysroot.
-cc_library_static {
-    name: "libc_musl_ldso_sysroot",
-    defaults: [
-        "libc_musl_defaults",
-        "libc_musl_ldso_sources",
-    ],
-    cflags: [
-        "-fno-stack-protector",
-        "-DLIBC_SONAME=libc.so",
-    ],
-}
-
 // An attempt to compile the dynamic linker as a standalone library separate from libc_musl.so.
 // Not used yet.
 cc_library_shared {
@@ -602,22 +589,6 @@
 //
 
 
-// A copy of libc_musl that uses libc.so as its soname for putting in the sysroot.
-cc_library_shared {
-    name: "libc_musl_for_sysroot",
-    defaults: ["libc_musl_defaults"],
-    whole_static_libs: ["libc_musl_static"],
-    shared: {
-        whole_static_libs: ["libc_musl_ldso_sysroot"],
-    },
-    ldflags: [
-        "-Wl,-e,_dlstart",
-        "-nostdlib",
-        "-Wl,--soname,libc.so",
-    ],
-    dynamic_list: "dynamic.list",
-}
-
 // An empty static library that will be copied to libdl.a, etc. in the sysroot.
 // Shouldn't be used by anything else besides the sysroot cc_genrule.
 cc_library_static {
@@ -687,6 +658,11 @@
         "chmod a+x $(out)",
 }
 
+cc_library_host_static {
+    name: "libz_static_for_sysroot",
+    whole_static_libs: ["libz"],
+}
+
 cc_genrule {
     name: "libc_musl_sysroot",
     host_supported: true,
@@ -716,14 +692,15 @@
         // libc++ headers
         ":libc_musl_sysroot_libc++_headers",
         ":libc_musl_sysroot_libc++abi_headers",
+        ":libc_musl_sysroot_zlib_headers",
 
         // Libraries
         ":libc_musl",
-        ":libc_musl_for_sysroot",
         ":libc_musl_static",
         ":libc++abi",
         ":libc++",
         ":libc++_static",
+        ":libz_static_for_sysroot",
 
         // Objects
         ":libc_musl_crti",
@@ -802,6 +779,7 @@
         "  -f $(location :libc++_static) " +
         "  -f $(location :clang_rt.crtbegin) " +
         "  -f $(location :clang_rt.crtend) " +
+        "  -f $(location :libz_static_for_sysroot) " +
         " && " +
         "$(location zip2zip) -i $(genDir)/libs.zip -o $(genDir)/libs_renamed.zip " +
         // rename libs from module names to desired names in sysroot
@@ -825,11 +803,14 @@
         " lib/clang_rt.crtbegin.o:lib/crtbeginT.o " +
         " lib/clang_rt.crtend.o:lib/crtend.o " +
         " lib/clang_rt.crtend.o:lib/crtendS.o " +
+        // rename static libz
+        " lib/libz_static_for_sysroot.a:lib/libz.a " +
         " && " +
         "$(location merge_zips) -ignore-duplicates $(out) " +
         " $(location :libc_musl_sysroot_bionic_headers) " +
         " $(location :libc_musl_sysroot_libc++_headers) " +
         " $(location :libc_musl_sysroot_libc++abi_headers) " +
+        " $(location :libc_musl_sysroot_zlib_headers) " +
         " $(location :libc_musl_sysroot_bits) " +
         " $(genDir)/sysroot.zip " +
         " $(genDir)/libs_renamed.zip",