Merge "Prevent potential stall on dns proxy operations."
diff --git a/libc/arch-arm/bionic/libgcc_compat.c b/libc/arch-arm/bionic/libgcc_compat.c
index 1a19701..a5cb219 100644
--- a/libc/arch-arm/bionic/libgcc_compat.c
+++ b/libc/arch-arm/bionic/libgcc_compat.c
@@ -66,7 +66,7 @@
  * any native shared library generated with it should now be safe from that
  * problem. On the other hand, existing shared libraries distributed with
  * applications that were generated with a previous version of the NDK
- * still need all 1.5/1.6 helper functions in libc.so and libn.so
+ * still need all 1.5/1.6 helper functions in libc.so and libm.so
  *
  * After 3.2, the toolchain was updated again, adding __aeabi_f2uiz to the
  * list of requirements. Technically, this is due to mis-linked NDK libraries
diff --git a/libc/include/elf.h b/libc/include/elf.h
index 8a86a63..c3e3226 100644
--- a/libc/include/elf.h
+++ b/libc/include/elf.h
@@ -28,30 +28,7 @@
 #ifndef _ELF_H
 #define _ELF_H
 
-/* these definitions are missing from the BSD sources */
-enum {
-    AT_NULL = 0,
-    AT_IGNORE,
-    AT_EXECFD,
-    AT_PHDR,
-    AT_PHENT,
-    AT_PHNUM,
-    AT_PAGESZ,
-    AT_BASE,
-    AT_FLAGS,
-    AT_ENTRY,
-    AT_NOTELF,
-    AT_UID,
-    AT_EUID,
-    AT_GID,
-    AT_EGID,
-    AT_PLATFORM,
-    AT_HWCAP,
-    AT_CLKTCK,
-
-    AT_SECURE = 23
-};
-
+#include <linux/auxvec.h>
 #include <sys/exec_elf.h>
 
 #endif /* _ELF_H */
diff --git a/libc/include/sys/exec_elf.h b/libc/include/sys/exec_elf.h
index f72f81e..eecbd64 100644
--- a/libc/include/sys/exec_elf.h
+++ b/libc/include/sys/exec_elf.h
@@ -35,68 +35,7 @@
 
 #include <machine/_types.h>
 #include <machine/exec.h>
-
-typedef __uint8_t	Elf_Byte;
-
-typedef __uint32_t	Elf32_Addr;	/* Unsigned program address */
-typedef __uint32_t	Elf32_Off;	/* Unsigned file offset */
-typedef __int32_t	Elf32_Sword;	/* Signed large integer */
-typedef __uint32_t	Elf32_Word;	/* Unsigned large integer */
-typedef __uint16_t	Elf32_Half;	/* Unsigned medium integer */
-
-typedef __uint64_t	Elf64_Addr;
-typedef __uint64_t	Elf64_Off;
-typedef __int32_t	Elf64_Shalf;
-
-#ifdef __alpha__
-typedef __int64_t	Elf64_Sword;
-typedef __uint64_t	Elf64_Word;
-#else
-typedef __int32_t	Elf64_Sword;
-typedef __uint32_t	Elf64_Word;
-#endif
-
-typedef __int64_t	Elf64_Sxword;
-typedef __uint64_t	Elf64_Xword;
-
-typedef __uint32_t	Elf64_Half;
-typedef __uint16_t	Elf64_Quarter;
-
-/*
- * e_ident[] identification indexes 
- * See http://www.caldera.com/developers/gabi/2000-07-17/ch4.eheader.html
- */
-#define EI_MAG0		0		/* file ID */
-#define EI_MAG1		1		/* file ID */
-#define EI_MAG2		2		/* file ID */
-#define EI_MAG3		3		/* file ID */
-#define EI_CLASS	4		/* file class */
-#define EI_DATA		5		/* data encoding */
-#define EI_VERSION	6		/* ELF header version */
-#define EI_OSABI	7		/* OS/ABI ID */
-#define EI_ABIVERSION	8		/* ABI version */ 
-#define EI_PAD		9		/* start of pad bytes */
-#define EI_NIDENT	16		/* Size of e_ident[] */
-
-/* e_ident[] magic number */
-#define	ELFMAG0		0x7f		/* e_ident[EI_MAG0] */
-#define	ELFMAG1		'E'		/* e_ident[EI_MAG1] */
-#define	ELFMAG2		'L'		/* e_ident[EI_MAG2] */
-#define	ELFMAG3		'F'		/* e_ident[EI_MAG3] */
-#define	ELFMAG		"\177ELF"	/* magic */
-#define	SELFMAG		4		/* size of magic */
-
-/* e_ident[] file class */
-#define	ELFCLASSNONE	0		/* invalid */
-#define	ELFCLASS32	1		/* 32-bit objs */
-#define	ELFCLASS64	2		/* 64-bit objs */
-#define	ELFCLASSNUM	3		/* number of classes */
-
-/* e_ident[] data encoding */
-#define ELFDATANONE	0		/* invalid */
-#define ELFDATA2LSB	1		/* Little-Endian */
-#define ELFDATA2MSB	2		/* Big-Endian */
-#define ELFDATANUM	3		/* number of data encode defines */
+#include <linux/elf.h>
 
 /* e_ident[] Operating System/ABI */
 #define ELFOSABI_SYSV		0	/* UNIX System V ABI */
