Merge "Remove duplicate item"
diff --git a/libc/include/getopt.h b/libc/include/getopt.h
index 6b4954b..56f1983 100644
--- a/libc/include/getopt.h
+++ b/libc/include/getopt.h
@@ -71,14 +71,19 @@
 #ifndef _GETOPT_DEFINED_
 #define _GETOPT_DEFINED_
 int	 getopt(int, char * const *, const char *);
-int	 getsubopt(char **, char * const *, char **);
+
 
 extern   char *optarg;                  /* getopt(3) external variables */
 extern   int opterr;
 extern   int optind;
 extern   int optopt;
 extern   int optreset;
+
+#if 0 /* MISSING FROM BIONIC */
+int       getsubopt(char **, char * const *, char **);
 extern   char *suboptarg;               /* getsubopt(3) external variable */
+#endif /* MISSING */
+
 #endif
 __END_DECLS
  
diff --git a/libc/include/sched.h b/libc/include/sched.h
index 33b9ad6..e702470 100644
--- a/libc/include/sched.h
+++ b/libc/include/sched.h
@@ -69,7 +69,7 @@
 #define CLONE_CHILD_SETTID   0x01000000
 #define CLONE_STOPPED        0x02000000
 
-#ifdef __GNU_SOURCE
+#ifdef _GNU_SOURCE
 extern int clone(int (*fn)(void *), void *child_stack, int flags, void*  arg, ...);
 #endif
 
diff --git a/libc/include/signal.h b/libc/include/signal.h
index 7bc3145..4401164 100644
--- a/libc/include/signal.h
+++ b/libc/include/signal.h
@@ -120,6 +120,7 @@
 extern int raise(int);
 extern int kill(pid_t, int);
 extern int killpg(int pgrp, int sig);
+extern int sigaltstack(const stack_t *ss, stack_t *oss);
 
 
 __END_DECLS
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index d164e95..c38ed5a 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -300,8 +300,10 @@
 #define L_cuserid	9	/* size for cuserid(); UT_NAMESIZE + 1 */
 
 __BEGIN_DECLS
+#if 0 /* MISSING FROM BIONIC */
 char	*ctermid(char *);
 char	*cuserid(char *);
+#endif /* MISSING */
 FILE	*fdopen(int, const char *);
 int	 fileno(FILE *);
 
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index f889159..97d8e46 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -50,7 +50,6 @@
 extern __noreturn void exit(int);
 extern __noreturn void abort(void);
 extern int atexit(void (*)(void));
-extern int on_exit(void (*)(int, void *), void *);
 
 extern char *getenv(const char *);
 extern int putenv(const char *);
@@ -164,6 +163,7 @@
 
 extern lldiv_t   lldiv(long long, long long);
 
+#if 1 /* MISSING FROM BIONIC - ENABLED FOR STLPort and libstdc++-v3 */
 /* make STLPort happy */
 extern int      mblen(const char *, size_t);
 extern size_t   mbstowcs(wchar_t *, const char *, size_t);
@@ -172,8 +172,14 @@
 /* Likewise, make libstdc++-v3 happy.  */
 extern int	wctomb(char *, wchar_t);
 extern size_t	wcstombs(char *, const wchar_t *, size_t);
+#endif /* MISSING */
+
 #define MB_CUR_MAX 1
 
+#if 0 /* MISSING FROM BIONIC */
+extern int on_exit(void (*)(int, void *), void *);
+#endif /* MISSING */
+
 __END_DECLS
 
 #endif /* _STDLIB_H_ */
diff --git a/libc/include/sys/cdefs_elf.h b/libc/include/sys/cdefs_elf.h
index e051b1d..1e57470 100644
--- a/libc/include/sys/cdefs_elf.h
+++ b/libc/include/sys/cdefs_elf.h
@@ -95,6 +95,10 @@
 	__asm__(".section _sec\n\t.asciz _str\n\t.previous")
 #endif
 
+/* GCC visibility helper macro */
+#define __LIBC_HIDDEN__							\
+	__attribute__ ((visibility ("hidden")))
+
 #define	__IDSTRING(_n,_s)		__SECTIONSTRING(.ident,_s)
 
 #define	__RCSID(_s)			__IDSTRING(rcsid,_s)
