Move bionic over to GCC's 'warning' attribute.

This is a better solution than the old __warn_references because it's
a compile-time rather than link-time warning, it doesn't rely on something
that doesn't appear to be supported by gold (which is why you only used
to see these warnings on mips builds), and the errors refer to the exact
call site(s) rather than just telling you which object file contains a
reference to the bad function.

This is primarily so we can build bionic for aarch64; building libc.so
caused these warnings to fire (because link time is the wrong time) and
warnings are errors.

Change-Id: I5df9281b2a9d98b164a9b11807ea9472c6faa9e3
diff --git a/libc/arch-arm/include/machine/cdefs.h b/libc/arch-arm/include/machine/cdefs.h
deleted file mode 100644
index 44f1542..0000000
--- a/libc/arch-arm/include/machine/cdefs.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*	$OpenBSD: cdefs.h,v 1.2 2005/11/24 20:46:44 deraadt Exp $	*/
-
-#ifndef	_MACHINE_CDEFS_H_
-#define	_MACHINE_CDEFS_H_
-
-#if defined(lint)
-#define __indr_reference(sym,alias)	__lint_equal__(sym,alias)
-#define __warn_references(sym,msg)
-#define __weak_alias(alias,sym)		__lint_equal__(sym,alias)
-#elif defined(__GNUC__) && defined(__STDC__)
-#define __weak_alias(alias,sym)					\
-	__asm__(".weak " __STRING(alias) " ; " __STRING(alias)	\
-	    " = " __STRING(sym));
-#define	__warn_references(sym,msg)				\
-	__asm__(".section .gnu.warning." __STRING(sym)		\
-	    " ; .ascii \"" msg "\" ; .text");
-#endif
-
-#endif /* !_MACHINE_CDEFS_H_ */
diff --git a/libc/arch-mips/include/machine/cdefs.h b/libc/arch-mips/include/machine/cdefs.h
deleted file mode 100644
index d52376a..0000000
--- a/libc/arch-mips/include/machine/cdefs.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*	$OpenBSD: cdefs.h,v 1.4 2006/01/10 00:04:04 millert Exp $	*/
-
-/*
- * Copyright (c) 2002-2003 Opsycon AB  (www.opsycon.se / www.opsycon.com)
- *
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 _MIPS_CDEFS_H_
-#define	_MIPS_CDEFS_H_
-
-#if defined(lint)
-#define __indr_reference(sym,alias)	__lint_equal__(sym,alias)
-#define __warn_references(sym,msg)
-#define __weak_alias(alias,sym)		__lint_equal__(sym,alias)
-#elif defined(__GNUC__) && defined(__STDC__)
-#define __weak_alias(alias,sym)				\
-	__asm__(".weak " __STRING(alias) " ; "		\
-	    __STRING(alias) " = " __STRING(sym))
-#define	__warn_references(sym,msg)			\
-	__asm__(".section .gnu.warning." __STRING(sym)	\
-	    " ; .ascii \"" msg "\" ; .text")
-#define	__indr_references(sym,msg)	/* nothing */
-#endif
-
-#endif /* !_MIPS_CDEFS_H_ */
diff --git a/libc/arch-x86/include/machine/cdefs.h b/libc/arch-x86/include/machine/cdefs.h
deleted file mode 100644
index 6efee6a..0000000
--- a/libc/arch-x86/include/machine/cdefs.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*	$OpenBSD: cdefs.h,v 1.9 2005/11/24 20:46:45 deraadt Exp $	*/
-
-/*
- * Written by J.T. Conklin <jtc@wimsey.com> 01/17/95.
- * Public domain.
- */
-
-#ifndef	_MACHINE_CDEFS_H_
-#define	_MACHINE_CDEFS_H_
-
-#if defined(lint)
-#define __indr_reference(sym,alias)	__lint_equal__(sym,alias)
-#define __warn_references(sym,msg)
-#define __weak_alias(alias,sym)		__lint_equal__(sym,alias)
-#elif defined(__GNUC__) && defined(__STDC__)
-#define __weak_alias(alias,sym)				\
-	__asm__(".weak " __STRING(alias) " ; "		\
-	    __STRING(alias) " = " __STRING(sym));
-#define __warn_references(sym,msg)			\
-	__asm__(".section .gnu.warning." __STRING(sym)	\
-	    " ; .ascii \"" msg "\" ; .text");
-#endif
-
-#endif /* !_MACHINE_CDEFS_H_ */
diff --git a/libc/arch-x86_64/include/machine/cdefs.h b/libc/arch-x86_64/include/machine/cdefs.h
deleted file mode 100644
index eb243a3..0000000
--- a/libc/arch-x86_64/include/machine/cdefs.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*	$OpenBSD: cdefs.h,v 1.3 2013/03/28 17:30:45 martynas Exp $	*/
-
-/*
- * Written by J.T. Conklin <jtc@wimsey.com> 01/17/95.
- * Public domain.
- */
-
-#ifndef	_MACHINE_CDEFS_H_
-#define	_MACHINE_CDEFS_H_
-
-#define __strong_alias(alias,sym)					\
-	__asm__(".global " __STRING(alias) " ; " __STRING(alias)	\
-	    " = " __STRING(sym))
-#define __weak_alias(alias,sym)						\
-	__asm__(".weak " __STRING(alias) " ; " __STRING(alias)		\
-	    " = " __STRING(sym))
-#define __warn_references(sym,msg)					\
-	__asm__(".section .gnu.warning." __STRING(sym)			\
-	    " ; .ascii \"" msg "\" ; .text")
-
-#endif /* !_MACHINE_CDEFS_H_ */
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 409afea..260a4e7 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -222,13 +222,13 @@
 ssize_t	 getdelim(char ** __restrict, size_t * __restrict, int,
 	    FILE * __restrict);
 ssize_t	 getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