@@ -121,52 +60,6 @@
                       (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
                       (ehdr).e_ident[EI_MAG3] == ELFMAG3)
 
-/* ELF Header */
-typedef struct elfhdr {
-	unsigned char	e_ident[EI_NIDENT]; /* ELF Identification */
-	Elf32_Half	e_type;		/* object file type */
-	Elf32_Half	e_machine;	/* machine */
-	Elf32_Word	e_version;	/* object file version */
-	Elf32_Addr	e_entry;	/* virtual entry point */
-	Elf32_Off	e_phoff;	/* program header table offset */
-	Elf32_Off	e_shoff;	/* section header table offset */
-	Elf32_Word	e_flags;	/* processor-specific flags */
-	Elf32_Half	e_ehsize;	/* ELF header size */
-	Elf32_Half	e_phentsize;	/* program header entry size */
-	Elf32_Half	e_phnum;	/* number of program header entries */
-	Elf32_Half	e_shentsize;	/* section header entry size */
-	Elf32_Half	e_shnum;	/* number of section header entries */
-	Elf32_Half	e_shstrndx;	/* section header table's "section 
-					   header string table" entry offset */
-} Elf32_Ehdr;
-
-typedef struct {
-	unsigned char	e_ident[EI_NIDENT];	/* Id bytes */
-	Elf64_Quarter	e_type;			/* file type */
-	Elf64_Quarter	e_machine;		/* machine type */
-	Elf64_Half	e_version;		/* version number */
-	Elf64_Addr	e_entry;		/* entry point */
-	Elf64_Off	e_phoff;		/* Program hdr offset */
-	Elf64_Off	e_shoff;		/* Section hdr offset */
-	Elf64_Half	e_flags;		/* Processor flags */
-	Elf64_Quarter	e_ehsize;		/* sizeof ehdr */
-	Elf64_Quarter	e_phentsize;		/* Program header entry size */
-	Elf64_Quarter	e_phnum;		/* Number of program headers */
-	Elf64_Quarter	e_shentsize;		/* Section header entry size */
-	Elf64_Quarter	e_shnum;		/* Number of section headers */
-	Elf64_Quarter	e_shstrndx;		/* String table index */
-} Elf64_Ehdr;
-
-/* e_type */
-#define ET_NONE		0		/* No file type */
-#define ET_REL		1		/* relocatable file */
-#define ET_EXEC		2		/* executable file */
-#define ET_DYN		3		/* shared object file */
-#define ET_CORE		4		/* core file */
-#define ET_NUM		5		/* number of types */
-#define ET_LOPROC	0xff00		/* reserved range for processor */
-#define ET_HIPROC	0xffff		/*  specific e_type */
-
 /* e_machine */
 #define EM_NONE		0		/* No Machine */
 #define EM_M32		1		/* AT&T WE 32100 */
@@ -195,66 +88,6 @@
 #define EM_VAX		75		/* DEC VAX */
 #define EM_NUM		15		/* number of machine types */
 
-/* Version */
-#define EV_NONE		0		/* Invalid */
-#define EV_CURRENT	1		/* Current */
-#define EV_NUM		2		/* number of versions */
-
-/* Section Header */
-typedef struct {
-	Elf32_Word	sh_name;	/* name - index into section header
-					   string table section */
-	Elf32_Word	sh_type;	/* type */
-	Elf32_Word	sh_flags;	/* flags */
-	Elf32_Addr	sh_addr;	/* address */
-	Elf32_Off	sh_offset;	/* file offset */
-	Elf32_Word	sh_size;	/* section size */
-	Elf32_Word	sh_link;	/* section header table index link */
-	Elf32_Word	sh_info;	/* extra information */
-	Elf32_Word	sh_addralign;	/* address alignment */
-	Elf32_Word	sh_entsize;	/* section entry size */
-} Elf32_Shdr;
-
-typedef struct {
-	Elf64_Half	sh_name;	/* section name */
-	Elf64_Half	sh_type;	/* section type */
-	Elf64_Xword	sh_flags;	/* section flags */
-	Elf64_Addr	sh_addr;	/* virtual address */
-	Elf64_Off	sh_offset;	/* file offset */
-	Elf64_Xword	sh_size;	/* section size */
-	Elf64_Half	sh_link;	/* link to another */
-	Elf64_Half	sh_info;	/* misc info */
-	Elf64_Xword	sh_addralign;	/* memory alignment */
-	Elf64_Xword	sh_entsize;	/* table entry size */
-} Elf64_Shdr;
-
-/* Special Section Indexes */
-#define SHN_UNDEF	0		/* undefined */
-#define SHN_LORESERVE	0xff00		/* lower bounds of reserved indexes */
-#define SHN_LOPROC	0xff00		/* reserved range for processor */
-#define SHN_HIPROC	0xff1f		/*   specific section indexes */
-#define SHN_ABS		0xfff1		/* absolute value */
-#define SHN_COMMON	0xfff2		/* common symbol */
-#define SHN_HIRESERVE	0xffff		/* upper bounds of reserved indexes */
-
-/* sh_type */
-#define SHT_NULL	0		/* inactive */
-#define SHT_PROGBITS	1		/* program defined information */
-#define SHT_SYMTAB	2		/* symbol table section */
-#define SHT_STRTAB	3		/* string table section */
-#define SHT_RELA	4		/* relocation section with addends*/
-#define SHT_HASH	5		/* symbol hash table section */
-#define SHT_DYNAMIC	6		/* dynamic section */
-#define SHT_NOTE	7		/* note section */
-#define SHT_NOBITS	8		/* no space section */
-#define SHT_REL		9		/* relation section without addends */
-#define SHT_SHLIB	10		/* reserved - purpose unknown */
-#define SHT_DYNSYM	11		/* dynamic symbol table section */
-#define SHT_NUM		12		/* number of section types */
-#define SHT_LOPROC	0x70000000	/* reserved range for processor */
-#define SHT_HIPROC	0x7fffffff	/*  specific section header types */
-#define SHT_LOUSER	0x80000000	/* reserved range for application */
-#define SHT_HIUSER	0xffffffff	/*  specific indexes */
 
 /* Section names */
 #define ELF_BSS         ".bss"		/* uninitialized data */
