From c59a74ce6528c3d8dfe644dfecd916cd6f928416 Mon Sep 17 00:00:00 2001
From: Waldemar Brodkorb <mail@waldemar-brodkorb.de>
Date: Mon, 16 Sep 2013 20:53:09 +0200
Subject: bus error on mips/mipsel is fixed now. thx to Rich Felker, added
 musl-git patch from today

---
 toolchain/musl/patches/0.9.13/musl-git.patch | 8837 ++++++++++++++++++++++++++
 1 file changed, 8837 insertions(+)
 create mode 100644 toolchain/musl/patches/0.9.13/musl-git.patch

(limited to 'toolchain/musl/patches')

diff --git a/toolchain/musl/patches/0.9.13/musl-git.patch b/toolchain/musl/patches/0.9.13/musl-git.patch
new file mode 100644
index 000000000..a6a87390f
--- /dev/null
+++ b/toolchain/musl/patches/0.9.13/musl-git.patch
@@ -0,0 +1,8837 @@
+diff -Nur musl-0.9.13/.gitignore musl-git/.gitignore
+--- musl-0.9.13/.gitignore	1970-01-01 01:00:00.000000000 +0100
++++ musl-git/.gitignore	2013-09-16 20:31:39.000000000 +0200
+@@ -0,0 +1,10 @@
++*.o
++*.lo
++*.a
++*.so
++*.so.1
++arch/*/bits/alltypes.h
++config.mak
++include/bits
++tools/musl-gcc
++lib/musl-gcc.specs
+diff -Nur musl-0.9.13/Makefile musl-git/Makefile
+--- musl-0.9.13/Makefile	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/Makefile	2013-09-16 20:31:39.000000000 +0200
+@@ -157,7 +157,7 @@
+ 	$(INSTALL) -D -m 644 $< $@
+ 
+ $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so
+-	$(INSTALL) -D -l $< $@ || true
++	$(INSTALL) -D -l $(libdir)/libc.so $@ || true
+ 
+ install-libs: $(ALL_LIBS:lib/%=$(DESTDIR)$(libdir)/%) $(if $(SHARED_LIBS),$(DESTDIR)$(LDSO_PATHNAME),)
+ 
+diff -Nur musl-0.9.13/arch/microblaze/bits/limits.h musl-git/arch/microblaze/bits/limits.h
+--- musl-0.9.13/arch/microblaze/bits/limits.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/arch/microblaze/bits/limits.h	2013-09-16 20:31:39.000000000 +0200
+@@ -1,6 +1,5 @@
+ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+-#define PAGE_SIZE 4096
+ #define LONG_BIT 32
+ #endif
+ 
+diff -Nur musl-0.9.13/arch/microblaze/reloc.h musl-git/arch/microblaze/reloc.h
+--- musl-0.9.13/arch/microblaze/reloc.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/arch/microblaze/reloc.h	2013-09-16 20:31:39.000000000 +0200
+@@ -49,7 +49,7 @@
+ 	for (a+=c+1; *a; a++);
+ 	for (a++; *a; a+=2) if (*a<20) t[*a] = a[1];
+ 	base = (char *)t[AT_BASE];
+-	if (!base) base = (char *)(t[AT_PHDR] & -4096);
++	if (!base) base = (char *)(t[AT_PHDR] & -t[AT_PAGESZ]);
+ 	for (a=dynv; *a; a+=2) if (*a<20) t[*a] = a[1];
+ 	n = t[DT_RELASZ];
+ 	for (a=(void *)(base+t[DT_RELA]); n; a+=3, n-=12)
+diff -Nur musl-0.9.13/arch/mips/bits/limits.h musl-git/arch/mips/bits/limits.h
+--- musl-0.9.13/arch/mips/bits/limits.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/arch/mips/bits/limits.h	2013-09-16 20:31:39.000000000 +0200
+@@ -1,6 +1,5 @@
+ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+-#define PAGE_SIZE 4096
+ #define LONG_BIT 32
+ #endif
+ 
+diff -Nur musl-0.9.13/arch/mips/bits/msg.h musl-git/arch/mips/bits/msg.h
+--- musl-0.9.13/arch/mips/bits/msg.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/arch/mips/bits/msg.h	2013-09-16 20:31:39.000000000 +0200
+@@ -1,12 +1,21 @@
+ struct msqid_ds
+ {
+ 	struct ipc_perm msg_perm;
++#if _MIPSEL || __MIPSEL || __MIPSEL__
+ 	time_t msg_stime;
+ 	int __unused1;
+ 	time_t msg_rtime;
+ 	int __unused2;
+ 	time_t msg_ctime;
+ 	int __unused3;
++#else
++	int __unused1;
++	time_t msg_stime;
++	int __unused2;
++	time_t msg_rtime;
++	int __unused3;
++	time_t msg_ctime;
++#endif
+ 	unsigned long msg_cbytes;
+ 	msgqnum_t msg_qnum;
+ 	msglen_t msg_qbytes;
+diff -Nur musl-0.9.13/arch/mips/bits/shm.h musl-git/arch/mips/bits/shm.h
+--- musl-0.9.13/arch/mips/bits/shm.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/arch/mips/bits/shm.h	2013-09-16 20:31:39.000000000 +0200
+@@ -5,11 +5,8 @@
+ 	struct ipc_perm shm_perm;
+ 	size_t shm_segsz;
+ 	time_t shm_atime;
+-	int __unused1;
+ 	time_t shm_dtime;
+-	int __unused2;
+ 	time_t shm_ctime;
+-	int __unused3;
+ 	pid_t shm_cpid;
+ 	pid_t shm_lpid;
+ 	unsigned long shm_nattch;
+diff -Nur musl-0.9.13/arch/mips/reloc.h musl-git/arch/mips/reloc.h
+--- musl-0.9.13/arch/mips/reloc.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/arch/mips/reloc.h	2013-09-16 20:31:39.000000000 +0200
+@@ -51,7 +51,7 @@
+ 	for (a+=c+1; *a; a++);
+ 	for (a++; *a; a+=2) if (*a<20) t[*a] = a[1];
+ 	base = (char *)t[AT_BASE];
+-	if (!base) base = (char *)(t[AT_PHDR] & -4096);
++	if (!base) base = (char *)(t[AT_PHDR] & -t[AT_PAGESZ]);
+ 	for (a=dynv; *a; a+=2) if (*a-0x70000000UL<20) t[*a&31] = a[1];
+ 	n = t[DT_MIPS_LOCAL_GOTNO - 0x70000000];
+ 	for (a=got; n; a++, n--) *a += (size_t)base;
+diff -Nur musl-0.9.13/arch/powerpc/bits/limits.h musl-git/arch/powerpc/bits/limits.h
+--- musl-0.9.13/arch/powerpc/bits/limits.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/arch/powerpc/bits/limits.h	2013-09-16 20:31:39.000000000 +0200
+@@ -1,6 +1,5 @@
+ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
+  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+-#define PAGE_SIZE 4096
+ #define LONG_BIT 32
+ #endif
+ 
+diff -Nur musl-0.9.13/arch/powerpc/reloc.h musl-git/arch/powerpc/reloc.h
+--- musl-0.9.13/arch/powerpc/reloc.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/arch/powerpc/reloc.h	2013-09-16 20:31:39.000000000 +0200
+@@ -46,7 +46,7 @@
+ 	for (a+=c+1; *a; a++);
+ 	for (a++; *a; a+=2) if (*a<20) t[*a] = a[1];
+ 	base = (char *)t[AT_BASE];
+-	if (!base) base = (char *)(t[AT_PHDR] & -4096);
++	if (!base) base = (char *)(t[AT_PHDR] & -t[AT_PAGESZ]);
+ 	for (a=dynv; *a; a+=2) if (*a<20) t[*a] = a[1];
+ 	n = t[DT_RELASZ];
+ 	for (a=(void *)(base+t[DT_RELA]); n; a+=3, n-=12)
+diff -Nur musl-0.9.13/include/elf.h musl-git/include/elf.h
+--- musl-0.9.13/include/elf.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/include/elf.h	2013-09-16 20:31:39.000000000 +0200
+@@ -105,6 +105,7 @@
+ #define ELFOSABI_HPUX		1
+ #define ELFOSABI_NETBSD		2
+ #define ELFOSABI_LINUX		3
++#define ELFOSABI_GNU		3
+ #define ELFOSABI_SOLARIS	6
+ #define ELFOSABI_AIX		7
+ #define ELFOSABI_IRIX		8
+@@ -211,7 +212,11 @@
+ #define EM_OPENRISC	92
+ #define EM_ARC_A5	93
+ #define EM_XTENSA	94
+-#define EM_NUM		95
++#define EM_AARCH64	183
++#define EM_TILEPRO	188
++#define EM_MICROBLAZE	189
++#define EM_TILEGX	191
++#define EM_NUM		192
+ #define EM_ALPHA	0x9026
+ 
+ #define EV_NONE		0
+@@ -487,6 +492,8 @@
+ #define PT_HIPROC	0x7fffffff
+ 
+ 
++#define PN_XNUM 0xffff
++
+ 
+ #define PF_X		(1 << 0)
+ #define PF_W		(1 << 1)
+@@ -512,12 +519,31 @@
+ #define NT_LWPSTATUS	16
+ #define NT_LWPSINFO	17
+ #define NT_PRFPXREG	20
++#define NT_SIGINFO	0x53494749
++#define NT_FILE		0x46494c45
+ #define NT_PRXFPREG	0x46e62b7f
+ #define NT_PPC_VMX	0x100
+ #define NT_PPC_SPE	0x101
+ #define NT_PPC_VSX	0x102
+ #define NT_386_TLS	0x200
+ #define NT_386_IOPERM	0x201
++#define NT_X86_XSTATE	0x202
++#define NT_S390_HIGH_GPRS	0x300
++#define NT_S390_TIMER	0x301
++#define NT_S390_TODCMP	0x302
++#define NT_S390_TODPREG	0x303
++#define NT_S390_CTRS	0x304
++#define NT_S390_PREFIX	0x305
++#define NT_S390_LAST_BREAK	0x306
++#define NT_S390_SYSTEM_CALL	0x307
++#define NT_S390_TDB	0x308
++#define NT_ARM_VFP	0x400
++#define NT_ARM_TLS	0x401
++#define NT_ARM_HW_BREAK	0x402
++#define NT_ARM_HW_WATCH	0x403
++#define NT_METAG_CBUF	0x500
++#define NT_METAG_RPIPE	0x501
++#define NT_METAG_TLS	0x502
+ #define NT_VERSION	1
+ 
+ 
+@@ -666,7 +692,15 @@
+ #define DF_1_ENDFILTEE	0x00004000
+ #define	DF_1_DISPRELDNE	0x00008000
+ #define	DF_1_DISPRELPND	0x00010000
+-
++#define	DF_1_NODIRECT	0x00020000
++#define	DF_1_IGNMULDEF	0x00040000
++#define	DF_1_NOKSYMS	0x00080000
++#define	DF_1_NOHDR	0x00100000
++#define	DF_1_EDITED	0x00200000
++#define	DF_1_NORELOC	0x00400000
++#define	DF_1_SYMINTPOSE	0x00800000
++#define	DF_1_GLOBAUDIT	0x01000000
++#define	DF_1_SINGLETON	0x02000000
+ 
+ #define DTF_1_PARINIT	0x00000001
+ #define DTF_1_CONFEXP	0x00000002
+@@ -832,6 +866,8 @@
+ 
+ #define AT_RANDOM	25
+ 
++#define AT_HWCAP2	26
++
+ #define AT_EXECFN	31
+ 
+ 
+@@ -979,6 +1015,7 @@
+ #define R_386_TLS_DTPMOD32 35
+ #define R_386_TLS_DTPOFF32 36
+ #define R_386_TLS_TPOFF32  37
++#define R_386_SIZE32       38
+ #define R_386_TLS_GOTDESC  39
+ #define R_386_TLS_DESC_CALL 40
+ #define R_386_TLS_DESC     41
+@@ -1109,20 +1146,6 @@
+ #define DT_SPARC_NUM	2
+ 
+ 
+-
+-#define HWCAP_SPARC_FLUSH	1
+-#define HWCAP_SPARC_STBAR	2
+-#define HWCAP_SPARC_SWAP	4
+-#define HWCAP_SPARC_MULDIV	8
+-#define HWCAP_SPARC_V9		16
+-#define HWCAP_SPARC_ULTRA3	32
+-#define HWCAP_SPARC_BLKINIT	64
+-#define HWCAP_SPARC_N2		128
+-
+-
+-
+-
+-
+ #define EF_MIPS_NOREORDER   1
+ #define EF_MIPS_PIC	    2
+ #define EF_MIPS_CPIC	    4
+@@ -1139,9 +1162,10 @@
+ #define EF_MIPS_ARCH_3	    0x20000000
+ #define EF_MIPS_ARCH_4	    0x30000000
+ #define EF_MIPS_ARCH_5	    0x40000000
+-#define EF_MIPS_ARCH_32	    0x60000000
+-#define EF_MIPS_ARCH_64	    0x70000000
+-
++#define EF_MIPS_ARCH_32     0x50000000
++#define EF_MIPS_ARCH_64     0x60000000
++#define EF_MIPS_ARCH_32R2   0x70000000
++#define EF_MIPS_ARCH_64R2   0x80000000
+ 
+ 
+ #define E_MIPS_ARCH_1	  0x00000000
+@@ -1149,8 +1173,8 @@
+ #define E_MIPS_ARCH_3	  0x20000000
+ #define E_MIPS_ARCH_4	  0x30000000
+ #define E_MIPS_ARCH_5	  0x40000000
+-#define E_MIPS_ARCH_32	  0x60000000
+-#define E_MIPS_ARCH_64	  0x70000000
++#define E_MIPS_ARCH_32	  0x50000000
++#define E_MIPS_ARCH_64	  0x60000000
+ 
+ 
+ 
+@@ -2020,7 +2044,8 @@
+ #define EF_ARM_VFP_FLOAT	0x400
+ #define EF_ARM_MAVERICK_FLOAT	0x800
+ 
+-
++#define EF_ARM_ABI_FLOAT_SOFT	0x200
++#define EF_ARM_ABI_FLOAT_HARD	0x400
+ 
+ 
+ #define EF_ARM_SYMSARESORTED	0x04
+@@ -2064,6 +2089,17 @@
+ #define SHT_ARM_ATTRIBUTES	(SHT_LOPROC + 3)
+ 
+ 
++#define R_AARCH64_NONE            0
++#define R_AARCH64_ABS64         257
++#define R_AARCH64_ABS32         258
++#define R_AARCH64_COPY         1024
++#define R_AARCH64_GLOB_DAT     1025
++#define R_AARCH64_JUMP_SLOT    1026
++#define R_AARCH64_RELATIVE     1027
++#define R_AARCH64_TLS_DTPMOD64 1028
++#define R_AARCH64_TLS_DTPREL64 1029
++#define R_AARCH64_TLS_TPREL64  1030
++#define R_AARCH64_TLSDESC      1031
+ 
+ 
+ #define R_ARM_NONE		0
+@@ -2079,7 +2115,7 @@
+ #define R_ARM_THM_PC22		10
+ #define R_ARM_THM_PC8		11
+ #define R_ARM_AMP_VCALL9	12
+-#define R_ARM_SWI24		13
++#define R_ARM_TLS_DESC		13
+ #define R_ARM_THM_SWI8		14
+ #define R_ARM_XPC25		15
+ #define R_ARM_THM_XPC22		16
+@@ -2094,12 +2130,78 @@
+ #define R_ARM_GOTPC		25
+ #define R_ARM_GOT32		26
+ #define R_ARM_PLT32		27
++#define R_ARM_CALL		28
++#define R_ARM_JUMP24		29
++#define R_ARM_THM_JUMP24	30
++#define R_ARM_BASE_ABS		31
+ #define R_ARM_ALU_PCREL_7_0	32
+ #define R_ARM_ALU_PCREL_15_8	33
+ #define R_ARM_ALU_PCREL_23_15	34
+ #define R_ARM_LDR_SBREL_11_0	35
+ #define R_ARM_ALU_SBREL_19_12	36
+ #define R_ARM_ALU_SBREL_27_20	37
++#define R_ARM_TARGET1		38
++#define R_ARM_SBREL31		39
++#define R_ARM_V4BX		40
++#define R_ARM_TARGET2		41
++#define R_ARM_PREL31		42
++#define R_ARM_MOVW_ABS_NC	43
++#define R_ARM_MOVT_ABS		44
++#define R_ARM_MOVW_PREL_NC	45
++#define R_ARM_MOVT_PREL		46
++#define R_ARM_THM_MOVW_ABS_NC	47
++#define R_ARM_THM_MOVT_ABS	48
++#define R_ARM_THM_MOVW_PREL_NC	49
++#define R_ARM_THM_MOVT_PREL	50
++#define R_ARM_THM_JUMP19	51
++#define R_ARM_THM_JUMP6		52
++#define R_ARM_THM_ALU_PREL_11_0	53
++#define R_ARM_THM_PC12		54
++#define R_ARM_ABS32_NOI		55
++#define R_ARM_REL32_NOI		56
++#define R_ARM_ALU_PC_G0_NC	57
++#define R_ARM_ALU_PC_G0		58
++#define R_ARM_ALU_PC_G1_NC	59
++#define R_ARM_ALU_PC_G1		60
++#define R_ARM_ALU_PC_G2		61
++#define R_ARM_LDR_PC_G1		62
++#define R_ARM_LDR_PC_G2		63
++#define R_ARM_LDRS_PC_G0	64
++#define R_ARM_LDRS_PC_G1	65
++#define R_ARM_LDRS_PC_G2	66
++#define R_ARM_LDC_PC_G0		67
++#define R_ARM_LDC_PC_G1		68
++#define R_ARM_LDC_PC_G2		69
++#define R_ARM_ALU_SB_G0_NC	70
++#define R_ARM_ALU_SB_G0		71
++#define R_ARM_ALU_SB_G1_NC	72
++#define R_ARM_ALU_SB_G1		73
++#define R_ARM_ALU_SB_G2		74
++#define R_ARM_LDR_SB_G0		75
++#define R_ARM_LDR_SB_G1		76
++#define R_ARM_LDR_SB_G2		77
++#define R_ARM_LDRS_SB_G0	78
++#define R_ARM_LDRS_SB_G1	79
++#define R_ARM_LDRS_SB_G2	80
++#define R_ARM_LDC_SB_G0		81
++#define R_ARM_LDC_SB_G1		82
++#define R_ARM_LDC_SB_G2		83
++#define R_ARM_MOVW_BREL_NC	84
++#define R_ARM_MOVT_BREL		85
++#define R_ARM_MOVW_BREL		86
++#define R_ARM_THM_MOVW_BREL_NC	87
++#define R_ARM_THM_MOVT_BREL	88
++#define R_ARM_THM_MOVW_BREL	89
++#define R_ARM_TLS_GOTDESC	90
++#define R_ARM_TLS_CALL		91
++#define R_ARM_TLS_DESCSEQ	92
++#define R_ARM_THM_TLS_CALL	93
++#define R_ARM_PLT32_ABS		94
++#define R_ARM_GOT_ABS		95
++#define R_ARM_GOT_PREL		96
++#define R_ARM_GOT_BREL12	97
++#define R_ARM_GOTOFF12		98
++#define R_ARM_GOTRELAX		99
+ #define R_ARM_GNU_VTENTRY	100
+ #define R_ARM_GNU_VTINHERIT	101
+ #define R_ARM_THM_PC11		102
+@@ -2113,7 +2215,15 @@
+ #define R_ARM_TLS_IE32		107
+ 
+ #define R_ARM_TLS_LE32		108
+-
++#define R_ARM_TLS_LDO12		109
++#define R_ARM_TLS_LE12		110
++#define R_ARM_TLS_IE12GP	111
++#define R_ARM_ME_TOO		128
++#define R_ARM_THM_TLS_DESCSEQ	129
++#define R_ARM_THM_TLS_DESCSEQ16	129
++#define R_ARM_THM_TLS_DESCSEQ32	130
++#define R_ARM_THM_GOT_BREL12	131
++#define R_ARM_IRELATIVE		160
+ #define R_ARM_RXPC25		249
+ #define R_ARM_RSBREL32		250
+ #define R_ARM_THM_RPC22		251
+@@ -2421,15 +2531,21 @@
+ #define R_X86_64_PC64		24
+ #define R_X86_64_GOTOFF64	25
+ #define R_X86_64_GOTPC32	26
+-
++#define R_X86_64_GOT64		27
++#define R_X86_64_GOTPCREL64	28
++#define R_X86_64_GOTPC64	29
++#define R_X86_64_GOTPLT64	30
++#define R_X86_64_PLTOFF64	31
++#define R_X86_64_SIZE32		32
++#define R_X86_64_SIZE64		33
+ 
+ #define R_X86_64_GOTPC32_TLSDESC 34
+ #define R_X86_64_TLSDESC_CALL   35
+ 
+ #define R_X86_64_TLSDESC        36
+ #define R_X86_64_IRELATIVE	37
+-
+-#define R_X86_64_NUM		38
++#define R_X86_64_RELATIVE64	38
++#define R_X86_64_NUM		39
+ 
+ 
+ 
+diff -Nur musl-0.9.13/include/limits.h musl-git/include/limits.h
+--- musl-0.9.13/include/limits.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/include/limits.h	2013-09-16 20:31:39.000000000 +0200
+@@ -40,7 +40,9 @@
+  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+ 
+ #define PIPE_BUF 4096
++#ifdef PAGE_SIZE
+ #define PAGESIZE PAGE_SIZE
++#endif
+ #define FILESIZEBITS 64
+ #define NAME_MAX 255
+ #define SYMLINK_MAX 255
+diff -Nur musl-0.9.13/include/net/if_arp.h musl-git/include/net/if_arp.h
+--- musl-0.9.13/include/net/if_arp.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/include/net/if_arp.h	2013-09-16 20:31:39.000000000 +0200
+@@ -52,6 +52,7 @@
+ #define ARPHRD_ROSE	270
+ #define ARPHRD_X25	271
+ #define ARPHRD_HWX25	272
++#define ARPHRD_CAN	280
+ #define ARPHRD_PPP	512
+ #define ARPHRD_CISCO	513
+ #define ARPHRD_HDLC	ARPHRD_CISCO
+@@ -84,7 +85,12 @@
+ #define ARPHRD_IEEE80211_PRISM 802
+ #define ARPHRD_IEEE80211_RADIOTAP 803
+ #define ARPHRD_IEEE802154 804
+-#define ARPHRD_IEEE802154_PHY 805
++#define ARPHRD_IEEE802154_MONITOR 805
++#define ARPHRD_PHONET 820
++#define ARPHRD_PHONET_PIPE 821
++#define ARPHRD_CAIF 822
++#define ARPHRD_IP6GRE 823
++#define ARPHRD_NETLINK 824
+ 
+ #define ARPHRD_VOID	  0xFFFF
+ #define ARPHRD_NONE	  0xFFFE
+diff -Nur musl-0.9.13/include/netinet/in.h musl-git/include/netinet/in.h
+--- musl-0.9.13/include/netinet/in.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/include/netinet/in.h	2013-09-16 20:31:39.000000000 +0200
+@@ -91,10 +91,12 @@
+ #define IPPROTO_NONE     59
+ #define IPPROTO_DSTOPTS  60
+ #define IPPROTO_MTP      92
++#define IPPROTO_BEETPH   94
+ #define IPPROTO_ENCAP    98
+ #define IPPROTO_PIM      103
+ #define IPPROTO_COMP     108
+ #define IPPROTO_SCTP     132
++#define IPPROTO_MH       135
+ #define IPPROTO_UDPLITE  136
+ #define IPPROTO_RAW      255
+ #define IPPROTO_MAX      256
+diff -Nur musl-0.9.13/include/sys/ptrace.h musl-git/include/sys/ptrace.h
+--- musl-0.9.13/include/sys/ptrace.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/include/sys/ptrace.h	2013-09-16 20:31:39.000000000 +0200
+@@ -37,6 +37,8 @@
+ #define PTRACE_INTERRUPT 0x4207
+ #define PTRACE_LISTEN 0x4208
+ #define PTRACE_PEEKSIGINFO 0x4209
++#define PTRACE_GETSIGMASK 0x420a
++#define PTRACE_SETSIGMASK 0x420b
+ 
+ #define PT_READ_I PTRACE_PEEKTEXT
+ #define PT_READ_D PTRACE_PEEKDATA
+diff -Nur musl-0.9.13/include/sys/resource.h musl-git/include/sys/resource.h
+--- musl-0.9.13/include/sys/resource.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/include/sys/resource.h	2013-09-16 20:31:39.000000000 +0200
+@@ -59,6 +59,9 @@
+ #define prlimit64 prlimit
+ #endif
+ 
++#define PRIO_MIN (-20)
++#define PRIO_MAX 20
++
+ #define PRIO_PROCESS 0
+ #define PRIO_PGRP    1
+ #define PRIO_USER    2
+diff -Nur musl-0.9.13/include/sys/socket.h musl-git/include/sys/socket.h
+--- musl-0.9.13/include/sys/socket.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/include/sys/socket.h	2013-09-16 20:31:39.000000000 +0200
+@@ -199,6 +199,7 @@
+ #define SO_NOFCS                43
+ #define SO_LOCK_FILTER          44
+ #define SO_SELECT_ERR_QUEUE     45
++#define SO_BUSY_POLL            46
+ 
+ #ifndef SOL_SOCKET
+ #define SOL_SOCKET      1
+diff -Nur musl-0.9.13/include/wait.h musl-git/include/wait.h
+--- musl-0.9.13/include/wait.h	1970-01-01 01:00:00.000000000 +0100
++++ musl-git/include/wait.h	2013-09-16 20:31:39.000000000 +0200
+@@ -0,0 +1,2 @@
++#warning redirecting incorrect #include <wait.h> to <sys/wait.h>
++#include <sys/wait.h>
+diff -Nur musl-0.9.13/src/aio/aio_readwrite.c musl-git/src/aio/aio_readwrite.c
+--- musl-0.9.13/src/aio/aio_readwrite.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/aio/aio_readwrite.c	2013-09-16 20:31:39.000000000 +0200
+@@ -2,8 +2,8 @@
+ #include <fcntl.h>
+ #include <errno.h>
+ #include <unistd.h>
+-#include <limits.h>
+ #include "pthread_impl.h"
++#include "libc.h"
+ 
+ static void dummy(void)
+ {
+diff -Nur musl-0.9.13/src/aio/lio_listio.c musl-git/src/aio/lio_listio.c
+--- musl-0.9.13/src/aio/lio_listio.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/aio/lio_listio.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,9 +1,9 @@
+ #include <aio.h>
+ #include <errno.h>
+-#include <limits.h>
+ #include <unistd.h>
+ #include <string.h>
+ #include "pthread_impl.h"
++#include "libc.h"
+ 
+ struct lio_state {
+ 	struct sigevent *sev;
+diff -Nur musl-0.9.13/src/conf/fpathconf.c musl-git/src/conf/fpathconf.c
+--- musl-0.9.13/src/conf/fpathconf.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/conf/fpathconf.c	2013-09-16 20:31:39.000000000 +0200
+@@ -19,11 +19,11 @@
+ 		[_PC_PRIO_IO] = -1,
+ 		[_PC_SOCK_MAXBUF] = -1,
+ 		[_PC_FILESIZEBITS] = FILESIZEBITS,
+-		[_PC_REC_INCR_XFER_SIZE] = PAGE_SIZE,
+-		[_PC_REC_MAX_XFER_SIZE] = PAGE_SIZE,
+-		[_PC_REC_MIN_XFER_SIZE] = PAGE_SIZE,
+-		[_PC_REC_XFER_ALIGN] = PAGE_SIZE,
+-		[_PC_ALLOC_SIZE_MIN] = PAGE_SIZE,
++		[_PC_REC_INCR_XFER_SIZE] = 4096,
++		[_PC_REC_MAX_XFER_SIZE] = 4096,
++		[_PC_REC_MIN_XFER_SIZE] = 4096,
++		[_PC_REC_XFER_ALIGN] = 4096,
++		[_PC_ALLOC_SIZE_MIN] = 4096,
+ 		[_PC_SYMLINK_MAX] = SYMLINK_MAX,
+ 		[_PC_2_SYMLINKS] = 1
+ 	};
+diff -Nur musl-0.9.13/src/conf/sysconf.c musl-git/src/conf/sysconf.c
+--- musl-0.9.13/src/conf/sysconf.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/conf/sysconf.c	2013-09-16 20:31:39.000000000 +0200
+@@ -3,6 +3,7 @@
+ #include <errno.h>
+ #include <sys/resource.h>
+ #include "syscall.h"
++#include "libc.h"
+ 
+ #define VER (-2)
+ #define OFLOW (-3)
+@@ -40,9 +41,9 @@
+ 		[_SC_AIO_PRIO_DELTA_MAX] = 0, /* ?? */
+ 		[_SC_DELAYTIMER_MAX] = _POSIX_DELAYTIMER_MAX,
+ 		[_SC_MQ_OPEN_MAX] = -1,
+-		[_SC_MQ_PRIO_MAX] = MQ_PRIO_MAX,
++		[_SC_MQ_PRIO_MAX] = OFLOW,
+ 		[_SC_VERSION] = VER,
+-		[_SC_PAGE_SIZE] = PAGE_SIZE,
++		[_SC_PAGE_SIZE] = OFLOW,
+ 		[_SC_RTSIG_MAX] = 63, /* ?? */
+ 		[_SC_SEM_NSEMS_MAX] = SEM_NSEMS_MAX,
+ 		[_SC_SEM_VALUE_MAX] = OFLOW,
+@@ -221,6 +222,9 @@
+ 	} else if (values[name] == OFLOW) {
+ 		if (name == _SC_ARG_MAX) return ARG_MAX;
+ 		if (name == _SC_SEM_VALUE_MAX) return SEM_VALUE_MAX;
++		if (name == _SC_MQ_PRIO_MAX) return MQ_PRIO_MAX;
++		/* name == _SC_PAGE_SIZE */
++		return PAGE_SIZE;
+ 	} else if (values[name] == CPUCNT) {
+ 		unsigned char set[128] = {1};
+ 		int i, cnt;
+diff -Nur musl-0.9.13/src/env/__libc_start_main.c musl-git/src/env/__libc_start_main.c
+--- musl-0.9.13/src/env/__libc_start_main.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/env/__libc_start_main.c	2013-09-16 20:31:39.000000000 +0200
+@@ -26,6 +26,7 @@
+ 	for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1];
+ 	__hwcap = aux[AT_HWCAP];
+ 	__sysinfo = aux[AT_SYSINFO];
++	libc.page_size = aux[AT_PAGESZ];
+ 
+ 	if (pn) {
+ 		__progname = __progname_full = pn;
+diff -Nur musl-0.9.13/src/internal/libc.h musl-git/src/internal/libc.h
+--- musl-0.9.13/src/internal/libc.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/internal/libc.h	2013-09-16 20:31:39.000000000 +0200
+@@ -3,6 +3,7 @@
+ 
+ #include <stdlib.h>
+ #include <stdio.h>
++#include <limits.h>
+ 
+ struct __libc {
+ 	void *main_thread;
+@@ -14,10 +15,15 @@
+ 	FILE *ofl_head;
+ 	int ofl_lock[2];
+ 	size_t tls_size;
++	size_t page_size;
+ };
+ 
+ extern size_t __hwcap;
+ 
++#ifndef PAGE_SIZE
++#define PAGE_SIZE libc.page_size
++#endif
++
+ #if !defined(__PIC__) || (100*__GNUC__+__GNUC_MINOR__ >= 303 && !defined(__PCC__))
+ 
+ #ifdef __PIC__
+diff -Nur musl-0.9.13/src/internal/libm.h musl-git/src/internal/libm.h
+--- musl-0.9.13/src/internal/libm.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/internal/libm.h	2013-09-16 20:31:39.000000000 +0200
+@@ -17,117 +17,115 @@
+ #include <float.h>
+ #include <math.h>
+ #include <complex.h>
++#include <endian.h>
+ 
+-#include "longdbl.h"
+-
+-#include "libc.h"
+-
+-union fshape {
+-	float value;
+-	uint32_t bits;
++#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
++#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
++union ldshape {
++	long double f;
++	struct {
++		uint64_t m;
++		uint16_t se;
++	} i;
+ };
+-
+-union dshape {
+-	double value;
+-	uint64_t bits;
++#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN
++union ldshape {
++	long double f;
++	struct {
++		uint64_t lo;
++		uint32_t mid;
++		uint16_t top;
++		uint16_t se;
++	} i;
++	struct {
++		uint64_t lo;
++		uint64_t hi;
++	} i2;
+ };
++#else
++#error Unsupported long double representation
++#endif
+ 
+-#define FORCE_EVAL(x) do {                          \
+-	if (sizeof(x) == sizeof(float)) {           \
+-		volatile float __x;                 \
+-		__x = (x);                          \
+-	} else if (sizeof(x) == sizeof(double)) {   \
+-		volatile double __x;                \
+-		__x = (x);                          \
+-	} else {                                    \
+-		volatile long double __x;           \
+-		__x = (x);                          \
+-	}                                           \
++#define FORCE_EVAL(x) do {                        \
++	if (sizeof(x) == sizeof(float)) {         \
++		volatile float __x;               \
++		__x = (x);                        \
++	} else if (sizeof(x) == sizeof(double)) { \
++		volatile double __x;              \
++		__x = (x);                        \
++	} else {                                  \
++		volatile long double __x;         \
++		__x = (x);                        \
++	}                                         \
+ } while(0)
+ 
+ /* Get two 32 bit ints from a double.  */
+-#define EXTRACT_WORDS(hi,lo,d)                                  \
+-do {                                                            \
+-  union dshape __u;                                             \
+-  __u.value = (d);                                              \
+-  (hi) = __u.bits >> 32;                                        \
+-  (lo) = (uint32_t)__u.bits;                                    \
+-} while (0)
+-
+-/* Get a 64 bit int from a double.  */
+-#define EXTRACT_WORD64(i,d)                                     \
+-do {                                                            \
+-  union dshape __u;                                             \
+-  __u.value = (d);                                              \
+-  (i) = __u.bits;                                               \
++#define EXTRACT_WORDS(hi,lo,d)                    \
++do {                                              \
++  union {double f; uint64_t i;} __u;              \
++  __u.f = (d);                                    \
++  (hi) = __u.i >> 32;                             \
++  (lo) = (uint32_t)__u.i;                         \
+ } while (0)
+ 
+ /* Get the more significant 32 bit int from a double.  */
+-#define GET_HIGH_WORD(i,d)                                      \
+-do {                                                            \
+-  union dshape __u;                                             \
+-  __u.value = (d);                                              \
+-  (i) = __u.bits >> 32;                                         \
++#define GET_HIGH_WORD(hi,d)                       \
++do {                                              \
++  union {double f; uint64_t i;} __u;              \
++  __u.f = (d);                                    \
++  (hi) = __u.i >> 32;                             \
+ } while (0)
+ 
+ /* Get the less significant 32 bit int from a double.  */
+-#define GET_LOW_WORD(i,d)                                       \
+-do {                                                            \
+-  union dshape __u;                                             \
+-  __u.value = (d);                                              \
+-  (i) = (uint32_t)__u.bits;                                     \
++#define GET_LOW_WORD(lo,d)                        \
++do {                                              \
++  union {double f; uint64_t i;} __u;              \
++  __u.f = (d);                                    \
++  (lo) = (uint32_t)__u.i;                         \
+ } while (0)
+ 
+ /* Set a double from two 32 bit ints.  */
+-#define INSERT_WORDS(d,hi,lo)                                   \
+-do {                                                            \
+-  union dshape __u;                                             \
+-  __u.bits = ((uint64_t)(hi) << 32) | (uint32_t)(lo);           \
+-  (d) = __u.value;                                              \
+-} while (0)
+-
+-/* Set a double from a 64 bit int.  */
+-#define INSERT_WORD64(d,i)                                      \
+-do {                                                            \
+-  union dshape __u;                                             \
+-  __u.bits = (i);                                               \
+-  (d) = __u.value;                                              \
++#define INSERT_WORDS(d,hi,lo)                     \
++do {                                              \
++  union {double f; uint64_t i;} __u;              \
++  __u.i = ((uint64_t)(hi)<<32) | (uint32_t)(lo);  \
++  (d) = __u.f;                                    \
+ } while (0)
+ 
+ /* Set the more significant 32 bits of a double from an int.  */
+-#define SET_HIGH_WORD(d,hi)                                     \
+-do {                                                            \
+-  union dshape __u;                                             \
+-  __u.value = (d);                                              \
+-  __u.bits &= 0xffffffff;                                       \
+-  __u.bits |= (uint64_t)(hi) << 32;                             \
+-  (d) = __u.value;                                              \
++#define SET_HIGH_WORD(d,hi)                       \
++do {                                              \
++  union {double f; uint64_t i;} __u;              \
++  __u.f = (d);                                    \
++  __u.i &= 0xffffffff;                            \
++  __u.i |= (uint64_t)(hi) << 32;                  \
++  (d) = __u.f;                                    \
+ } while (0)
+ 
+ /* Set the less significant 32 bits of a double from an int.  */
+-#define SET_LOW_WORD(d,lo)                                      \
+-do {                                                            \
+-  union dshape __u;                                             \
+-  __u.value = (d);                                              \
+-  __u.bits &= 0xffffffff00000000ull;                            \
+-  __u.bits |= (uint32_t)(lo);                                   \
+-  (d) = __u.value;                                              \
++#define SET_LOW_WORD(d,lo)                        \
++do {                                              \
++  union {double f; uint64_t i;} __u;              \
++  __u.f = (d);                                    \
++  __u.i &= 0xffffffff00000000ull;                 \
++  __u.i |= (uint32_t)(lo);                        \
++  (d) = __u.f;                                    \
+ } while (0)
+ 
+ /* Get a 32 bit int from a float.  */
+-#define GET_FLOAT_WORD(i,d)                                     \
+-do {                                                            \
+-  union fshape __u;                                             \
+-  __u.value = (d);                                              \
+-  (i) = __u.bits;                                               \
++#define GET_FLOAT_WORD(w,d)                       \
++do {                                              \
++  union {float f; uint32_t i;} __u;               \
++  __u.f = (d);                                    \
++  (w) = __u.i;                                    \
+ } while (0)
+ 
+ /* Set a float from a 32 bit int.  */
+-#define SET_FLOAT_WORD(d,i)                                     \
+-do {                                                            \
+-  union fshape __u;                                             \
+-  __u.bits = (i);                                               \
+-  (d) = __u.value;                                              \
++#define SET_FLOAT_WORD(d,w)                       \
++do {                                              \
++  union {float f; uint32_t i;} __u;               \
++  __u.i = (w);                                    \
++  (d) = __u.f;                                    \
+ } while (0)
+ 
+ /* fdlibm kernel functions */
+@@ -157,15 +155,4 @@
+ long double __polevll(long double, const long double *, int);
+ long double __p1evll(long double, const long double *, int);
+ 
+-#if 0
+-/* Attempt to get strict C99 semantics for assignment with non-C99 compilers. */
+-#define STRICT_ASSIGN(type, lval, rval) do {    \
+-        volatile type __v = (rval);             \
+-        (lval) = __v;                           \
+-} while (0)
+-#else
+-/* Should work with -fexcess-precision=standard (>=gcc-4.5) or -ffloat-store */
+-#define STRICT_ASSIGN(type, lval, rval) ((lval) = (type)(rval))
+-#endif
+-
+ #endif
+diff -Nur musl-0.9.13/src/internal/longdbl.h musl-git/src/internal/longdbl.h
+--- musl-0.9.13/src/internal/longdbl.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/internal/longdbl.h	1970-01-01 01:00:00.000000000 +0100
+@@ -1,137 +0,0 @@
+-#ifndef _LDHACK_H
+-#define _LDHACK_H
+-
+-#include <float.h>
+-#include <stdint.h>
+-
+-#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
+-#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
+-union ldshape {
+-	long double value;
+-	struct {
+-		uint64_t m;
+-		uint16_t exp:15;
+-		uint16_t sign:1;
+-		uint16_t pad;
+-	} bits;
+-};
+-#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
+-union ldshape {
+-	long double value;
+-	struct {
+-		uint64_t mlo;
+-		uint64_t mhi:48;
+-		uint16_t exp:15;
+-		uint16_t sign:1;
+-	} bits;
+-};
+-#else
+-#error Unsupported long double representation
+-#endif
+-
+-
+-// FIXME: hacks to make freebsd+openbsd long double code happy
+-
+-// union and macros for freebsd
+-
+-#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
+-
+-union IEEEl2bits {
+-	long double e;
+-	struct {
+-		uint32_t manl:32;
+-		uint32_t manh:32;
+-		uint32_t exp:15;
+-		uint32_t sign:1;
+-		uint32_t pad:16;
+-	} bits;
+-	struct {
+-		uint64_t man:64;
+-		uint32_t expsign:16;
+-		uint32_t pad:16;
+-	} xbits;
+-};
+-
+-#define LDBL_MANL_SIZE 32
+-#define LDBL_MANH_SIZE 32
+-#define LDBL_NBIT (1ull << LDBL_MANH_SIZE-1)
+-#undef LDBL_IMPLICIT_NBIT
+-#define mask_nbit_l(u) ((u).bits.manh &= ~LDBL_NBIT)
+-
+-#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
+-/*
+-// ld128 float.h
+-//#define LDBL_MAX 1.189731495357231765085759326628007016E+4932L
+-#define LDBL_MAX 0x1.ffffffffffffffffffffffffffffp+16383
+-#define LDBL_MAX_EXP 16384
+-#define LDBL_HAS_INFINITY 1
+-//#define LDBL_MIN 3.362103143112093506262677817321752603E-4932L
+-#define LDBL_MIN 0x1p-16382
+-#define LDBL_HAS_QUIET_NAN 1
+-#define LDBL_HAS_DENORM 1
+-//#define LDBL_EPSILON 1.925929944387235853055977942584927319E-34L
+-#define LDBL_EPSILON 0x1p-112
+-#define LDBL_MANT_DIG 113
+-#define LDBL_MIN_EXP (-16381)
+-#define LDBL_MAX_10_EXP 4932
+-#define LDBL_DENORM_MIN 0x0.0000000000000000000000000001p-16381
+-#define LDBL_MIN_10_EXP (-4931)
+-#define LDBL_DIG 33
+-*/
+-
+-union IEEEl2bits {
+-	long double e;
+-	struct {
+-		uint64_t manl:64;
+-		uint64_t manh:48;
+-		uint32_t exp:15;
+-		uint32_t sign:1;
+-	} bits;
+-	struct {
+-		uint64_t unused0:64;
+-		uint64_t unused1:48;
+-		uint32_t expsign:16;
+-	} xbits;
+-};
+-
+-#define LDBL_MANL_SIZE 64
+-#define LDBL_MANH_SIZE 48
+-#define LDBL_NBIT (1ull << LDBL_MANH_SIZE)
+-#define LDBL_IMPLICIT_NBIT 1
+-#define mask_nbit_l(u)
+-
+-#endif
+-
+-
+-// macros for openbsd
+-
+-#define GET_LDOUBLE_WORDS(se,mh,ml, f) do{ \
+-	union IEEEl2bits u; \
+-	u.e = (f); \
+-	(se) = u.xbits.expsign; \
+-	(mh) = u.bits.manh; \
+-	(ml) = u.bits.manl; \
+-}while(0)
+-
+-#define SET_LDOUBLE_WORDS(f,  se,mh,ml) do{ \
+-	union IEEEl2bits u; \
+-	u.xbits.expsign = (se); \
+-	u.bits.manh = (mh); \
+-	u.bits.manl = (ml); \
+-	(f) = u.e; \
+-}while(0)
+-
+-#define GET_LDOUBLE_EXP(se, f) do{ \
+-	union IEEEl2bits u; \
+-	u.e = (f); \
+-	(se) = u.xbits.expsign; \
+-}while(0)
+-
+-#define SET_LDOUBLE_EXP(f, se) do{ \
+-	union IEEEl2bits u; \
+-	u.e = (f); \
+-	u.xbits.expsign = (se); \
+-	(f) = u.e; \
+-}while(0)
+-
+-#endif
+diff -Nur musl-0.9.13/src/ldso/dynlink.c musl-git/src/ldso/dynlink.c
+--- musl-0.9.13/src/ldso/dynlink.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/ldso/dynlink.c	2013-09-16 20:31:39.000000000 +0200
+@@ -614,6 +614,8 @@
+ 						sys_path = "";
+ 					}
+ 					fclose(f);
++				} else if (errno != ENOENT) {
++					sys_path = "";
+ 				}
+ 			}
+ 			if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
+@@ -978,6 +980,7 @@
+ 		env_preload = 0;
+ 		libc.secure = 1;
+ 	}
++	libc.page_size = aux[AT_PAGESZ];
+ 
+ 	/* If the dynamic linker was invoked as a program itself, AT_BASE
+ 	 * will not be set. In that case, we assume the base address is
+diff -Nur musl-0.9.13/src/legacy/getpagesize.c musl-git/src/legacy/getpagesize.c
+--- musl-0.9.13/src/legacy/getpagesize.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/legacy/getpagesize.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,5 +1,5 @@
+ #include <unistd.h>
+-#include <limits.h>
++#include "libc.h"
+ 
+ int getpagesize(void)
+ {
+diff -Nur musl-0.9.13/src/legacy/valloc.c musl-git/src/legacy/valloc.c
+--- musl-0.9.13/src/legacy/valloc.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/legacy/valloc.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,6 +1,6 @@
+ #define _BSD_SOURCE
+ #include <stdlib.h>
+-#include <limits.h>
++#include "libc.h"
+ 
+ void *valloc(size_t size)
+ {
+diff -Nur musl-0.9.13/src/math/__cosl.c musl-git/src/math/__cosl.c
+--- musl-0.9.13/src/math/__cosl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__cosl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,4 +1,5 @@
+ /* origin: FreeBSD /usr/src/lib/msun/ld80/k_cosl.c */
++/* origin: FreeBSD /usr/src/lib/msun/ld128/k_cosl.c */
+ /*
+  * ====================================================
+  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+@@ -14,7 +15,8 @@
+ 
+ #include "libm.h"
+ 
+-#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
++#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
++#if LDBL_MANT_DIG == 64
+ /*
+  * ld80 version of __cos.c.  See __cos.c for most comments.
+  */
+@@ -43,7 +45,6 @@
+  */
+ static const long double
+ C1 =  0.0416666666666666666136L;        /*  0xaaaaaaaaaaaaaa9b.0p-68 */
+-
+ static const double
+ C2 = -0.0013888888888888874,            /* -0x16c16c16c16c10.0p-62 */
+ C3 =  0.000024801587301571716,          /*  0x1a01a01a018e22.0p-68 */
+@@ -51,13 +52,43 @@
+ C5 =  0.0000000020876754400407278,      /*  0x11eed8caaeccf1.0p-81 */
+ C6 = -1.1470297442401303e-11,           /* -0x19393412bd1529.0p-89 */
+ C7 =  4.7383039476436467e-14;           /*  0x1aac9d9af5c43e.0p-97 */
++#define POLY(z) (z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*C7)))))))
++#elif LDBL_MANT_DIG == 113
++/*
++ * ld128 version of __cos.c.  See __cos.c for most comments.
++ */
++/*
++ * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]:
++ * |cos(x) - c(x))| < 2**-122.0
++ *
++ * 113-bit precision requires more care than 64-bit precision, since
++ * simple methods give a minimax polynomial with coefficient for x^2
++ * that is 1 ulp below 0.5, but we want it to be precisely 0.5.  See
++ * above for more details.
++ */
++static const long double
++C1 =  0.04166666666666666666666666666666658424671L,
++C2 = -0.001388888888888888888888888888863490893732L,
++C3 =  0.00002480158730158730158730158600795304914210L,
++C4 = -0.2755731922398589065255474947078934284324e-6L,
++C5 =  0.2087675698786809897659225313136400793948e-8L,
++C6 = -0.1147074559772972315817149986812031204775e-10L,
++C7 =  0.4779477332386808976875457937252120293400e-13L;
++static const double
++C8 = -0.1561920696721507929516718307820958119868e-15,
++C9 =  0.4110317413744594971475941557607804508039e-18,
++C10 = -0.8896592467191938803288521958313920156409e-21,
++C11 =  0.1601061435794535138244346256065192782581e-23;
++#define POLY(z) (z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+ \
++	z*(C8+z*(C9+z*(C10+z*C11)))))))))))
++#endif
+ 
+ long double __cosl(long double x, long double y)
+ {
+ 	long double hz,z,r,w;
+ 
+ 	z  = x*x;
+-	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*C7))))));
++	r  = POLY(z);
+ 	hz = 0.5*z;
+ 	w  = 1.0-hz;
+ 	return w + (((1.0-w)-hz) + (z*r-x*y));
+diff -Nur musl-0.9.13/src/math/__fpclassify.c musl-git/src/math/__fpclassify.c
+--- musl-0.9.13/src/math/__fpclassify.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__fpclassify.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,10 +1,11 @@
+-#include "libm.h"
++#include <math.h>
++#include <stdint.h>
+ 
+ int __fpclassify(double x)
+ {
+-	union dshape u = { x };
+-	int e = u.bits>>52 & 0x7ff;
+-	if (!e) return u.bits<<1 ? FP_SUBNORMAL : FP_ZERO;
+-	if (e==0x7ff) return u.bits<<12 ? FP_NAN : FP_INFINITE;
++	union {double f; uint64_t i;} u = {x};
++	int e = u.i>>52 & 0x7ff;
++	if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
++	if (e==0x7ff) return u.i<<12 ? FP_NAN : FP_INFINITE;
+ 	return FP_NORMAL;
+ }
+diff -Nur musl-0.9.13/src/math/__fpclassifyf.c musl-git/src/math/__fpclassifyf.c
+--- musl-0.9.13/src/math/__fpclassifyf.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__fpclassifyf.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,10 +1,11 @@
+-#include "libm.h"
++#include <math.h>
++#include <stdint.h>
+ 
+ int __fpclassifyf(float x)
+ {
+-	union fshape u = { x };
+-	int e = u.bits>>23 & 0xff;
+-	if (!e) return u.bits<<1 ? FP_SUBNORMAL : FP_ZERO;
+-	if (e==0xff) return u.bits<<9 ? FP_NAN : FP_INFINITE;
++	union {float f; uint32_t i;} u = {x};
++	int e = u.i>>23 & 0xff;
++	if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO;
++	if (e==0xff) return u.i<<9 ? FP_NAN : FP_INFINITE;
+ 	return FP_NORMAL;
+ }
+diff -Nur musl-0.9.13/src/math/__fpclassifyl.c musl-git/src/math/__fpclassifyl.c
+--- musl-0.9.13/src/math/__fpclassifyl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__fpclassifyl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -5,26 +5,28 @@
+ #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
+ int __fpclassifyl(long double x)
+ {
+-	union ldshape u = { x };
+-	int e = u.bits.exp;
+-	if (!e) {
+-		if (u.bits.m >> 63) return FP_NAN;
+-		else if (u.bits.m) return FP_SUBNORMAL;
+-		else return FP_ZERO;
+-	}
++	union ldshape u = {x};
++	int e = u.i.se & 0x7fff;
++	int msb = u.i.m>>63;
++	if (!e && !msb)
++		return u.i.m ? FP_SUBNORMAL : FP_ZERO;
++	if (!msb)
++		return FP_NAN;
+ 	if (e == 0x7fff)
+-		return u.bits.m & (uint64_t)-1>>1 ? FP_NAN : FP_INFINITE;
+-	return u.bits.m & (uint64_t)1<<63 ? FP_NORMAL : FP_NAN;
++		return u.i.m << 1 ? FP_NAN : FP_INFINITE;
++	return FP_NORMAL;
+ }
+ #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
+ int __fpclassifyl(long double x)
+ {
+-	union ldshape u = { x };
+-	int e = u.bits.exp;
++	union ldshape u = {x};
++	int e = u.i.se & 0x7fff;
+ 	if (!e)
+-		return u.bits.mlo | u.bits.mhi ? FP_SUBNORMAL : FP_ZERO;
+-	if (e == 0x7fff)
+-		return u.bits.mlo | u.bits.mhi ? FP_NAN : FP_INFINITE;
++		return u.i2.lo | u.i2.hi ? FP_SUBNORMAL : FP_ZERO;
++	if (e == 0x7fff) {
++		u.i.se = 0;
++		return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE;
++	}
+ 	return FP_NORMAL;
+ }
+ #endif
+diff -Nur musl-0.9.13/src/math/__invtrigl.c musl-git/src/math/__invtrigl.c
+--- musl-0.9.13/src/math/__invtrigl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__invtrigl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,7 +1,7 @@
++#include <float.h>
+ #include "__invtrigl.h"
+ 
+ #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
+-
+ static const long double
+ pS0 =  1.66666666666666666631e-01L,
+ pS1 = -4.16313987993683104320e-01L,
+@@ -28,4 +28,36 @@
+ 	q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*(qS4+z*qS5))));
+ 	return p/q;
+ }
++#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
++static const long double
++pS0 =  1.66666666666666666666666666666700314e-01L,
++pS1 = -7.32816946414566252574527475428622708e-01L,
++pS2 =  1.34215708714992334609030036562143589e+00L,
++pS3 = -1.32483151677116409805070261790752040e+00L,
++pS4 =  7.61206183613632558824485341162121989e-01L,
++pS5 = -2.56165783329023486777386833928147375e-01L,
++pS6 =  4.80718586374448793411019434585413855e-02L,
++pS7 = -4.42523267167024279410230886239774718e-03L,
++pS8 =  1.44551535183911458253205638280410064e-04L,
++pS9 = -2.10558957916600254061591040482706179e-07L,
++qS1 = -4.84690167848739751544716485245697428e+00L,
++qS2 =  9.96619113536172610135016921140206980e+00L,
++qS3 = -1.13177895428973036660836798461641458e+01L,
++qS4 =  7.74004374389488266169304117714658761e+00L,
++qS5 = -3.25871986053534084709023539900339905e+00L,
++qS6 =  8.27830318881232209752469022352928864e-01L,
++qS7 = -1.18768052702942805423330715206348004e-01L,
++qS8 =  8.32600764660522313269101537926539470e-03L,
++qS9 = -1.99407384882605586705979504567947007e-04L;
++
++const long double pio2_hi = 1.57079632679489661923132169163975140L;
++const long double pio2_lo = 4.33590506506189051239852201302167613e-35L;
++
++long double __invtrigl_R(long double z)
++{
++	long double p, q;
++	p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*(pS5+z*(pS6+z*(pS7+z*(pS8+z*pS9)))))))));
++	q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*(qS4+z*(qS5+z*(pS6+z*(pS7+z*(pS8+z*pS9))))))));
++	return p/q;
++}
+ #endif
+diff -Nur musl-0.9.13/src/math/__invtrigl.h musl-git/src/math/__invtrigl.h
+--- musl-0.9.13/src/math/__invtrigl.h	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__invtrigl.h	2013-09-16 20:31:39.000000000 +0200
+@@ -1,10 +1,6 @@
+-#include <float.h>
+-
+-#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
+ /* shared by acosl, asinl and atan2l */
+ #define pio2_hi __pio2_hi
+ #define pio2_lo __pio2_lo
+ extern const long double pio2_hi, pio2_lo;
+ 
+ long double __invtrigl_R(long double z);
+-#endif
+diff -Nur musl-0.9.13/src/math/__rem_pio2.c musl-git/src/math/__rem_pio2.c
+--- musl-0.9.13/src/math/__rem_pio2.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__rem_pio2.c	2013-09-16 20:31:39.000000000 +0200
+@@ -112,7 +112,7 @@
+ 		uint32_t high;
+ medium:
+ 		/* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+-		STRICT_ASSIGN(double, fn, x*invpio2 + 0x1.8p52);
++		fn = x*invpio2 + 0x1.8p52;
+ 		fn = fn - 0x1.8p52;
+ // FIXME
+ #ifdef HAVE_EFFICIENT_IRINT
+diff -Nur musl-0.9.13/src/math/__rem_pio2_large.c musl-git/src/math/__rem_pio2_large.c
+--- musl-0.9.13/src/math/__rem_pio2_large.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__rem_pio2_large.c	2013-09-16 20:31:39.000000000 +0200
+@@ -415,7 +415,8 @@
+ 		fw = 0.0;
+ 		for (i=jz; i>=0; i--)
+ 			fw += fq[i];
+-		STRICT_ASSIGN(double,fw,fw);
++		// TODO: drop excess precision here once double_t is used
++		fw = (double)fw;
+ 		y[0] = ih==0 ? fw : -fw;
+ 		fw = fq[0]-fw;
+ 		for (i=1; i<=jz; i++)
+diff -Nur musl-0.9.13/src/math/__rem_pio2f.c musl-git/src/math/__rem_pio2f.c
+--- musl-0.9.13/src/math/__rem_pio2f.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__rem_pio2f.c	2013-09-16 20:31:39.000000000 +0200
+@@ -44,7 +44,7 @@
+ 	/* 25+53 bit pi is good enough for medium size */
+ 	if (ix < 0x4dc90fdb) {  /* |x| ~< 2^28*(pi/2), medium size */
+ 		/* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+-		STRICT_ASSIGN(double, fn, x*invpio2 + 0x1.8p52);
++		fn = x*invpio2 + 0x1.8p52;
+ 		fn = fn - 0x1.8p52;
+ // FIXME
+ #ifdef HAVE_EFFICIENT_IRINT
+diff -Nur musl-0.9.13/src/math/__rem_pio2l.c musl-git/src/math/__rem_pio2l.c
+--- musl-0.9.13/src/math/__rem_pio2l.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__rem_pio2l.c	2013-09-16 20:31:39.000000000 +0200
+@@ -13,15 +13,22 @@
+  * Optimized by Bruce D. Evans.
+  */
+ #include "libm.h"
+-#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
+-/* ld80 version of __rem_pio2(x,y)
++#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
++/* ld80 and ld128 version of __rem_pio2(x,y)
+  *
+  * return the remainder of x rem pi/2 in y[0]+y[1]
+  * use __rem_pio2_large() for large x
+  */
+ 
+-#define BIAS    (LDBL_MAX_EXP - 1)
+-
++#if LDBL_MANT_DIG == 64
++/* u ~< 0x1p25*pi/2 */
++#define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < ((0x3fff + 25)<<16 | 0x921f>>1 | 0x8000))
++#define TOINT 0x1.8p63
++#define QUOBITS(x) ((uint32_t)(int32_t)x & 0x7fffffff)
++#define ROUND1 22
++#define ROUND2 61
++#define NX 3
++#define NY 2
+ /*
+  * invpio2:  64 bits of 2/pi
+  * pio2_1:   first  39 bits of pi/2
+@@ -32,60 +39,61 @@
+  * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
+  */
+ static const double
+-two24  =  1.67772160000000000000e+07, /* 0x41700000, 0x00000000 */
+ pio2_1 =  1.57079632679597125389e+00, /* 0x3FF921FB, 0x54444000 */
+ pio2_2 = -1.07463465549783099519e-12, /* -0x12e7b967674000.0p-92 */
+ pio2_3 =  6.36831716351370313614e-25; /*  0x18a2e037074000.0p-133 */
+-
+ static const long double
+ invpio2 =  6.36619772367581343076e-01L, /*  0xa2f9836e4e44152a.0p-64 */
+ pio2_1t = -1.07463465549719416346e-12L, /* -0x973dcb3b399d747f.0p-103 */
+ pio2_2t =  6.36831716351095013979e-25L, /*  0xc51701b839a25205.0p-144 */
+ pio2_3t = -2.75299651904407171810e-37L; /* -0xbb5bf6c7ddd660ce.0p-185 */
++#elif LDBL_MANT_DIG == 113
++/* u ~< 0x1p45*pi/2 */
++#define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.top) < ((0x3fff + 45)<<16 | 0x921f))
++#define TOINT 0x1.8p112
++#define QUOBITS(x) ((uint32_t)(int64_t)x & 0x7fffffff)
++#define ROUND1 51
++#define ROUND2 119
++#define NX 5
++#define NY 3
++static const long double
++invpio2 =  6.3661977236758134307553505349005747e-01L,	/*  0x145f306dc9c882a53f84eafa3ea6a.0p-113 */
++pio2_1  =  1.5707963267948966192292994253909555e+00L,	/*  0x1921fb54442d18469800000000000.0p-112 */
++pio2_1t =  2.0222662487959507323996846200947577e-21L,	/*  0x13198a2e03707344a4093822299f3.0p-181 */
++pio2_2  =  2.0222662487959507323994779168837751e-21L,	/*  0x13198a2e03707344a400000000000.0p-181 */
++pio2_2t =  2.0670321098263988236496903051604844e-43L,	/*  0x127044533e63a0105df531d89cd91.0p-254 */
++pio2_3  =  2.0670321098263988236499468110329591e-43L,	/*  0x127044533e63a0105e00000000000.0p-254 */
++pio2_3t = -2.5650587247459238361625433492959285e-65L;	/* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */
++#endif
+ 
+ int __rem_pio2l(long double x, long double *y)
+ {
+-	union IEEEl2bits u,u1;
++	union ldshape u,uz;
+ 	long double z,w,t,r,fn;
+-	double tx[3],ty[2];
+-	int e0,ex,i,j,nx,n;
+-	int16_t expsign;
+-
+-	u.e = x;
+-	expsign = u.xbits.expsign;
+-	ex = expsign & 0x7fff;
+-	if (ex < BIAS + 25 || (ex == BIAS + 25 && u.bits.manh < 0xc90fdaa2)) {
+-		union IEEEl2bits u2;
+-		int ex1;
++	double tx[NX],ty[NY];
++	int ex,ey,n,i;
+ 
+-		/* |x| ~< 2^25*(pi/2), medium size */
+-		/* Use a specialized rint() to get fn.  Assume round-to-nearest. */
+-		fn = x*invpio2 + 0x1.8p63;
+-		fn = fn - 0x1.8p63;
+-// FIXME
+-//#ifdef HAVE_EFFICIENT_IRINT
+-//		n = irint(fn);
+-//#else
+-		n = fn;
+-//#endif
++	u.f = x;
++	ex = u.i.se & 0x7fff;
++	if (SMALL(u)) {
++		/* rint(x/(pi/2)), Assume round-to-nearest. */
++		fn = x*invpio2 + TOINT - TOINT;
++		n = QUOBITS(fn);
+ 		r = x-fn*pio2_1;
+-		w = fn*pio2_1t;    /* 1st round good to 102 bit */
+-		j = ex;
++		w = fn*pio2_1t;  /* 1st round good to 102/180 bits (ld80/ld128) */
+ 		y[0] = r-w;
+-		u2.e = y[0];
+-		ex1 = u2.xbits.expsign & 0x7fff;
+-		i = j-ex1;
+-		if (i > 22) {  /* 2nd iteration needed, good to 141 */
++		u.f = y[0];
++		ey = u.i.se & 0x7fff;
++		if (ex - ey > ROUND1) {  /* 2nd iteration needed, good to 141/248 (ld80/ld128) */
+ 			t = r;
+ 			w = fn*pio2_2;
+ 			r = t-w;
+ 			w = fn*pio2_2t-((t-r)-w);
+ 			y[0] = r-w;
+-			u2.e = y[0];
+-			ex1 = u2.xbits.expsign & 0x7fff;
+-			i = j-ex1;
+-			if (i > 61) {  /* 3rd iteration need, 180 bits acc */
+-				t = r; /* will cover all possible cases */
++			u.f = y[0];
++			ey = u.i.se & 0x7fff;
++			if (ex - ey > ROUND2) {  /* 3rd iteration, good to 180/316 bits */
++				t = r; /* will cover all possible cases (not verified for ld128) */
+ 				w = fn*pio2_3;
+ 				r = t-w;
+ 				w = fn*pio2_3t-((t-r)-w);
+@@ -102,23 +110,26 @@
+ 		y[0] = y[1] = x - x;
+ 		return 0;
+ 	}
+-	/* set z = scalbn(|x|,ilogb(x)-23) */
+-	u1.e = x;
+-	e0 = ex - BIAS - 23;            /* e0 = ilogb(|x|)-23; */
+-	u1.xbits.expsign = ex - e0;
+-	z = u1.e;
+-	for (i=0; i<2; i++) {
++	/* set z = scalbn(|x|,-ilogb(x)+23) */
++	uz.f = x;
++	uz.i.se = 0x3fff + 23;
++	z = uz.f;
++	for (i=0; i < NX - 1; i++) {
+ 		tx[i] = (double)(int32_t)z;
+-		z     = (z-tx[i])*two24;
++		z     = (z-tx[i])*0x1p24;
+ 	}
+-	tx[2] = z;
+-	nx = 3;
+-	while (tx[nx-1] == 0.0)
+-		nx--;     /* skip zero term */
+-	n = __rem_pio2_large(tx,ty,e0,nx,2);
+-	r = (long double)ty[0] + ty[1];
+-	w = ty[1] - (r - ty[0]);
+-	if (expsign < 0) {
++	tx[i] = z;
++	while (tx[i] == 0)
++		i--;
++	n = __rem_pio2_large(tx, ty, ex-0x3fff-23, i+1, NY);
++	w = ty[1];
++	if (NY == 3)
++		w += ty[2];
++	r = ty[0] + w;
++	/* TODO: for ld128 this does not follow the recommendation of the
++	comments of __rem_pio2_large which seem wrong if |ty[0]| > |ty[1]+ty[2]| */
++	w -= r - ty[0];
++	if (u.i.se >> 15) {
+ 		y[0] = -r;
+ 		y[1] = -w;
+ 		return -n;
+diff -Nur musl-0.9.13/src/math/__signbitl.c musl-git/src/math/__signbitl.c
+--- musl-0.9.13/src/math/__signbitl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__signbitl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,11 +1,9 @@
+ #include "libm.h"
+ 
+-// FIXME: should be a macro
+ #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
+ int __signbitl(long double x)
+ {
+ 	union ldshape u = {x};
+-
+-	return u.bits.sign;
++	return u.i.se >> 15;
+ }
+ #endif
+diff -Nur musl-0.9.13/src/math/__sinl.c musl-git/src/math/__sinl.c
+--- musl-0.9.13/src/math/__sinl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__sinl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,4 +1,5 @@
+ /* origin: FreeBSD /usr/src/lib/msun/ld80/k_sinl.c */
++/* origin: FreeBSD /usr/src/lib/msun/ld128/k_sinl.c */
+ /*
+  * ====================================================
+  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+@@ -13,7 +14,8 @@
+ 
+ #include "libm.h"
+ 
+-#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
++#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
++#if LDBL_MANT_DIG == 64
+ /*
+  * ld80 version of __sin.c.  See __sin.c for most comments.
+  */
+@@ -23,10 +25,8 @@
+  *
+  * See __cosl.c for more details about the polynomial.
+  */
+-
+ static const long double
+ S1 = -0.166666666666666666671L;   /* -0xaaaaaaaaaaaaaaab.0p-66 */
+-
+ static const double
+ S2 =  0.0083333333333333332,      /*  0x11111111111111.0p-59 */
+ S3 = -0.00019841269841269427,     /* -0x1a01a01a019f81.0p-65 */
+@@ -35,6 +35,34 @@
+ S6 =  1.6059006598854211e-10,     /*  0x161242b90243b5.0p-85 */
+ S7 = -7.6429779983024564e-13,     /* -0x1ae42ebd1b2e00.0p-93 */
+ S8 =  2.6174587166648325e-15;     /*  0x179372ea0b3f64.0p-101 */
++#define POLY(z) (S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*S8))))))
++#elif LDBL_MANT_DIG == 113
++/*
++ * ld128 version of __sin.c.  See __sin.c for most comments.
++ */
++/*
++ * Domain [-0.7854, 0.7854], range ~[-1.53e-37, 1.659e-37]
++ * |sin(x)/x - s(x)| < 2**-122.1
++ *
++ * See __cosl.c for more details about the polynomial.
++ */
++static const long double
++S1 = -0.16666666666666666666666666666666666606732416116558L,
++S2 =  0.0083333333333333333333333333333331135404851288270047L,
++S3 = -0.00019841269841269841269841269839935785325638310428717L,
++S4 =  0.27557319223985890652557316053039946268333231205686e-5L,
++S5 = -0.25052108385441718775048214826384312253862930064745e-7L,
++S6 =  0.16059043836821614596571832194524392581082444805729e-9L,
++S7 = -0.76471637318198151807063387954939213287488216303768e-12L,
++S8 =  0.28114572543451292625024967174638477283187397621303e-14L;
++static const double
++S9  = -0.82206352458348947812512122163446202498005154296863e-17,
++S10 =  0.19572940011906109418080609928334380560135358385256e-19,
++S11 = -0.38680813379701966970673724299207480965452616911420e-22,
++S12 =  0.64038150078671872796678569586315881020659912139412e-25;
++#define POLY(z) (S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*(S8+ \
++	z*(S9+z*(S10+z*(S11+z*S12))))))))))
++#endif
+ 
+ long double __sinl(long double x, long double y, int iy)
+ {
+@@ -42,7 +70,7 @@
+ 
+ 	z = x*x;
+ 	v = z*x;
+-	r = S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*S8)))));
++	r = POLY(z);
+ 	if (iy == 0)
+ 		return x+v*(S1+z*r);
+ 	return x-((z*(0.5*y-v*r)-y)-v*S1);
+diff -Nur musl-0.9.13/src/math/__tanl.c musl-git/src/math/__tanl.c
+--- musl-0.9.13/src/math/__tanl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/__tanl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -1,4 +1,5 @@
+ /* origin: FreeBSD /usr/src/lib/msun/ld80/k_tanl.c */
++/* origin: FreeBSD /usr/src/lib/msun/ld128/k_tanl.c */
+ /*
+  * ====================================================
+  * Copyright 2004 Sun Microsystems, Inc.  All Rights Reserved.
+@@ -12,7 +13,8 @@
+ 
+ #include "libm.h"
+ 
+-#if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
++#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
++#if LDBL_MANT_DIG == 64
+ /*
+  * ld80 version of __tan.c.  See __tan.c for most comments.
+  */
+@@ -22,14 +24,12 @@
+  *
+  * See __cosl.c for more details about the polynomial.
+  */
+-
+ static const long double
+ T3 =  0.333333333333333333180L,         /*  0xaaaaaaaaaaaaaaa5.0p-65 */
+ T5 =  0.133333333333333372290L,         /*  0x88888888888893c3.0p-66 */
+ T7 =  0.0539682539682504975744L,        /*  0xdd0dd0dd0dc13ba2.0p-68 */
+ pio4   =  0.785398163397448309628L,     /*  0xc90fdaa22168c235.0p-64 */
+ pio4lo = -1.25413940316708300586e-20L;  /* -0xece675d1fc8f8cbb.0p-130 */
+-
+ static const double
+ T9  =  0.021869488536312216,            /*  0x1664f4882cc1c2.0p-58 */
+ T11 =  0.0088632355256619590,           /*  0x1226e355c17612.0p-59 */
+@@ -44,6 +44,59 @@
+ T29 =  0.0000078293456938132840,        /*  0x106b59141a6cb3.0p-69 */
+ T31 = -0.0000032609076735050182,        /* -0x1b5abef3ba4b59.0p-71 */
+ T33 =  0.0000023261313142559411;        /*  0x13835436c0c87f.0p-71 */
++#define RPOLY(w) (T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + \
++	w * (T25 + w * (T29 + w * T33)))))))
++#define VPOLY(w) (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + \
++	w * (T27 + w * T31))))))
++#elif LDBL_MANT_DIG == 113
++/*
++ * ld128 version of __tan.c.  See __tan.c for most comments.
++ */
++/*
++ * Domain [-0.67434, 0.67434], range ~[-3.37e-36, 1.982e-37]
++ * |tan(x)/x - t(x)| < 2**-117.8 (XXX should be ~1e-37)
++ *
++ * See __cosl.c for more details about the polynomial.
++ */
++static const long double
++T3 = 0x1.5555555555555555555555555553p-2L,
++T5 = 0x1.1111111111111111111111111eb5p-3L,
++T7 = 0x1.ba1ba1ba1ba1ba1ba1ba1b694cd6p-5L,
++T9 = 0x1.664f4882c10f9f32d6bbe09d8bcdp-6L,
++T11 = 0x1.226e355e6c23c8f5b4f5762322eep-7L,
++T13 = 0x1.d6d3d0e157ddfb5fed8e84e27b37p-9L,
++T15 = 0x1.7da36452b75e2b5fce9ee7c2c92ep-10L,
++T17 = 0x1.355824803674477dfcf726649efep-11L,
++T19 = 0x1.f57d7734d1656e0aceb716f614c2p-13L,
++T21 = 0x1.967e18afcb180ed942dfdc518d6cp-14L,
++T23 = 0x1.497d8eea21e95bc7e2aa79b9f2cdp-15L,
++T25 = 0x1.0b132d39f055c81be49eff7afd50p-16L,
++T27 = 0x1.b0f72d33eff7bfa2fbc1059d90b6p-18L,
++T29 = 0x1.5ef2daf21d1113df38d0fbc00267p-19L,
++T31 = 0x1.1c77d6eac0234988cdaa04c96626p-20L,
++T33 = 0x1.cd2a5a292b180e0bdd701057dfe3p-22L,
++T35 = 0x1.75c7357d0298c01a31d0a6f7d518p-23L,
++T37 = 0x1.2f3190f4718a9a520f98f50081fcp-24L,
++pio4 = 0x1.921fb54442d18469898cc51701b8p-1L,
++pio4lo = 0x1.cd129024e088a67cc74020bbea60p-116L;
++static const double
++T39 =  0.000000028443389121318352,	/*  0x1e8a7592977938.0p-78 */
++T41 =  0.000000011981013102001973,	/*  0x19baa1b1223219.0p-79 */
++T43 =  0.0000000038303578044958070,	/*  0x107385dfb24529.0p-80 */
++T45 =  0.0000000034664378216909893,	/*  0x1dc6c702a05262.0p-81 */
++T47 = -0.0000000015090641701997785,	/* -0x19ecef3569ebb6.0p-82 */
++T49 =  0.0000000029449552300483952,	/*  0x194c0668da786a.0p-81 */
++T51 = -0.0000000022006995706097711,	/* -0x12e763b8845268.0p-81 */
++T53 =  0.0000000015468200913196612,	/*  0x1a92fc98c29554.0p-82 */
++T55 = -0.00000000061311613386849674,	/* -0x151106cbc779a9.0p-83 */
++T57 =  1.4912469681508012e-10;		/*  0x147edbdba6f43a.0p-85 */
++#define RPOLY(w) (T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + \
++	w * (T25 + w * (T29 + w * (T33 + w * (T37 + w * (T41 + \
++	w * (T45 + w * (T49 + w * (T53 + w * T57)))))))))))))
++#define VPOLY(w) (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + \
++	w * (T27 + w * (T31 + w * (T35 + w * (T39 + w * (T43 + \
++	w * (T47 + w * (T51 + w * T55))))))))))))
++#endif
+ 
+ long double __tanl(long double x, long double y, int odd) {
+ 	long double z, r, v, w, s, a, t;
+@@ -62,10 +115,8 @@
+ 	}
+ 	z = x * x;
+ 	w = z * z;
+-	r = T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 +
+-	     w * (T25 + w * (T29 + w * T33))))));
+-	v = z * (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 +
+-	     w * (T27 + w * T31))))));
++	r = RPOLY(w);
++	v = z * VPOLY(w);
+ 	s = z * x;
+ 	r = y + z * (s * (r + v) + y) + T3 * s;
+ 	w = x + r;
+@@ -76,7 +127,6 @@
+ 	}
+ 	if (!odd)
+ 		return w;
+-
+ 	/*
+ 	 * if allow error up to 2 ulp, simply return
+ 	 * -1.0 / (x+r) here
+diff -Nur musl-0.9.13/src/math/acoshf.c musl-git/src/math/acoshf.c
+--- musl-0.9.13/src/math/acoshf.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/acoshf.c	2013-09-16 20:31:39.000000000 +0200
+@@ -3,14 +3,15 @@
+ /* acosh(x) = log(x + sqrt(x*x-1)) */
+ float acoshf(float x)
+ {
+-	union {float f; int32_t i;} u = {.f = x};
++	union {float f; uint32_t i;} u = {x};
++	uint32_t a = u.i & 0x7fffffff;
+ 
+-	if (u.i < 0x3f800000+(1<<23))
+-		/* x < 2, invalid if x < 1 or nan */
++	if (a < 0x3f800000+(1<<23))
++		/* |x| < 2, invalid if x < 1 or nan */
+ 		/* up to 2ulp error in [1,1.125] */
+ 		return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1)));
+-	if (u.i < 0x3f800000+(12<<23))
+-		/* x < 0x1p12 */
++	if (a < 0x3f800000+(12<<23))
++		/* |x| < 0x1p12 */
+ 		return logf(2*x - 1/(x+sqrtf(x*x-1)));
+ 	/* x >= 0x1p12 */
+ 	return logf(x) + 0.693147180559945309417232121458176568f;
+diff -Nur musl-0.9.13/src/math/acoshl.c musl-git/src/math/acoshl.c
+--- musl-0.9.13/src/math/acoshl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/acoshl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -9,16 +9,14 @@
+ /* acosh(x) = log(x + sqrt(x*x-1)) */
+ long double acoshl(long double x)
+ {
+-	union {
+-		long double f;
+-		struct{uint64_t m; int16_t se; uint16_t pad;} i;
+-	} u = {.f = x};
++	union ldshape u = {x};
++	int e = u.i.se & 0x7fff;
+ 
+-	if (u.i.se < 0x3fff + 1)
+-		/* x < 2, invalid if x < 1 or nan */
++	if (e < 0x3fff + 1)
++		/* |x| < 2, invalid if x < 1 or nan */
+ 		return log1pl(x-1 + sqrtl((x-1)*(x-1)+2*(x-1)));
+-	if (u.i.se < 0x3fff + 32)
+-		/* x < 0x1p32 */
++	if (e < 0x3fff + 32)
++		/* |x| < 0x1p32 */
+ 		return logl(2*x - 1/(x+sqrtl(x*x-1)));
+ 	return logl(x) + 0.693147180559945309417232121458176568L;
+ }
+diff -Nur musl-0.9.13/src/math/acosl.c musl-git/src/math/acosl.c
+--- musl-0.9.13/src/math/acosl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/acosl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -23,46 +23,45 @@
+ }
+ #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
+ #include "__invtrigl.h"
++#if LDBL_MANT_DIG == 64
++#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32)
++#elif LDBL_MANT_DIG == 113
++#define CLEARBOTTOM(u) (u.i.lo = 0)
++#endif
+ 
+ long double acosl(long double x)
+ {
+-	union IEEEl2bits u;
+-	long double z, w, s, c, df;
+-	int16_t expsign, expt;
+-	u.e = x;
+-	expsign = u.xbits.expsign;
+-	expt = expsign & 0x7fff;
++	union ldshape u = {x};
++	long double z, s, c, f;
++	uint16_t e = u.i.se & 0x7fff;
++
+ 	/* |x| >= 1 or nan */
+-	if (expt >= 0x3fff) {
+-		if (expt == 0x3fff &&
+-			((u.bits.manh & ~LDBL_NBIT) | u.bits.manl) == 0) {
+-			if (expsign > 0)
+-				return 0;  /* acos(1) = 0 */
+-			return 2*pio2_hi + 0x1p-120f;  /* acos(-1)= pi */
+-		}
+-		return 0/(x-x);  /* acos(|x|>1) is NaN */
++	if (e >= 0x3fff) {
++		if (x == 1)
++			return 0;
++		if (x == -1)
++			return 2*pio2_hi + 0x1p-120f;
++		return 0/(x-x);
+ 	}
+ 	/* |x| < 0.5 */
+-	if (expt < 0x3fff - 1) {
+-		if (expt < 0x3fff - 65)
+-			return pio2_hi + 0x1p-120f;  /* x < 0x1p-65: acosl(x)=pi/2 */
+-		return pio2_hi - (x - (pio2_lo - x * __invtrigl_R(x*x)));
++	if (e < 0x3fff - 1) {
++		if (e < 0x3fff - LDBL_MANT_DIG - 1)
++			return pio2_hi + 0x1p-120f;
++		return pio2_hi - (__invtrigl_R(x*x)*x - pio2_lo + x);
+ 	}
+ 	/* x < -0.5 */
+-	if (expsign < 0) {
+-		z = (1.0 + x) * 0.5;
++	if (u.i.se >> 15) {
++		z = (1 + x)*0.5;
+ 		s = sqrtl(z);
+-		w = __invtrigl_R(z) * s - pio2_lo;
+-		return 2*(pio2_hi - (s + w));
++		return 2*(pio2_hi - (__invtrigl_R(z)*s - pio2_lo + s));
+ 	}
+ 	/* x > 0.5 */
+-	z = (1.0 - x) * 0.5;
++	z = (1 - x)*0.5;
+ 	s = sqrtl(z);
+-	u.e = s;
+-	u.bits.manl = 0;
+-	df = u.e;
+-	c = (z - df * df) / (s + df);
+-	w = __invtrigl_R(z) * s + c;
+-	return 2*(df + w);
++	u.f = s;
++	CLEARBOTTOM(u);
++	f = u.f;
++	c = (z - f*f)/(s + f);
++	return 2*(__invtrigl_R(z)*s + c + f);
+ }
+ #endif
+diff -Nur musl-0.9.13/src/math/asinhl.c musl-git/src/math/asinhl.c
+--- musl-0.9.13/src/math/asinhl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/asinhl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -9,10 +9,7 @@
+ /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */
+ long double asinhl(long double x)
+ {
+-	union {
+-		long double f;
+-		struct{uint64_t m; uint16_t se; uint16_t pad;} i;
+-	} u = {.f = x};
++	union ldshape u = {x};
+ 	unsigned e = u.i.se & 0x7fff;
+ 	unsigned s = u.i.se >> 15;
+ 
+diff -Nur musl-0.9.13/src/math/asinl.c musl-git/src/math/asinl.c
+--- musl-0.9.13/src/math/asinl.c	2013-08-30 23:30:53.000000000 +0200
++++ musl-git/src/math/asinl.c	2013-09-16 20:31:39.000000000 +0200
+@@ -23,27 +23,29 @@
+ }
+ #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
+ #include "__invtrigl.h"
+-/* 0.95 */
+-#define THRESH  ((0xe666666666666666ULL>>(64-(LDBL_MANH_SIZE-1)))|LDBL_NBIT)
++#if LDBL_MANT_DIG == 64
++#define CLOSETO1(u) (u.i.m>>56 >= 0xf7)
++#define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32)
++#elif LDBL_MANT_DIG == 113
++#define CLOSETO1(u) (u.i.top >= 0xee00)
++#define CLEARBOTTOM(u) (u.i.lo = 0)
++#endif
+ 
+ long double asinl(long double x)
+ {
+-	union IEEEl2bits u;
+-	long double z,r,s;
+-	uint16_t expsign, expt;
++	union ldshape u = {x};
++	long double z, r, s;
++	uint16_t e = u.i.se & 0x7fff;
++	int sign = u.i.se >> 15;
+ 
+-	u.e = x;
+-	expsign = u.xbits.expsign;
+-	expt = expsign & 0x7fff;
+-	if (expt >= 0x3fff) {   /* |x| >= 1 or nan */
+-		if (expt == 0x3fff &&
+-		    ((u.bits.manh&~LDBL_NBIT)|u.bits.manl) == 0)
+-			/* asin(+-1)=+-pi/2 with inexact */
++	if (e >= 0x3fff) {   /* |x| >= 1 or nan */
++		/* asin(+-1)=+-pi/2 with inexact */
++		if (x == 1 || x == -1)
+ 			return x*pio2_hi + 0x1p-120f;
+ 		return 0/(x-x);
+ 	}
+-	if (expt < 0x3fff - 1) {  /* |x| < 0.5 */
+-		if (expt < 0x3fff - 32) {  /* |x|<0x1p-32, asinl(x)=x */
++	if (e < 0x3fff - 1) {  /* |x| < 0.5 */
++		if (e < 0x3fff - (LDBL_MANT_DIG+1)/2) {
+ 			/* return x with