Merge "Remove some dead data."
diff --git a/libc/bionic/libc_logging.cpp b/libc/bionic/libc_logging.cpp
index 8b3d3f1..e656a12 100644
--- a/libc/bionic/libc_logging.cpp
+++ b/libc/bionic/libc_logging.cpp
@@ -453,7 +453,7 @@
   // found that all logd crashes thus far have had no problem stuffing
   // the UNIX domain socket and moving on so not critical *today*.
 
-  int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM, 0));
+  int log_fd = TEMP_FAILURE_RETRY(socket(PF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0));
   if (log_fd < 0) {
     return -1;
   }
diff --git a/libc/bionic/malloc_debug_common.cpp b/libc/bionic/malloc_debug_common.cpp
index cbca160..9399237 100644
--- a/libc/bionic/malloc_debug_common.cpp
+++ b/libc/bionic/malloc_debug_common.cpp
@@ -408,7 +408,7 @@
     dlclose(malloc_impl_handle);
     return;
   }
-  if (malloc_debug_initialize(&g_hash_table) == -1) {
+  if (!malloc_debug_initialize(&g_hash_table)) {
     dlclose(malloc_impl_handle);
     return;
   }
diff --git a/libc/bionic/semaphore.c b/libc/bionic/semaphore.c
index 7387d6e..1fa019e 100644
--- a/libc/bionic/semaphore.c
+++ b/libc/bionic/semaphore.c
@@ -126,11 +126,8 @@
 }
 
 
-sem_t *sem_open(const char *name, int oflag, ...)
+sem_t *sem_open(const char *name __unused, int oflag __unused, ...)
 {
-    name=name;
-    oflag=oflag;
-
     errno = ENOSYS;
     return SEM_FAILED;
 }
diff --git a/libc/dns/gethnamaddr.c b/libc/dns/gethnamaddr.c
index 6f30f75..80fdcbe 100644
--- a/libc/dns/gethnamaddr.c
+++ b/libc/dns/gethnamaddr.c
@@ -90,7 +90,7 @@
 // This should be synchronized to ResponseCode.h
 static const int DnsProxyQueryResult = 222;
 
-static const char const AskedForGot[] =
+static const char AskedForGot[] =
 			  "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
 
 #define	MAXPACKET	(64*1024)
diff --git a/libc/dns/resolv/res_send.c b/libc/dns/resolv/res_send.c
index 4a010d5..de09385 100644
--- a/libc/dns/resolv/res_send.c
+++ b/libc/dns/resolv/res_send.c
@@ -1277,8 +1277,6 @@
 	char hbuf[NI_MAXHOST];
 	char sbuf[NI_MAXSERV];
 