@@ -279,45 +112,6 @@
 #define ELF_SYMTAB      ".symtab"	/* symbol table */
 #define ELF_TEXT        ".text"		/* code */
 
-
-/* Section Attribute Flags - sh_flags */
-#define SHF_WRITE	0x1		/* Writable */
-#define SHF_ALLOC	0x2		/* occupies memory */
-#define SHF_EXECINSTR	0x4		/* executable */
-#define SHF_MASKPROC	0xf0000000	/* reserved bits for processor */
-					/*  specific section attributes */
-
-/* Symbol Table Entry */
-typedef struct elf32_sym {
-	Elf32_Word	st_name;	/* name - index into string table */
-	Elf32_Addr	st_value;	/* symbol value */
-	Elf32_Word	st_size;	/* symbol size */
-	unsigned char	st_info;	/* type and binding */
-	unsigned char	st_other;	/* 0 - no defined meaning */
-	Elf32_Half	st_shndx;	/* section header index */
-} Elf32_Sym;
-
-typedef struct {
-	Elf64_Half	st_name;	/* Symbol name index in str table */
-	Elf_Byte	st_info;	/* type / binding attrs */
-	Elf_Byte	st_other;	/* unused */
-	Elf64_Quarter	st_shndx;	/* section index of symbol */
-	Elf64_Xword	st_value;	/* value of symbol */
-	Elf64_Xword	st_size;	/* size of symbol */
-} Elf64_Sym;
-
-/* Symbol table index */
-#define STN_UNDEF	0		/* undefined */
-
-/* Extract symbol info - st_info */
-#define ELF32_ST_BIND(x)	((x) >> 4)
-#define ELF32_ST_TYPE(x)	(((unsigned int) x) & 0xf)
-#define ELF32_ST_INFO(b,t)	(((b) << 4) + ((t) & 0xf))
-
-#define ELF64_ST_BIND(x)	((x) >> 4)
-#define ELF64_ST_TYPE(x)	(((unsigned int) x) & 0xf)
-#define ELF64_ST_INFO(b,t)	(((b) << 4) + ((t) & 0xf))
-
 /* Symbol Binding - ELF32_ST_BIND - st_info */
 #define STB_LOCAL	0		/* Local symbol */
 #define STB_GLOBAL	1		/* Global symbol */
@@ -336,290 +130,6 @@
 #define STT_LOPROC	13		/* reserved range for processor */
 #define STT_HIPROC	15		/*  specific symbol types */
 
