Improve <sys/cdefs.h>.
Fix and use __RENAME (and lose ___RENAME --- two underscores should be
enough for anybody). This was the point of this change, because I want
to use __RENAME to support the two basename variants and the two
strerror_r variants.
Lose a bunch of macros that weren't being used.
Lose three dead files from the DNS code.
Change-Id: I3ef645c566b16a52217bc2e68c7d54b37c7c9522
diff --git a/libc/dns/resolv/__dn_comp.c b/libc/dns/resolv/__dn_comp.c
deleted file mode 100644
index 93d3f19..0000000
--- a/libc/dns/resolv/__dn_comp.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/* $NetBSD: __dn_comp.c,v 1.4 2005/09/13 01:44:10 christos Exp $ */
-
-/*
- * written by matthew green, 22/04/97.
- * public domain.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: __dn_comp.c,v 1.4 2005/09/13 01:44:10 christos Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#if defined(__indr_reference)
-__indr_reference(__dn_comp,dn_comp)
-#else
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-
-/* XXX THIS IS A MESS! SEE <resolv.h> XXX */
-
-#undef dn_comp
-int dn_comp(const char *, u_char *, int, u_char **, u_char **);
-
-int
-dn_comp(const char *exp_dn, u_char *comp_dn, u_char **dnptrs,
- u_char **lastdnptr, int length)
-{
-
- return __dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr);
-}
-
-#endif
diff --git a/libc/dns/resolv/__res_close.c b/libc/dns/resolv/__res_close.c
deleted file mode 100644
index 3af50b0..0000000
--- a/libc/dns/resolv/__res_close.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/* $NetBSD: __res_close.c,v 1.4 2005/09/13 01:44:10 christos Exp $ */
-
-/*
- * written by matthew green, 22/04/97.
- * public domain.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: __res_close.c,v 1.4 2005/09/13 01:44:10 christos Exp $");
-#endif /* LIBC_SCCS and not lint */
-
-#if defined(__indr_reference)
-__indr_reference(__res_close, res_close)
-#else
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#include "resolv_private.h"
-
-/* XXX THIS IS A MESS! SEE <resolv.h> XXX */
-
-#undef res_close
-void res_close(void);
-
-void
-res_close(void)
-{
-
- __res_close();
-}
-
-#endif
diff --git a/libc/dns/resolv/__res_send.c b/libc/dns/resolv/__res_send.c
deleted file mode 100644
index 198b05c..0000000
--- a/libc/dns/resolv/__res_send.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* $NetBSD: __res_send.c,v 1.4 2005/09/13 01:44:10 christos Exp $ */
-
-/*
- * written by matthew green, 22/04/97.
- * public domain.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: __res_send.c,v 1.4 2005/09/13 01:44:10 christos Exp $");
-#endif
-
-#if defined(__indr_reference)
-__indr_reference(__res_send, res_send)
-#else
-
-#include <sys/types.h>
-#include <netinet/in.h>
-#ifdef ANDROID_CHANGES
-#include "resolv_private.h"
-#else
-#include <resolv.h>
-#endif
-
-/* XXX THIS IS A MESS! SEE <resolv.h> XXX */
-
-#undef res_send
-int res_send(const u_char *, int, u_char *, int);
-
-int
-res_send(const u_char *buf, int buflen, u_char *ans, int anssiz)
-{
-
- return __res_send(buf, buflen, ans, anssiz);
-}
-
-#endif
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index 4450bb6..32557d9 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -82,9 +82,9 @@
#if defined(__BIONIC_FORTIFY)
extern int __open_2(const char*, int);
-extern int __open_real(const char*, int, ...) __asm__(__USER_LABEL_PREFIX__ "open");
+extern int __open_real(const char*, int, ...) __RENAME(open);
extern int __openat_2(int, const char*, int);
-extern int __openat_real(int, const char*, int, ...) __asm__(__USER_LABEL_PREFIX__ "openat");
+extern int __openat_real(int, const char*, int, ...) __RENAME(openat);
__errordecl(__creat_missing_mode, "called with O_CREAT, but missing mode");
__errordecl(__creat_too_many_args, "too many arguments");
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 74e5732..516f8cb 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -408,7 +408,7 @@
#endif
extern char* __fgets_chk(char*, int, FILE*, size_t);
-extern char* __fgets_real(char*, int, FILE*) __asm__(__USER_LABEL_PREFIX__ "fgets");
+extern char* __fgets_real(char*, int, FILE*) __RENAME(fgets);
__errordecl(__fgets_too_big_error, "fgets called with size bigger than buffer");
__errordecl(__fgets_too_small_error, "fgets called with size less than zero");
diff --git a/libc/include/string.h b/libc/include/string.h
index 8df68e3..643132d 100644
--- a/libc/include/string.h
+++ b/libc/include/string.h
@@ -180,8 +180,7 @@
return __builtin___memset_chk(s, c, n, __bos0(s));
}
-extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t)
- __asm__(__USER_LABEL_PREFIX__ "strlcpy");
+extern size_t __strlcpy_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcpy);
extern size_t __strlcpy_chk(char *, const char *, size_t, size_t);
__BIONIC_FORTIFY_INLINE
@@ -204,8 +203,7 @@
return __strlcpy_chk(dest, src, size, bos);
}
-extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t)
- __asm__(__USER_LABEL_PREFIX__ "strlcat");
+extern size_t __strlcat_real(char* __restrict, const char* __restrict, size_t) __RENAME(strlcat);
extern size_t __strlcat_chk(char* __restrict, const char* __restrict, size_t, size_t);
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 0286616..c333823 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -267,20 +267,6 @@
#endif /* NO_KERNEL_RCSIDS */
#endif /* _KERNEL */
-#if !defined(_STANDALONE) && !defined(_KERNEL)
-#ifdef __GNUC__
-#define __RENAME(x) ___RENAME(x)
-#else
-#ifdef __lint__
-#define __RENAME(x) __symbolrename(x)
-#else
-#error "No function renaming possible"
-#endif /* __lint__ */
-#endif /* __GNUC__ */
-#else /* _STANDALONE || _KERNEL */
-#define __RENAME(x) no renaming in kernel or standalone environment
-#endif
-
/*
* A barrier to stop the optimizer from moving code or assume live
* register values. This is gcc specific, the version is more or less
@@ -359,60 +345,15 @@
#endif
/*
- * Macros for manipulating "link sets". Link sets are arrays of pointers
- * to objects, which are gathered up by the linker.
- *
- * Object format-specific code has provided us with the following macros:
- *
- * __link_set_add_text(set, sym)
- * Add a reference to the .text symbol `sym' to `set'.
- *
- * __link_set_add_rodata(set, sym)
- * Add a reference to the .rodata symbol `sym' to `set'.
- *
- * __link_set_add_data(set, sym)
- * Add a reference to the .data symbol `sym' to `set'.
- *
- * __link_set_add_bss(set, sym)
- * Add a reference to the .bss symbol `sym' to `set'.
- *
- * __link_set_decl(set, ptype)
- * Provide an extern declaration of the set `set', which
- * contains an array of the pointer type `ptype'. This
- * macro must be used by any code which wishes to reference
- * the elements of a link set.
- *
- * __link_set_start(set)
- * This points to the first slot in the link set.
- *
- * __link_set_end(set)
- * This points to the (non-existent) slot after the last
- * entry in the link set.
- *
- * __link_set_count(set)
- * Count the number of entries in link set `set'.
- *
- * In addition, we provide the following macros for accessing link sets:
- *
- * __link_set_foreach(pvar, set)
- * Iterate over the link set `set'. Because a link set is
- * an array of pointers, pvar must be declared as "type **pvar",
- * and the actual entry accessed as "*pvar".
- *
- * __link_set_entry(set, idx)
- * Access the link set entry at index `idx' from set `set'.
+ * Some BSD source needs these macros.
+ * Originally they embedded the rcs versions of each source file
+ * in the generated binary. We strip strings during build anyway,.
*/
-#define __link_set_foreach(pvar, set) \
- for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++)
-
-#define __link_set_entry(set, idx) (__link_set_begin(set)[idx])
-
-/*
- * Some of the FreeBSD sources used in Bionic need this.
- * Originally, this is used to embed the rcs versions of each source file
- * in the generated binary. We certainly don't want this in Bionic.
- */
-#define __FBSDID(s) /* nothing */
+#define __IDSTRING(_prefix,_s) /* nothing */
+#define __COPYRIGHT(_s) /* nothing */
+#define __FBSDID(_s) /* nothing */
+#define __RCSID(_s) /* nothing */
+#define __SCCSID(_s) /* nothing */
/*-
* The following definitions are an extension of the behavior originally
@@ -570,11 +511,24 @@
#endif
#define __bos0(s) __builtin_object_size((s), 0)
-#define __BIONIC_FORTIFY_INLINE \
- extern __inline__ \
- __attribute__ ((always_inline)) \
- __attribute__ ((gnu_inline))
+#define __BIONIC_FORTIFY_INLINE extern __inline__ __always_inline __attribute__((gnu_inline))
#endif
#define __BIONIC_FORTIFY_UNKNOWN_SIZE ((size_t) -1)
+/* 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__ __LIBC_ABI_PUBLIC__
+#endif
+
+/* Used to tag non-static symbols that are public and exposed by the shared library. */
+#define __LIBC_ABI_PUBLIC__ __attribute__((visibility ("default")))
+
+/* Used to rename functions so that the compiler emits a call to 'x' rather than the function this was applied to. */
+#define __RENAME(x) __asm__(#x)
+
#endif /* !_SYS_CDEFS_H_ */
diff --git a/libc/include/sys/cdefs_elf.h b/libc/include/sys/cdefs_elf.h
index 4dd7dc3..6bb0a57 100644
--- a/libc/include/sys/cdefs_elf.h
+++ b/libc/include/sys/cdefs_elf.h
@@ -30,27 +30,13 @@
#ifndef _SYS_CDEFS_ELF_H_
#define _SYS_CDEFS_ELF_H_
-#ifdef __LEADING_UNDERSCORE
-#define _C_LABEL(x) __CONCAT(_,x)
-#define _C_LABEL_STRING(x) "_"x
-#else
-#define _C_LABEL(x) x
-#define _C_LABEL_STRING(x) x
-#endif
+#define __strong_alias(alias, sym) \
+ __asm__(".global " #alias "\n" \
+ #alias " = " #sym);
-#define ___RENAME(x) __asm__(___STRING(_C_LABEL(x)))
-
-#define __indr_reference(sym,alias) /* nada, since we do weak refs */
-
-#define __strong_alias(alias,sym) \
- __asm__(".global " _C_LABEL_STRING(#alias) "\n" \
- _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
-
-#define __weak_alias(alias,sym) \
- __asm__(".weak " _C_LABEL_STRING(#alias) "\n" \
- _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
-#define __weak_extern(sym) \
- __asm__(".weak " _C_LABEL_STRING(#sym));
+#define __weak_alias(alias,sym) \
+ __asm__(".weak " #alias "\n" \
+ #alias " = " #sym);
/* We use __warnattr instead of __warn_references.
* TODO: remove this and put an empty definition in one of the upstream-* compatibility headers.
@@ -58,74 +44,4 @@
#define __warn_references(sym,msg) \
/*__asm__(".section .gnu.warning." #sym "\n\t.ascii \"" msg "\"\n\t.text");*/
-#define __SECTIONSTRING(_sec, _str) \
- __asm__(".section " #_sec "\n\t.asciz \"" _str "\"\n\t.previous")
-
-/* 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__ __LIBC_ABI_PUBLIC__
-#endif
-
-/* Used to tag non-static symbols that are public and exposed by the shared library. */
-#define __LIBC_ABI_PUBLIC__ __attribute__((visibility ("default")))
-
-#define __IDSTRING(_n,_s) __SECTIONSTRING(.ident,_s)
-
-#define __RCSID(_s) __IDSTRING(rcsid,_s)
-#define __SCCSID(_s)
-#define __SCCSID2(_s)
-#if 0 /* XXX userland __COPYRIGHTs have \ns in them */
-#define __COPYRIGHT(_s) __SECTIONSTRING(.copyright,_s)
-#else
-#define __COPYRIGHT(_s) \
- static const char copyright[] \
- __attribute__((__unused__,__section__(".copyright"))) = _s
-#endif
-
-#define __KERNEL_RCSID(_n, _s) __RCSID(_s)
-#define __KERNEL_SCCSID(_n, _s)
-#if 0 /* XXX see above */
-#define __KERNEL_COPYRIGHT(_n, _s) __COPYRIGHT(_s)
-#else
-#define __KERNEL_COPYRIGHT(_n, _s) __SECTIONSTRING(.copyright, _s)
-#endif
-
-#ifndef __lint__
-#define __link_set_make_entry(set, sym) \
- static void const * const __link_set_##set##_sym_##sym \
- __section("link_set_" #set) __used = &sym
-#define __link_set_make_entry2(set, sym, n) \
- static void const * const __link_set_##set##_sym_##sym##_##n \
- __section("link_set_" #set) __used = &sym[n]
-#else
-#define __link_set_make_entry(set, sym) \
- extern void const * const __link_set_##set##_sym_##sym
-#define __link_set_make_entry2(set, sym, n) \
- extern void const * const __link_set_##set##_sym_##sym##_##n
-#endif /* __lint__ */
-
-#define __link_set_add_text(set, sym) __link_set_make_entry(set, sym)
-#define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym)
-#define __link_set_add_data(set, sym) __link_set_make_entry(set, sym)
-#define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym)
-#define __link_set_add_text2(set, sym, n) __link_set_make_entry2(set, sym, n)
-#define __link_set_add_rodata2(set, sym, n) __link_set_make_entry2(set, sym, n)
-#define __link_set_add_data2(set, sym, n) __link_set_make_entry2(set, sym, n)
-#define __link_set_add_bss2(set, sym, n) __link_set_make_entry2(set, sym, n)
-
-#define __link_set_decl(set, ptype) \
- extern ptype * const __start_link_set_##set[]; \
- extern ptype * const __stop_link_set_##set[] \
-
-#define __link_set_start(set) (__start_link_set_##set)
-#define __link_set_end(set) (__stop_link_set_##set)
-
-#define __link_set_count(set) \
- (__link_set_end(set) - __link_set_start(set))
-
#endif /* !_SYS_CDEFS_ELF_H_ */
diff --git a/libc/include/sys/socket.h b/libc/include/sys/socket.h
index ae2f238..a8840ff 100644
--- a/libc/include/sys/socket.h
+++ b/libc/include/sys/socket.h
@@ -294,8 +294,7 @@
#if defined(__BIONIC_FORTIFY)
__errordecl(__recvfrom_error, "recvfrom called with size bigger than buffer");
extern ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, const struct sockaddr*, socklen_t*);
-extern ssize_t __recvfrom_real(int, void*, size_t, int, const struct sockaddr*, socklen_t*)
- __asm__(__USER_LABEL_PREFIX__ "recvfrom");
+extern ssize_t __recvfrom_real(int, void*, size_t, int, const struct sockaddr*, socklen_t*) __RENAME(recvfrom);
__BIONIC_FORTIFY_INLINE
ssize_t recvfrom(int fd, void* buf, size_t len, int flags, const struct sockaddr* src_addr, socklen_t* addr_len) {
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index c0c168b..a6cc368 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -162,7 +162,7 @@
#if defined(__BIONIC_FORTIFY)
extern mode_t __umask_chk(mode_t);
-extern mode_t __umask_real(mode_t) __asm__(__USER_LABEL_PREFIX__ "umask");
+extern mode_t __umask_real(mode_t) __RENAME(umask);
__errordecl(__umask_invalid_mode, "umask called with invalid mode");
__BIONIC_FORTIFY_INLINE
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 7fbafdf..781fc44 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -201,8 +201,7 @@
extern ssize_t __read_chk(int, void*, size_t, size_t);
__errordecl(__read_dest_size_error, "read called with size bigger than destination");
__errordecl(__read_count_toobig_error, "read called with count > SSIZE_MAX");
-extern ssize_t __read_real(int, void*, size_t)
- __asm__(__USER_LABEL_PREFIX__ "read");
+extern ssize_t __read_real(int, void*, size_t) __RENAME(read);
__BIONIC_FORTIFY_INLINE
ssize_t read(int fd, void* buf, size_t count) {