diff --git a/libc/include/sys/fsuid.h b/libc/include/sys/fsuid.h
index 3257bc0..bc47e3d 100644
--- a/libc/include/sys/fsuid.h
+++ b/libc/include/sys/fsuid.h
@@ -33,8 +33,10 @@
 
 __BEGIN_DECLS
 
+#if 0 /* MISSING FROM BIONIC */
 extern int setfsuid(uid_t);
 extern int setfsgid(gid_t);
+#endif /* MISSING */
 
 __END_DECLS
 
diff --git a/libc/include/sys/mount.h b/libc/include/sys/mount.h
index 62c4ee2..ba88447 100644
--- a/libc/include/sys/mount.h
+++ b/libc/include/sys/mount.h
@@ -92,7 +92,10 @@
 		   const void *);
 extern int umount(const char *);
 extern int umount2(const char *, int);
+
+#if 0 /* MISSING FROM BIONIC */
 extern int pivot_root(const char *, const char *);
+#endif /* MISSING */
 
 __END_DECLS
 
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index d5c88dc..38e2825 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -61,16 +61,13 @@
 extern pid_t  getpgrp(void);
 extern int    setpgrp(void);
 extern pid_t  setsid(void);
-extern pid_t  getsid(pid_t);
 
 extern int execv(const char *, char * const *);
 extern int execvp(const char *, char * const *);
 extern int execve(const char *, char * const *, char * const *);
-extern int execvpe(const char *, char * const *, char * const *);
 extern int execl(const char *, const char *, ...);
 extern int execlp(const char *, const char *, ...);
 extern int execle(const char *, const char *, ...);
-extern int execlpe(const char *, const char *, ...);
 extern int capget(cap_user_header_t hdrp, cap_user_data_t datap);
 extern int capset(cap_user_header_t hdrp, const cap_user_data_t datap);
 extern int prctl(int  option,  unsigned long arg2, unsigned long arg3,
@@ -94,11 +91,8 @@
 extern int setresgid(gid_t, gid_t, gid_t);
 extern int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid);
 extern int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid);
-extern int getfsuid(uid_t);
-extern int setfsuid(uid_t);
 extern int issetugid(void);
 extern char* getlogin(void);
-extern int getlogin_r(char* name, size_t namesize);
 extern char* getusershell(void);
 extern void setusershell(void);
 extern void endusershell(void);
@@ -156,9 +150,6 @@
 extern int usleep(unsigned long);
 
 extern int gethostname(char *, size_t);
-extern int sethostname(const char *, size_t);
-extern int getdomainname(char *, size_t);
-extern int setdomainname(const char *, size_t);
 
 extern int getdtablesize(void);
 
@@ -195,6 +186,18 @@
 extern pid_t tcgetpgrp(int fd);
 extern int   tcsetpgrp(int fd, pid_t _pid);
 
+#if 0 /* MISSING FROM BIONIC */
+extern pid_t  getsid(pid_t);
+extern int execvpe(const char *, char * const *, char * const *);
+extern int execlpe(const char *, const char *, ...);
+extern int getfsuid(uid_t);
+extern int setfsuid(uid_t);
+extern int getlogin_r(char* name, size_t namesize);
+extern int sethostname(const char *, size_t);
+extern int getdomainname(char *, size_t);
+extern int setdomainname(const char *, size_t);
+#endif /* MISSING */
+
 /* Used to retry syscalls that can return EINTR. */
 #define TEMP_FAILURE_RETRY(exp) ({         \
     typeof (exp) _rc;                      \
diff --git a/libc/netbsd/gethnamaddr.c b/libc/netbsd/gethnamaddr.c
index 1c219b2..3ebe53e 100644
--- a/libc/netbsd/gethnamaddr.c
+++ b/libc/netbsd/gethnamaddr.c
@@ -104,9 +104,9 @@
 static void map_v4v6_hostent(struct hostent *, char **, char *);
 static void addrsort(char **, int, res_state);
 