-/* Relocation entry with implicit addend */
-typedef struct {
-	Elf32_Addr	r_offset;	/* offset of relocation */
-	Elf32_Word	r_info;		/* symbol table index and type */
-} Elf32_Rel;
-
-/* Relocation entry with explicit addend */
-typedef struct {
-	Elf32_Addr	r_offset;	/* offset of relocation */
-	Elf32_Word	r_info;		/* symbol table index and type */
-	Elf32_Sword	r_addend;
-} Elf32_Rela;
-
-/* Extract relocation info - r_info */
-#define ELF32_R_SYM(i)		((i) >> 8)
-#define ELF32_R_TYPE(i)		((unsigned char) (i))
-#define ELF32_R_INFO(s,t) 	(((s) << 8) + (unsigned char)(t))
-
-typedef struct {
-	Elf64_Xword	r_offset;	/* where to do it */
-	Elf64_Xword	r_info;		/* index & type of relocation */
-} Elf64_Rel;
-
-typedef struct {
-	Elf64_Xword	r_offset;	/* where to do it */
-	Elf64_Xword	r_info;		/* index & type of relocation */
-	Elf64_Sxword	r_addend;	/* adjustment value */
-} Elf64_Rela;
-
-#define	ELF64_R_SYM(info)	((info) >> 32)
-#define	ELF64_R_TYPE(info)	((info) & 0xFFFFFFFF)
-#define ELF64_R_INFO(s,t) 	(((s) << 32) + (__uint32_t)(t))
-
-/* Program Header */
-typedef struct {
-	Elf32_Word	p_type;		/* segment type */
-	Elf32_Off	p_offset;	/* segment offset */
-	Elf32_Addr	p_vaddr;	/* virtual address of segment */
-	Elf32_Addr	p_paddr;	/* physical address - ignored? */
-	Elf32_Word	p_filesz;	/* number of bytes in file for seg. */
-	Elf32_Word	p_memsz;	/* number of bytes in mem. for seg. */
-	Elf32_Word	p_flags;	/* flags */
-	Elf32_Word	p_align;	/* memory alignment */
-} Elf32_Phdr;
-
-typedef struct {
-	Elf64_Half	p_type;		/* entry type */
-	Elf64_Half	p_flags;	/* flags */
-	Elf64_Off	p_offset;	/* offset */
-	Elf64_Addr	p_vaddr;	/* virtual address */
-	Elf64_Addr	p_paddr;	/* physical address */
-	Elf64_Xword	p_filesz;	/* file size */
-	Elf64_Xword	p_memsz;	/* memory size */
-	Elf64_Xword	p_align;	/* memory & file alignment */
-} Elf64_Phdr;
-
-/* Segment types - p_type */
-#define PT_NULL		0		/* unused */
-#define PT_LOAD		1		/* loadable segment */
-#define PT_DYNAMIC	2		/* dynamic linking section */
-#define PT_INTERP	3		/* the RTLD */
-#define PT_NOTE		4		/* auxiliary information */
-#define PT_SHLIB	5		/* reserved - purpose undefined */
-#define PT_PHDR		6		/* program header */
-#define PT_NUM		7		/* Number of segment types */
-#define PT_LOOS		0x60000000	/* reserved range for OS */
-#define PT_HIOS		0x6fffffff	/*  specific segment types */
-#define PT_LOPROC	0x70000000	/* reserved range for processor */
-#define PT_HIPROC	0x7fffffff	/*  specific segment types */
-
-/* Segment flags - p_flags */
-#define PF_X		0x1		/* Executable */
-#define PF_W		0x2		/* Writable */
-#define PF_R		0x4		/* Readable */
-#define PF_MASKPROC	0xf0000000	/* reserved bits for processor */
-					/*  specific segment flags */
-
-/* Dynamic structure */
-typedef struct {
-	Elf32_Sword	d_tag;		/* controls meaning of d_val */
-	union {
-		Elf32_Word	d_val;	/* Multiple meanings - see d_tag */
-		Elf32_Addr	d_ptr;	/* program virtual address */
-	} d_un;
-} Elf32_Dyn;
-
-typedef struct {
-	Elf64_Xword	d_tag;		/* controls meaning of d_val */
-	union {
-		Elf64_Addr	d_ptr;
-		Elf64_Xword	d_val;
-	} d_un;
-} Elf64_Dyn;
-
-/* Dynamic Array Tags - d_tag */
-#define DT_NULL		0		/* marks end of _DYNAMIC array */
-#define DT_NEEDED	1		/* string table offset of needed lib */
-#define DT_PLTRELSZ	2		/* size of relocation entries in PLT */
-#define DT_PLTGOT	3		/* address PLT/GOT */
-#define DT_HASH		4		/* address of symbol hash table */
-#define DT_STRTAB	5		/* address of string table */
-#define DT_SYMTAB	6		/* address of symbol table */
-#define DT_RELA		7		/* address of relocation table */
-#define DT_RELASZ	8		/* size of relocation table */
-#define DT_RELAENT	9		/* size of relocation entry */
-#define DT_STRSZ	10		/* size of string table */
-#define DT_SYMENT	11		/* size of symbol table entry */
-#define DT_INIT		12		/* address of initialization func. */
-#define DT_FINI		13		/* address of termination function */
-#define DT_SONAME	14		/* string table offset of shared obj */
-#define DT_RPATH	15		/* string table offset of library
-					   search path */
-#define DT_SYMBOLIC	16		/* start sym search in shared obj. */
-#define DT_REL		17		/* address of rel. tbl. w addends */
-#define DT_RELSZ	18		/* size of DT_REL relocation table */
-#define DT_RELENT	19		/* size of DT_REL relocation entry */
-#define DT_PLTREL	20		/* PLT referenced relocation entry */
-#define DT_DEBUG	21		/* bugger */
-#define DT_TEXTREL	22		/* Allow rel. mod. to unwritable seg */
-#define DT_JMPREL	23		/* add. of PLT's relocation entries */
-#define DT_BIND_NOW	24		/* Bind now regardless of env setting */
-#define DT_NUM		25		/* Number used. */
-#define DT_LOPROC	0x70000000	/* reserved range for processor */
-#define DT_HIPROC	0x7fffffff	/*  specific dynamic array tags */
-	
-/* Standard ELF hashing function */
-unsigned int elf_hash(const unsigned char *name);
-
-/*
- * Note Definitions
- */
-typedef struct {
-	Elf32_Word namesz;
-	Elf32_Word descsz;
-	Elf32_Word type;
-} Elf32_Note;
-
-typedef struct {
-	Elf64_Half namesz;
-	Elf64_Half descsz;
-	Elf64_Half type;
-} Elf64_Note;
-
-/*
- * XXX - these _KERNEL items aren't part of the ABI!
- */
-#if defined(_KERNEL) || defined(_DYN_LOADER)
-
-#define ELF32_NO_ADDR	((u_long) ~0)	/* Indicates addr. not yet filled in */
-#define ELF_AUX_ENTRIES	8		/* Size of aux array passed to loader */
-
-typedef struct {
-	Elf32_Sword	au_id;				/* 32-bit id */
-	Elf32_Word	au_v;				/* 32-bit value */
-} Aux32Info;
-
-#define ELF64_NO_ADDR	((__uint64_t) ~0)/* Indicates addr. not yet filled in */
-#define ELF64_AUX_ENTRIES	8	/* Size of aux array passed to loader */
-
-typedef struct {
-	Elf64_Shalf	au_id;				/* 32-bit id */
-	Elf64_Xword	au_v;				/* 64-bit id */
-} Aux64Info;
-
-enum AuxID {
-	AUX_null = 0,
-	AUX_ignore = 1,
-	AUX_execfd = 2,
-	AUX_phdr = 3,			/* &phdr[0] */
-	AUX_phent = 4,			/* sizeof(phdr[0]) */
-	AUX_phnum = 5,			/* # phdr entries */
-	AUX_pagesz = 6,			/* PAGESIZE */
-	AUX_base = 7,			/* ld.so base addr */
-	AUX_flags = 8,			/* processor flags */
-	AUX_entry = 9,			/* a.out entry */
-	AUX_sun_uid = 2000,		/* euid */
-	AUX_sun_ruid = 2001,		/* ruid */
-	AUX_sun_gid = 2002,		/* egid */
-	AUX_sun_rgid = 2003		/* rgid */
-};
-
-struct elf_args {
-        u_long  arg_entry;		/* program entry point */
-        u_long  arg_interp;		/* Interpreter load address */
-        u_long  arg_phaddr;		/* program header address */
-        u_long  arg_phentsize;		/* Size of program header */
-        u_long  arg_phnum;		/* Number of program headers */
-        u_long  arg_os;			/* OS tag */
-};
-
-#endif
-
-#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
-#define ELFSIZE ARCH_ELFSIZE
-#endif
-
-#if defined(ELFSIZE)
-#define CONCAT(x,y)	__CONCAT(x,y)
-#define ELFNAME(x)	CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
-#define ELFNAME2(x,y)	CONCAT(x,CONCAT(_elf,CONCAT(ELFSIZE,CONCAT(_,y))))
-#define ELFNAMEEND(x)	CONCAT(x,CONCAT(_elf,ELFSIZE))
-#define ELFDEFNNAME(x)	CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
-#endif
-
-#if defined(ELFSIZE) && (ELFSIZE == 32)
-#define Elf_Ehdr	Elf32_Ehdr
-#define Elf_Phdr	Elf32_Phdr
-#define Elf_Shdr	Elf32_Shdr
-#define Elf_Sym		Elf32_Sym
-#define Elf_Rel		Elf32_Rel
-#define Elf_RelA	Elf32_Rela
-#define Elf_Dyn		Elf32_Dyn
-#define Elf_Half	Elf32_Half
-#define Elf_Word	Elf32_Word
-#define Elf_Sword	Elf32_Sword
-#define Elf_Addr	Elf32_Addr
-#define Elf_Off		Elf32_Off
-#define Elf_Nhdr	Elf32_Nhdr
-#define Elf_Note	Elf32_Note
-
-#define ELF_R_SYM	ELF32_R_SYM
-#define ELF_R_TYPE	ELF32_R_TYPE
-#define ELF_R_INFO	ELF32_R_INFO
-#define ELFCLASS	ELFCLASS32
-
-#define ELF_ST_BIND	ELF32_ST_BIND
-#define ELF_ST_TYPE	ELF32_ST_TYPE
-#define ELF_ST_INFO	ELF32_ST_INFO
-
-#define AuxInfo		Aux32Info
-#elif defined(ELFSIZE) && (ELFSIZE == 64)
-#define Elf_Ehdr	Elf64_Ehdr
-#define Elf_Phdr	Elf64_Phdr
-#define Elf_Shdr	Elf64_Shdr
-#define Elf_Sym		Elf64_Sym
-#define Elf_Rel		Elf64_Rel
-#define Elf_RelA	Elf64_Rela
-#define Elf_Dyn		Elf64_Dyn
-#define Elf_Half	Elf64_Half
-#define Elf_Word	Elf64_Word
-#define Elf_Sword	Elf64_Sword
-#define Elf_Addr	Elf64_Addr
-#define Elf_Off		Elf64_Off
-#define Elf_Nhdr	Elf64_Nhdr
-#define Elf_Note	Elf64_Note
-
-#define ELF_R_SYM	ELF64_R_SYM
-#define ELF_R_TYPE	ELF64_R_TYPE
-#define ELF_R_INFO	ELF64_R_INFO
-#define ELFCLASS	ELFCLASS64
-
-#define ELF_ST_BIND	ELF64_ST_BIND
-#define ELF_ST_TYPE	ELF64_ST_TYPE
-#define ELF_ST_INFO	ELF64_ST_INFO
-
-#define AuxInfo		Aux64Info
-#endif
-
-#ifndef _KERNEL
-extern Elf_Dyn		_DYNAMIC[];
-#endif
-
-#ifdef	_KERNEL
-#ifdef _KERN_DO_ELF64
-int exec_elf64_makecmds(struct proc *, struct exec_package *);
-void *elf64_copyargs(struct exec_package *, struct ps_strings *,
-        void *, void *);
-int exec_elf64_fixup(struct proc *, struct exec_package *);
-char *elf64_check_brand(Elf64_Ehdr *);
-int elf64_os_pt_note(struct proc *, struct exec_package *, Elf64_Ehdr *,
-	char *, size_t, size_t);
-#endif
-#ifdef _KERN_DO_ELF
-int exec_elf32_makecmds(struct proc *, struct exec_package *);
-void *elf32_copyargs(struct exec_package *, struct ps_strings *,
-        void *, void *);
-int exec_elf32_fixup(struct proc *, struct exec_package *);
-char *elf32_check_brand(Elf32_Ehdr *);
-int elf32_os_pt_note(struct proc *, struct exec_package *, Elf32_Ehdr *,
-	char *, size_t, size_t);
-#endif
-
-#endif /* _KERNEL */
-
-#define ELF_TARG_VER	1	/* The ver for which this code is intended */
+#define PT_GNU_RELRO    0x6474e552      /* Read-only post relocation */
 
 #endif /* _SYS_EXEC_ELF_H_ */
