auto import from //branches/cupcake/...@126645
diff --git a/libc/bionic/__errno.c b/libc/bionic/__errno.c
index ffc6e61..8f33cce 100644
--- a/libc/bionic/__errno.c
+++ b/libc/bionic/__errno.c
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 #include <errno.h>
-#include <sys/tls.h>
+#include <bionic_tls.h>
 
 volatile int*  __errno( void )
 {
diff --git a/libc/bionic/libc_init_common.c b/libc/bionic/libc_init_common.c
index 0944cb0..de4919d 100644
--- a/libc/bionic/libc_init_common.c
+++ b/libc/bionic/libc_init_common.c
@@ -36,7 +36,7 @@
 #include "atexit.h"
 #include "libc_init_common.h"
 
-#include <sys/tls.h>
+#include <bionic_tls.h>
 #include <errno.h>
 
 extern void _init(void);
diff --git a/libc/bionic/libc_init_static.c b/libc/bionic/libc_init_static.c
index f5a1d80..ec463f7 100644
--- a/libc/bionic/libc_init_static.c
+++ b/libc/bionic/libc_init_static.c
@@ -55,7 +55,7 @@
 #include "atexit.h"
 #include "libc_init_common.h"
 
-#include <sys/tls.h>
+#include <bionic_tls.h>
 #include <errno.h>
 
 __noreturn void __libc_init(uintptr_t *elfdata,
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index 2fd740e..6114f40 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -33,7 +33,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <sys/atomics.h>
-#include <sys/tls.h>
+#include <bionic_tls.h>
 #include <sys/mman.h>
 #include <pthread.h>
 #include <time.h>
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index b3b0adf..79e526b 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -41,6 +41,16 @@
 #include <sys/cdefs.h>
 #include <sys/_types.h>
 
+/* va_list and size_t must be defined by stdio.h according to Posix */
+#define __need___va_list
+#include <stdarg.h>
+
+/* note that this forces stddef.h to *only* define size_t */
+#define __need_size_t
+#include <stddef.h>
+
+#include <stddef.h>
+
 #if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
 #include <sys/types.h>	/* XXX should be removed */
 #endif
diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h
index a821e03..acfe694 100644
--- a/libc/include/stdlib.h
+++ b/libc/include/stdlib.h
@@ -29,6 +29,13 @@
 #define _STDLIB_H_
 
 #include <sys/cdefs.h>
+
+/* wchar_t is required in stdlib.h according to POSIX.
+ * note that defining __need_wchar_t prevents stddef.h
+ * to define all other symbols it does normally */
+#define __need_wchar_t
+#include <stddef.h>
+
 #include <stddef.h>
 #include <string.h>
 #include <alloca.h>
diff --git a/libc/include/sys/android/atomics.h b/libc/include/sys/android/atomics.h
deleted file mode 100644
index 75017b9..0000000
--- a/libc/include/sys/android/atomics.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <sys/atomics.h>
\ No newline at end of file
diff --git a/libc/include/sys/android/tls.h b/libc/include/sys/android/tls.h
deleted file mode 100644
index 274ac35..0000000
--- a/libc/include/sys/android/tls.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <sys/tls.h>
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 7ab0f82..5e6363f 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -77,6 +77,10 @@
 extern int    mknod(const char *, mode_t, dev_t);
 extern mode_t umask(mode_t);
 
+#define  stat64    stat
+#define  fstat64   fstat
+#define  lstat64   lstat
+
 static __inline__ int mkfifo(const char *__p, mode_t __m)
 {
   return mknod(__p, (__m & ~S_IFMT) | S_IFIFO, (dev_t)0);
diff --git a/libc/include/wchar.h b/libc/include/wchar.h
index 3dadc98..e2feb60 100644
--- a/libc/include/wchar.h
+++ b/libc/include/wchar.h
@@ -30,11 +30,17 @@
 
 #include <sys/cdefs.h>
 #include <stdio.h>
+
+/* wchar_t is required in stdlib.h according to POSIX */
+#define __need___wchar_t
 #include <stddef.h>
+
 #include <stdarg.h>
 #include <time.h>
 #include <malloc.h>
 
+#include <stddef.h>
+
 /* IMPORTANT: Any code that relies on wide character support is essentially
  *            non-portable and/or broken. the only reason this header exist
  *            is because I'm really a nice guy. However, I'm not nice enough
@@ -44,11 +50,6 @@
 
 __BEGIN_DECLS
 
-#ifndef __cplusplus
-/* wchar_t is a builtin keyword of g++ */
-typedef unsigned char            wchar_t;
-#endif
-
 typedef int                     wint_t;
 typedef struct { int  dummy; }  mbstate_t;
 
diff --git a/libc/include/sys/tls.h b/libc/private/bionic_tls.h
similarity index 100%
rename from libc/include/sys/tls.h
rename to libc/private/bionic_tls.h
diff --git a/libc/unistd/sysconf.c b/libc/unistd/sysconf.c
index a19edbb..d3089a4 100644
--- a/libc/unistd/sysconf.c
+++ b/libc/unistd/sysconf.c
@@ -28,7 +28,7 @@
 #include <unistd.h>
 #include <sys/sysconf.h>
 #include <limits.h>
-#include <sys/tls.h>
+#include <bionic_tls.h>
 #include <asm/page.h>
 #include <stdio.h>  /* for FOPEN_MAX */
 #include <errno.h>
diff --git a/linker/Android.mk b/linker/Android.mk
index 5d11148..98eceda 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -18,6 +18,10 @@
 
 LOCAL_CFLAGS += -DPRELINK -DLINKER_TEXT_BASE=$(LINKER_TEXT_BASE) -DLINKER_AREA_SIZE=$(LINKER_AREA_SIZE)
 
+# we need to access the Bionic private header <bionic_tls.h>
+# in the linker
+LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/private
+
 ifeq ($(TARGET_ARCH),arm)
 LOCAL_CFLAGS += -DANDROID_ARM_LINKER
 else
diff --git a/linker/linker.c b/linker/linker.c
index 34ed80e..8f15f62 100644
--- a/linker/linker.c
+++ b/linker/linker.c
@@ -14,7 +14,9 @@
 #include <sys/mman.h>
 
 #include <sys/atomics.h>
-#include <sys/tls.h>
+
+/* special private C library header - see Android.mk */
+#include <bionic_tls.h>
 
 #include "linker.h"
 #include "linker_debug.h"