Snap for 8253222 from 20d468b1fb706e19044789b2331148581ac9b9da to sdk-release

Change-Id: Ifb5b867d75d4dcb99dbd46868e2bbb39bb13c6cb
diff --git a/Android.bp b/Android.bp
index 2c7c6bb..51bd202 100644
--- a/Android.bp
+++ b/Android.bp
@@ -615,6 +615,23 @@
     ],
 }
 
+// The linker and trampoline compiled as a .o file to use as part of the sysroot
+// crt.
+cc_object {
+    name: "libc_musl_linker_object",
+    defaults: ["libc_musl_defaults"],
+    srcs: [
+        ":musl_linker_asm",
+        "android/ldso_trampoline.cpp",
+    ],
+    cflags: [
+        // These are required to make sure the C code in ldso_trampoline.c
+        // doesn't have any dependencies on libc.
+        "-fno-stack-protector",
+        "-ftrivial-auto-var-init=uninitialized",
+    ],
+}
+
 // The architecture-specific bits have to be handled separately because the label varies based
 // on architecture, which prevents using $(locations) to find them and requires using $(in)
 // instead, which would mix in all the other files if this were part of the main libc_musl_sysroot
@@ -684,10 +701,16 @@
         // Bionic kernel uapi headers
         ":libc_musl_sysroot_bionic_headers",
 
+        // libc++ headers
+        ":libc_musl_sysroot_libc++_headers",
+        ":libc_musl_sysroot_libc++abi_headers",
+
         // Libraries
         ":libc_musl",
         ":libc_musl_for_sysroot",
         ":libc_musl_static",
+        ":libc++abi",
+        ":libc++",
 
         // Objects
         ":libc_musl_crti",
@@ -696,11 +719,8 @@
         ":libc_musl_rcrt1",
         ":libc_musl_Scrt1",
 
-        // Embedded linker objects
-        ":libc_musl_crtbegin_dynamic",
-        ":libc_musl_crtbegin_static",
-        ":libc_musl_crtbegin_so",
-        ":libc_musl_crtend",
+        // Embedded linker objects and linker scripts
+        ":libc_musl_linker_object",
         ":musl_linker_script",
 
         // Wrapper scripts
@@ -719,6 +739,9 @@
     cmd: "includes=($(locations include/**/*.h)) && " +
         "bits=($(locations arch/generic/bits/*.h)) && " +
         "android_bits=($(locations android/include/bits/*.h)) && " +
+        "ln -s libc_musl.so $(genDir)/ld-musl.so.1 && " +
+        "echo -e 'GROUP ( Scrt1-real.o libc_musl_linker_object.o )\nINCLUDE linker.script' > $(genDir)/Scrt1.ld && " +
+        "echo -e 'GROUP ( libc_musl.so )' > $(genDir)/libc.so && " +
         "$(location soong_zip) -o $(genDir)/sysroot.zip " +
         " -j " +
         "  -f $(location LICENSE) " +
@@ -740,13 +763,15 @@
         "  -f $(location :libc_musl_crtn) " +
         "  -f $(location :libc_musl_crt1) " +
         "  -f $(location :libc_musl_rcrt1) " +
-        "  -f $(location :libc_musl_Scrt1) " +
         // embedded linker crt objects
-        "  -f $(location :libc_musl_crtbegin_dynamic) " +
-        "  -f $(location :libc_musl_crtbegin_static) " +
-        "  -f $(location :libc_musl_crtbegin_so) " +
-        "  -f $(location :libc_musl_crtend) " +
         "  -f $(location :musl_linker_script) " +
+        "  -f $(location :libc_musl_linker_object) " +
+        // libs
+        "  -f $(location :libc_musl) " +
+        "  -f $(location :libc++abi) " +
+        "  -f $(location :libc++) " +
+        "  -f $(genDir)/ld-musl.so.1 " +
+        "  -f $(genDir)/libc.so " +
         // clang wrappers
         " -P bin -j " +
         "  -f $(location :libc_musl_clang_wrapper) " +
@@ -755,17 +780,17 @@
         // libs in a separate zip so they can be renamed
         "$(location soong_zip) -o $(genDir)/libs.zip " +
         " -P lib -j " +
-        "  -f $(location :libc_musl) " +
-        "  -f $(location :libc_musl_for_sysroot) " +
         "  -f $(location :libc_musl_static) " +
         "  -f $(location :libc_musl_sysroot_static_empty) " +
+        "  -f $(genDir)/Scrt1.ld " +
+        "  -f $(location :libc_musl_Scrt1) " +
         " && " +
         "$(location zip2zip) -i $(genDir)/libs.zip -o $(genDir)/libs_renamed.zip " +
         // rename libs from module names to desired names in sysroot
         " lib/libc_musl_static.a:lib/libc.a " +
-        " lib/libc_musl.so:lib/libc_musl.so " +
-        " lib/libc_musl_for_sysroot.so:lib/libc.so " +
-        " lib/libc_musl_for_sysroot.so:lib/ld-musl.so.1 " +
+        // Swap in linker script for Scrt1.o
+        " lib/Scrt1.o:lib/Scrt1-real.o " +
+        " lib/Scrt1.ld:lib/Scrt1.o " +
         // copy empty static libs
         " lib/libc_musl_sysroot_static_empty.a:lib/libcrypt.a " +
         " lib/libc_musl_sysroot_static_empty.a:lib/libdl.a " +
@@ -776,8 +801,13 @@
         " lib/libc_musl_sysroot_static_empty.a:lib/libutil.a " +
         " lib/libc_musl_sysroot_static_empty.a:lib/libxnet.a " +
         " && " +
-        "$(location merge_zips) -ignore-duplicates $(out) $(location :libc_musl_sysroot_bionic_headers) " +
-        " $(location :libc_musl_sysroot_bits) $(genDir)/sysroot.zip $(genDir)/libs_renamed.zip",
+        "$(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_bits) " +
+        " $(genDir)/sysroot.zip " +
+        " $(genDir)/libs_renamed.zip",
 }
 
 build=["sources.bp"]
diff --git a/android/ldso_trampoline.cpp b/android/ldso_trampoline.cpp
index 16288ea..72b550c 100644
--- a/android/ldso_trampoline.cpp
+++ b/android/ldso_trampoline.cpp
@@ -45,7 +45,7 @@
 __attribute__((visibility("hidden"))) extern const char __dlwrap_linker_end;
 
 // The real entry point of the binary to use after linker bootstrapping.
-extern "C" void _start();
+__attribute__((visibility("hidden"))) extern "C" void _start();
 
 // Allocate some R/W memory to store a copy of the program headers.
 static ElfW(Phdr) phdr_copy[64];