diff --git a/libc/kernel/common/linux/stddef.h b/libc/kernel/common/linux/stddef.h
index 5412f47..cca408c 100644
--- a/libc/kernel/common/linux/stddef.h
+++ b/libc/kernel/common/linux/stddef.h
@@ -7,25 +7,24 @@
  ***   structures, and macros generated from the original header, and thus,
  ***   contains no copyrightable information.
  ***
+ ***   To edit the content of this header, modify the corresponding
+ ***   source file (e.g. under external/kernel-headers/original/) then
+ ***   run bionic/libc/kernel/tools/update_all.py
+ ***
+ ***   Any manual change here will be lost the next time this script will
+ ***   be run. You've been warned!
+ ***
  ****************************************************************************
  ****************************************************************************/
 #ifndef _LINUX_STDDEF_H
 #define _LINUX_STDDEF_H
-
 #include <linux/compiler.h>
-
 #undef NULL
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #ifdef __cplusplus
 #define NULL 0
 #else
 #define NULL ((void *)0)
+/* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */
 #endif
-
-#undef offsetof
-#ifdef __compiler_offsetof
-#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
-#else
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
 #endif
diff --git a/libc/zoneinfo/zoneinfo.dat b/libc/zoneinfo/zoneinfo.dat
index 49b99ec..2e53be0 100644
--- a/libc/zoneinfo/zoneinfo.dat
+++ b/libc/zoneinfo/zoneinfo.dat
Binary files differ
diff --git a/libc/zoneinfo/zoneinfo.idx b/libc/zoneinfo/zoneinfo.idx
index c9eefc6..c888563 100644
--- a/libc/zoneinfo/zoneinfo.idx
+++ b/libc/zoneinfo/zoneinfo.idx
Binary files differ
diff --git a/libc/zoneinfo/zoneinfo.version b/libc/zoneinfo/zoneinfo.version
index c4f4922..10d350a 100644
--- a/libc/zoneinfo/zoneinfo.version
+++ b/libc/zoneinfo/zoneinfo.version
@@ -1 +1 @@
-2011n
+2012b
diff --git a/libm/src/s_logb.c b/libm/src/s_logb.c
index 30edb87..57f91c4 100644
--- a/libm/src/s_logb.c
+++ b/libm/src/s_logb.c
@@ -36,9 +36,9 @@
 	if(ix>=0x7ff00000) return x*x;
 	if(ix<0x00100000) {
 		x *= two54;		 /* convert subnormal x to normal */
-		GET_FLOAT_WORD(ix,x);
+		GET_HIGH_WORD(ix,x);
 		ix &= 0x7fffffff;
-		return (float) ((ix>>20)-1023-54);
+		return (double) ((ix>>20)-1023-54);
 	} else
 		return (double) ((ix>>20)-1023);
 }