-char	*gets(char *);
+
 #if __BSD_VISIBLE && !defined(__SYS_ERRLIST)
 #define __SYS_ERRLIST
-
 extern int sys_nerr;			/* perror(3) external variables */
 extern char *sys_errlist[];
 #endif
+
 void	 perror(const char *);
 int	 printf(const char * __restrict, ...)
 		__printflike(1, 2);
@@ -251,13 +251,16 @@
 		__printflike(1, 0);
 
 #ifndef __AUDIT__
-char	*gets(char *);
-int	 sprintf(char * __restrict, const char * __restrict, ...)
-		__printflike(2, 3);
-char	*tmpnam(char *);
-int	 vsprintf(char * __restrict, const char * __restrict,
-    __va_list)
-		__printflike(2, 0);
+char* gets(char*) __warnattr("gets is very unsafe; consider using fgets");
+int sprintf(char* __restrict, const char* __restrict, ...)
+    __printflike(2, 3) __warnattr("sprintf is often misused; please use snprintf");
+char* tmpnam(char*) __warnattr("tmpnam possibly used unsafely; consider using mkstemp");
+int vsprintf(char* __restrict, const char* __restrict, __va_list)
+    __printflike(2, 0) __warnattr("vsprintf is often misused; please use vsnprintf");
+#if __XPG_VISIBLE
+char* tempnam(const char*, const char*)
+    __warnattr("tempnam possibly used unsafely; consider using mkstemp");
+#endif
 #endif
 
 extern int rename(const char*, const char*);
@@ -320,9 +323,6 @@
 int	 putchar_unlocked(int);
 #endif /* __POSIX_VISIBLE >= 199506 */
 
-#if __XPG_VISIBLE
-char	*tempnam(const char *, const char *);
-#endif
 __END_DECLS
 
 #endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index 9fa84c1..72b554f 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -51,9 +51,9 @@
 extern int unsetenv(const char *);
 extern int clearenv(void);
 
-extern char *mkdtemp(char *);
-extern char *mktemp(char *);
-extern int mkstemp(char *);
+extern char* mkdtemp(char*);
+extern char* mktemp(char*) __warnattr("mktemp possibly used unsafely; consider using mkstemp");
+extern int mkstemp(char*);
 
 extern long strtol(const char *, char **, int);
 extern long long strtoll(const char *, char **, int);
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index c7f2ac7..b4dad74 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -334,8 +334,10 @@
 
 #if __GNUC_PREREQ__(4, 3)
 #define __errordecl(name, msg) extern void name(void) __attribute__((__error__(msg)))
+#define __warnattr(msg) __attribute__((__warning__(msg)))
 #else
 #define __errordecl(name, msg) extern void name(void)
+#define __warnattr(msg)
 #endif
 
 /*
diff --git a/libc/include/sys/cdefs_elf.h b/libc/include/sys/cdefs_elf.h
index 0887fa5..bb846b7 100644
--- a/libc/include/sys/cdefs_elf.h
+++ b/libc/include/sys/cdefs_elf.h
@@ -38,20 +38,10 @@
 #define _C_LABEL_STRING(x)	x
 #endif
 
-#if __STDC__
 #define	___RENAME(x)	__asm__(___STRING(_C_LABEL(x)))
-#else
-#ifdef __LEADING_UNDERSCORE
-#define	___RENAME(x)	____RENAME(_/**/x)
-#define	____RENAME(x)	__asm__(___STRING(x))
-#else
-#define	___RENAME(x)	__asm__(___STRING(x))
-#endif
-#endif
 
 #define	__indr_reference(sym,alias)	/* nada, since we do weak refs */
 
-#if __STDC__
 #define	__strong_alias(alias,sym)	       				\
     __asm__(".global " _C_LABEL_STRING(#alias) "\n"			\
 	    _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
@@ -61,39 +51,15 @@
 	    _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
 #define	__weak_extern(sym)						\
     __asm__(".weak " _C_LABEL_STRING(#sym));
+
+/* We use __warnattr instead of __warn_references.
+ * TODO: remove this and put an empty definition in one of the upstream-* compatibility headers.
+ */
 #define	__warn_references(sym,msg)					\
-    __asm__(".section .gnu.warning." #sym "\n\t.ascii \"" msg "\"\n\t.text");
+    /*__asm__(".section .gnu.warning." #sym "\n\t.ascii \"" msg "\"\n\t.text");*/
 
-#else /* !__STDC__ */
-
-#ifdef __LEADING_UNDERSCORE
-#define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
-#define	___weak_alias(alias,sym)					\
-    __asm__(".weak alias\nalias = sym");
-#else
-#define	__weak_alias(alias,sym)						\
-    __asm__(".weak alias\nalias = sym");
-#endif
-#ifdef __LEADING_UNDERSCORE
-#define __weak_extern(sym) ___weak_extern(_/**/sym)
-#define	___weak_extern(sym)						\
-    __asm__(".weak sym");
-#else
-#define	__weak_extern(sym)						\
-    __asm__(".weak sym");
-#endif
-#define	__warn_references(sym,msg)					\
-    __asm__(".section .gnu.warning.sym\n\t.ascii msg ; .text");
-
-#endif /* !__STDC__ */
-
-#if __STDC__
 #define	__SECTIONSTRING(_sec, _str)					\
 	__asm__(".section " #_sec "\n\t.asciz \"" _str "\"\n\t.previous")
-#else
-#define	__SECTIONSTRING(_sec, _str)					\
-	__asm__(".section _sec\n\t.asciz _str\n\t.previous")
-#endif
 
 /* GCC visibility helper macro */
 /* This must be used to tag non-static functions that are private, i.e.