Merge "ARM: make sure __on_dlclose() actually gets called"
diff --git a/libc/Android.mk b/libc/Android.mk
index 8085ac5..04301ef 100644
--- a/libc/Android.mk
+++ b/libc/Android.mk
@@ -362,7 +362,6 @@
 # =========================================================
 ifeq ($(TARGET_ARCH),arm)
 libc_common_src_files += \
-	arch-arm/bionic/__get_pc.S \
 	arch-arm/bionic/__get_sp.S \
 	arch-arm/bionic/_exit_with_stack_teardown.S \
 	arch-arm/bionic/_setjmp.S \
diff --git a/libc/arch-arm/bionic/__get_pc.S b/libc/arch-arm/bionic/__get_pc.S
deleted file mode 100644
index 4fc8929..0000000
--- a/libc/arch-arm/bionic/__get_pc.S
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.
- */
-.global __get_pc
-.type __get_pc, %function
-
-__get_pc:
-	mov r0, pc
-	bx lr
-
diff --git a/libc/arch-arm/bionic/crtbegin.c b/libc/arch-arm/bionic/crtbegin.c
index 9dcd254..0e2d31e 100644
--- a/libc/arch-arm/bionic/crtbegin.c
+++ b/libc/arch-arm/bionic/crtbegin.c
@@ -31,7 +31,6 @@
     void (**preinit_array)(void);
     void (**init_array)(void);
     void (**fini_array)(void);
-    void (**ctors_array)(void);
 } structors_array_t;
 
 extern int main(int argc, char **argv, char **env);
@@ -52,10 +51,7 @@
 __attribute__ ((section (".fini_array")))
 void (*__FINI_ARRAY__)(void) = (void (*)(void)) -1;
 