diff --git a/linker/Android.mk b/linker/Android.mk
index 8f8cc2b..7541f65 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -12,7 +12,7 @@
 
 LOCAL_LDFLAGS := -shared
 
-LOCAL_CFLAGS += -fno-stack-protector
+LOCAL_CFLAGS += -fno-stack-protector -Wstrict-overflow=5
 
 # Set LINKER_DEBUG to either 1 or 0
 #
diff --git a/linker/debugger.c b/linker/debugger.c
index ef8286c..40411b1 100644
--- a/linker/debugger.c
+++ b/linker/debugger.c
@@ -32,6 +32,7 @@
 #include <ctype.h>
 #include <signal.h>
 #include <sys/mman.h>
+#include <sys/prctl.h>
 #include <errno.h>
 
 #include "linker.h"
@@ -46,6 +47,8 @@
         ret = (cond); \
     } while (ret < 0 && errno == EINTR)
 
+// see man(2) prctl, specifically the section about PR_GET_NAME
+#define MAX_TASK_NAME_LEN (16)
 
 static int socket_abstract_client(const char *name, int type)
 {
@@ -100,6 +103,7 @@
 static void logSignalSummary(int signum, const siginfo_t* info)
 {
     char buffer[128];
+    char threadname[MAX_TASK_NAME_LEN + 1]; // one more for termination
 
     char* signame;
     switch (signum) {
@@ -113,9 +117,16 @@
         default:        signame = "???";        break;
     }
 
+    if (prctl(PR_GET_NAME, (unsigned long)threadname, 0, 0, 0) != 0) {
+        strcpy(threadname, "<name unknown>");
+    } else {
+        // short names are null terminated by prctl, but the manpage
+        // implies that 16 byte names are not.
+        threadname[MAX_TASK_NAME_LEN] = 0;
+    }
     format_buffer(buffer, sizeof(buffer),
-        "Fatal signal %d (%s) at 0x%08x (code=%d)",
-        signum, signame, info->si_addr, info->si_code);
+        "Fatal signal %d (%s) at 0x%08x (code=%d), thread %d (%s)",
+        signum, signame, info->si_addr, info->si_code, gettid(), threadname);
 
     __libc_android_log_write(ANDROID_LOG_FATAL, "libc", buffer);
 }
