Merge "Use icu4c to implement <wctype.h>."
diff --git a/README.md b/README.md
index 6f8edf4..0dd7490 100644
--- a/README.md
+++ b/README.md
@@ -219,6 +219,9 @@
### Host tests
The host tests require that you have `lunch`ed either an x86 or x86_64 target.
+Note that due to ABI limitations (specifically, the size of pthread_mutex_t),
+32-bit bionic requires PIDs less than 65536. To enforce this, set /proc/sys/kernel/pid_max
+to 65536.
$ ./tests/run-on-host.sh 32
$ ./tests/run-on-host.sh 64 # For x86_64-bit *targets* only.
diff --git a/android-changes-for-ndk-developers.md b/android-changes-for-ndk-developers.md
index 8925926..5b0fe38 100644
--- a/android-changes-for-ndk-developers.md
+++ b/android-changes-for-ndk-developers.md
@@ -11,6 +11,92 @@
and “pax-utils” for scanelf.
+## Changes to library search order
+
+We have made various fixes to library search order when resolving symbols.
+
+With API 22, load order switched from depth-first to breadth-first to
+fix dlsym(3).
+
+Before API 23, the default search order was to try the main executable,
+LD_PRELOAD libraries, the library itself, and its DT_NEEDED libraries
+in that order. For API 23 and later, for any given library, the dynamic
+linker divides other libraries into the global group and the local
+group. The global group is shared by all libraries and contains the main
+executable, LD_PRELOAD libraries, and any library with the DF_1_GLOBAL
+flag set (by passing “-z global” to ld(1)). The local group is
+the breadth-first transitive closure of the library and its DT_NEEDED
+libraries. The M dynamic linker searches the global group followed by
+the local group. This allows ASAN, for example, to ensure that it can
+intercept any symbol.
+
+
+## RTLD_LOCAL (Available in API level >= 23)
+
+The dlopen(3) RTLD_LOCAL flag used to be ignored but is implemented
+correctly in API 23 and later. Note that RTLD_LOCAL is the default,
+so even calls to dlopen(3) that didn’t explicitly use RTLD_LOCAL will
+be affected (unless they explicitly used RTLD_GLOBAL). With RTLD_LOCAL,
+symbols will not be made available to libraries loaded by later calls
+to dlopen(3) (as opposed to being referenced by DT_NEEDED entries).
+
+
+## GNU hashes (Availible in API level >= 23)
+
+The GNU hash style available with --hash-style=gnu allows faster
+symbol lookup and is now supported by the dynamic linker in API 23 and
+above. (Use --hash-style=both if you want to build code that uses this
+feature >= Android M but still works on older releases.)
+
+
+## Correct soname/path handling (Available in API level >= 23)
+
+The dynamic linker now understands the difference
+between a library’s soname and its path (public bug
+https://code.google.com/p/android/issues/detail?id=6670). API level 23
+is the first release where search by soname is implemented. Earlier
+releases would assume that the basename of the library was the soname,
+and used that to search for already-loaded libraries. For example,
+`dlopen("/this/directory/does/not/exist/libc.so", RTLD_NOW)` would
+find `/system/lib/libc.so` because it’s already loaded. This also meant
+that it was impossible to have two libraries `"dir1/libx.so"` and
+`"dir2/libx.so"` --- the dynamic linker couldn’t tell the difference
+and would always use whichever was loaded first, even if you explicitly
+tried to load both. This also applied to DT_NEEDED entries.
+
+Some apps have bad DT_NEEDED entries (usually absolute paths on the build
+machine’s file system) that used to work because we ignored everything
+but the basename. These apps will fail to load on API level 23 and above.
+
+
+## Symbol versioning (Available in API level >= 23)
+
+Symbol versioning allows libraries to provide better backwards
+compatibility. For example, if a library author knowingly changes
+the behavior of a function, they can provide two versions in the same
+library so that old code gets the old version and new code gets the new
+version. This is supported in API level 23 and above.
+
+
+## Opening shared libraries directly from an APK
+
+In API level 23 and above, it’s possible to open a .so file directly from
+your APK. Just use `System.loadLibrary("foo")` exactly as normal but set
+`android:extractNativeLibs="false"` in your `AndroidManifest.xml`. In
+older releases, the .so files were extracted from the APK file
+at install time. This meant that they took up space in your APK and
+again in your installation directory (and this was counted against you
+and reported to the user as space taken up by your app). Any .so file
+that you want to load directly from your APK must be page aligned
+(on a 4096-byte boundary) in the zip file and stored uncompressed.
+Current versions of the zipalign tool take care of alignment.
+
+Note that in API level 23 and above dlopen(3) will open a library from
+any zip file, not just your APK. Just give dlopen(3) a path of the form
+"my_zip_file.zip!/libs/libstuff.so". As with APKs, the library must be
+page-aligned and stored uncompressed for this to work.
+
+
## Private API (Enforced for API level >= 24)
Native libraries must use only public API, and must not link against
@@ -204,7 +290,7 @@
the -soname linker option).
-## Writable and Executable Segments (AOSP master)
+## Writable and Executable Segments (Enforced for API level >= 26)
Each segment in an ELF file has associated flags that tell the
dynamic linker what permissions to give the corresponding page in
@@ -222,15 +308,16 @@
into your app. The middleware vendor is aware of the problem and has a fix
available.
-## Invalid ELF header/section headers (AOSP master)
+## Invalid ELF header/section headers (Enforced for API level >= 26)
-Android loader now checks for invalid values in ELF header and section headers and fails
-if they are invalid.
+In API level 26 and above the dynamic linker checks more values in
+the ELF header and section headers and fails if they are invalid.
*Example error*
+```
dlopen failed: "/data/data/com.example.bad/lib.so" has unsupported e_shentsize: 0x0 (expected 0x28)
+```
-*Resolution*
-Do not use tools that produce invalid/malformed elf-files. Note that using them puts application
-under high risk of being incompatible with future versions of Android.
-
+*Resolution*: don't use tools that produce invalid/malformed
+ELF files. Note that using them puts application under high risk of
+being incompatible with future versions of Android.
diff --git a/libc/Android.bp b/libc/Android.bp
index cc8d8f5..82d2b05 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -796,14 +796,14 @@
cortex_a7: {
srcs: [
"arch-arm/cortex-a7/bionic/memset.S",
+ "arch-arm/cortex-a7/bionic/memcpy.S",
+ "arch-arm/cortex-a7/bionic/__strcat_chk.S",
+ "arch-arm/cortex-a7/bionic/__strcpy_chk.S",
- "arch-arm/cortex-a15/bionic/memcpy.S",
"arch-arm/cortex-a15/bionic/stpcpy.S",
"arch-arm/cortex-a15/bionic/strcat.S",
- "arch-arm/cortex-a15/bionic/__strcat_chk.S",
"arch-arm/cortex-a15/bionic/strcmp.S",
"arch-arm/cortex-a15/bionic/strcpy.S",
- "arch-arm/cortex-a15/bionic/__strcpy_chk.S",
"arch-arm/cortex-a15/bionic/strlen.S",
"arch-arm/denver/bionic/memmove.S",
@@ -1262,6 +1262,7 @@
"bionic/ifaddrs.cpp",
"bionic/inotify_init.cpp",
"bionic/ioctl.cpp",
+ "bionic/langinfo.cpp",
"bionic/lchown.cpp",
"bionic/lfs64_support.cpp",
"bionic/__libc_current_sigrtmax.cpp",
diff --git a/libc/arch-arm/cortex-a7/bionic/__strcat_chk.S b/libc/arch-arm/cortex-a7/bionic/__strcat_chk.S
new file mode 100644
index 0000000..da40f6c
--- /dev/null
+++ b/libc/arch-arm/cortex-a7/bionic/__strcat_chk.S
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+ .syntax unified
+
+ .thumb
+ .thumb_func
+
+// Get the length of src string, then get the source of the dst string.
+// Check that the two lengths together don't exceed the threshold, then
+// do a memcpy of the data.
+ENTRY(__strcat_chk)
+ pld [r0, #0]
+ push {r0, lr}
+ .cfi_def_cfa_offset 8
+ .cfi_rel_offset r0, 0
+ .cfi_rel_offset lr, 4
+ push {r4, r5}
+ .cfi_adjust_cfa_offset 8
+ .cfi_rel_offset r4, 0
+ .cfi_rel_offset r5, 4
+
+ mov lr, r2
+
+ // Save the dst register to r5
+ mov r5, r0
+
+ // Zero out r4
+ eor r4, r4, r4
+
+ // r1 contains the address of the string to count.
+.L_strlen_start:
+ mov r0, r1
+ ands r3, r1, #7
+ beq .L_mainloop
+
+ // Align to a double word (64 bits).
+ rsb r3, r3, #8
+ lsls ip, r3, #31
+ beq .L_align_to_32
+
+ ldrb r2, [r1], #1
+ cbz r2, .L_update_count_and_finish
+
+.L_align_to_32:
+ bcc .L_align_to_64
+ ands ip, r3, #2
+ beq .L_align_to_64
+
+ ldrb r2, [r1], #1
+ cbz r2, .L_update_count_and_finish
+ ldrb r2, [r1], #1
+ cbz r2, .L_update_count_and_finish
+
+.L_align_to_64:
+ tst r3, #4
+ beq .L_mainloop
+ ldr r3, [r1], #4
+
+ sub ip, r3, #0x01010101
+ bic ip, ip, r3
+ ands ip, ip, #0x80808080
+ bne .L_zero_in_second_register
+
+ .p2align 2
+.L_mainloop:
+ ldrd r2, r3, [r1], #8
+
+ pld [r1, #64]
+
+ sub ip, r2, #0x01010101
+ bic ip, ip, r2
+ ands ip, ip, #0x80808080
+ bne .L_zero_in_first_register
+
+ sub ip, r3, #0x01010101
+ bic ip, ip, r3
+ ands ip, ip, #0x80808080
+ bne .L_zero_in_second_register
+ b .L_mainloop
+
+.L_update_count_and_finish:
+ sub r3, r1, r0
+ sub r3, r3, #1
+ b .L_finish
+
+.L_zero_in_first_register:
+ sub r3, r1, r0
+ lsls r2, ip, #17
+ bne .L_sub8_and_finish
+ bcs .L_sub7_and_finish
+ lsls ip, ip, #1
+ bne .L_sub6_and_finish
+
+ sub r3, r3, #5
+ b .L_finish
+
+.L_sub8_and_finish:
+ sub r3, r3, #8
+ b .L_finish
+
+.L_sub7_and_finish:
+ sub r3, r3, #7
+ b .L_finish
+
+.L_sub6_and_finish:
+ sub r3, r3, #6
+ b .L_finish
+
+.L_zero_in_second_register:
+ sub r3, r1, r0
+ lsls r2, ip, #17
+ bne .L_sub4_and_finish
+ bcs .L_sub3_and_finish
+ lsls ip, ip, #1
+ bne .L_sub2_and_finish
+
+ sub r3, r3, #1
+ b .L_finish
+
+.L_sub4_and_finish:
+ sub r3, r3, #4
+ b .L_finish
+
+.L_sub3_and_finish:
+ sub r3, r3, #3
+ b .L_finish
+
+.L_sub2_and_finish:
+ sub r3, r3, #2
+
+.L_finish:
+ cmp r4, #0
+ bne .L_strlen_done
+
+ // Time to get the dst string length.
+ mov r1, r5
+
+ // Save the original source address to r5.
+ mov r5, r0
+
+ // Save the current length (adding 1 for the terminator).
+ add r4, r3, #1
+ b .L_strlen_start
+
+ // r0 holds the pointer to the dst string.
+ // r3 holds the dst string length.
+ // r4 holds the src string length + 1.
+.L_strlen_done:
+ add r2, r3, r4
+ cmp r2, lr
+ itt hi
+ movhi r0, lr
+ bhi __strcat_chk_fail
+
+ // Set up the registers for the memcpy code.
+ mov r1, r5
+ pld [r1, #64]
+ mov r2, r4
+ add r0, r0, r3
+ pop {r4, r5}
+ .cfi_adjust_cfa_offset -8
+ .cfi_restore r4
+ .cfi_restore r5
+
+#include "memcpy_base.S"
+
+ // Undo the above cfi directives
+ .cfi_adjust_cfa_offset 8
+ .cfi_rel_offset r4, 0
+ .cfi_rel_offset r5, 4
+END(__strcat_chk)
diff --git a/libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S b/libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S
new file mode 100644
index 0000000..026adcc
--- /dev/null
+++ b/libc/arch-arm/cortex-a7/bionic/__strcpy_chk.S
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+ .syntax unified
+
+ .thumb
+ .thumb_func
+
+// Get the length of the source string first, then do a memcpy of the data
+// instead of a strcpy.
+ENTRY(__strcpy_chk)
+ pld [r0, #0]
+ push {r0, lr}
+ .cfi_def_cfa_offset 8
+ .cfi_rel_offset r0, 0
+ .cfi_rel_offset lr, 4
+
+ mov lr, r2
+ mov r0, r1
+
+ ands r3, r1, #7
+ beq .L_mainloop
+
+ // Align to a double word (64 bits).
+ rsb r3, r3, #8
+ lsls ip, r3, #31
+ beq .L_align_to_32
+
+ ldrb r2, [r0], #1
+ cbz r2, .L_update_count_and_finish
+
+.L_align_to_32:
+ bcc .L_align_to_64
+ ands ip, r3, #2
+ beq .L_align_to_64
+
+ ldrb r2, [r0], #1
+ cbz r2, .L_update_count_and_finish
+ ldrb r2, [r0], #1
+ cbz r2, .L_update_count_and_finish
+
+.L_align_to_64:
+ tst r3, #4
+ beq .L_mainloop
+ ldr r3, [r0], #4
+
+ sub ip, r3, #0x01010101
+ bic ip, ip, r3
+ ands ip, ip, #0x80808080
+ bne .L_zero_in_second_register
+
+ .p2align 2
+.L_mainloop:
+ ldrd r2, r3, [r0], #8
+
+ pld [r0, #64]
+
+ sub ip, r2, #0x01010101
+ bic ip, ip, r2
+ ands ip, ip, #0x80808080
+ bne .L_zero_in_first_register
+
+ sub ip, r3, #0x01010101
+ bic ip, ip, r3
+ ands ip, ip, #0x80808080
+ bne .L_zero_in_second_register
+ b .L_mainloop
+
+.L_update_count_and_finish:
+ sub r3, r0, r1
+ sub r3, r3, #1
+ b .L_check_size
+
+.L_zero_in_first_register:
+ sub r3, r0, r1
+ lsls r2, ip, #17
+ bne .L_sub8_and_finish
+ bcs .L_sub7_and_finish
+ lsls ip, ip, #1
+ bne .L_sub6_and_finish
+
+ sub r3, r3, #5
+ b .L_check_size
+
+.L_sub8_and_finish:
+ sub r3, r3, #8
+ b .L_check_size
+
+.L_sub7_and_finish:
+ sub r3, r3, #7
+ b .L_check_size
+
+.L_sub6_and_finish:
+ sub r3, r3, #6
+ b .L_check_size
+
+.L_zero_in_second_register:
+ sub r3, r0, r1
+ lsls r2, ip, #17
+ bne .L_sub4_and_finish
+ bcs .L_sub3_and_finish
+ lsls ip, ip, #1
+ bne .L_sub2_and_finish
+
+ sub r3, r3, #1
+ b .L_check_size
+
+.L_sub4_and_finish:
+ sub r3, r3, #4
+ b .L_check_size
+
+.L_sub3_and_finish:
+ sub r3, r3, #3
+ b .L_check_size
+
+.L_sub2_and_finish:
+ sub r3, r3, #2
+
+.L_check_size:
+ pld [r1, #0]
+ pld [r1, #64]
+ ldr r0, [sp]
+
+ // Add 1 for copy length to get the string terminator.
+ add r2, r3, #1
+
+ cmp r2, lr
+ itt hi
+ movhi r0, r2
+ bhi __strcpy_chk_fail
+
+#include "memcpy_base.S"
+
+END(__strcpy_chk)
diff --git a/libc/arch-arm/cortex-a7/bionic/memcpy.S b/libc/arch-arm/cortex-a7/bionic/memcpy.S
new file mode 100644
index 0000000..9407a08
--- /dev/null
+++ b/libc/arch-arm/cortex-a7/bionic/memcpy.S
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * Copyright (c) 2013 ARM Ltd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the company may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <private/bionic_asm.h>
+
+ .text
+ .syntax unified
+ .fpu neon
+
+ENTRY(__memcpy_chk)
+ cmp r2, r3
+ bls memcpy
+
+ // Preserve lr for backtrace.
+ push {lr}
+ .cfi_def_cfa_offset 4
+ .cfi_rel_offset lr, 0
+ bl __memcpy_chk_fail
+END(__memcpy_chk)
+
+// Prototype: void *memcpy (void *dst, const void *src, size_t count).
+ENTRY(memcpy)
+ pld [r1, #64]
+ push {r0, lr}
+ .cfi_def_cfa_offset 8
+ .cfi_rel_offset r0, 0
+ .cfi_rel_offset lr, 4
+
+#include "memcpy_base.S"
+END(memcpy)
diff --git a/libc/arch-arm/cortex-a7/bionic/memcpy_base.S b/libc/arch-arm/cortex-a7/bionic/memcpy_base.S
new file mode 100644
index 0000000..1d152bb
--- /dev/null
+++ b/libc/arch-arm/cortex-a7/bionic/memcpy_base.S
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+/*
+ * Copyright (c) 2013 ARM Ltd
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the company may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+.L_memcpy_base:
+ // Assumes that n >= 0, and dst, src are valid pointers.
+ // For any sizes less than 832 use the neon code that doesn't
+ // care about the src alignment. This avoids any checks
+ // for src alignment, and offers the best improvement since
+ // smaller sized copies are dominated by the overhead of
+ // the pre and post main loop.
+ // For larger copies, if src and dst cannot both be aligned to
+ // word boundaries, use the neon code.
+ // For all other copies, align dst to a double word boundary
+ // and copy using LDRD/STRD instructions.
+
+ cmp r2, #16
+ blo .L_copy_less_than_16_unknown_align
+
+.L_copy_unknown_alignment:
+ // Unknown alignment of src and dst.
+ // Assumes that the first few bytes have already been prefetched.
+
+ // Align destination to 128 bits. The mainloop store instructions
+ // require this alignment or they will throw an exception.
+ rsb r3, r0, #0
+ ands r3, r3, #0xF
+ beq 2f
+
+ // Copy up to 15 bytes (count in r3).
+ sub r2, r2, r3
+ movs ip, r3, lsl #31
+
+ itt mi
+ ldrbmi lr, [r1], #1
+ strbmi lr, [r0], #1
+ itttt cs
+ ldrbcs ip, [r1], #1
+ ldrbcs lr, [r1], #1
+ strbcs ip, [r0], #1
+ strbcs lr, [r0], #1
+
+ movs ip, r3, lsl #29
+ bge 1f
+ // Copies 4 bytes, dst 32 bits aligned before, at least 64 bits after.
+ vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
+ vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0, :32]!
+1: bcc 2f
+ // Copies 8 bytes, dst 64 bits aligned before, at least 128 bits after.
+ vld1.8 {d0}, [r1]!
+ vst1.8 {d0}, [r0, :64]!
+
+2: // Make sure we have at least 64 bytes to copy.
+ subs r2, r2, #64
+ blo 2f
+
+1: // The main loop copies 64 bytes at a time.
+ vld1.8 {d0 - d3}, [r1]!
+ vld1.8 {d4 - d7}, [r1]!
+ pld [r1, #(64*4)]
+ subs r2, r2, #64
+ vst1.8 {d0 - d3}, [r0, :128]!
+ vst1.8 {d4 - d7}, [r0, :128]!
+ bhs 1b
+
+2: // Fix-up the remaining count and make sure we have >= 32 bytes left.
+ adds r2, r2, #32
+ blo 3f
+
+ // 32 bytes. These cache lines were already preloaded.
+ vld1.8 {d0 - d3}, [r1]!
+ sub r2, r2, #32
+ vst1.8 {d0 - d3}, [r0, :128]!
+3: // Less than 32 left.
+ add r2, r2, #32
+ tst r2, #0x10
+ beq .L_copy_less_than_16_unknown_align
+ // Copies 16 bytes, destination 128 bits aligned.
+ vld1.8 {d0, d1}, [r1]!
+ vst1.8 {d0, d1}, [r0, :128]!
+
+.L_copy_less_than_16_unknown_align:
+ // Copy up to 15 bytes (count in r2).
+ movs ip, r2, lsl #29
+ bcc 1f
+ vld1.8 {d0}, [r1]!
+ vst1.8 {d0}, [r0]!
+1: bge 2f
+ vld4.8 {d0[0], d1[0], d2[0], d3[0]}, [r1]!
+ vst4.8 {d0[0], d1[0], d2[0], d3[0]}, [r0]!
+
+2: // Copy 0 to 4 bytes.
+ lsls r2, r2, #31
+ itt ne
+ ldrbne lr, [r1], #1
+ strbne lr, [r0], #1
+ itttt cs
+ ldrbcs ip, [r1], #1
+ ldrbcs lr, [r1]
+ strbcs ip, [r0], #1
+ strbcs lr, [r0]
+
+ pop {r0, pc}
diff --git a/libc/bionic/bionic_arc4random.cpp b/libc/bionic/bionic_arc4random.cpp
index 429ff7f..4ff18ab 100644
--- a/libc/bionic/bionic_arc4random.cpp
+++ b/libc/bionic/bionic_arc4random.cpp
@@ -38,11 +38,12 @@
#include "private/libc_logging.h"
void __libc_safe_arc4random_buf(void* buf, size_t n, KernelArgumentBlock& args) {
- static bool have_getrandom = syscall(SYS_getrandom, nullptr, 0, 0) != -1 || errno != ENOSYS;
static bool have_urandom = access("/dev/urandom", R_OK) == 0;
static size_t at_random_bytes_consumed = 0;
- if (have_getrandom || have_urandom) {
+ // Only call arc4random_buf once we `have_urandom', since in getentropy_getrandom we may fallback
+ // to use /dev/urandom, if the kernel entropy pool hasn't been initialized or not enough bytes
+ if (have_urandom) {
arc4random_buf(buf, n);
return;
}
diff --git a/libc/bionic/getentropy_linux.c b/libc/bionic/getentropy_linux.c
index 98fb6fb..cf0aa45 100644
--- a/libc/bionic/getentropy_linux.c
+++ b/libc/bionic/getentropy_linux.c
@@ -102,7 +102,7 @@
ret = getentropy_getrandom(buf, len);
if (ret != -1)
return (ret);
- if (errno != ENOSYS)
+ if (errno != ENOSYS && errno != EAGAIN)
return (-1);
/*
@@ -200,7 +200,11 @@
if (len > 256)
return (-1);
do {
- ret = syscall(SYS_getrandom, buf, len, 0);
+ /*
+ * Use GRND_NONBLOCK to avoid blocking before the
+ * entropy pool has been initialized
+ */
+ ret = syscall(SYS_getrandom, buf, len, GRND_NONBLOCK);
} while (ret == -1 && errno == EINTR);
if ((size_t)ret != len)
diff --git a/libc/bionic/langinfo.cpp b/libc/bionic/langinfo.cpp
new file mode 100644
index 0000000..6f5057c
--- /dev/null
+++ b/libc/bionic/langinfo.cpp
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <langinfo.h>
+
+#include <stdlib.h>
+
+char* nl_langinfo(nl_item item) {
+ const char* result = "";
+ switch (item) {
+ case CODESET: result = (MB_CUR_MAX == 1) ? "ASCII" : "UTF-8"; break;
+
+ case D_T_FMT: result = "%F %T %z"; break;
+ case D_FMT: result = "%F"; break;
+ case T_FMT: result = "%T"; break;
+ case T_FMT_AMPM: result = "%I:%M:%S %p"; break;
+ case AM_STR: result = "AM"; break;
+ case PM_STR: result = "PM"; break;
+ case DAY_1: result = "Sunday"; break;
+ case DAY_2: result = "Monday"; break;
+ case DAY_3: result = "Tuesday"; break;
+ case DAY_4: result = "Wednesday"; break;
+ case DAY_5: result = "Thursday"; break;
+ case DAY_6: result = "Friday"; break;
+ case DAY_7: result = "Saturday"; break;
+ case ABDAY_1: result = "Sun"; break;
+ case ABDAY_2: result = "Mon"; break;
+ case ABDAY_3: result = "Tue"; break;
+ case ABDAY_4: result = "Wed"; break;
+ case ABDAY_5: result = "Thu"; break;
+ case ABDAY_6: result = "Fri"; break;
+ case ABDAY_7: result = "Sat"; break;
+ case MON_1: result = "January"; break;
+ case MON_2: result = "February"; break;
+ case MON_3: result = "March"; break;
+ case MON_4: result = "April"; break;
+ case MON_5: result = "May"; break;
+ case MON_6: result = "June"; break;
+ case MON_7: result = "July"; break;
+ case MON_8: result = "August"; break;
+ case MON_9: result = "September"; break;
+ case MON_10: result = "October"; break;
+ case MON_11: result = "November"; break;
+ case MON_12: result = "December"; break;
+ case ABMON_1: result = "Jan"; break;
+ case ABMON_2: result = "Feb"; break;
+ case ABMON_3: result = "Mar"; break;
+ case ABMON_4: result = "Apr"; break;
+ case ABMON_5: result = "May"; break;
+ case ABMON_6: result = "Jun"; break;
+ case ABMON_7: result = "Jul"; break;
+ case ABMON_8: result = "Aug"; break;
+ case ABMON_9: result = "Sep"; break;
+ case ABMON_10: result = "Oct"; break;
+ case ABMON_11: result = "Nov"; break;
+ case ABMON_12: result = "Dec"; break;
+ case ERA: result = ""; break;
+ case ERA_D_FMT: result = ""; break;
+ case ERA_D_T_FMT: result = ""; break;
+ case ERA_T_FMT: result = ""; break;
+ case ALT_DIGITS: result = ""; break;
+
+ case RADIXCHAR: result = "."; break;
+ case THOUSEP: result = ""; break;
+
+ case YESEXPR: result = "^[yY]"; break;
+ case NOEXPR: result = "^[nN]"; break;
+
+ case CRNCYSTR: result = ""; break;
+
+ default: break;
+ }
+ return const_cast<char*>(result);
+}
+
+char* nl_langinfo_l(nl_item item, locale_t) {
+ return nl_langinfo(item);
+}
diff --git a/libc/bionic/malloc_common.cpp b/libc/bionic/malloc_common.cpp
index e050619..3fceb71 100644
--- a/libc/bionic/malloc_common.cpp
+++ b/libc/bionic/malloc_common.cpp
@@ -175,8 +175,7 @@
static const char* DEBUG_SHARED_LIB = "libc_malloc_debug.so";
static const char* DEBUG_MALLOC_PROPERTY_OPTIONS = "libc.debug.malloc.options";
static const char* DEBUG_MALLOC_PROPERTY_PROGRAM = "libc.debug.malloc.program";
-static const char* DEBUG_MALLOC_PROPERTY_ENV_ENABLED = "libc.debug.malloc.env_enabled";
-static const char* DEBUG_MALLOC_ENV_ENABLE = "LIBC_DEBUG_MALLOC_ENABLE";
+static const char* DEBUG_MALLOC_ENV_OPTIONS = "LIBC_DEBUG_MALLOC_OPTIONS";
static void* libc_malloc_impl_handle = nullptr;
@@ -309,20 +308,21 @@
// Initializes memory allocation framework once per process.
static void malloc_init_impl(libc_globals* globals) {
char value[PROP_VALUE_MAX];
- if (__system_property_get(DEBUG_MALLOC_PROPERTY_OPTIONS, value) == 0 || value[0] == '\0') {
- return;
- }
- // Check to see if only a specific program should have debug malloc enabled.
- if (__system_property_get(DEBUG_MALLOC_PROPERTY_PROGRAM, value) != 0 &&
- strstr(getprogname(), value) == nullptr) {
- return;
- }
+ // If DEBUG_MALLOC_ENV_OPTIONS is set then it overrides the system properties.
+ const char* options = getenv(DEBUG_MALLOC_ENV_OPTIONS);
+ if (options == nullptr || options[0] == '\0') {
+ if (__system_property_get(DEBUG_MALLOC_PROPERTY_OPTIONS, value) == 0 || value[0] == '\0') {
+ return;
+ }
+ options = value;
- // Check for the special environment variable instead.
- if (__system_property_get(DEBUG_MALLOC_PROPERTY_ENV_ENABLED, value) != 0
- && value[0] != '\0' && getenv(DEBUG_MALLOC_ENV_ENABLE) == nullptr) {
- return;
+ // Check to see if only a specific program should have debug malloc enabled.
+ char program[PROP_VALUE_MAX];
+ if (__system_property_get(DEBUG_MALLOC_PROPERTY_PROGRAM, program) != 0 &&
+ strstr(getprogname(), program) == nullptr) {
+ return;
+ }
}
// Load the debug malloc shared library.
@@ -334,7 +334,7 @@
}
// Initialize malloc debugging in the loaded module.
- auto init_func = reinterpret_cast<bool (*)(const MallocDispatch*, int*)>(
+ auto init_func = reinterpret_cast<bool (*)(const MallocDispatch*, int*, const char*)>(
dlsym(malloc_impl_handle, "debug_initialize"));
if (init_func == nullptr) {
error_log("%s: debug_initialize routine not found in %s", getprogname(), DEBUG_SHARED_LIB);
@@ -374,7 +374,7 @@
return;
}
- if (!init_func(&__libc_malloc_default_dispatch, &gMallocLeakZygoteChild)) {
+ if (!init_func(&__libc_malloc_default_dispatch, &gMallocLeakZygoteChild, options)) {
dlclose(malloc_impl_handle);
return;
}
diff --git a/libc/include/langinfo.h b/libc/include/langinfo.h
new file mode 100644
index 0000000..5c884ac
--- /dev/null
+++ b/libc/include/langinfo.h
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LANGINFO_H_
+#define _LANGINFO_H_
+
+#include <sys/cdefs.h>
+
+#include <nl_types.h>
+#include <xlocale.h>
+
+__BEGIN_DECLS
+
+#define CODESET 1
+#define D_T_FMT 2
+#define D_FMT 3
+#define T_FMT 4
+#define T_FMT_AMPM 5
+#define AM_STR 6
+#define PM_STR 7
+#define DAY_1 8
+#define DAY_2 9
+#define DAY_3 10
+#define DAY_4 11
+#define DAY_5 12
+#define DAY_6 13
+#define DAY_7 14
+#define ABDAY_1 15
+#define ABDAY_2 16
+#define ABDAY_3 17
+#define ABDAY_4 18
+#define ABDAY_5 19
+#define ABDAY_6 20
+#define ABDAY_7 21
+#define MON_1 22
+#define MON_2 23
+#define MON_3 24
+#define MON_4 25
+#define MON_5 26
+#define MON_6 27
+#define MON_7 28
+#define MON_8 29
+#define MON_9 30
+#define MON_10 31
+#define MON_11 32
+#define MON_12 33
+#define ABMON_1 34
+#define ABMON_2 35
+#define ABMON_3 36
+#define ABMON_4 37
+#define ABMON_5 38
+#define ABMON_6 39
+#define ABMON_7 40
+#define ABMON_8 41
+#define ABMON_9 42
+#define ABMON_10 43
+#define ABMON_11 44
+#define ABMON_12 45
+#define ERA 46
+#define ERA_D_FMT 47
+#define ERA_D_T_FMT 48
+#define ERA_T_FMT 49
+#define ALT_DIGITS 50
+#define RADIXCHAR 51
+#define THOUSEP 52
+#define YESEXPR 53
+#define NOEXPR 54
+#define CRNCYSTR 55
+
+char* nl_langinfo(nl_item) __INTRODUCED_IN_FUTURE;
+char* nl_langinfo_l(nl_item, locale_t) __INTRODUCED_IN_FUTURE;
+
+__END_DECLS
+
+#endif
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index eb75e8f..f9c5ede 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1288,6 +1288,8 @@
msgget; # future
msgrcv; # future
msgsnd; # future
+ nl_langinfo; # future
+ nl_langinfo_l; # future
pthread_getname_np; # future
quotactl; # future
semctl; # future
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index 28755d4..179d8bf 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1210,6 +1210,8 @@
msgget; # future
msgrcv; # future
msgsnd; # future
+ nl_langinfo; # future
+ nl_langinfo_l; # future
pthread_getname_np; # future
quotactl; # future
semctl; # future
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 1fba8ee..f122937 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1313,6 +1313,8 @@
msgget; # future
msgrcv; # future
msgsnd; # future
+ nl_langinfo; # future
+ nl_langinfo_l; # future
pthread_getname_np; # future
quotactl; # future
semctl; # future
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index f61f615..a969703 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1272,6 +1272,8 @@
msgget; # future
msgrcv; # future
msgsnd; # future
+ nl_langinfo; # future
+ nl_langinfo_l; # future
pthread_getname_np; # future
quotactl; # future
semctl; # future
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index 28755d4..179d8bf 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1210,6 +1210,8 @@
msgget; # future
msgrcv; # future
msgsnd; # future
+ nl_langinfo; # future
+ nl_langinfo_l; # future
pthread_getname_np; # future
quotactl; # future
semctl; # future
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index a166361..dfa839e 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1270,6 +1270,8 @@
msgget; # future
msgrcv; # future
msgsnd; # future
+ nl_langinfo; # future
+ nl_langinfo_l; # future
pthread_getname_np; # future
quotactl; # future
semctl; # future
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index 28755d4..179d8bf 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1210,6 +1210,8 @@
msgget; # future
msgrcv; # future
msgsnd; # future
+ nl_langinfo; # future
+ nl_langinfo_l; # future
pthread_getname_np; # future
quotactl; # future
semctl; # future
diff --git a/libc/malloc_debug/Android.bp b/libc/malloc_debug/Android.bp
index 8ce3ff3..708c101 100644
--- a/libc/malloc_debug/Android.bp
+++ b/libc/malloc_debug/Android.bp
@@ -111,7 +111,6 @@
"tests/backtrace_fake.cpp",
"tests/log_fake.cpp",
"tests/libc_fake.cpp",
- "tests/property_fake.cpp",
"tests/malloc_debug_config_tests.cpp",
"tests/malloc_debug_unit_tests.cpp",
],
diff --git a/libc/malloc_debug/Config.cpp b/libc/malloc_debug/Config.cpp
index c9fb850..cb75bd6 100644
--- a/libc/malloc_debug/Config.cpp
+++ b/libc/malloc_debug/Config.cpp
@@ -37,8 +37,6 @@
#include <string>
#include <vector>
-#include <sys/system_properties.h>
-
#include <private/bionic_macros.h>
#include "Config.h"
@@ -329,13 +327,7 @@
// This function is designed to be called once. A second call will not
// reset all variables.
-bool Config::SetFromProperties() {
- char property_str[PROP_VALUE_MAX];
- memset(property_str, 0, sizeof(property_str));
- if (!__system_property_get("libc.debug.malloc.options", property_str)) {
- return false;
- }
-
+bool Config::Set(const char* options_str) {
// Initialize a few default values.
fill_alloc_value = DEFAULT_FILL_ALLOC_VALUE;
fill_free_value = DEFAULT_FILL_FREE_VALUE;
@@ -426,7 +418,7 @@
}
// Process each property name we can find.
- PropertyParser parser(property_str);
+ PropertyParser parser(options_str);
bool valid = true;
std::string property;
std::string value;
diff --git a/libc/malloc_debug/Config.h b/libc/malloc_debug/Config.h
index ac620ad..ca56dc8 100644
--- a/libc/malloc_debug/Config.h
+++ b/libc/malloc_debug/Config.h
@@ -56,7 +56,7 @@
constexpr uint64_t HEADER_OPTIONS = FRONT_GUARD | REAR_GUARD | BACKTRACE | FREE_TRACK | LEAK_TRACK;
struct Config {
- bool SetFromProperties();
+ bool Set(const char* str);
size_t front_guard_bytes = 0;
size_t rear_guard_bytes = 0;
diff --git a/libc/malloc_debug/DebugData.cpp b/libc/malloc_debug/DebugData.cpp
index fdc2810..339efdf 100644
--- a/libc/malloc_debug/DebugData.cpp
+++ b/libc/malloc_debug/DebugData.cpp
@@ -37,8 +37,8 @@
#include "malloc_debug.h"
#include "TrackData.h"
-bool DebugData::Initialize() {
- if (!config_.SetFromProperties()) {
+bool DebugData::Initialize(const char* options) {
+ if (!config_.Set(options)) {
return false;
}
diff --git a/libc/malloc_debug/DebugData.h b/libc/malloc_debug/DebugData.h
index 7e2df0c..7228a72 100644
--- a/libc/malloc_debug/DebugData.h
+++ b/libc/malloc_debug/DebugData.h
@@ -49,7 +49,7 @@
DebugData() = default;
~DebugData() = default;
- bool Initialize();
+ bool Initialize(const char* options);
static bool Disabled();
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index d2bcf99..bb16faa 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/malloc_debug/malloc_debug.cpp
@@ -62,7 +62,8 @@
// ------------------------------------------------------------------------
__BEGIN_DECLS
-bool debug_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_child);
+bool debug_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_child,
+ const char* options);
void debug_finalize();
void debug_get_malloc_leak_info(
uint8_t** info, size_t* overall_size, size_t* info_size, size_t* total_memory,
@@ -178,8 +179,9 @@
return g_debug->GetPointer(header);
}
-bool debug_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_child) {
- if (malloc_zygote_child == nullptr) {
+bool debug_initialize(const MallocDispatch* malloc_dispatch, int* malloc_zygote_child,
+ const char* options) {
+ if (malloc_zygote_child == nullptr || options == nullptr) {
return false;
}
@@ -194,7 +196,7 @@
}
DebugData* debug = new DebugData();
- if (!debug->Initialize()) {
+ if (!debug->Initialize(options)) {
delete debug;
DebugDisableFinalize();
return false;
diff --git a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp b/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
index 49edaba..f988124 100644
--- a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
@@ -25,8 +25,6 @@
#include "log_fake.h"
-extern "C" int property_set(const char*, const char*);
-
class MallocDebugConfigTest : public ::testing::Test {
protected:
void SetUp() override {
@@ -38,10 +36,9 @@
std::unique_ptr<Config> config;
- bool InitConfig(const char* property_value) {
+ bool InitConfig(const char* options) {
config.reset(new Config);
- property_set("libc.debug.malloc.options", property_value);
- return config->SetFromProperties();
+ return config->Set(options);
}
};
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
index edb03f6..1b08a39 100644
--- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
@@ -44,8 +44,7 @@
__BEGIN_DECLS
-int property_set(const char*, const char*);
-bool debug_initialize(const MallocDispatch*, int*);
+bool debug_initialize(const MallocDispatch*, int*, const char*);
void debug_finalize();
void* debug_malloc(size_t);
@@ -98,10 +97,9 @@
}
}
- void Init(const char* property_value) {
- property_set("libc.debug.malloc.options", property_value);
+ void Init(const char* options) {
zygote = 0;
- ASSERT_TRUE(debug_initialize(&dispatch, &zygote));
+ ASSERT_TRUE(debug_initialize(&dispatch, &zygote, options));
initialized = true;
}
diff --git a/libc/malloc_debug/tests/property_fake.cpp b/libc/malloc_debug/tests/property_fake.cpp
deleted file mode 100644
index d9f0ad8..0000000
--- a/libc/malloc_debug/tests/property_fake.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#include <string>
-#include <unordered_map>
-
-#include <sys/system_properties.h>
-
-std::unordered_map<std::string, std::string> g_properties;
-
-extern "C" int property_set(const char* name, const char* value) {
- if (g_properties.count(name) != 0) {
- g_properties.erase(name);
- }
- g_properties[name] = value;
- return 0;
-}
-
-extern "C" int property_get(const char* key, char* value, const char* default_value) {
- if (g_properties.count(key) == 0) {
- if (default_value == nullptr) {
- return 0;
- }
- strncpy(value, default_value, PROP_VALUE_MAX-1);
- } else {
- strncpy(value, g_properties[key].c_str(), PROP_VALUE_MAX-1);
- }
- value[PROP_VALUE_MAX-1] = '\0';
- return strlen(value);
-}
-
-extern "C" int __system_property_get(const char* key, char* value) {
- if (g_properties.count(key) == 0) {
- return 0;
- } else {
- strncpy(value, g_properties[key].c_str(), PROP_VALUE_MAX-1);
- }
- value[PROP_VALUE_MAX-1] = '\0';
- return strlen(value);
-}
diff --git a/libc/upstream-openbsd/lib/libc/include/langinfo.h b/libc/upstream-openbsd/lib/libc/include/langinfo.h
deleted file mode 100644
index a871ab8..0000000
--- a/libc/upstream-openbsd/lib/libc/include/langinfo.h
+++ /dev/null
@@ -1,3 +0,0 @@
-/* Hack to build "vfprintf.c". */
-#define RADIXCHAR 1
-#define nl_langinfo(i) ((i == RADIXCHAR) ? (char*) "." : NULL)
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 266ca6e..62e6bb6 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1804,10 +1804,13 @@
ProtectedDataGuard guard;
soinfo* si = find_library(ns, translated_name, flags, extinfo, caller);
if (si != nullptr) {
- failure_guard.disable();
- si->call_constructors();
void* handle = si->to_handle();
LD_LOG(kLogDlopen,
+ "... dlopen calling constructors: realpath=\"%s\", soname=\"%s\", handle=%p",
+ si->get_realpath(), si->get_soname(), handle);
+ si->call_constructors();
+ failure_guard.disable();
+ LD_LOG(kLogDlopen,
"... dlopen successful: realpath=\"%s\", soname=\"%s\", handle=%p",
si->get_realpath(), si->get_soname(), handle);
return handle;
diff --git a/tests/Android.bp b/tests/Android.bp
index 643b295..a9d302a 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -68,6 +68,7 @@
"grp_pwd_test.cpp",
"ifaddrs_test.cpp",
"inttypes_test.cpp",
+ "langinfo_test.cpp",
"libc_logging_test.cpp",
"libgen_basename_test.cpp",
"libgen_test.cpp",
@@ -482,7 +483,10 @@
include_dirs: ["bionic/libc"],
- ldflags: ["-Wl,--export-dynamic"],
+ ldflags: [
+ "-Wl,--rpath,${ORIGIN}/../bionic-loader-test-libs",
+ "-Wl,--export-dynamic",
+ ],
sanitize: {
never: false,
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index ed50ea5..e629e41 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -98,7 +98,7 @@
}
TEST_F(DlExtTest, ExtInfoUseFd) {
- const std::string lib_path = g_testlib_root + "/libdlext_test_fd/libdlext_test_fd.so";
+ const std::string lib_path = get_testlib_root() + "/libdlext_test_fd/libdlext_test_fd.so";
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD;
@@ -116,7 +116,7 @@
}
TEST_F(DlExtTest, ExtInfoUseFdWithOffset) {
- const std::string lib_path = g_testlib_root + "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
+ const std::string lib_path = get_testlib_root() + "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD | ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET;
@@ -142,7 +142,7 @@
}
TEST_F(DlExtTest, ExtInfoUseFdWithInvalidOffset) {
- const std::string lib_path = g_testlib_root + "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
+ const std::string lib_path = get_testlib_root() + "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_LIBRARY_FD | ANDROID_DLEXT_USE_LIBRARY_FD_OFFSET;
@@ -228,7 +228,7 @@
TEST(dlfcn, dlopen_from_zip_absolute_path) {
const std::string lib_zip_path = "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
- const std::string lib_path = g_testlib_root + lib_zip_path;
+ const std::string lib_path = get_testlib_root() + lib_zip_path;
void* handle = dlopen((lib_path + "!/libdir/libatest_simple_zip.so").c_str(), RTLD_NOW);
ASSERT_TRUE(handle != nullptr) << dlerror();
@@ -242,7 +242,7 @@
TEST(dlfcn, dlopen_from_zip_with_dt_runpath) {
const std::string lib_zip_path = "/libdlext_test_runpath_zip/libdlext_test_runpath_zip_zipaligned.zip";
- const std::string lib_path = g_testlib_root + lib_zip_path;
+ const std::string lib_path = get_testlib_root() + lib_zip_path;
void* handle = dlopen((lib_path + "!/libdir/libtest_dt_runpath_d_zip.so").c_str(), RTLD_NOW);
@@ -261,7 +261,7 @@
TEST(dlfcn, dlopen_from_zip_ld_library_path) {
const std::string lib_zip_path = "/libdlext_test_zip/libdlext_test_zip_zipaligned.zip";
- const std::string lib_path = g_testlib_root + lib_zip_path + "!/libdir";
+ const std::string lib_path = get_testlib_root() + lib_zip_path + "!/libdir";
typedef void (*fn_t)(const char*);
fn_t android_update_LD_LIBRARY_PATH =
@@ -631,7 +631,7 @@
ASSERT_STREQ("android_init_namespaces failed: error initializing public namespace: "
"the list of public libraries is empty.", dlerror());
- const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = get_testlib_root() + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
@@ -639,20 +639,20 @@
// Check that libraries added to public namespace are NODELETE
dlclose(handle_public);
- handle_public = dlopen((g_testlib_root + "/public_namespace_libs/" + g_public_lib).c_str(),
+ handle_public = dlopen((get_testlib_root() + "/public_namespace_libs/" + g_public_lib).c_str(),
RTLD_NOW | RTLD_NOLOAD);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
android_namespace_t* ns1 =
android_create_namespace("private", nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
ASSERT_TRUE(ns1 != nullptr) << dlerror();
android_namespace_t* ns2 =
android_create_namespace("private_isolated", nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED, nullptr, nullptr);
ASSERT_TRUE(ns2 != nullptr) << dlerror();
@@ -743,7 +743,7 @@
static const char* root_lib = "libnstest_root_not_isolated.so";
std::string path = std::string("libc.so:libc++.so:libdl.so:libm.so:") + g_public_lib;
- const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = get_testlib_root() + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
@@ -753,14 +753,14 @@
android_namespace_t* ns_not_isolated =
android_create_namespace("private", nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
ASSERT_TRUE(ns_not_isolated != nullptr) << dlerror();
android_namespace_t* ns_isolated =
android_create_namespace("private_isolated1",
nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
nullptr,
nullptr);
@@ -768,10 +768,10 @@
android_namespace_t* ns_isolated2 =
android_create_namespace("private_isolated2",
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
nullptr,
ANDROID_NAMESPACE_TYPE_ISOLATED,
- g_testlib_root.c_str(),
+ get_testlib_root().c_str(),
nullptr);
ASSERT_TRUE(ns_isolated2 != nullptr) << dlerror();
@@ -779,7 +779,7 @@
ASSERT_STREQ("dlopen failed: library \"libnstest_root_not_isolated.so\" not found", dlerror());
std::string lib_private_external_path =
- g_testlib_root + "/private_namespace_libs_external/libnstest_private_external.so";
+ get_testlib_root() + "/private_namespace_libs_external/libnstest_private_external.so";
// Load lib_private_external_path to default namespace
// (it should remain invisible for the isolated namespaces after this)
@@ -808,7 +808,7 @@
extinfo.library_namespace = ns_isolated2;
- // this should work because isolation_path for private_isolated2 includes g_testlib_root
+ // this should work because isolation_path for private_isolated2 includes get_testlib_root()
handle2 = android_dlopen_ext(root_lib, RTLD_NOW, &extinfo);
ASSERT_TRUE(handle2 != nullptr) << dlerror();
dlclose(handle2);
@@ -849,7 +849,7 @@
static const char* root_lib_isolated = "libnstest_root.so";
std::string path = std::string("libc.so:libc++.so:libdl.so:libm.so:") + g_public_lib;
- const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = get_testlib_root() + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
@@ -860,18 +860,18 @@
// preload this library to the default namespace to check if it
// is shared later on.
void* handle_dlopened =
- dlopen((g_testlib_root + "/private_namespace_libs/libnstest_dlopened.so").c_str(), RTLD_NOW);
+ dlopen((get_testlib_root() + "/private_namespace_libs/libnstest_dlopened.so").c_str(), RTLD_NOW);
ASSERT_TRUE(handle_dlopened != nullptr) << dlerror();
android_namespace_t* ns_not_isolated =
android_create_namespace("private", nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
ASSERT_TRUE(ns_not_isolated != nullptr) << dlerror();
android_namespace_t* ns_isolated_shared =
android_create_namespace("private_isolated_shared", nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED | ANDROID_NAMESPACE_TYPE_SHARED,
nullptr, nullptr);
ASSERT_TRUE(ns_isolated_shared != nullptr) << dlerror();
@@ -880,7 +880,7 @@
ASSERT_STREQ("dlopen failed: library \"libnstest_root_not_isolated.so\" not found", dlerror());
std::string lib_private_external_path =
- g_testlib_root + "/private_namespace_libs_external/libnstest_private_external.so";
+ get_testlib_root() + "/private_namespace_libs_external/libnstest_private_external.so";
// Load lib_private_external_path to default namespace
// (it should remain invisible for the isolated namespaces after this)
@@ -971,12 +971,12 @@
// preload this library to the default namespace to check if it
// is shared later on.
void* handle_dlopened =
- dlopen((g_testlib_root + "/private_namespace_libs/libnstest_dlopened.so").c_str(), RTLD_NOW);
+ dlopen((get_testlib_root() + "/private_namespace_libs/libnstest_dlopened.so").c_str(), RTLD_NOW);
ASSERT_TRUE(handle_dlopened != nullptr) << dlerror();
android_namespace_t* ns_isolated_shared =
android_create_namespace("private_isolated_shared", nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED | ANDROID_NAMESPACE_TYPE_SHARED,
nullptr, nullptr);
ASSERT_TRUE(ns_isolated_shared != nullptr) << dlerror();
@@ -997,7 +997,7 @@
ASSERT_TRUE(handle == nullptr)
<< "Error: libnstest_dlopened.so is still accessible in shared namespace";
- handle = android_dlopen_ext((g_testlib_root + "/private_namespace_libs/libnstest_dlopened.so").c_str(),
+ handle = android_dlopen_ext((get_testlib_root() + "/private_namespace_libs/libnstest_dlopened.so").c_str(),
RTLD_NOW | RTLD_NOLOAD, &extinfo);
ASSERT_TRUE(handle == nullptr)
<< "Error: libnstest_dlopened.so is still accessible in shared namespace";
@@ -1006,14 +1006,14 @@
ASSERT_TRUE(handle == nullptr)
<< "Error: libnstest_dlopened.so is still accessible in default namespace";
- handle = dlopen((g_testlib_root + "/private_namespace_libs/libnstest_dlopened.so").c_str(),
+ handle = dlopen((get_testlib_root() + "/private_namespace_libs/libnstest_dlopened.so").c_str(),
RTLD_NOW | RTLD_NOLOAD);
ASSERT_TRUE(handle == nullptr)
<< "Error: libnstest_dlopened.so is still accessible in default namespace";
// Now lets see if the soinfo area gets reused in the wrong way:
// load a library to default namespace.
- const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = get_testlib_root() + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
@@ -1029,12 +1029,12 @@
ASSERT_TRUE(android_init_namespaces(path.c_str(), nullptr));
- const std::string lib_public_path = g_testlib_root + "/public_namespace_libs";
+ const std::string lib_public_path = get_testlib_root() + "/public_namespace_libs";
android_namespace_t* ns1 =
android_create_namespace("isolated1",
nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
lib_public_path.c_str(),
nullptr);
@@ -1043,7 +1043,7 @@
android_namespace_t* ns2 =
android_create_namespace("isolated2",
nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
lib_public_path.c_str(),
nullptr);
@@ -1062,7 +1062,7 @@
android_namespace_t* ns1_child =
android_create_namespace("isolated1_child",
nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_ISOLATED,
nullptr,
ns1);
@@ -1097,22 +1097,22 @@
static const char* root_lib = "libnstest_root.so";
std::string path = std::string("libc.so:libc++.so:libdl.so:libm.so:") + g_public_lib;
- const std::string lib_public_path = g_testlib_root + "/public_namespace_libs/" + g_public_lib;
+ const std::string lib_public_path = get_testlib_root() + "/public_namespace_libs/" + g_public_lib;
void* handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
ASSERT_TRUE(handle_public != nullptr) << dlerror();
- ASSERT_TRUE(android_init_namespaces(path.c_str(), (g_testlib_root + "/private_namespace_libs").c_str()))
+ ASSERT_TRUE(android_init_namespaces(path.c_str(), (get_testlib_root() + "/private_namespace_libs").c_str()))
<< dlerror();
android_namespace_t* ns = android_create_namespace(
"private", nullptr,
- (g_testlib_root + "/private_namespace_libs").c_str(),
+ (get_testlib_root() + "/private_namespace_libs").c_str(),
ANDROID_NAMESPACE_TYPE_REGULAR, nullptr, nullptr);
ASSERT_TRUE(ns != nullptr) << dlerror();
- std::string private_library_absolute_path = g_testlib_root + "/private_namespace_libs/" + root_lib;
+ std::string private_library_absolute_path = get_testlib_root() + "/private_namespace_libs/" + root_lib;
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_NAMESPACE;
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index 5908fc3..46f6ec0 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -25,6 +25,7 @@
#include "private/ScopeGuard.h"
#include <string>
+#include <thread>
#include "gtest_globals.h"
#include "dlfcn_symlink_support.h"
@@ -754,24 +755,45 @@
#endif
}
-static void* ConcurrentDlErrorFn(void*) {
- dlopen("/child/thread", RTLD_NOW);
- return reinterpret_cast<void*>(strdup(dlerror()));
+static void ConcurrentDlErrorFn(std::string& error) {
+ ASSERT_TRUE(dlerror() == nullptr);
+
+ void* handle = dlopen("/child/thread", RTLD_NOW);
+ ASSERT_TRUE(handle == nullptr);
+
+ const char* err = dlerror();
+ ASSERT_TRUE(err != nullptr);
+
+ error = err;
+}
+
+TEST(dlfcn, dlerror_concurrent_buffer) {
+ void* handle = dlopen("/main/thread", RTLD_NOW);
+ ASSERT_TRUE(handle == nullptr);
+ const char* main_thread_error = dlerror();
+ ASSERT_TRUE(main_thread_error != nullptr);
+ ASSERT_SUBSTR("/main/thread", main_thread_error);
+
+ std::string child_thread_error;
+ std::thread t(ConcurrentDlErrorFn, std::ref(child_thread_error));
+ t.join();
+ ASSERT_SUBSTR("/child/thread", child_thread_error.c_str());
+
+ // Check that main thread local buffer was not modified.
+ ASSERT_SUBSTR("/main/thread", main_thread_error);
}
TEST(dlfcn, dlerror_concurrent) {
- dlopen("/main/thread", RTLD_NOW);
+ void* handle = dlopen("/main/thread", RTLD_NOW);
+ ASSERT_TRUE(handle == nullptr);
+
+ std::string child_thread_error;
+ std::thread t(ConcurrentDlErrorFn, std::ref(child_thread_error));
+ t.join();
+ ASSERT_SUBSTR("/child/thread", child_thread_error.c_str());
+
const char* main_thread_error = dlerror();
- ASSERT_SUBSTR("/main/thread", main_thread_error);
-
- pthread_t t;
- ASSERT_EQ(0, pthread_create(&t, nullptr, ConcurrentDlErrorFn, nullptr));
- void* result;
- ASSERT_EQ(0, pthread_join(t, &result));
- char* child_thread_error = static_cast<char*>(result);
- ASSERT_SUBSTR("/child/thread", child_thread_error);
- free(child_thread_error);
-
+ ASSERT_TRUE(main_thread_error != nullptr);
ASSERT_SUBSTR("/main/thread", main_thread_error);
}
@@ -991,6 +1013,22 @@
ASSERT_TRUE(addr != nullptr);
}
+// Check that RTLD_NEXT of a libc symbol works in dlopened library
+TEST(dlfcn, rtld_next_from_library) {
+ void* library_with_close = dlopen("libtest_check_rtld_next_from_library.so", RTLD_NOW);
+ ASSERT_TRUE(library_with_close != nullptr) << dlerror();
+ void* expected_addr = dlsym(RTLD_DEFAULT, "close");
+ ASSERT_TRUE(expected_addr != nullptr) << dlerror();
+ typedef void* (*get_libc_close_ptr_fn_t)();
+ get_libc_close_ptr_fn_t get_libc_close_ptr =
+ reinterpret_cast<get_libc_close_ptr_fn_t>(dlsym(library_with_close, "get_libc_close_ptr"));
+ ASSERT_TRUE(get_libc_close_ptr != nullptr) << dlerror();
+ ASSERT_EQ(expected_addr, get_libc_close_ptr());
+
+ dlclose(library_with_close);
+}
+
+
TEST(dlfcn, dlsym_weak_func) {
dlerror();
void* handle = dlopen("libtest_dlsym_weak_func.so", RTLD_NOW);
@@ -1137,7 +1175,7 @@
#if defined(__BIONIC__)
TEST(dlfcn, dt_runpath_absolute_path) {
- std::string libpath = g_testlib_root + "/libtest_dt_runpath_d.so";
+ std::string libpath = get_testlib_root() + "/libtest_dt_runpath_d.so";
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
ASSERT_TRUE(handle != nullptr) << dlerror();
@@ -1152,7 +1190,7 @@
}
TEST(dlfcn, dlopen_invalid_rw_load_segment) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-rw_load_segment.so";
void* handle = dlopen(libpath.c_str(), RTLD_NOW);
@@ -1162,7 +1200,7 @@
}
TEST(dlfcn, dlopen_invalid_unaligned_shdr_offset) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-unaligned_shdr_offset.so";
@@ -1173,7 +1211,7 @@
}
TEST(dlfcn, dlopen_invalid_zero_shentsize) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-zero_shentsize.so";
@@ -1184,7 +1222,7 @@
}
TEST(dlfcn, dlopen_invalid_zero_shstrndx) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-zero_shstrndx.so";
@@ -1195,7 +1233,7 @@
}
TEST(dlfcn, dlopen_invalid_empty_shdr_table) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-empty_shdr_table.so";
@@ -1206,7 +1244,7 @@
}
TEST(dlfcn, dlopen_invalid_zero_shdr_table_offset) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-zero_shdr_table_offset.so";
@@ -1217,7 +1255,7 @@
}
TEST(dlfcn, dlopen_invalid_zero_shdr_table_content) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-zero_shdr_table_content.so";
@@ -1228,7 +1266,7 @@
}
TEST(dlfcn, dlopen_invalid_textrels) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-textrels.so";
@@ -1239,7 +1277,7 @@
}
TEST(dlfcn, dlopen_invalid_textrels2) {
- const std::string libpath = g_testlib_root +
+ const std::string libpath = get_testlib_root() +
"/" + kPrebuiltElfDir +
"/libtest_invalid-textrels2.so";
diff --git a/tests/gtest_globals.cpp b/tests/gtest_globals.cpp
index 4f2c82e..bb99dd6 100644
--- a/tests/gtest_globals.cpp
+++ b/tests/gtest_globals.cpp
@@ -21,11 +21,20 @@
#include <string>
-static std::string get_testlib_root() {
+static std::string init_testlib_root() {
std::string out_path;
const char* data_dir = getenv("ANDROID_DATA");
if (data_dir == nullptr) {
- out_path = "/data";
+ // Calculate ANDROID_DATA assuming the binary is in "$ANDROID_DATA/somedir/binary-dir/binary"
+ std::string path = get_executable_path();
+
+ path = get_dirname(path.c_str());
+ path += "/../..";
+
+ if (!get_realpath(path.c_str(), &out_path)) {
+ printf("Failed to get realpath for \"%s\"", path.c_str());
+ abort();
+ }
} else {
out_path = data_dir;
}
@@ -35,12 +44,18 @@
out_path += "64";
#endif
out_path += "/bionic-loader-test-libs";
+
std::string real_path;
if (!get_realpath(out_path, &real_path)) {
+ printf("\"%s\": does not exists", out_path.c_str());
abort();
}
return real_path;
}
-const std::string g_testlib_root = get_testlib_root();
+const std::string& get_testlib_root() {
+ static const std::string testlib_root = init_testlib_root();
+ return testlib_root;
+}
+
diff --git a/tests/gtest_globals.h b/tests/gtest_globals.h
index fab2a39..019849d 100644
--- a/tests/gtest_globals.h
+++ b/tests/gtest_globals.h
@@ -21,6 +21,6 @@
constexpr const char* kPrebuiltElfDir = "prebuilt-elf-files";
-extern const std::string g_testlib_root;
+const std::string& get_testlib_root();
#endif // _BIONIC_TESTS_GTEST_GLOBALS_H
diff --git a/tests/gtest_globals_cts.cpp b/tests/gtest_globals_cts.cpp
index bf891a1..2532ef1 100644
--- a/tests/gtest_globals_cts.cpp
+++ b/tests/gtest_globals_cts.cpp
@@ -18,4 +18,8 @@
#include <string>
-const std::string g_testlib_root = "/data/local/tmp/lib/bionic-loader-test-libs";
+static const std::string g_testlib_root = "/data/local/tmp/lib/bionic-loader-test-libs";
+
+const std::string& get_testlib_root() {
+ return g_testlib_root;
+}
diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp
index aacf9ae..b12c28f 100644
--- a/tests/gtest_main.cpp
+++ b/tests/gtest_main.cpp
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
+#include <libgen.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
@@ -65,6 +66,15 @@
return true;
}
+std::string get_dirname(const char* path) {
+#if defined(__BIONIC__)
+ return dirname(path);
+#else
+ // GLIBC does not have const char* dirname
+ return dirname(const_cast<char*>(path));
+#endif
+}
+
int get_argc() {
return g_argc;
}
diff --git a/tests/langinfo_test.cpp b/tests/langinfo_test.cpp
new file mode 100644
index 0000000..6eae8bc
--- /dev/null
+++ b/tests/langinfo_test.cpp
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include <langinfo.h>
+
+TEST(langinfo, category_CTYPE) {
+ ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+ EXPECT_STREQ("UTF-8", nl_langinfo(CODESET));
+}
+
+TEST(langinfo, category_TIME) {
+ ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+#if defined(__BIONIC__)
+ // bionic's C locale is ISO rather than en_US.
+ EXPECT_STREQ("%F %T %z", nl_langinfo(D_T_FMT));
+ EXPECT_STREQ("%F", nl_langinfo(D_FMT));
+#else
+ EXPECT_STREQ("%a %d %b %Y %r %Z", nl_langinfo(D_T_FMT));
+ EXPECT_STREQ("%m/%d/%Y", nl_langinfo(D_FMT));
+#endif
+ EXPECT_STREQ("%T", nl_langinfo(T_FMT));
+ EXPECT_STREQ("%I:%M:%S %p", nl_langinfo(T_FMT_AMPM));
+ EXPECT_STREQ("AM", nl_langinfo(AM_STR));
+ EXPECT_STREQ("PM", nl_langinfo(PM_STR));
+ EXPECT_STREQ("Sunday", nl_langinfo(DAY_1));
+ EXPECT_STREQ("Monday", nl_langinfo(DAY_2));
+ EXPECT_STREQ("Tuesday", nl_langinfo(DAY_3));
+ EXPECT_STREQ("Wednesday", nl_langinfo(DAY_4));
+ EXPECT_STREQ("Thursday", nl_langinfo(DAY_5));
+ EXPECT_STREQ("Friday", nl_langinfo(DAY_6));
+ EXPECT_STREQ("Saturday", nl_langinfo(DAY_7));
+ EXPECT_STREQ("Sun", nl_langinfo(ABDAY_1));
+ EXPECT_STREQ("Mon", nl_langinfo(ABDAY_2));
+ EXPECT_STREQ("Tue", nl_langinfo(ABDAY_3));
+ EXPECT_STREQ("Wed", nl_langinfo(ABDAY_4));
+ EXPECT_STREQ("Thu", nl_langinfo(ABDAY_5));
+ EXPECT_STREQ("Fri", nl_langinfo(ABDAY_6));
+ EXPECT_STREQ("Sat", nl_langinfo(ABDAY_7));
+ EXPECT_STREQ("January", nl_langinfo(MON_1));
+ EXPECT_STREQ("February", nl_langinfo(MON_2));
+ EXPECT_STREQ("March", nl_langinfo(MON_3));
+ EXPECT_STREQ("April", nl_langinfo(MON_4));
+ EXPECT_STREQ("May", nl_langinfo(MON_5));
+ EXPECT_STREQ("June", nl_langinfo(MON_6));
+ EXPECT_STREQ("July", nl_langinfo(MON_7));
+ EXPECT_STREQ("August", nl_langinfo(MON_8));
+ EXPECT_STREQ("September", nl_langinfo(MON_9));
+ EXPECT_STREQ("October", nl_langinfo(MON_10));
+ EXPECT_STREQ("November", nl_langinfo(MON_11));
+ EXPECT_STREQ("December", nl_langinfo(MON_12));
+ EXPECT_STREQ("Jan", nl_langinfo(ABMON_1));
+ EXPECT_STREQ("Feb", nl_langinfo(ABMON_2));
+ EXPECT_STREQ("Mar", nl_langinfo(ABMON_3));
+ EXPECT_STREQ("Apr", nl_langinfo(ABMON_4));
+ EXPECT_STREQ("May", nl_langinfo(ABMON_5));
+ EXPECT_STREQ("Jun", nl_langinfo(ABMON_6));
+ EXPECT_STREQ("Jul", nl_langinfo(ABMON_7));
+ EXPECT_STREQ("Aug", nl_langinfo(ABMON_8));
+ EXPECT_STREQ("Sep", nl_langinfo(ABMON_9));
+ EXPECT_STREQ("Oct", nl_langinfo(ABMON_10));
+ EXPECT_STREQ("Nov", nl_langinfo(ABMON_11));
+ EXPECT_STREQ("Dec", nl_langinfo(ABMON_12));
+ EXPECT_STREQ("", nl_langinfo(ERA));
+ EXPECT_STREQ("", nl_langinfo(ERA_D_FMT));
+ EXPECT_STREQ("", nl_langinfo(ERA_D_T_FMT));
+ EXPECT_STREQ("", nl_langinfo(ERA_T_FMT));
+ EXPECT_STREQ("", nl_langinfo(ALT_DIGITS));
+}
+
+TEST(langinfo, category_NUMERIC) {
+ ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+ EXPECT_STREQ(".", nl_langinfo(RADIXCHAR));
+ EXPECT_STREQ("", nl_langinfo(THOUSEP));
+}
+
+TEST(langinfo, category_MESSAGES) {
+ ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+ EXPECT_STREQ("^[yY]", nl_langinfo(YESEXPR));
+ EXPECT_STREQ("^[nN]", nl_langinfo(NOEXPR));
+}
+
+TEST(langinfo, category_MONETARY) {
+ ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+ // POSIX says that if the currency symbol is the empty string (as it is for
+ // the C locale), an implementation can return the empty string and not
+ // include the leading [+-.] that signifies where the currency symbol should
+ // appear. For consistency with localeconv (which POSIX says to prefer for
+ // RADIXCHAR, THOUSEP, and CRNCYSTR) we return the empty string. glibc
+ // disagrees.
+#if defined(__BIONIC__)
+ EXPECT_STREQ("", nl_langinfo(CRNCYSTR));
+#else
+ EXPECT_STREQ("-", nl_langinfo(CRNCYSTR));
+#endif
+}
+
+TEST(langinfo, invalid) {
+ ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+ EXPECT_STREQ("", nl_langinfo(-1));
+ EXPECT_STREQ("", nl_langinfo(0));
+ EXPECT_STREQ("", nl_langinfo(666));
+}
+
+TEST(langinfo, matches_localeconv) {
+ ASSERT_STREQ("C.UTF-8", setlocale(LC_ALL, "C.UTF-8"));
+
+ EXPECT_STREQ(localeconv()->decimal_point, nl_langinfo(RADIXCHAR));
+ EXPECT_STREQ(localeconv()->thousands_sep, nl_langinfo(THOUSEP));
+#if defined(__BIONIC__)
+ // (See comment in category_MONETARY test.)
+ EXPECT_STREQ(localeconv()->currency_symbol, nl_langinfo(CRNCYSTR));
+#endif
+}
diff --git a/tests/libs/Android.bp b/tests/libs/Android.bp
index fe0d6ab..4cd991a 100644
--- a/tests/libs/Android.bp
+++ b/tests/libs/Android.bp
@@ -411,6 +411,24 @@
}
// -----------------------------------------------------------------------------
+// Check that RTLD_NEXT of a libc symbol works in dlopened library
+// -----------------------------------------------------------------------------
+cc_test_library {
+ name: "libtest_check_rtld_next_from_library",
+ defaults: ["bionic_testlib_defaults"],
+ srcs: ["check_rtld_next_from_library.cpp"],
+
+ target: {
+ android: {
+ shared_libs: ["libdl"],
+ },
+ host: {
+ host_ldlibs: ["-ldl"],
+ },
+ },
+}
+
+// -----------------------------------------------------------------------------
// Library with constructor that calls dlopen() b/7941716
// -----------------------------------------------------------------------------
cc_test_library {
diff --git a/tests/libs/check_rtld_next_from_library.cpp b/tests/libs/check_rtld_next_from_library.cpp
new file mode 100644
index 0000000..45d8eea
--- /dev/null
+++ b/tests/libs/check_rtld_next_from_library.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlfcn.h>
+#include <stdlib.h>
+
+static void* g_libc_close_ptr;
+
+static void __attribute__((constructor)) __libc_close_lookup() {
+ g_libc_close_ptr = dlsym(RTLD_NEXT, "close");
+}
+
+// A libc function used for RTLD_NEXT
+// This function in not supposed to be called
+extern "C" int __attribute__((weak)) close(int) {
+ abort();
+}
+
+extern "C" void* get_libc_close_ptr() {
+ return g_libc_close_ptr;
+}
+
+
diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp
index b488e82..f8b35cc 100644
--- a/tests/unistd_test.cpp
+++ b/tests/unistd_test.cpp
@@ -530,12 +530,7 @@
static int CloneStartRoutine(int (*start_routine)(void*)) {
void* child_stack[1024];
- int clone_result = clone(start_routine, &child_stack[1024], CLONE_NEWNS | SIGCHLD, NULL);
- if (clone_result == -1 && errno == EPERM && getuid() != 0) {
- GTEST_LOG_(INFO) << "This test only works if you have permission to CLONE_NEWNS; try running as root.\n";
- return clone_result;
- }
- return clone_result;
+ return clone(start_routine, &child_stack[1024], SIGCHLD, NULL);
}
static int GetPidCachingCloneStartRoutine(void*) {
diff --git a/tests/utils.h b/tests/utils.h
index c62da75..4c3aef4 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -128,6 +128,8 @@
// Get realpath
bool get_realpath(const std::string& path, std::string* realpath);
+// Get dirname
+std::string get_dirname(const char* path);
// Access to argc/argv/envp
int get_argc();
diff --git a/tools/versioner/src/SymbolDatabase.cpp b/tools/versioner/src/SymbolDatabase.cpp
index 90c0c9f..bd4b99d 100644
--- a/tools/versioner/src/SymbolDatabase.cpp
+++ b/tools/versioner/src/SymbolDatabase.cpp
@@ -130,7 +130,7 @@
}
if (result.count(symbol_name) != 0) {
- if (verbose) {
+ if (strict) {
printf("duplicated symbol '%s' in '%s'\n", symbol_name.str().c_str(), file.str().c_str());
}
}
diff --git a/tools/versioner/src/Utils.cpp b/tools/versioner/src/Utils.cpp
index dd087a5..3806110 100644
--- a/tools/versioner/src/Utils.cpp
+++ b/tools/versioner/src/Utils.cpp
@@ -25,6 +25,8 @@
#include <string>
#include <vector>
+#include <android-base/strings.h>
+
#include "DeclarationDatabase.h"
std::string getWorkingDir() {
@@ -35,8 +37,8 @@
return buf;
}
-std::vector<std::string> collectFiles(const std::string& directory) {
- std::vector<std::string> files;
+std::vector<std::string> collectHeaders(const std::string& directory) {
+ std::vector<std::string> headers;
char* dir_argv[2] = { const_cast<char*>(directory.c_str()), nullptr };
FTS* fts = fts_open(dir_argv, FTS_LOGICAL | FTS_NOCHDIR, nullptr);
@@ -51,11 +53,15 @@
continue;
}
- files.push_back(ent->fts_path);
+ if (!android::base::EndsWith(ent->fts_path, ".h")) {
+ continue;
+ }
+
+ headers.push_back(ent->fts_path);
}
fts_close(fts);
- return files;
+ return headers;
}
llvm::StringRef StripPrefix(llvm::StringRef string, llvm::StringRef prefix) {
diff --git a/tools/versioner/src/Utils.h b/tools/versioner/src/Utils.h
index 7876f23..44a34f8 100644
--- a/tools/versioner/src/Utils.h
+++ b/tools/versioner/src/Utils.h
@@ -27,7 +27,7 @@
#include <llvm/ADT/StringRef.h>
std::string getWorkingDir();
-std::vector<std::string> collectFiles(const std::string& directory);
+std::vector<std::string> collectHeaders(const std::string& directory);
static inline std::string dirname(const std::string& path) {
std::unique_ptr<char, decltype(&free)> path_copy(strdup(path.c_str()), free);
diff --git a/tools/versioner/src/versioner.cpp b/tools/versioner/src/versioner.cpp
index 86349e1..6c287d9 100644
--- a/tools/versioner/src/versioner.cpp
+++ b/tools/versioner/src/versioner.cpp
@@ -22,7 +22,12 @@
#include <sys/types.h>
#include <unistd.h>
+#if defined(__linux__)
+#include <sched.h>
+#endif
+
#include <atomic>
+#include <chrono>
#include <functional>
#include <iostream>
#include <map>
@@ -36,6 +41,7 @@
#include <llvm/ADT/StringRef.h>
+#include <android-base/macros.h>
#include <android-base/parseint.h>
#include "Arch.h"
@@ -48,15 +54,32 @@
#include "versioner.h"
+using namespace std::chrono_literals;
using namespace std::string_literals;
-bool add_include;
+bool strict;
bool verbose;
-static int max_thread_count = 48;
+bool add_include;
+
+static int getCpuCount();
+static int max_thread_count = getCpuCount();
+
+static int getCpuCount() {
+#if defined(__linux__)
+ cpu_set_t cpu_set;
+ int rc = sched_getaffinity(getpid(), sizeof(cpu_set), &cpu_set);
+ if (rc != 0) {
+ err(1, "sched_getaffinity failed");
+ }
+ return CPU_COUNT(&cpu_set);
+#else
+ return 1;
+#endif
+}
static CompilationRequirements collectRequirements(const Arch& arch, const std::string& header_dir,
const std::string& dependency_dir) {
- std::vector<std::string> headers = collectFiles(header_dir);
+ std::vector<std::string> headers = collectHeaders(header_dir);
std::vector<std::string> dependencies = { header_dir };
if (!dependency_dir.empty()) {
auto collect_children = [&dependencies, &dependency_dir](const std::string& dir_path) {
@@ -158,6 +181,7 @@
initializeTargetCC1FlagCache(vfs, types, requirements);
std::vector<std::pair<CompilationType, const std::string&>> jobs;
+ std::atomic<size_t> job_index(0);
for (CompilationType type : types) {
CompilationRequirements& req = requirements[type.arch];
for (const std::string& header : req.headers) {
@@ -173,13 +197,17 @@
}
} else {
// Spawn threads.
+ size_t cpu_count = getCpuCount();
for (size_t i = 0; i < thread_count; ++i) {
- threads.emplace_back([&jobs, &result, &header_dir, vfs, thread_count, i]() {
- size_t index = i;
- while (index < jobs.size()) {
- const auto& job = jobs[index];
+ threads.emplace_back([&jobs, &job_index, &result, &header_dir, vfs, cpu_count, i]() {
+ while (true) {
+ size_t idx = job_index++;
+ if (idx >= jobs.size()) {
+ return;
+ }
+
+ const auto& job = jobs[idx];
compileHeader(vfs, result.get(), job.first, job.second);
- index += thread_count;
}
});
}
@@ -362,7 +390,7 @@
failed = true;
}
- if (verbose) {
+ if (strict) {
auto extra_it = extra_availability.find(symbol_name);
if (extra_it != extra_availability.end()) {
printf("%s: declaration marked unavailable but symbol available in [%s]\n",
@@ -402,7 +430,7 @@
fprintf(stderr, "\n");
fprintf(stderr, "Validation:\n");
fprintf(stderr, " -p PATH\tcompare against NDK platform at PATH\n");
- fprintf(stderr, " -v\t\tenable verbose warnings\n");
+ fprintf(stderr, " -s\t\tenable strict warnings\n");
fprintf(stderr, "\n");
fprintf(stderr, "Preprocessing:\n");
fprintf(stderr, " -o PATH\tpreprocess header files and emit them at PATH\n");
@@ -411,6 +439,7 @@
fprintf(stderr, "Miscellaneous:\n");
fprintf(stderr, " -d\t\tdump function availability\n");
fprintf(stderr, " -j THREADS\tmaximum number of threads to use\n");
+ fprintf(stderr, " -v\t\tenable verbose logging\n");
fprintf(stderr, " -h\t\tdisplay this message\n");
exit(0);
}
@@ -427,7 +456,7 @@
bool dump = false;
int c;
- while ((c = getopt(argc, argv, "a:r:p:vo:fdj:hi")) != -1) {
+ while ((c = getopt(argc, argv, "a:r:p:so:fdj:vhi")) != -1) {
default_args = false;
switch (c) {
case 'a': {
@@ -472,8 +501,8 @@
break;
}
- case 'v':
- verbose = true;
+ case 's':
+ strict = true;
break;
case 'o':
@@ -500,6 +529,10 @@
}
break;
+ case 'v':
+ verbose = true;
+ break;
+
case 'h':
usage(true);
break;
@@ -572,8 +605,15 @@
symbol_database = parsePlatforms(compilation_types, platform_dir);
}
+ auto start = std::chrono::high_resolution_clock::now();
std::unique_ptr<HeaderDatabase> declaration_database =
compileHeaders(compilation_types, header_dir, dependency_dir);
+ auto end = std::chrono::high_resolution_clock::now();
+
+ if (verbose) {
+ auto diff = (end - start) / 1.0ms;
+ printf("Compiled headers for %zu targets in %0.2LFms\n", compilation_types.size(), diff);
+ }
bool failed = false;
if (dump) {
diff --git a/tools/versioner/src/versioner.h b/tools/versioner/src/versioner.h
index 97b1509..a5f2c7d 100644
--- a/tools/versioner/src/versioner.h
+++ b/tools/versioner/src/versioner.h
@@ -22,6 +22,7 @@
#include <unordered_map>
#include <unordered_set>
+extern bool strict;
extern bool verbose;
extern bool add_include;