-__attribute__ ((section (".ctors")))
-void (*__CTOR_LIST__)(void) = (void (*)(void)) -1;
-
-__attribute__((visbility("hidden")))
+__attribute__((visibility("hidden")))
 void _start() {
   structors_array_t array;
   void *elfdata;
@@ -63,7 +59,6 @@
   array.preinit_array = &__PREINIT_ARRAY__;
   array.init_array =    &__INIT_ARRAY__;
   array.fini_array =    &__FINI_ARRAY__;
-  array.ctors_array =   &__CTOR_LIST__;
 
   elfdata = __builtin_frame_address(0) + sizeof(void *);
   __libc_init(elfdata, (void *) 0, &main, &array);
diff --git a/libc/arch-arm/bionic/crtend.S b/libc/arch-arm/bionic/crtend.S
index 7196fc1..fffb0ab 100644
--- a/libc/arch-arm/bionic/crtend.S
+++ b/libc/arch-arm/bionic/crtend.S
@@ -35,9 +35,6 @@
 	.section .fini_array, "aw"
 	.long 0
 
-	.section .ctors, "aw"
-	.long 0
-
 #if defined(__linux__) && defined(__ELF__)
 	.section .note.GNU-stack,"",%progbits
 #endif
diff --git a/libc/arch-arm/bionic/crtend_so.S b/libc/arch-arm/bionic/crtend_so.S
index 0cb9947..bb6570e 100644
--- a/libc/arch-arm/bionic/crtend_so.S
+++ b/libc/arch-arm/bionic/crtend_so.S
@@ -26,16 +26,6 @@
  * SUCH DAMAGE.
  */
 
-/* This is the same than crtend.S except that a shared library
- * cannot have a .preinit_array
- */
-	
-	.section .init_array, "aw"
-	.long 0
-
-	.section .fini_array, "aw"
-	.long 0
-
 #if defined(__linux__) && defined(__ELF__)
 	.section .note.GNU-stack,"",%progbits
 #endif
diff --git a/libc/arch-mips/bionic/crtbegin.S b/libc/arch-mips/bionic/crtbegin.S
index d85d52c..40b689e 100644
--- a/libc/arch-mips/bionic/crtbegin.S
+++ b/libc/arch-mips/bionic/crtbegin.S
@@ -70,8 +70,6 @@
 1:	.long	__PREINIT_ARRAY__
 	.long	__INIT_ARRAY__
 	.long	__FINI_ARRAY__
-	.long	__CTOR_LIST__
-	.long	__DTOR_LIST__
 
 	.section .preinit_array, "aw"
 	.type __PREINIT_ARRAY__, @object
@@ -92,18 +90,6 @@
 	.long -1
 	.long __do_global_dtors_aux
 
-	.section .ctors, "aw"
-	.type __CTOR_LIST__, @object
-	.globl __CTOR_LIST__
-__CTOR_LIST__:
-	.long -1
-
-	.section .dtors, "aw"
-	.type __DTOR_LIST__, @object
-	.globl __DTOR_LIST__
-__DTOR_LIST__:
-	.long -1
-
 	.abicalls
 	.text
 	.align	2
diff --git a/libc/arch-mips/bionic/crtend.S b/libc/arch-mips/bionic/crtend.S
index 7a319be..6984d0e 100644
--- a/libc/arch-mips/bionic/crtend.S
+++ b/libc/arch-mips/bionic/crtend.S
@@ -35,13 +35,3 @@
 	.section .fini_array, "aw"
 	.long 0
 
-	.section .ctors, "aw"
-	.type __CTOR_END__, @object
-__CTOR_END__:
-	.long 0
-
-	.section .dtors, "aw"
-	.type __DTOR_END__, @object
-__DTOR_END__:
-	.long 0
-
diff --git a/libc/arch-x86/string/ssse3-strcmp-latest.S b/libc/arch-x86/string/ssse3-strcmp-latest.S
index 69c6425..673ba57 100644
--- a/libc/arch-x86/string/ssse3-strcmp-latest.S
+++ b/libc/arch-x86/string/ssse3-strcmp-latest.S
@@ -102,7 +102,7 @@
 	/* calculate left number to compare */		\
 	mov	$16, %esi;				\
 	sub	%ecx, %esi;				\
-	cmp	%esi, %ebp;				\
+	cmpl	%esi, %ebp;				\
 	jbe	L(more8byteseq);			\
 	sub	%esi, %ebp
 #endif
@@ -116,7 +116,7 @@
 	movl	STR2(%esp), %eax
 #ifdef USE_AS_STRNCMP
 	movl	CNT(%esp), %ebp
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	jb	L(less16bytes_sncmp)
 	jmp	L(more16bytes)
 #endif
@@ -172,18 +172,18 @@
 	add	$8, %edx
 	add	$8, %eax
 #ifdef USE_AS_STRNCMP
-	cmp	$8, %ebp
+	cmpl	$8, %ebp
 	lea	-8(%ebp), %ebp
 	je	L(eq)
 L(more16bytes):
 #endif
 	movl	%edx, %ecx
 	and	$0xfff, %ecx
-	cmp	$0xff0, %ecx
+	cmpl	$0xff0, %ecx
 	ja	L(crosspage)
 	mov	%eax, %ecx
 	and	$0xfff, %ecx
-	cmp	$0xff0, %ecx
+	cmpl	$0xff0, %ecx
 	ja	L(crosspage)
 	pxor	%xmm0, %xmm0
 	movlpd	(%eax), %xmm1
@@ -197,7 +197,7 @@
 	sub	$0xffff, %ecx
 	jnz	L(less16bytes)
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(eq)
 #endif
@@ -220,7 +220,7 @@
 	xor	%ecx, %eax
 	xor	%edi, %edx
 	xor	%ebx, %ebx
-	cmp	%edi, %ecx
+	cmpl	%edi, %ecx
 	je	L(ashr_0)
 	ja	L(bigger)
 	or	$0x20, %ebx
@@ -229,37 +229,37 @@
 L(bigger):
 	lea	15(%edi), %edi
 	sub	%ecx, %edi
-	cmp	$8, %edi
+	cmpl	$8, %edi
 	jle	L(ashr_less_8)
-	cmp	$14, %edi
+	cmpl	$14, %edi
 	je	L(ashr_15)
-	cmp	$13, %edi
+	cmpl	$13, %edi
 	je	L(ashr_14)
-	cmp	$12, %edi
+	cmpl	$12, %edi
 	je	L(ashr_13)
-	cmp	$11, %edi
+	cmpl	$11, %edi
 	je	L(ashr_12)
-	cmp	$10, %edi
+	cmpl	$10, %edi
 	je	L(ashr_11)
-	cmp	$9, %edi
+	cmpl	$9, %edi
 	je	L(ashr_10)
 L(ashr_less_8):
 	je	L(ashr_9)
-	cmp	$7, %edi
+	cmpl	$7, %edi
 	je	L(ashr_8)
-	cmp	$6, %edi
+	cmpl	$6, %edi
 	je	L(ashr_7)
-	cmp	$5, %edi
+	cmpl	$5, %edi
 	je	L(ashr_6)
-	cmp	$4, %edi
+	cmpl	$4, %edi
 	je	L(ashr_5)
-	cmp	$3, %edi
+	cmpl	$3, %edi
 	je	L(ashr_4)
-	cmp	$2, %edi
+	cmpl	$2, %edi
 	je	L(ashr_3)
-	cmp	$1, %edi
+	cmpl	$1, %edi
 	je	L(ashr_2)
-	cmp	$0, %edi
+	cmpl	$0, %edi
 	je	L(ashr_1)
 
 /*
@@ -297,7 +297,7 @@
 	sub	$0xffff, %esi
 	jnz	L(exit)
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -355,7 +355,7 @@
 	sub	$0xffff, %esi
 	jnz	L(exit)
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -380,7 +380,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -396,7 +396,7 @@
 	jnz	L(ashr_1_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$15, %ebp
+	cmpl	$15, %ebp
 	jbe	L(ashr_1_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -462,7 +462,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -486,7 +486,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -502,7 +502,7 @@
 	jnz	L(ashr_2_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$14, %ebp
+	cmpl	$14, %ebp
 	jbe	L(ashr_2_exittail)
 #endif
 
@@ -569,7 +569,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -593,7 +593,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -609,7 +609,7 @@
 	jnz	L(ashr_3_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$13, %ebp
+	cmpl	$13, %ebp
 	jbe	L(ashr_3_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -675,7 +675,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -700,7 +700,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -717,7 +717,7 @@
 	jnz	L(ashr_4_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$12, %ebp
+	cmpl	$12, %ebp
 	jbe	L(ashr_4_exittail)
 #endif
 
@@ -784,7 +784,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -808,7 +808,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -824,7 +824,7 @@
 	jnz	L(ashr_5_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$11, %ebp
+	cmpl	$11, %ebp
 	jbe	L(ashr_5_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -891,7 +891,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -915,7 +915,7 @@
 	sub	$0xffff, %esi
 	jnz	L(exit)
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -932,7 +932,7 @@
 	jnz	L(ashr_6_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$10, %ebp
+	cmpl	$10, %ebp
 	jbe	L(ashr_6_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -999,7 +999,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1024,7 +1024,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1041,7 +1041,7 @@
 	jnz	L(ashr_7_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$9, %ebp
+	cmpl	$9, %ebp
 	jbe	L(ashr_7_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1108,7 +1108,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1132,7 +1132,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1148,7 +1148,7 @@
 	jnz	L(ashr_8_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$8, %ebp
+	cmpl	$8, %ebp
 	jbe	L(ashr_8_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1215,7 +1215,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1239,7 +1239,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1255,7 +1255,7 @@
 	jnz	L(ashr_9_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$7, %ebp
+	cmpl	$7, %ebp
 	jbe	L(ashr_9_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1321,7 +1321,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1345,7 +1345,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1361,7 +1361,7 @@
 	jnz	L(ashr_10_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$6, %ebp
+	cmpl	$6, %ebp
 	jbe	L(ashr_10_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1427,7 +1427,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1451,7 +1451,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1467,7 +1467,7 @@
 	jnz	L(ashr_11_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$5, %ebp
+	cmpl	$5, %ebp
 	jbe	L(ashr_11_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1533,7 +1533,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1558,7 +1558,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1574,7 +1574,7 @@
 	jnz	L(ashr_12_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$4, %ebp
+	cmpl	$4, %ebp
 	jbe	L(ashr_12_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1640,7 +1640,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1664,7 +1664,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1680,7 +1680,7 @@
 	jnz	L(ashr_13_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$3, %ebp
+	cmpl	$3, %ebp
 	jbe	L(ashr_13_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1746,7 +1746,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1770,7 +1770,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1786,7 +1786,7 @@
 	jnz	L(ashr_14_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$2, %ebp
+	cmpl	$2, %ebp
 	jbe	L(ashr_14_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1853,7 +1853,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1877,7 +1877,7 @@
 	jnz	L(exit)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$16, %ebp
+	cmpl	$16, %ebp
 	lea	-16(%ebp), %ebp
 	jbe	L(more8byteseq)
 #endif
@@ -1893,7 +1893,7 @@
 	jnz	L(ashr_15_exittail)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$1, %ebp
+	cmpl	$1, %ebp
 	jbe	L(ashr_15_exittail)
 #endif
 	pxor	%xmm0, %xmm0
@@ -1955,12 +1955,12 @@
 	test	$0x40, %cl
 	jnz	L(Byte6)
 #ifdef USE_AS_STRNCMP
-	cmp	$7, %ebp
+	cmpl	$7, %ebp
 	jbe	L(eq)
 #endif
 
-	movzx	7(%eax), %ecx
-	movzx	7(%edx), %eax
+	movzbl	7(%eax), %ecx
+	movzbl	7(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -1968,11 +1968,11 @@
 	.p2align 4
 L(Byte0):
 #ifdef USE_AS_STRNCMP
-	cmp	$0, %ebp
+	cmpl	$0, %ebp
 	jbe	L(eq)
 #endif
-	movzx	(%eax), %ecx
-	movzx	(%edx), %eax
+	movzbl	(%eax), %ecx
+	movzbl	(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -1980,11 +1980,11 @@
 	.p2align 4
 L(Byte1):
 #ifdef USE_AS_STRNCMP
-	cmp	$1, %ebp
+	cmpl	$1, %ebp
 	jbe	L(eq)
 #endif
-	movzx	1(%eax), %ecx
-	movzx	1(%edx), %eax
+	movzbl	1(%eax), %ecx
+	movzbl	1(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -1992,11 +1992,11 @@
 	.p2align 4
 L(Byte2):
 #ifdef USE_AS_STRNCMP
-	cmp	$2, %ebp
+	cmpl	$2, %ebp
 	jbe	L(eq)
 #endif
-	movzx	2(%eax), %ecx
-	movzx	2(%edx), %eax
+	movzbl	2(%eax), %ecx
+	movzbl	2(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -2004,11 +2004,11 @@
 	.p2align 4
 L(Byte3):
 #ifdef USE_AS_STRNCMP
-	cmp	$3, %ebp
+	cmpl	$3, %ebp
 	jbe	L(eq)
 #endif
-	movzx	3(%eax), %ecx
-	movzx	3(%edx), %eax
+	movzbl	3(%eax), %ecx
+	movzbl	3(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -2016,11 +2016,11 @@
 	.p2align 4
 L(Byte4):
 #ifdef USE_AS_STRNCMP
-	cmp	$4, %ebp
+	cmpl	$4, %ebp
 	jbe	L(eq)
 #endif
-	movzx	4(%eax), %ecx
-	movzx	4(%edx), %eax
+	movzbl	4(%eax), %ecx
+	movzbl	4(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -2028,11 +2028,11 @@
 	.p2align 4
 L(Byte5):
 #ifdef USE_AS_STRNCMP
-	cmp	$5, %ebp
+	cmpl	$5, %ebp
 	jbe	L(eq)
 #endif
-	movzx	5(%eax), %ecx
-	movzx	5(%edx), %eax
+	movzbl	5(%eax), %ecx
+	movzbl	5(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -2040,11 +2040,11 @@
 	.p2align 4
 L(Byte6):
 #ifdef USE_AS_STRNCMP
-	cmp	$6, %ebp
+	cmpl	$6, %ebp
 	jbe	L(eq)
 #endif
-	movzx	6(%eax), %ecx
-	movzx	6(%edx), %eax
+	movzbl	6(%eax), %ecx
+	movzbl	6(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -2054,7 +2054,7 @@
 	add	$8, %eax
 	add	$8, %edx
 #ifdef USE_AS_STRNCMP
-	cmp	$8, %ebp
+	cmpl	$8, %ebp
 	lea	-8(%ebp), %ebp
 	jbe	L(eq)
 #endif
@@ -2081,11 +2081,11 @@
 	jnz	L(Byte6)
 
 #ifdef USE_AS_STRNCMP
-	cmp	$7, %ebp
+	cmpl	$7, %ebp
 	jbe	L(eq)
 #endif
-	movzx	7(%eax), %ecx
-	movzx	7(%edx), %eax
+	movzbl	7(%eax), %ecx
+	movzbl	7(%edx), %eax
 
 	sub	%ecx, %eax
 	RETURN
@@ -2129,7 +2129,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$1, %ebp
+	cmpl	$1, %ebp
 	je	L(eq)
 
 	movzbl	1(%eax), %ecx
@@ -2138,7 +2138,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$2, %ebp
+	cmpl	$2, %ebp
 	je	L(eq)
 
 	movzbl	2(%eax), %ecx
@@ -2147,7 +2147,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$3, %ebp
+	cmpl	$3, %ebp
 	je	L(eq)
 
 	movzbl	3(%eax), %ecx
@@ -2156,7 +2156,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$4, %ebp
+	cmpl	$4, %ebp
 	je	L(eq)
 
 	movzbl	4(%eax), %ecx
@@ -2165,7 +2165,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$5, %ebp
+	cmpl	$5, %ebp
 	je	L(eq)
 
 	movzbl	5(%eax), %ecx
@@ -2174,7 +2174,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$6, %ebp
+	cmpl	$6, %ebp
 	je	L(eq)
 
 	movzbl	6(%eax), %ecx
@@ -2183,7 +2183,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$7, %ebp
+	cmpl	$7, %ebp
 	je	L(eq)
 
 	movzbl	7(%eax), %ecx
@@ -2193,7 +2193,7 @@
 	je	L(eq)
 
 
-	cmp	$8, %ebp
+	cmpl	$8, %ebp
 	je	L(eq)
 
 	movzbl	8(%eax), %ecx
@@ -2202,7 +2202,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$9, %ebp
+	cmpl	$9, %ebp
 	je	L(eq)
 
 	movzbl	9(%eax), %ecx
@@ -2211,7 +2211,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$10, %ebp
+	cmpl	$10, %ebp
 	je	L(eq)
 
 	movzbl	10(%eax), %ecx
@@ -2220,7 +2220,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$11, %ebp
+	cmpl	$11, %ebp
 	je	L(eq)
 
 	movzbl	11(%eax), %ecx
@@ -2230,7 +2230,7 @@
 	je	L(eq)
 
 
-	cmp	$12, %ebp
+	cmpl	$12, %ebp
 	je	L(eq)
 
 	movzbl	12(%eax), %ecx
@@ -2239,7 +2239,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$13, %ebp
+	cmpl	$13, %ebp
 	je	L(eq)
 
 	movzbl	13(%eax), %ecx
@@ -2248,7 +2248,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$14, %ebp
+	cmpl	$14, %ebp
 	je	L(eq)
 
 	movzbl	14(%eax), %ecx
@@ -2257,7 +2257,7 @@
 	test	%cl, %cl
 	je	L(eq)
 
-	cmp	$15, %ebp
+	cmpl	$15, %ebp
 	je	L(eq)
 
 	movzbl	15(%eax), %ecx
diff --git a/libc/bionic/libc_init_common.h b/libc/bionic/libc_init_common.h
index 35050a1..c55594b 100644
--- a/libc/bionic/libc_init_common.h
+++ b/libc/bionic/libc_init_common.h
@@ -35,9 +35,6 @@
     void (**preinit_array)(void);
     void (**init_array)(void);
     void (**fini_array)(void);
-#ifndef __i386__
-    void (**ctors_array)(void);
-#endif
 } structors_array_t;
 
 extern void __libc_init_common(uintptr_t *elfdata);
diff --git a/libc/bionic/libc_init_static.c b/libc/bionic/libc_init_static.c
index f97961d..97156e8 100644
--- a/libc/bionic/libc_init_static.c
+++ b/libc/bionic/libc_init_static.c
@@ -80,11 +80,6 @@
     /* pre-init array. */
     call_array(structors->preinit_array);
 
-#ifndef __i386__
-    /* .ctors section initializers, for non-arm-eabi ABIs */
-    call_array(structors->ctors_array);
-#endif
-
     // call static constructors
     call_array(structors->init_array);
 
diff --git a/libc/netbsd/resolv/res_send.c b/libc/netbsd/resolv/res_send.c
index 72a7ada..f3ee539 100644
--- a/libc/netbsd/resolv/res_send.c
+++ b/libc/netbsd/resolv/res_send.c
@@ -644,6 +644,11 @@
 			errno = ETIMEDOUT;	/* no answer obtained */
 	} else
 		errno = terrno;