diff --git a/linker/linker.c b/linker/linker.c
index 5656941..7463811 100644
--- a/linker/linker.c
+++ b/linker/linker.c
@@ -906,10 +906,10 @@
 {
     Elf32_Ehdr *ehdr = (Elf32_Ehdr *)header;
     Elf32_Phdr *phdr = (Elf32_Phdr *)((unsigned char *)header + ehdr->e_phoff);
-    unsigned char *base = (unsigned char *)si->base;
+    Elf32_Addr base = (Elf32_Addr) si->base;
     int cnt;
     unsigned len;
-    unsigned char *tmp;
+    Elf32_Addr tmp;
     unsigned char *pbase;
     unsigned char *extra_base;
     unsigned extra_len;
@@ -933,7 +933,7 @@
             TRACE("[ %d - Trying to load segment from '%s' @ 0x%08x "
                   "(0x%08x). p_vaddr=0x%08x p_offset=0x%08x ]\n", pid, si->name,
                   (unsigned)tmp, len, phdr->p_vaddr, phdr->p_offset);
-            pbase = mmap(tmp, len, PFLAGS_TO_PROT(phdr->p_flags),
+            pbase = mmap((void *)tmp, len, PFLAGS_TO_PROT(phdr->p_flags),
                          MAP_PRIVATE | MAP_FIXED, fd,
                          phdr->p_offset & (~PAGE_MASK));
             if (pbase == MAP_FAILED) {
@@ -975,7 +975,7 @@
              *                  |                     |
              *                 _+---------------------+  page boundary
              */
-            tmp = (unsigned char *)(((unsigned)pbase + len + PAGE_SIZE - 1) &
+            tmp = (Elf32_Addr)(((unsigned)pbase + len + PAGE_SIZE - 1) &
                                     (~PAGE_MASK));
             if (tmp < (base + phdr->p_vaddr + phdr->p_memsz)) {
                 extra_len = base + phdr->p_vaddr + phdr->p_memsz - tmp;
@@ -1030,6 +1030,17 @@
             DEBUG_DUMP_PHDR(phdr, "PT_DYNAMIC", pid);
             /* this segment contains the dynamic linking information */
             si->dynamic = (unsigned *)(base + phdr->p_vaddr);
+        } else if (phdr->p_type == PT_GNU_RELRO) {
+            if ((phdr->p_vaddr >= si->size)
+                    || ((phdr->p_vaddr + phdr->p_memsz) >= si->size)
+                    || ((base + phdr->p_vaddr + phdr->p_memsz) < base)) {
+                DL_ERR("%d invalid GNU_RELRO in '%s' "
+                       "p_vaddr=0x%08x p_memsz=0x%08x", pid, si->name,
+                       phdr->p_vaddr, phdr->p_memsz);
+                goto fail;
+            }
+            si->gnu_relro_start = (Elf32_Addr) (base + phdr->p_vaddr);
+            si->gnu_relro_len = (unsigned) phdr->p_memsz;
         } else {
 #ifdef ANDROID_ARM_LINKER
             if (phdr->p_type == PT_ARM_EXIDX) {
@@ -1251,10 +1262,29 @@
         TRACE("%5d unloading '%s'\n", pid, si->name);
         call_destructors(si);
 
+        /*
+         * Make sure that we undo the PT_GNU_RELRO protections we added
+         * in link_image. This is needed to undo the DT_NEEDED hack below.
+         */
+        if ((si->gnu_relro_start != 0) && (si->gnu_relro_len != 0)) {
+            Elf32_Addr start = (si->gnu_relro_start & ~PAGE_MASK);
+            unsigned len = (si->gnu_relro_start - start) + si->gnu_relro_len;
+            if (mprotect((void *) start, len, PROT_READ | PROT_WRITE) < 0)
+                DL_ERR("%5d %s: could not undo GNU_RELRO protections. "
+                       "Expect a crash soon. errno=%d (%s)",
+                       pid, si->name, errno, strerror(errno));
+
+        }
+
         for(d = si->dynamic; *d; d += 2) {
             if(d[0] == DT_NEEDED){
                 soinfo *lsi = (soinfo *)d[1];
+
+                // The next line will segfault if the we don't undo the
+                // PT_GNU_RELRO protections (see comments above and in
+                // link_image().
                 d[1] = 0;
+
                 if (validate_soinfo(lsi)) {
                     TRACE("%5d %s needs to unload %s\n", pid,
                           si->name, lsi->name);
@@ -1749,6 +1779,17 @@
                 }
                 DEBUG_DUMP_PHDR(phdr, "PT_DYNAMIC", pid);
                 si->dynamic = (unsigned *) (si->base + phdr->p_vaddr);
+            } else if (phdr->p_type == PT_GNU_RELRO) {
+                if ((phdr->p_vaddr >= si->size)
+                        || ((phdr->p_vaddr + phdr->p_memsz) >= si->size)
+                        || ((si->base + phdr->p_vaddr + phdr->p_memsz) < si->base)) {
+                    DL_ERR("%d invalid GNU_RELRO in '%s' "
+                           "p_vaddr=0x%08x p_memsz=0x%08x", pid, si->name,
+                           phdr->p_vaddr, phdr->p_memsz);
+                    goto fail;
+                }
+                si->gnu_relro_start = (Elf32_Addr) (si->base + phdr->p_vaddr);
+                si->gnu_relro_len = (unsigned) phdr->p_memsz;
             }
         }
     }
@@ -1890,7 +1931,7 @@
                of the DT_NEEDED entry itself, so that we can retrieve the
                soinfo directly later from the dynamic segment.  This is a hack,
                but it allows us to map from DT_NEEDED to soinfo efficiently
-               later on when we resolve relocations, trying to look up a symgol
+               later on when we resolve relocations, trying to look up a symbol
                with dlsym().
             */
             d[1] = (unsigned)lsi;
@@ -1938,6 +1979,16 @@
     }
 #endif
 
+    if (si->gnu_relro_start != 0 && si->gnu_relro_len != 0) {
+        Elf32_Addr start = (si->gnu_relro_start & ~PAGE_MASK);
+        unsigned len = (si->gnu_relro_start - start) + si->gnu_relro_len;
+        if (mprotect((void *) start, len, PROT_READ) < 0) {
+            DL_ERR("%5d GNU_RELRO mprotect of library '%s' failed: %d (%s)\n",
+                   pid, si->name, errno, strerror(errno));
+            goto fail;
+        }
+    }
+
     /* If this is a SET?ID program, dup /dev/null to opened stdin,
        stdout and stderr to close a security hole described in:
 
@@ -2147,6 +2198,8 @@
     si->wrprotect_start = 0xffffffff;
     si->wrprotect_end = 0;
     si->refcount = 1;
+    si->gnu_relro_start = 0;
+    si->gnu_relro_len = 0;
 
         /* Use LD_LIBRARY_PATH if we aren't setuid/setgid */
     if (ldpath_env)
@@ -2264,6 +2317,8 @@
     linker_so.flags |= FLAG_LINKER;
     linker_so.wrprotect_start = 0xffffffff;
     linker_so.wrprotect_end = 0;
+    linker_so.gnu_relro_start = 0;
+    linker_so.gnu_relro_len = 0;
 
     if (link_image(&linker_so, 0)) {
         // It would be nice to print an error message, but if the linker
diff --git a/linker/linker.h b/linker/linker.h
index eb3c4c3..0c986cd 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -31,7 +31,8 @@
 
 #include <unistd.h>
 #include <sys/types.h>
-#include <linux/elf.h>
+#include <elf.h>
+#include <sys/exec_elf.h>
 
 #undef PAGE_MASK
 #undef PAGE_SIZE
@@ -143,6 +144,10 @@
     struct link_map linkmap;
 
     int constructors_called;
+
+    Elf32_Addr gnu_relro_start;
+    unsigned gnu_relro_len;
+
 };