-	alen = alen;
-
 	if ((statp->options & RES_DEBUG) != 0U) {
 		if (getnameinfo(address, (socklen_t)alen, hbuf, sizeof(hbuf),
 		    sbuf, sizeof(sbuf), niflags)) {
diff --git a/libc/dns/resolv/res_state.c b/libc/dns/resolv/res_state.c
index 01f68e9..57791d1 100644
--- a/libc/dns/resolv/res_state.c
+++ b/libc/dns/resolv/res_state.c
@@ -211,10 +211,9 @@
 }
 
 void
-__res_put_state(res_state res)
+__res_put_state(res_state res __unused)
 {
     /* nothing to do */
-    res=res;
 }
 
 res_static
diff --git a/libc/include/ctype.h b/libc/include/ctype.h
index a66df12..6e97326 100644
--- a/libc/include/ctype.h
+++ b/libc/include/ctype.h
@@ -56,8 +56,6 @@
 __BEGIN_DECLS
 
 extern const char	*_ctype_;
-extern const short	*_tolower_tab_;
-extern const short	*_toupper_tab_;
 
 #if defined(__GNUC__) || defined(_ANSI_LIBRARY) || defined(lint)
 int	isalnum(int);
diff --git a/libc/include/sys/cdefs_elf.h b/libc/include/sys/cdefs_elf.h
index c21214c..b5db13e 100644
--- a/libc/include/sys/cdefs_elf.h
+++ b/libc/include/sys/cdefs_elf.h
@@ -64,6 +64,13 @@
 /* Used to tag non-static symbols that are private and never exposed by the shared library. */
 #define __LIBC_HIDDEN__ __attribute__((visibility ("hidden")))
 
+/* Like __LIBC_HIDDEN__, but preserves binary compatibility for LP32. */
+#ifdef __LP64__
+#define __LIBC64_HIDDEN__ __LIBC_HIDDEN__
+#else
+#define __LIBC64_HIDDEN__
+#endif
+
 /* Used to tag non-static symbols that are public and exposed by the shared library. */
 #define __LIBC_ABI_PUBLIC__ __attribute__((visibility ("default")))
 
diff --git a/libc/upstream-openbsd/android/include/openbsd-compat.h b/libc/upstream-openbsd/android/include/openbsd-compat.h
index 8618e31..f00d91a 100644
--- a/libc/upstream-openbsd/android/include/openbsd-compat.h
+++ b/libc/upstream-openbsd/android/include/openbsd-compat.h
@@ -17,6 +17,8 @@
 #ifndef _BIONIC_OPENBSD_COMPAT_H_included
 #define _BIONIC_OPENBSD_COMPAT_H_included
 
+#include <sys/cdefs.h>
+
 #define __USE_BSD
 
 /* OpenBSD's <ctype.h> uses these names, which conflicted with stlport.
@@ -34,4 +36,8 @@
 /* OpenBSD has this, but we can't really implement it correctly on Linux. */
 #define issetugid() 0
 
+/* LP32 NDK ctype.h contained references to these. */
+__LIBC64_HIDDEN__ extern const short *_tolower_tab_;
+__LIBC64_HIDDEN__ extern const short *_toupper_tab_;
+
 #endif
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 8cf9fea..506c3f2 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -60,7 +60,6 @@
  *
  * open issues / todo:
  *
- * - are we doing everything we should for ARM_COPY relocations?
  * - cleaner error reporting
  * - after linking, set as much stuff as possible to READONLY
  *   and NOEXEC
@@ -1061,52 +1060,17 @@
         break;
 
     case R_AARCH64_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_AARCH64_COPY may only appear in executable objects where e_type is
-              * set to ET_EXEC.
-              *
-              * FLAG_EXE is set for both ET_DYN and ET_EXEC executables.
-              * We should explicitly disallow ET_DYN executables from having
-              * R_AARCH64_COPY relocations.
-              */
-            DL_ERR("%s R_AARCH64_COPY relocations only supported for ET_EXEC", si->name);
-            return -1;
-        }
-        count_relocation(kRelocCopy);
-        MARK(rela->r_offset);
-        TRACE_TYPE(RELO, "RELO COPY %16llx <- %lld @ %16llx %s\n",
-                   reloc,
-                   s->st_size,
-                   (sym_addr + rela->r_addend),
-                   sym_name);
-        if (reloc == (sym_addr + rela->r_addend)) {
-            ElfW(Sym)* src = soinfo_do_lookup(NULL, sym_name, &lsi, needed);
-
-            if (src == NULL) {
-                DL_ERR("%s R_AARCH64_COPY relocation source cannot be resolved", si->name);
-                return -1;
-            }
-            if (lsi->has_DT_SYMBOLIC) {
-                DL_ERR("%s invalid R_AARCH64_COPY relocation against DT_SYMBOLIC shared "
-                       "library %s (built with -Bsymbolic?)", si->name, lsi->name);
-                return -1;
-            }
-            if (s->st_size < src->st_size) {
-                DL_ERR("%s R_AARCH64_COPY relocation size mismatch (%lld < %lld)",
-                       si->name, s->st_size, src->st_size);
-                return -1;
-            }
-            memcpy(reinterpret_cast<void*>(reloc),
-                   reinterpret_cast<void*>(src->st_value + lsi->load_bias), src->st_size);
-        } else {
-            DL_ERR("%s R_AARCH64_COPY relocation target cannot be resolved", si->name);
-            return -1;
-        }
-        break;
+        /*
+         * ET_EXEC is not supported so this should not happen.
+         *
+         * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
+         *
+         * Section 4.7.1.10 "Dynamic relocations"
+         * R_AARCH64_COPY may only appear in executable objects where e_type is
+         * set to ET_EXEC.
+         */
+        DL_ERR("%s R_AARCH64_COPY relocations are not supported", si->name);
+        return -1;
     case R_AARCH64_TLS_TPREL64:
         TRACE_TYPE(RELO, "RELO TLS_TPREL64 *** %16llx <- %16llx - %16llx\n",
                    reloc, (sym_addr + rela->r_addend), rela->r_offset);
@@ -1284,48 +1248,17 @@
             *reinterpret_cast<ElfW(Addr)*>(reloc) += sym_addr - rel->r_offset;
             break;
         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, "RELO %08x <- %d @ %08x %s", reloc, s->st_size, sym_addr, sym_name);
-            if (reloc == sym_addr) {
-                ElfW(Sym)* src = soinfo_do_lookup(NULL, sym_name, &lsi, needed);
-
-                if (src == NULL) {
-                    DL_ERR("%s R_ARM_COPY relocation source cannot be resolved", si->name);
-                    return -1;
-                }
-                if (lsi->has_DT_SYMBOLIC) {
-                    DL_ERR("%s invalid R_ARM_COPY relocation against DT_SYMBOLIC shared "
-                           "library %s (built with -Bsymbolic?)", si->name, lsi->name);
-                    return -1;
-                }
-                if (s->st_size < src->st_size) {
-                    DL_ERR("%s R_ARM_COPY relocation size mismatch (%d < %d)",
-                           si->name, s->st_size, src->st_size);
-                    return -1;
-                }
-                memcpy(reinterpret_cast<void*>(reloc),
-                       reinterpret_cast<void*>(src->st_value + lsi->load_bias), src->st_size);
-            } else {
-                DL_ERR("%s R_ARM_COPY relocation target cannot be resolved", si->name);
-                return -1;
-            }
-            break;
+            /*
+             * ET_EXEC is not supported so this should not happen.
+             *
+             * 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.
+             */
+            DL_ERR("%s R_ARM_COPY relocations are not supported", si->name);
+            return -1;
 #elif defined(__i386__)
         case R_386_JMP_SLOT:
             count_relocation(kRelocAbsolute);
@@ -2193,13 +2126,11 @@
     si->dynamic = NULL;
     si->ref_count = 1;
 
-#if defined(__LP64__)
     ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base);
     if (elf_hdr->e_type != ET_DYN) {
         __libc_format_fd(2, "error: only position independent executables (PIE) are supported.\n");
         exit(EXIT_FAILURE);
     }
-#endif
 
     // Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid).
     parse_LD_LIBRARY_PATH(ldpath_env);