+
+#if USE_RESOLV_CACHE
+        _resolv_cache_query_failed(cache, buf, buflen);
+#endif
+
 	return (-1);
  fail:
 #if USE_RESOLV_CACHE
diff --git a/libc/stdio/vfprintf.c b/libc/stdio/vfprintf.c
index 427fc7f..646b6b1 100644
--- a/libc/stdio/vfprintf.c
+++ b/libc/stdio/vfprintf.c
@@ -827,6 +827,7 @@
 		munmap(argtable, argtablesiz);
 		argtable = NULL;
 	}
+        va_end(orgap);
 	return (__sferror(fp) ? EOF : ret);
 	/* NOTREACHED */
 }
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 09d9dd8..9d882a8 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -434,26 +434,28 @@
 
 static Elf32_Sym *
 soinfo_do_lookup(soinfo *si, const char *name, Elf32_Addr *offset,
-                 soinfo *needed[])
+                 soinfo *needed[], bool ignore_local)
 {
     unsigned elf_hash = elfhash(name);
-    Elf32_Sym *s;
+    Elf32_Sym *s = NULL;
     soinfo *lsi = si;
     int i;
 
-    /* Look for symbols in the local scope (the object who is
-     * searching). This happens with C++ templates on i386 for some
-     * reason.
-     *
-     * Notes on weak symbols:
-     * The ELF specs are ambiguous about treatment of weak definitions in
-     * dynamic linking.  Some systems return the first definition found
-     * and some the first non-weak definition.   This is system dependent.
-     * Here we return the first definition found for simplicity.  */
+    if (!ignore_local) {
+        /* Look for symbols in the local scope (the object who is
+         * searching). This happens with C++ templates on i386 for some
+         * reason.
+         *
+         * Notes on weak symbols:
+         * The ELF specs are ambiguous about treatment of weak definitions in
+         * dynamic linking.  Some systems return the first definition found
+         * and some the first non-weak definition.   This is system dependent.
+         * Here we return the first definition found for simplicity.  */
 
-    s = soinfo_elf_lookup(si, elf_hash, name);
-    if(s != NULL)
-        goto done;
+        s = soinfo_elf_lookup(si, elf_hash, name);
+        if(s != NULL)
+            goto done;
+    }
 
     /* Next, look for it in the preloads list */
     for(i = 0; preloads[i] != NULL; i++) {
@@ -684,6 +686,7 @@
     if (hdr->e_ident[EI_MAG1] != ELFMAG1) return -1;
     if (hdr->e_ident[EI_MAG2] != ELFMAG2) return -1;
     if (hdr->e_ident[EI_MAG3] != ELFMAG3) return -1;
+    if (hdr->e_type != ET_DYN) return -1;
 
     /* TODO: Should we verify anything else in the header? */
 #ifdef ANDROID_ARM_LINKER
@@ -959,7 +962,11 @@
         }
         if(sym != 0) {
             sym_name = (char *)(strtab + symtab[sym].st_name);
-            s = soinfo_do_lookup(si, sym_name, &offset, needed);
+            bool ignore_local = false;
+#if defined(ANDROID_ARM_LINKER)
+            ignore_local = (type == R_ARM_COPY);
+#endif
+            s = soinfo_do_lookup(si, sym_name, &offset, needed, ignore_local);
             if(s == NULL) {
                 /* We only allow an undefined symbol if this is a weak
                    reference..   */
@@ -1139,10 +1146,29 @@
 
 #ifdef ANDROID_ARM_LINKER
         case R_ARM_COPY:
+            if ((si->flags & FLAG_EXE) == 0) {
+                /*
+                 * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
+                 *
+                 * Section 4.7.1.10 "Dynamic relocations"
+                 * R_ARM_COPY may only appear in executable objects where e_type is
+                 * set to ET_EXEC.
+                 *
+                 * TODO: FLAG_EXE is set for both ET_DYN and ET_EXEC executables.
+                 * We should explicitly disallow ET_DYN executables from having
+                 * R_ARM_COPY relocations.
+                 */
+                DL_ERR("%s R_ARM_COPY relocations only supported for ET_EXEC", si->name);
+                return -1;
+            }
             count_relocation(kRelocCopy);
             MARK(rel->r_offset);
             TRACE_TYPE(RELO, "%5d RELO %08x <- %d @ %08x %s\n", pid,
                        reloc, s->st_size, sym_addr, sym_name);
+            if (reloc == sym_addr) {
+                DL_ERR("Internal linker error detected. reloc == symaddr");
+                return -1;
+            }
             memcpy((void*)reloc, (void*)sym_addr, s->st_size);
             break;
 #endif /* ANDROID_ARM_LINKER */
@@ -1201,7 +1227,7 @@
 
         /* This is an undefined reference... try to locate it */
         sym_name = si->strtab + sym->st_name;
-        s = soinfo_do_lookup(si, sym_name, &base, needed);
+        s = soinfo_do_lookup(si, sym_name, &base, needed, false);
         if (s == NULL) {
             /* We only allow an undefined symbol if this is a weak
                reference..   */
@@ -1804,7 +1830,7 @@
         exit(-1);
     }
 
-        /* bootstrap the link map, the main exe always needs to be first */
+    /* bootstrap the link map, the main exe always needs to be first */
     si->flags |= FLAG_EXE;
     link_map* map = &(si->linkmap);
 
@@ -1839,7 +1865,7 @@
                                    &linker_soinfo.dynamic, NULL);
     insert_soinfo_into_debug_map(&linker_soinfo);
 
-        /* extract information passed from the kernel */
+    /* extract information passed from the kernel */
     while(vecs[0] != 0){
         switch(vecs[0]){
         case AT_PHDR:
diff --git a/linker/linker_debug.h b/linker/linker_debug.h
index f1b6208..48a7abf 100644
--- a/linker/linker_debug.h
+++ b/linker/linker_debug.h
@@ -61,6 +61,11 @@
  */
 #if LINKER_DEBUG
 #include "linker_format.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 extern int debug_verbosity;
 #if LINKER_DEBUG_TO_LOG
 extern int format_log(int, const char *, const char *, ...);
@@ -75,6 +80,11 @@
         if (debug_verbosity > (v)) format_fd(1, x);  \
     } while (0)
 #endif /* !LINKER_DEBUG_TO_LOG */
+
+#ifdef __cplusplus
+};
+#endif
+
 #else /* !LINKER_DEBUG */
 #define _PRINTVF(v,f,x...)   do {} while(0)
 #endif /* LINKER_DEBUG */