-void _sethtent(int);
-void _endhtent(void);
-struct hostent *_gethtent(void);
+static void _sethtent(int);
+static void _endhtent(void);
+static struct hostent *_gethtent(void);
 void ht_sethostent(int);
 void ht_endhostent(void);
 struct hostent *ht_gethostbyname(char *);
@@ -114,11 +114,11 @@
 void dns_service(void);
 #undef dn_skipname
 int dn_skipname(const u_char *, const u_char *);
-int _gethtbyaddr(void *, void *, va_list);
-int _gethtbyname(void *, void *, va_list);
-struct hostent *_gethtbyname2(const char *, int);
-int _dns_gethtbyaddr(void *, void *, va_list);
-int _dns_gethtbyname(void *, void *, va_list);
+static int _gethtbyaddr(void *, void *, va_list);
+static int _gethtbyname(void *, void *, va_list);
+static struct hostent *_gethtbyname2(const char *, int);
+static int _dns_gethtbyaddr(void *, void *, va_list);
+static int _dns_gethtbyname(void *, void *, va_list);
 
 static struct hostent *gethostbyname_internal(const char *, int, res_state);
 
@@ -692,7 +692,7 @@
 	return hp;
 }
 
-void
+static void
 _sethtent(int f)
 {
     res_static  rs = __res_get_static();
@@ -704,7 +704,7 @@
 	rs->stayopen = f;
 }
 
-void
+static void
 _endhtent(void)
 {
     res_static  rs = __res_get_static();
@@ -716,7 +716,7 @@
 	}
 }
 
-struct hostent *
+static struct hostent *
 _gethtent(void)
 {
 	char *p;
@@ -829,7 +829,7 @@
 	return NS_SUCCESS;
 }
 
-struct hostent *
+static struct hostent *
 _gethtbyname2(const char *name, int af)
 {
 	struct hostent *p;
@@ -920,7 +920,7 @@
 }
 
 /*ARGSUSED*/
-int
+static int
 _gethtbyaddr(void *rv, void *cb_data, va_list ap)
 {
 	struct hostent *p;
@@ -1053,7 +1053,7 @@
 }
 
 /*ARGSUSED*/
-int
+static int
 _dns_gethtbyname(void *rv, void *cb_data, va_list ap)
 {
 	querybuf *buf;
@@ -1113,7 +1113,7 @@
 }
 
 /*ARGSUSED*/
-int
+static int
 _dns_gethtbyaddr(void *rv, void	*cb_data, va_list ap)
 {
 	char qbuf[MAXDNAME + 1], *qp, *ep;
diff --git a/libc/string/memmove.c b/libc/string/memmove.c
index fcaf4ee..98ecfc9 100644
--- a/libc/string/memmove.c
+++ b/libc/string/memmove.c
@@ -31,7 +31,10 @@
 {
   const char *p = src;
   char *q = dst;
-  if (__builtin_expect(q < p, 1)) {
+  /* We can use the optimized memcpy if the destination is below the
+   * source (i.e. q < p), or if it is completely over it (i.e. q >= p+n).
+   */
+  if (__builtin_expect((q < p) || ((size_t)(q - p) >= n), 1)) {
     return memcpy(dst, src, n);
   } else {
 #define PRELOAD_DISTANCE 64
diff --git a/libc/unistd/abort.c b/libc/unistd/abort.c
index 3e3aab0..8b8659b 100644
--- a/libc/unistd/abort.c
+++ b/libc/unistd/abort.c
@@ -40,7 +40,7 @@
     __libc_android_log_print(ANDROID_LOG_DEBUG, "libc-abort", (format), ##__VA_ARGS__ )
 
 #ifdef __arm__
-void
+__LIBC_HIDDEN__ void
 __libc_android_abort(void)
 #else
 void
diff --git a/libstdc++/include/cstdlib b/libstdc++/include/cstdlib
index e520543..bb6f5a5 100644
--- a/libstdc++/include/cstdlib
+++ b/libstdc++/include/cstdlib
@@ -42,7 +42,9 @@
 using ::exit;
 using ::abort;
 using ::atexit;
+#if 0 /* MISSING FROM BIONIC */
 using ::on_exit;
+#endif
 
 using ::getenv;
 using ::putenv;