From 41c5ee50eee769f85253946e4c4b5706de37e9e9 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 8 Sep 2012 22:48:22 -0400 Subject: [PATCH 01/16] disable sync_file_range for now something is wrong with the logic for the argument layout, resulting in compile errors on mips due to too many args to syscall... further information on how it's supposed to work will be needed before it can be reactivated. --- src/linux/sync_file_range.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/linux/sync_file_range.c b/src/linux/sync_file_range.c index 739e602a..a47dc386 100644 --- a/src/linux/sync_file_range.c +++ b/src/linux/sync_file_range.c @@ -1,13 +1,14 @@ #define _GNU_SOURCE #include +#include #include "syscall.h" int sync_file_range(int fd, off_t pos, off_t len, unsigned flags) { -#if defined(SYS_sync_file_range2) +#if 0 && defined(SYS_sync_file_range2) return syscall(SYS_sync_file_range2, fd, flags, __SYSCALL_LL_E(pos), __SYSCALL_LL_E(len)); -#elif defined(SYS_sync_file_range) +#elif 0 && defined(SYS_sync_file_range) return syscall(SYS_sync_file_range, fd, __SYSCALL_LL_O(pos), __SYSCALL_LL_E(len), flags); #else -- 2.20.1 From 21419914c530c505cb450733b724257be703d9db Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 00:55:31 -0400 Subject: [PATCH 02/16] fix broken mips syscall asm this code was using $10 to save the syscall number, but $10 is not necessarily preserved by the kernel across syscalls. only mattered for syscalls that got interrupted by a signal and restarted. as far as i can tell, $25 is preserved by the kernel across syscalls. --- src/internal/mips/syscall.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/internal/mips/syscall.s b/src/internal/mips/syscall.s index 01a5917b..28575408 100644 --- a/src/internal/mips/syscall.s +++ b/src/internal/mips/syscall.s @@ -3,7 +3,7 @@ .global __syscall .type __syscall,@function __syscall: - move $10, $4 + move $25, $4 move $4, $5 move $5, $6 move $6, $7 @@ -13,7 +13,7 @@ __syscall: subu $sp, $sp, 32 sw $8, 16($sp) sw $9, 20($sp) - move $2, $10 + move $2, $25 syscall beq $7, $0, 1f addu $sp, $sp, 32 -- 2.20.1 From be48e22b424b6f858da0151a0b3b68bdb96b41ca Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 00:59:30 -0400 Subject: [PATCH 03/16] fix mips syscall_cp_asm code (saved register usage) --- src/thread/mips/syscall_cp.s | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/thread/mips/syscall_cp.s b/src/thread/mips/syscall_cp.s index 9a796bd6..8dd4c442 100644 --- a/src/thread/mips/syscall_cp.s +++ b/src/thread/mips/syscall_cp.s @@ -7,7 +7,7 @@ __syscall_cp_asm: __cp_begin: lw $4, 0($4) bne $4, $0, 2f - move $10, $5 + move $25, $5 move $4, $6 move $5, $7 lw $6, 16($sp) @@ -17,7 +17,7 @@ __cp_begin: subu $sp, $sp, 32 sw $8, 16($sp) sw $9, 20($sp) - move $2, $10 + move $2, $25 syscall .global __cp_end __cp_end: -- 2.20.1 From 328810d32524e4928fec50b57e37e1bf330b2e40 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 01:01:19 -0400 Subject: [PATCH 04/16] inline syscall support for mips this drastically reduces the size of some functions which are purely syscall wrappers. disabled for clang due to known bugs satisfying register constraints. --- arch/mips/syscall_arch.h | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/arch/mips/syscall_arch.h b/arch/mips/syscall_arch.h index 68e8dce3..f3df2dcd 100644 --- a/arch/mips/syscall_arch.h +++ b/arch/mips/syscall_arch.h @@ -5,6 +5,61 @@ #define __SYSCALL_SSLEN 16 +#ifndef __clang__ + +#define __asm_syscall(...) do { \ + register long r2 __asm__("$2"); \ + register long r7 __asm__("$7"); \ + __asm__ __volatile__ ( \ + "move $2,%2 ; syscall" \ + : "=&r"(r2), "=r"(r7) : __VA_ARGS__ \ + : "$1", "$3", "$8", "$9", "$10", "$11", "$12", "$13", \ + "$14", "$15", "$24", "hi", "lo", "memory"); \ + return r7 ? -r2 : r2; \ + } while (0) + +static inline long __syscall0(long n) +{ + register long r25 __asm__("$25") = n; + __asm_syscall("r"(r25)); +} + +static inline long __syscall1(long n, long a) +{ + register long r25 __asm__("$25") = n; + register long r4 __asm__("$4") = a; + __asm_syscall("r"(r25), "r"(r4)); +} + +static inline long __syscall2(long n, long a, long b) +{ + register long r25 __asm__("$25") = n; + register long r4 __asm__("$4") = a; + register long r5 __asm__("$5") = b; + __asm_syscall("r"(r25), "r"(r4), "r"(r5)); +} + +static inline long __syscall3(long n, long a, long b, long c) +{ + register long r25 __asm__("$25") = n; + register long r4 __asm__("$4") = a; + register long r5 __asm__("$5") = b; + register long r6 __asm__("$6") = c; + __asm_syscall("r"(r25), "r"(r4), "r"(r5), "r"(r6)); +} + +static inline long __syscall4(long n, long a, long b, long c, long d) +{ + register long r25 __asm__("$25") = n; + register long r4 __asm__("$4") = a; + register long r5 __asm__("$5") = b; + register long r6 __asm__("$6") = c; + register long r7 __asm__("$7") = d; + __asm_syscall("r"(r25), "r"(r4), "r"(r5), "r"(r6), "r"(r7)); +} + +#else + static inline long __syscall0(long n) { return (__syscall)(n); @@ -30,6 +85,8 @@ static inline long __syscall4(long n, long a, long b, long c, long d) return (__syscall)(n, a, b, c, d); } +#endif + static inline long __syscall5(long n, long a, long b, long c, long d, long e) { return (__syscall)(n, a, b, c, d, e); -- 2.20.1 From 5e3c243d8df6b1504db9c1e6442d47ed38937e02 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 01:29:19 -0400 Subject: [PATCH 05/16] inline syscall support for arm most pure-syscall-wrapper functions compile to the smallest/simplest code possible (save r7 ; load syscall # ; svc 0 ; restore r7 ; tail call to __syscall_ret). --- arch/arm/syscall_arch.h | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/arch/arm/syscall_arch.h b/arch/arm/syscall_arch.h index 48b0e36b..14ca8525 100644 --- a/arch/arm/syscall_arch.h +++ b/arch/arm/syscall_arch.h @@ -5,6 +5,57 @@ #define __SYSCALL_SSLEN 8 +#ifndef __clang__ + +#define __asm_syscall(...) do { \ + __asm__ __volatile__ ( "svc 0" \ + : "=r"(r0) : __VA_ARGS__ : "memory"); \ + return r0; \ + } while (0) + +static inline long __syscall0(long n) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0"); + __asm_syscall("r"(r7)); +} + +static inline long __syscall1(long n, long a) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0") = a; + __asm_syscall("r"(r7), "r"(r0)); +} + +static inline long __syscall2(long n, long a, long b) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0") = a; + register long r1 __asm__("r1") = b; + __asm_syscall("r"(r7), "r"(r0), "r"(r1)); +} + +static inline long __syscall3(long n, long a, long b, long c) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0") = a; + register long r1 __asm__("r1") = b; + register long r2 __asm__("r2") = c; + __asm_syscall("r"(r7), "r"(r0), "r"(r1), "r"(r2)); +} + +static inline long __syscall4(long n, long a, long b, long c, long d) +{ + register long r7 __asm__("r7") = n; + register long r0 __asm__("r0") = a; + register long r1 __asm__("r1") = b; + register long r2 __asm__("r2") = c; + register long r3 __asm__("r3") = d; + __asm_syscall("r"(r7), "r"(r0), "r"(r1), "r"(r2), "r"(r3)); +} + +#else + static inline long __syscall0(long n) { return (__syscall)(n); @@ -30,6 +81,8 @@ static inline long __syscall4(long n, long a, long b, long c, long d) return (__syscall)(n, a, b, c, d); } +#endif + static inline long __syscall5(long n, long a, long b, long c, long d, long e) { return (__syscall)(n, a, b, c, d, e); -- 2.20.1 From 9a3bbce447403d735282586786dc436ec1ffbad4 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 14:53:06 -0400 Subject: [PATCH 06/16] add 7-arg syscall support for mips no syscalls actually use that many arguments; the issue is that some syscalls with 64-bit arguments have them ordered badly so that breaking them into aligned 32-bit half-arguments wastes slots with padding, and a 7th slot is needed for the last argument. --- src/internal/mips/syscall.s | 7 +++++-- src/internal/syscall.h | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/internal/mips/syscall.s b/src/internal/mips/syscall.s index 28575408..e18a382e 100644 --- a/src/internal/mips/syscall.s +++ b/src/internal/mips/syscall.s @@ -3,17 +3,20 @@ .global __syscall .type __syscall,@function __syscall: - move $25, $4 + move $2, $4 move $4, $5 move $5, $6 move $6, $7 lw $7, 16($sp) lw $8, 20($sp) lw $9, 24($sp) + lw $10,28($sp) subu $sp, $sp, 32 sw $8, 16($sp) sw $9, 20($sp) - move $2, $25 + sw $10,24($sp) + sw $2 ,28($sp) + lw $2, 28($sp) syscall beq $7, $0, 1f addu $sp, $sp, 32 diff --git a/src/internal/syscall.h b/src/internal/syscall.h index ffaf640a..50409ef8 100644 --- a/src/internal/syscall.h +++ b/src/internal/syscall.h @@ -14,9 +14,10 @@ long __syscall_cp(long, long, long, long, long, long, long); #define __syscall4(n,a,b,c,d) __syscall4(n,(long)(a),(long)(b),(long)(c),(long)(d)) #define __syscall5(n,a,b,c,d,e) __syscall5(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e)) #define __syscall6(n,a,b,c,d,e,f) __syscall6(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),(long)(f)) +#define __syscall7(n,a,b,c,d,e,f,g) (__syscall)(n,(long)(a),(long)(b),(long)(c),(long)(d),(long)(e),(long)(f),(long)g) -#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,n,...) n -#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,6,5,4,3,2,1,0) +#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n +#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0) #define __SYSCALL_CONCAT_X(a,b) a##b #define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) #define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) -- 2.20.1 From 3d939be2e3bcd4bfaf5cba27c9122a77a9c67021 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 14:58:55 -0400 Subject: [PATCH 07/16] reenable sync_file_range; should no longer break on mips --- src/linux/sync_file_range.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linux/sync_file_range.c b/src/linux/sync_file_range.c index a47dc386..6859abc0 100644 --- a/src/linux/sync_file_range.c +++ b/src/linux/sync_file_range.c @@ -5,10 +5,10 @@ int sync_file_range(int fd, off_t pos, off_t len, unsigned flags) { -#if 0 && defined(SYS_sync_file_range2) +#if defined(SYS_sync_file_range2) return syscall(SYS_sync_file_range2, fd, flags, __SYSCALL_LL_E(pos), __SYSCALL_LL_E(len)); -#elif 0 && defined(SYS_sync_file_range) +#elif defined(SYS_sync_file_range) return syscall(SYS_sync_file_range, fd, __SYSCALL_LL_O(pos), __SYSCALL_LL_E(len), flags); #else -- 2.20.1 From 141138c41b5b1cbb74c61690c9b6dbacce4e1983 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:09:29 -0400 Subject: [PATCH 08/16] add linux ppoll syscall wrapper --- include/poll.h | 10 ++++++++++ src/linux/ppoll.c | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/linux/ppoll.c diff --git a/include/poll.h b/include/poll.h index 36ef7fee..ace3f3aa 100644 --- a/include/poll.h +++ b/include/poll.h @@ -5,6 +5,8 @@ extern "C" { #endif +#incluce + #define POLLIN 0x001 #define POLLPRI 0x002 #define POLLOUT 0x004 @@ -28,6 +30,14 @@ struct pollfd int poll (struct pollfd *, nfds_t, int); +#ifdef _GNU_SOURCE +#define __NEED_time_t +#define __NEED_struct_timespec +#define __NEED_sigset_t +#include +int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); +#endif + #ifdef __cplusplus } #endif diff --git a/src/linux/ppoll.c b/src/linux/ppoll.c new file mode 100644 index 00000000..8f4aab9b --- /dev/null +++ b/src/linux/ppoll.c @@ -0,0 +1,9 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask) +{ + struct timespec tmp = *to; + return syscall_cp(SYS_ppoll, fds, n, &tmp, mask); +} -- 2.20.1 From 743546a9339d3da4304fd63f74872e90ac792f63 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:27:26 -0400 Subject: [PATCH 09/16] fix typo introduced in poll.h --- include/poll.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/poll.h b/include/poll.h index ace3f3aa..f0e68b2f 100644 --- a/include/poll.h +++ b/include/poll.h @@ -5,7 +5,7 @@ extern "C" { #endif -#incluce +#include #define POLLIN 0x001 #define POLLPRI 0x002 -- 2.20.1 From ea544bfe808ef74c6d1727312069c12dd1c5c150 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:29:33 -0400 Subject: [PATCH 10/16] add preadv/pwritev syscall wrappers --- include/sys/uio.h | 9 +++++++++ src/unistd/preadv.c | 13 +++++++++++++ src/unistd/pwritev.c | 13 +++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 src/unistd/preadv.c create mode 100644 src/unistd/pwritev.c diff --git a/include/sys/uio.h b/include/sys/uio.h index 624ff422..60c5c2fe 100644 --- a/include/sys/uio.h +++ b/include/sys/uio.h @@ -11,6 +11,10 @@ extern "C" { #define __NEED_ssize_t #define __NEED_struct_iovec +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define __NEED_off_t +#endif + #ifdef _GNU_SOURCE #define __NEED_pid_t #endif @@ -20,6 +24,11 @@ extern "C" { ssize_t readv (int, const struct iovec *, int); ssize_t writev (int, const struct iovec *, int); +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +ssize_t preadv (int, const struct iovec *, int, off_t); +ssize_t pwritev (int, const struct iovec *, int, off_t); +#endif + #ifdef _GNU_SOURCE ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); diff --git a/src/unistd/preadv.c b/src/unistd/preadv.c new file mode 100644 index 00000000..371e46f8 --- /dev/null +++ b/src/unistd/preadv.c @@ -0,0 +1,13 @@ +#define _GNU_SOURCE +#include +#include +#include "syscall.h" +#include "libc.h" + +ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs) +{ + return syscall_cp(SYS_preadv, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); +} + +LFS64(preadv); diff --git a/src/unistd/pwritev.c b/src/unistd/pwritev.c new file mode 100644 index 00000000..1df268d5 --- /dev/null +++ b/src/unistd/pwritev.c @@ -0,0 +1,13 @@ +#define _GNU_SOURCE +#include +#include +#include "syscall.h" +#include "libc.h" + +ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs) +{ + return syscall_cp(SYS_pwritev, fd, iov, count, + (long)(ofs), (long)(ofs>>32)); +} + +LFS64(pwritev); -- 2.20.1 From 2416c63b81f7f79ea781725cf1117c191775c699 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:33:47 -0400 Subject: [PATCH 11/16] fix up lfs64 junk for preadv/pwritev --- include/sys/uio.h | 5 +++++ src/unistd/preadv.c | 2 +- src/unistd/pwritev.c | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/sys/uio.h b/include/sys/uio.h index 60c5c2fe..09b6ab9e 100644 --- a/include/sys/uio.h +++ b/include/sys/uio.h @@ -27,6 +27,11 @@ ssize_t writev (int, const struct iovec *, int); #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) ssize_t preadv (int, const struct iovec *, int, off_t); ssize_t pwritev (int, const struct iovec *, int, off_t); +#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) +#define preadv64 preadv +#define pwritev64 pwritev +#define off64_t off_t +#endif #endif #ifdef _GNU_SOURCE diff --git a/src/unistd/preadv.c b/src/unistd/preadv.c index 371e46f8..46d9ece7 100644 --- a/src/unistd/preadv.c +++ b/src/unistd/preadv.c @@ -1,4 +1,4 @@ -#define _GNU_SOURCE +#define _BSD_SOURCE #include #include #include "syscall.h" diff --git a/src/unistd/pwritev.c b/src/unistd/pwritev.c index 1df268d5..aec5d323 100644 --- a/src/unistd/pwritev.c +++ b/src/unistd/pwritev.c @@ -1,4 +1,4 @@ -#define _GNU_SOURCE +#define _BSD_SOURCE #include #include #include "syscall.h" -- 2.20.1 From a660180c6a93681c6efb54fb5826c08d4df60208 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:37:19 -0400 Subject: [PATCH 12/16] mincore syscall wrapper --- include/sys/mman.h | 1 + src/mman/mincore.c | 8 ++++++++ 2 files changed, 9 insertions(+) create mode 100644 src/mman/mincore.c diff --git a/include/sys/mman.h b/include/sys/mman.h index 0fa32e6a..136b45b3 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -33,6 +33,7 @@ void *mremap (void *, size_t, size_t, int, ...); #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) int madvise (void *, size_t, int); +int mincore (void *, size_t, unsigned char *); #endif int shm_open (const char *, int, mode_t); diff --git a/src/mman/mincore.c b/src/mman/mincore.c new file mode 100644 index 00000000..4bb19f85 --- /dev/null +++ b/src/mman/mincore.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int mincore (void *addr, size_t len, unsigned char *vec) +{ + return syscall(SYS_mincore, addr, len, vec); +} -- 2.20.1 From c87584a3e962dabd7b97733bfc3700e003d87d28 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 9 Sep 2012 16:50:20 -0400 Subject: [PATCH 13/16] add setdomainname syscall, fix getdomainname (previously a stub) --- include/unistd.h | 1 + src/misc/getdomainname.c | 10 +++++++++- src/misc/setdomainname.c | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/misc/setdomainname.c diff --git a/include/unistd.h b/include/unistd.h index 4f6953c4..d3bb781a 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -165,6 +165,7 @@ int getpagesize(void); int getdtablesize(void); int sethostname(const char *, size_t); int getdomainname(char *, size_t); +int setdomainname(const char *, size_t); int setgroups(size_t, const gid_t []); char *getpass(const char *); int daemon(int, int); diff --git a/src/misc/getdomainname.c b/src/misc/getdomainname.c index 7eb113d7..59df566d 100644 --- a/src/misc/getdomainname.c +++ b/src/misc/getdomainname.c @@ -1,9 +1,17 @@ +#define _GNU_SOURCE #include #include #include +#include int getdomainname(char *name, size_t len) { - *name = 0; + struct utsname temp; + uname(&temp); + if (!len || strlen(temp.domainname) >= len) { + errno = EINVAL; + return -1; + } + strcpy(name, temp.domainname); return 0; } diff --git a/src/misc/setdomainname.c b/src/misc/setdomainname.c new file mode 100644 index 00000000..22d3f746 --- /dev/null +++ b/src/misc/setdomainname.c @@ -0,0 +1,8 @@ +#define _GNU_SOURCE +#include +#include "syscall.h" + +int setdomainname(const char *name, size_t len) +{ + return syscall(SYS_setdomainname, name, len); +} -- 2.20.1 From 2c1cd2399a237db968a521cdaef3d47a3fb2c2e9 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 10 Sep 2012 15:30:52 -0400 Subject: [PATCH 14/16] add LIBCC (compiler runtime) logic and override to configure this should both fix the issue with ARM needing -lgcc_eh (although that's really a bug in the libgcc build process that's causing considerable bloat, which should be fixed) and make it easier to build musl using clang/llvm in place of gcc. unfortunately I don't know a good way to detect and support pcc's -lpcc since it's not in pcc's default library search path... --- configure | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/configure b/configure index 4e3931c1..93518a7d 100755 --- a/configure +++ b/configure @@ -34,6 +34,7 @@ Some influential environment variables: CC C compiler command [detected] CFLAGS C compiler flags [-Os -pipe ...] CROSS_COMPILE prefix for cross compiler and tools [none] + LIBCC compiler runtime library [detected] Use these variables to override the choices made by configure. @@ -128,6 +129,7 @@ CFLAGS=*) CFLAGS=${arg#*=} ;; CPPFLAGS=*) CPPFLAGS=${arg#*=} ;; LDFLAGS=*) LDFLAGS=${arg#*=} ;; CROSS_COMPILE=*) CROSS_COMPILE=${arg#*=} ;; +LIBCC=*) LIBCC=${arg#*=} ;; *=*) ;; *) target=$arg ;; esac @@ -286,6 +288,10 @@ printf "warning: disabling dynamic linking support\n" shared=no } +# Find compiler runtime library +test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh +test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt +printf "using compiler runtime libraries: %s\n" "$LIBCC" printf "creating config.mak... " @@ -309,6 +315,7 @@ CFLAGS_C99FSE = $CFLAGS_C99FSE CPPFLAGS = $CPPFLAGS LDFLAGS = $LDFLAGS_AUTO $LDFLAGS CROSS_COMPILE = $CROSS_COMPILE +LIBCC = $LIBCC EOF test "x$static" = xno && echo "STATIC_LIBS =" test "x$shared" = xno && echo "SHARED_LIBS =" -- 2.20.1 From 3b5e69052a867e9d99cf4c655d775bd06e3437f1 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 10 Sep 2012 18:05:02 -0400 Subject: [PATCH 15/16] fix ppoll with null timeout argument --- src/linux/ppoll.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linux/ppoll.c b/src/linux/ppoll.c index 8f4aab9b..d49e836e 100644 --- a/src/linux/ppoll.c +++ b/src/linux/ppoll.c @@ -4,6 +4,6 @@ int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask) { - struct timespec tmp = *to; - return syscall_cp(SYS_ppoll, fds, n, &tmp, mask); + return syscall_cp(SYS_ppoll, fds, n, + to ? (struct timespec []){*to} : 0, mask); } -- 2.20.1 From 1701e4f3d46b14c4c4be8a46e64f8eaf15a5c061 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 10 Sep 2012 18:16:11 -0400 Subject: [PATCH 16/16] reenable word-at-at-time copying in memmove before restrict was added, memove called memcpy for forward copies and used a byte-at-a-time loop for reverse copies. this was changed to avoid invoking UB now that memcpy has an undefined copying order, making memmove considerably slower. performance is still rather bad, so I'll be adding asm soon. --- src/string/memmove.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/string/memmove.c b/src/string/memmove.c index 9153a644..27f670e1 100644 --- a/src/string/memmove.c +++ b/src/string/memmove.c @@ -1,13 +1,36 @@ #include +#include + +#define WT size_t +#define WS (sizeof(WT)) void *memmove(void *dest, const void *src, size_t n) { char *d = dest; const char *s = src; + if (d==s) return d; - if ((size_t)(d-s) < n) - while (n--) d[n] = s[n]; - else - while (n--) *d++ = *s++; + if (s+n <= d || d+n <= s) return memcpy(d, s, n); + + if (d=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s; + } + for (; n; n--) *d++ = *s++; + } else { + if ((uintptr_t)s % WS == (uintptr_t)d % WS) { + while ((uintptr_t)(d+n) % WS) { + if (!n--) return dest; + d[n] = s[n]; + } + while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n); + } + while (n) n--, d[n] = s[n]; + } + return dest; } -- 2.20.1