Rich Felker [Fri, 22 Feb 2013 04:19:18 +0000 (23:19 -0500)]
fix wrong return value from wmemmove on forward copies
rofl0r [Thu, 21 Feb 2013 14:40:08 +0000 (15:40 +0100)]
scsci/sg.h: fix usage of undefined macro HZ
this macro is 100 on all archs, at least in userspace, according
to kernel headers.
rofl0r [Thu, 21 Feb 2013 14:35:34 +0000 (15:35 +0100)]
add arpa/ftp.h
Rich Felker [Thu, 21 Feb 2013 04:01:22 +0000 (23:01 -0500)]
use memcmp instead of str[n]cmp for temp function XXXXXX checking
Rich Felker [Thu, 21 Feb 2013 03:58:46 +0000 (22:58 -0500)]
fix error cases in mkostemps core
1. wrong return value and missing errno for negative suffix len
2. failure to catch suffix len > strlen
3. remove unwanted clearing of input string in invalid case
Rich Felker [Thu, 21 Feb 2013 03:56:53 +0000 (22:56 -0500)]
remove leftover unused variable in mktemp after refactoring
Rich Felker [Thu, 21 Feb 2013 03:43:23 +0000 (22:43 -0500)]
add mkostemp, mkstemps, and mkostemps functions and reorganize temp internals
based on patch contributed by Anthony G. Basile (blueness)
some issues remain with the filename generation algorithm and other
small bugs, but this patch has been sitting around long enough that I
feel it's best to get it committed and then work out any remaining
issues.
Rich Felker [Sun, 17 Feb 2013 19:30:19 +0000 (14:30 -0500)]
remove unused #undef environ now that libc.h no longer #defines it
Rich Felker [Sun, 17 Feb 2013 19:24:39 +0000 (14:24 -0500)]
consistently use the internal name __environ for environ
patch by Jens Gustedt.
previously, the intended policy was to use __environ in code that must
conform to the ISO C namespace requirements, and environ elsewhere.
this policy was not followed in practice anyway, making things
confusing. on top of that, Jens reported that certain combinations of
link-time optimization options were breaking with the inconsistent
references; this seems to be a compiler or linker bug, but having it
go away is a nice side effect of the changes made here.
Rich Felker [Sun, 17 Feb 2013 18:21:56 +0000 (13:21 -0500)]
add fgetgrent function
based on patch by Isaac Dunham, moved to its own file to avoid
increasing bss on static linked programs not using this nonstandard
function but using the standard getgrent function, and vice versa.
Rich Felker [Thu, 7 Feb 2013 08:13:35 +0000 (03:13 -0500)]
fix typo in newly-added error message for EOWNERDEAD
Rich Felker [Thu, 7 Feb 2013 08:05:54 +0000 (03:05 -0500)]
improve error strings
this definitely has the potential to be a bikeshed topic, so some
justification is in order. most of the changes made fit into one of
the following categories:
1. alignment with text in posix, xsh 2.3
2. eliminating overly-specific text for shared error codes
3. making the message match more closely with the macro name
4. removing extraneous words
in particular, the EAGAIN/EWOULDBLOCK text is updated to match the
description of EAGAIN (which covers both uses) rather than saying the
operation would block, and ENOTSUP/EOPNOTSUPP is updated not to
mention sockets.
the distinction between ENFILE/EMFILE has also been clarified; ENFILE
is aligned with the posix text, and EMFILE, which lacks concise posix
text matching any historic message, is updated to emphasize that the
exhausted resource is not open files/open file descriptions, but
rather the integer 'address space' of file descriptors.
some messages may be further tweaked based on feedback.
rofl0r [Wed, 6 Feb 2013 01:15:51 +0000 (02:15 +0100)]
arm: add __aeabi_atexit()
arm eabi requires this symbol for static C++ dtors.
usually it is provided by libstdc++, but when a C++ program
doesn't use the std lib (free-standing), the libc has to provide
it.
this was encountered while building transmission, which
depends on such a C++ library (libutp).
this function is nearly identical to __cxa_atexit, but it has the
order of argumens swapped for "performance reasons".
see page 25 of
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0043d/IHI0043D_rtabi.pdf
there are other aeabi specific C++ support functions missing, but
it is not clear yet that GCC makes use of them so we omit them for
the moment.
rofl0r [Wed, 6 Feb 2013 01:11:49 +0000 (02:11 +0100)]
Makefile: make it possible to build arch specific C files
Rich Felker [Sun, 3 Feb 2013 23:21:04 +0000 (18:21 -0500)]
base system() on posix_spawn
this avoids duplicating the fragile logic for executing an external
program without fork.
Rich Felker [Sun, 3 Feb 2013 22:09:47 +0000 (17:09 -0500)]
fix unsigned comparison bug in posix_spawn
read should never return anything but 0 or sizeof ec here, but if it
does, we want to treat any other return as "success". then the caller
will get back the pid and is responsible for waiting on it when it
immediately exits.
Rich Felker [Sun, 3 Feb 2013 21:42:40 +0000 (16:42 -0500)]
overhaul posix_spawn to use CLONE_VM instead of vfork
the proposed change was described in detail in detail previously on
the mailing list. in short, vfork is unsafe because:
1. the compiler could make optimizations that cause the child to
clobber the parent's local vars.
2. strace is buggy and allows the vforking parent to run before the
child execs when run under strace.
the new design uses a close-on-exec pipe instead of vfork semantics to
synchronize the parent and child so that the parent does not return
before the child has finished using its arguments (and now, also its
stack). this also allows reporting exec failures to the caller instead
of giving the caller a child that mysteriously exits with status 127
on exec error.
basic testing has been performed on both the success and failure code
paths. further testing should be done.
Rich Felker [Sun, 3 Feb 2013 21:09:05 +0000 (16:09 -0500)]
streamline old-kernel fallback path of pipe2 to use syscalls directly
also, don't waste code/time on F_GETFL since pipes always have blank
flags initially (at least on old kernels, which are all this fallback
code matters for).
Rich Felker [Sun, 3 Feb 2013 06:26:33 +0000 (01:26 -0500)]
fix regression that made shared libs crash on arm
Rich Felker [Sat, 2 Feb 2013 07:07:38 +0000 (02:07 -0500)]
dynamically allocate storage for gethostby* buffers
this change shaves ~1k off libc.so bss size, and also avoids hard
errors in the case where the static buffer was not large enough to
hold the result.
this whole framework is really ugly and might should be replaced or at
least heavily overhauled when some changes/factorizations are made to
getaddrinfo internals in the future.
Rich Felker [Sat, 2 Feb 2013 06:59:53 +0000 (01:59 -0500)]
fix blank ai_canonname from getaddrinfo for non-CNAMEs
Rich Felker [Sat, 2 Feb 2013 06:32:12 +0000 (01:32 -0500)]
fix memory leak due to double call to getaddrinfo in gethostbyname*
Rich Felker [Sat, 2 Feb 2013 06:31:10 +0000 (01:31 -0500)]
fix error returns in gethostby*_r functions
they're supposed to return an error code rather than using errno.
Rich Felker [Sat, 2 Feb 2013 05:59:25 +0000 (00:59 -0500)]
fix uninitialized map_len being used in munmap failure paths in load_library
this bug seems to have been introduced when the map_library signatures
was changed to return the mapping in a temp dso structure instead of
into separate variables.
Rich Felker [Sat, 2 Feb 2013 03:25:19 +0000 (22:25 -0500)]
fix stale locks left behind when pthread_create fails
this bug seems to have been around a long time.
Rich Felker [Sat, 2 Feb 2013 03:23:24 +0000 (22:23 -0500)]
if pthread_create fails, it must not attempt mmap if there is no mapping
this bug was introduced when support for application-provided stacks
was originally added.
Rich Felker [Sat, 2 Feb 2013 03:10:40 +0000 (22:10 -0500)]
pthread stack treatment overhaul for application-provided stacks, etc.
the main goal of these changes is to address the case where an
application provides a stack of size N, but TLS has size M that's a
significant portion of the size N (or even larger than N), thus giving
the application less stack space than it expected or no stack at all!
the new strategy pthread_create now uses is to only put TLS on the
application-provided stack if TLS is smaller than 1/8 of the stack
size or 2k, whichever is smaller. this ensures that the application
always has "close enough" to what it requested, and the threshold is
chosen heuristically to make sure "sane" amounts of TLS still end up
in the application-provided stack.
if TLS does not fit the above criteria, pthread_create uses mmap to
obtain space for TLS, but still uses the application-provided stack
for actual call frame stack. this is to avoid wasting memory, and for
the sake of supporting ugly hacks like garbage collection based on
assumptions that the implementation will use the provided stack range.
in order for the above heuristics to ever succeed, the amount of TLS
space wasted on POSIX TSD (pthread_key_create based) needed to be
reduced. otherwise, these changes would preclude any use of
pthread_create without mmap, which would have serious memory usage and
performance costs for applications trying to create huge numbers of
threads using pre-allocated stack space. the new value of
PTHREAD_KEYS_MAX is the minimum allowed by POSIX, 128. this should
still be plenty more than real-world applications need, especially now
that C11/gcc-style TLS is now supported in musl, and most apps and
libraries choose to use that instead of POSIX TSD when available.
at the same time, PTHREAD_STACK_MIN has been decreased. it was
originally set to PAGE_SIZE back when there was no support for TLS or
application-provided stacks, and requests smaller than a whole page
did not make sense. now, there are two good reasons to support
requests smaller than a page: (1) applications could provide
pre-allocated stacks smaller than a page, and (2) with smaller stack
sizes, stack+TLS+TSD can all fit in one page, making it possible for
applications which need huge numbers of threads with minimal stack
needs to allocate exactly one page per thread. the new value of
PTHREAD_STACK_MIN, 2k, is aligned with the minimum size for
sigaltstack.
rofl0r [Sat, 2 Feb 2013 02:08:57 +0000 (03:08 +0100)]
make some arrays const
this way they'll go into .rodata, decreasing memory pressure.
Rich Felker [Fri, 1 Feb 2013 21:41:53 +0000 (16:41 -0500)]
replace __wake function with macro that performs direct syscall
this should generate faster and smaller code, especially with inline
syscalls. the conditional with cnt is ugly, but thankfully cnt is
always a constant anyway so it gets evaluated at compile time. it may
be preferable to make separate __wake and __wakeall macros without a
count argument.
priv flag is not used yet; private futex support still needs to be
done at some point in the future.
Rich Felker [Fri, 1 Feb 2013 20:57:28 +0000 (15:57 -0500)]
fix up minor misplacement of restrict keyword in spawnattr sched stubs
Rich Felker [Fri, 1 Feb 2013 06:49:07 +0000 (01:49 -0500)]
release notes for 0.9.9
Rich Felker [Fri, 1 Feb 2013 06:10:59 +0000 (01:10 -0500)]
revert regex "cleanup" that seems unjustified and may break backtracking
it's not clear to me at the moment whether the code that was removed
(and which is now being re-added) is needed, but it's far from being a
no-op, and i don't want to risk breaking regex in this release.
Rich Felker [Thu, 31 Jan 2013 05:49:53 +0000 (00:49 -0500)]
SOL_TCP is nonstandard and not in the reserved namespace
alternatively, we could define it in sys/socket.h since SO* is
reserved there, and tcp.h includes sys/socket.h in extensions mode.
note that SOL_TCP is simply wrong and it's only here for compatibility
with broken applications. the correct argument to pass for setting TCP
socket options is IPPROTO_TCP, which of course has the same value as
SOL_TCP but works everywhere.
Rich Felker [Sat, 26 Jan 2013 16:40:40 +0000 (11:40 -0500)]
fix tm_to_time logic for number of days in november
report/patch by Hiltjo Posthuma <hiltjo@codemadness.org>
Rich Felker [Thu, 24 Jan 2013 03:18:45 +0000 (22:18 -0500)]
add RTLD_NODELETE flag for dlopen
this is a trivial no-op, because dlclose never deletes libraries. thus
we might as well have it in the header in case some application wants
it, since we're already providing it anyway.
Rich Felker [Thu, 24 Jan 2013 03:07:45 +0000 (22:07 -0500)]
add support for RTLD_NOLOAD to dlopen
based on patch by Pierre Carrier <pierre@gcarrier.fr> that just added
the flag constant, but with minimal additional code so that it
actually works as documented. this is a nonstandard option but some
major software (reportedly, Firefox) uses it and it was easy to add
anyway.
Rich Felker [Thu, 24 Jan 2013 01:21:36 +0000 (20:21 -0500)]
fix regression in dlsym: rejection of special RTLD_* handles as invalid
Rich Felker [Sat, 19 Jan 2013 01:35:26 +0000 (20:35 -0500)]
use a common definition of NULL as 0L for C and C++
the historical mess of having different definitions for C and C++
comes from the historical C definition as (void *)0 and the fact that
(void *)0 can't be used in C++ because it does not convert to other
pointer types implicitly. however, using plain 0 in C++ exposed bugs
in C++ programs that call variadic functions with NULL as an argument
and (wrongly; this is UB) expect it to arrive as a null pointer. on
64-bit machines, the high bits end up containing junk. glibc dodges
the issue by using a GCC extension __null to define NULL; this is
observably non-conforming because a conforming application could
observe the definition of NULL via stringizing and see that it is
neither an integer constant expression with value zero nor such an
expression cast to void.
switching to 0L eliminates the issue and provides compatibility with
broken applications, since on all musl targets, long and pointers have
the same size, representation, and argument-passing convention. we
could maintain separate C and C++ definitions of NULL (i.e. just use
0L on C++ and use (void *)0 on C) but after careful analysis, it seems
extremely difficult for a C program to even determine whether NULL has
integer or pointer type, much less depend in subtle, unintentional
ways, on whether it does. C89 seems to have no way to make the
distinction. on C99, the fact that (int)(void *)0 is not an integer
constant expression, along with subtle VLA/sizeof semantics, can be
used to make the distinction, but many compilers are non-conforming
and give the wrong result to this test anyway. on C11, _Generic can
trivially make the distinction, but it seems unlikely that code
targetting C11 would be so backwards in caring which definition of
NULL an implementation uses.
as such, the simplest path of using the same definition for NULL in
both C and C++ was chosen. the #undef directive was also removed so
that the compiler can catch and give a warning or error on
redefinition if buggy programs have defined their own versions of
NULL prior to inclusion of standard headers.
Rich Felker [Wed, 16 Jan 2013 16:49:00 +0000 (11:49 -0500)]
fix warning building dynlink.c stub for static libc
struct dso was not defined in this case, and it's not needed in the
code that was using it anyway; void pointers work just as well.
Rich Felker [Wed, 16 Jan 2013 16:47:35 +0000 (11:47 -0500)]
fix bug in dladdr that prevented resolving addresses in the PLT
Szabolcs Nagy [Tue, 15 Jan 2013 00:05:29 +0000 (01:05 +0100)]
remove unused "params" related code from regex
some structs and functions had reference to the params
feature of tre that is not used by the code anymore
Rich Felker [Mon, 14 Jan 2013 23:04:49 +0000 (18:04 -0500)]
Merge remote-tracking branch 'nsz/math'
Szabolcs Nagy [Sun, 13 Jan 2013 23:06:49 +0000 (00:06 +0100)]
regex: remove an unused local variable from regexec
pos_start local variable is not used in tre_tnfa_run_backtrack
Szabolcs Nagy [Sun, 13 Jan 2013 22:54:48 +0000 (23:54 +0100)]
in crypt_des change unnecessary union keybuf into unsigned char[]
original FreeSec code accessed keybuf as uint32* and uint8* as well
(incorrectly), this got fixed with an union, but then it seems the
uint32* access is no longer needed so the code can be simplified
Szabolcs Nagy [Sun, 13 Jan 2013 22:18:32 +0000 (23:18 +0100)]
crypt: fix the prototype of md5_sum, sha256_sum and sha512_sum
the internal sha2 hash sum functions had incorrect array size
in the prototype for the message digest argument, fixed by
using pointer so it is not misleading
Szabolcs Nagy [Sun, 13 Jan 2013 22:15:39 +0000 (23:15 +0100)]
fix lio_listio return value in LIO_WAIT mode
Szabolcs Nagy [Sat, 12 Jan 2013 18:14:34 +0000 (19:14 +0100)]
add MOD_TAI to sys/timex.h and update STA_RONLY
Szabolcs Nagy [Sat, 12 Jan 2013 18:13:59 +0000 (19:13 +0100)]
add SWAP_FLAG_DISCARD to sys/swap.h
Szabolcs Nagy [Sat, 12 Jan 2013 17:25:13 +0000 (18:25 +0100)]
add mount flags to sys/mount.h
added various MS_*, MNT_*, UMOUNT_* flags following the linux
headers, with one exception: MS_NOUSER is defined as (1U<<31)
instead of (1<<31) which invokes undefined behaviour
the S_* flags were removed following glibc
Szabolcs Nagy [Sat, 12 Jan 2013 17:24:45 +0000 (18:24 +0100)]
add IN_EXCL_UNLINK to sys/inotify.h
Szabolcs Nagy [Sat, 12 Jan 2013 16:29:45 +0000 (17:29 +0100)]
add EPOLLWAKEUP flag to sys/epoll.h
Szabolcs Nagy [Sat, 12 Jan 2013 14:37:00 +0000 (15:37 +0100)]
add RB_SW_SUSPEND and RB_KEXEC to sys/reboot.h
using the glibc names for the magic constants of the linux reboot syscall
Szabolcs Nagy [Fri, 11 Jan 2013 01:07:40 +0000 (02:07 +0100)]
add missing mmap options and madvices to bits/mman.h based on linux headers
Szabolcs Nagy [Fri, 11 Jan 2013 01:05:19 +0000 (02:05 +0100)]
add missing EXTPROC flag to bits/termios.h
mips and powerpc already had this termios flag defined
Szabolcs Nagy [Fri, 11 Jan 2013 01:03:45 +0000 (02:03 +0100)]
add missing F_GETOWNER_UIDS flag to bits/fcntl.h
Szabolcs Nagy [Fri, 11 Jan 2013 01:00:14 +0000 (02:00 +0100)]
add missing EHWPOISON to bits/errno.h
it was already defined for mips, but was missing from other archs
Szabolcs Nagy [Fri, 11 Jan 2013 00:58:54 +0000 (01:58 +0100)]
add missing ptrace requests and options to sys/ptrace.h
Szabolcs Nagy [Fri, 11 Jan 2013 00:54:53 +0000 (01:54 +0100)]
add missing multicast socket options to netinet/in.h
based on linux headers add the missing MCAST_* options
under _GNU_SOURCE as they are not in the reserved namespace
(this api was originally specified by RFC 3678)
Szabolcs Nagy [Fri, 11 Jan 2013 00:46:09 +0000 (01:46 +0100)]
add missing protocol families to sys/socket.h
missing protocol families based on current linux headers:
PF_RDS, PF_LLC, PF_CAN, PF_TIPC, PF_NFC
Rich Felker [Thu, 10 Jan 2013 22:57:30 +0000 (17:57 -0500)]
fix another case of cloexec/nonblock flags not matching arch values
Rich Felker [Thu, 10 Jan 2013 19:05:40 +0000 (14:05 -0500)]
check for invalid handles in dlsym/dlclose
this is wasteful and useless from a standpoint of sane programs, but
it is required by the standard, and the current requirements were
upheld with the closure of Austin Group issue #639:
http://austingroupbugs.net/view.php?id=639
Szabolcs Nagy [Mon, 7 Jan 2013 22:54:13 +0000 (23:54 +0100)]
math: erf and erfc cleanup
common part of erf and erfc was put in a separate function which
saved some space and the new code is using unsigned arithmetics
erfcf had a bug: for some inputs in [7.95,8] the result had
more than 60ulp error: in expf(-z*z - 0.5625f) the argument
must be exact but not enough lowbits of z were zeroed,
-SET_FLOAT_WORD(z, ix&0xfffff000);
+SET_FLOAT_WORD(z, ix&0xffffe000);
fixed the issue
rofl0r [Fri, 4 Jan 2013 17:47:17 +0000 (18:47 +0100)]
setjmp.h: add struct tag for sigjmp_buf (GCC C++ compatibility)
the anonymous struct typedef with array notation breaks with
GCC in C++ mode:
error: non-local function 'static<anonymous struct>
(& boost::signal_handler::jump_buffer())[1]' uses anonymous type
this is a known GCC issue, as search results for that error msg
suggest.
since this is hard to work around in the calling C++ code, a
fix in musl is preferable.
rofl0r [Fri, 4 Jan 2013 12:05:42 +0000 (13:05 +0100)]
add legacy header values.h
some programs (procps, babl) expect it, and it doesn't seem to
cause any harm to just add it.
it's small and straightforward.
since math.h also defines MAXFLOAT, we undef it in both places,
before defining it.
rofl0r [Fri, 4 Jan 2013 11:57:15 +0000 (12:57 +0100)]
time.h: add BSD aliases for otherwise internal struct tm members
rofl0r [Tue, 1 Jan 2013 07:07:26 +0000 (08:07 +0100)]
wait.h: add linux specific, thread-related waitpid() flags
these flags are needed in order to be able to handle lwp id's
which the kernel returns after clone() calls for new threads
via ptrace(PTRACE_GETEVENTMSG).
fortunately, they're the same for all archs and in the reserved
namespace.
rofl0r [Tue, 1 Jan 2013 06:59:11 +0000 (07:59 +0100)]
__assert_fail(): remove _Noreturn, to get proper stacktraces
for _Noreturn functions, gcc generates code that trashes the
stack frame, and so it makes it impossible to inspect the causes
of an assert error in gdb.
abort() is not affected (i have not yet investigated why).
Rich Felker [Wed, 2 Jan 2013 01:19:20 +0000 (20:19 -0500)]
add some new-ish IPPROTO constants that were missing
Szabolcs Nagy [Tue, 1 Jan 2013 21:20:45 +0000 (22:20 +0100)]
math: bessel cleanup (jn.c and jnf.c)
both jn and yn functions had integer overflow issues for large
and small n
to handle these issues nm1 (== |n|-1) is used instead of n and -n
in the code and some loops are changed to make sure the iteration
counter does not overflow
(another solution could be to use larger integer type or even double
but that has more size and runtime cost, on x87 loading int64_t or
even uint32_t into an fpu register is more than two times slower than
loading int32_t, and using double for n slows down iteration logic)
yn(-1,0) now returns inf
posix2008 specifies that on overflow and at +-0 all y0,y1,yn functions
return -inf, this is not consistent with math when n<0 odd integer in yn
(eg. when x->0, yn(-1,x)->inf, but historically yn(-1,0) seems to be
special cased and returned -inf)
some threshold values in jnf and ynf were fixed that seems to be
incorrectly copy-pasted from the double version
Szabolcs Nagy [Tue, 1 Jan 2013 21:11:28 +0000 (22:11 +0100)]
math: bessel cleanup (j1.c and j1f.c)
a common code path in j1 and y1 was factored out so the resulting
object code is a bit smaller
unsigned int arithmetics is used for bit manipulation
j1(-inf) now returns 0 instead of -0
an incorrect threshold in the common code of j1f and y1f got fixed
(this caused spurious overflow and underflow exceptions)
the else branch in pone and pzero functions are fixed
(so code analyzers dont warn about uninitialized values)
Szabolcs Nagy [Tue, 1 Jan 2013 20:59:46 +0000 (21:59 +0100)]
math: bessel cleanup (j0.c and j0f.c)
a common code path in j0 and y0 was factored out so the resulting
object code is smaller
unsigned int arithmetics is used for bit manipulation
the logic of j0 got a bit simplified (x < 1 case was handled
separately with a bit higher precision than now, but there are large
errors in other domains anyway so that branch has been removed)
some threshold values were adjusted in j0f and y0f
Rich Felker [Fri, 28 Dec 2012 20:39:33 +0000 (15:39 -0500)]
expose [v]asprintf under _BSD_SOURCE
reported/requested by Strake; simplified from the provided patch
Rich Felker [Fri, 28 Dec 2012 01:44:44 +0000 (20:44 -0500)]
align EPOLL_* flags with fcntl O_* flag definitions, which vary by arch
the old definitions were wrong on some archs. actually, EPOLL_NONBLOCK
probably should not even be defined; it is not accepted by the kernel
and it's not clear to me whether it has any use at all, even if it did
work. this issue should be revisited at some point, but I'm leaving it
in place for now in case some applications reference it.
Rich Felker [Thu, 27 Dec 2012 04:48:02 +0000 (23:48 -0500)]
fix alignment logic in strlcpy
Rich Felker [Wed, 26 Dec 2012 21:55:49 +0000 (16:55 -0500)]
add linux extension POLLRDHUP to poll.h
the POLL prefix is in the reserved namespace for poll.h, so no feature
test macro checks are needed.
Rich Felker [Wed, 26 Dec 2012 02:51:11 +0000 (21:51 -0500)]
fix reference to libc struct in static tls init code
libc is the macro, __libc is the internal symbol, but under some
configurations on old/broken compilers, the symbol might not actually
exist and the libc macro might instead use __libc_loc() to obtain
access to the object.
Rich Felker [Thu, 20 Dec 2012 17:16:02 +0000 (12:16 -0500)]
clean up and fix logic for making mmap fail on invalid/unsupported offsets
the previous logic was assuming the kernel would give EINVAL when
passed an invalid address, but instead with MAP_FIXED it was giving
EPERM, as it considered this an attempt to map over kernel memory.
instead of trying to get the kernel to do the rigth thing, the new
code just handles the error in userspace.
I have also cleaned up the code to use a single mask to check for
invalid low bits and unsupported high bits, so it's simpler and more
clearly correct. the old code was actually wrong for sizeof(long)
smaller than sizeof(off_t) but not equal to 4; now it should be
correct for all possibilities.
for 64-bit systems, the low-bits test is new and extraneous (the
kernel should catch the error anyway when the mmap2 syscall is not
used), but it's cheap anyway. if this is an issue, the OFF_MASK
definition could be tweaked to omit the low bits when SYS_mmap2 is not
defined.
Rich Felker [Wed, 19 Dec 2012 18:07:37 +0000 (13:07 -0500)]
merge a few fixes by sh4rm4
rofl0r [Wed, 19 Dec 2012 18:02:22 +0000 (19:02 +0100)]
socket.h: add SO_(SND/RCV)BUFFORCE to generic block
Szabolcs Nagy [Wed, 19 Dec 2012 09:57:54 +0000 (10:57 +0100)]
math: more correct tgmath.h type cast logic
__IS_FP is a portable integer constant expression now
(uses that unsigned long long is larger than float)
the result casting logic should work now on all compilers
supporting typeof
rofl0r [Wed, 19 Dec 2012 06:32:38 +0000 (07:32 +0100)]
add inet_network (required for wine)
rofl0r [Wed, 19 Dec 2012 05:09:57 +0000 (06:09 +0100)]
x86_64/bits/signal.h: fix typo in REG_CSGSFS
rofl0r [Wed, 19 Dec 2012 04:08:07 +0000 (05:08 +0100)]
link.h: expose glibc/svr4 dynlinker debugging glue
this is already implemented in the dynliker (see struct debug),
but was not exposed.
we need it to do so to make wine happy...
Szabolcs Nagy [Wed, 19 Dec 2012 03:05:30 +0000 (04:05 +0100)]
math: new type cast logic in tgmath.h
* return type logic is simplified a bit and fixed (see below)
* return type of conj and cproj were wrong on int arguments
* added comments about the pending issues
(usually we don't have comments in public headers but this is
not the biggest issue with tgmath.h)
casting the result to the right type cannot be done in c99
(c11 _Generic can solve this but that is not widely supported),
so the typeof extension of gcc is used and that the ?: operator
has special semantics when one of the operands is a null
pointer constant
the standard is very strict about the definition of null
pointer constants so typeof with ?: is still not enough so
compiler specific workaround is used for now
on gcc '!1.0' is a null pointer constant so we can use the old
__IS_FP logic (eventhough it's non-standard)
on clang (and on gcc as well) 'sizeof(void)-1' is a null
pointer constant so we can use
!(sizeof(*(0?(int*)0:(void*)__IS_FP(x)))-1)
(this is non-standard as well), the old logic is used by
default and this new one on clang
Szabolcs Nagy [Sun, 16 Dec 2012 19:28:43 +0000 (20:28 +0100)]
math: use 0x1p-120f and 0x1p120f for tiny and huge values
previously 0x1p-1000 and 0x1p1000 was used for raising inexact
exception like x+tiny (when x is big) or x+huge (when x is small)
the rational is that these float consts are large enough
(0x1p-120 + 1 raises inexact even on ld128 which has 113 mant bits)
and float consts maybe smaller or easier to load on some platforms
(on i386 this reduced the object file size by 4bytes in some cases)
Szabolcs Nagy [Sun, 16 Dec 2012 19:22:17 +0000 (20:22 +0100)]
math: tgammal.c fixes
this is not a full rewrite just fixes to the special case logic:
+-0 and non-integer x<INT_MIN inputs incorrectly raised invalid
exception and for +-0 the return value was wrong
so integer test and odd/even test for negative inputs are changed
and a useless overflow test was removed
Szabolcs Nagy [Sun, 16 Dec 2012 18:52:42 +0000 (19:52 +0100)]
math: tanh.c cleanup similar to sinh, cosh
comments are kept in the double version of the function
compared to fdlibm/freebsd we partition the domain into one
more part and select different threshold points:
now the [log(5/3)/2,log(3)/2] and [log(3)/2,inf] domains
should have <1.5ulp error
(so only the last bit may be wrong, assuming good exp, expm1)
(note that log(3)/2 and log(5/3)/2 are the points where tanh
changes resolution: tanh(log(3)/2)=0.5, tanh(log(5/3)/2)=0.25)
for some x < log(5/3)/2 (~=0.2554) the error can be >1.5ulp
but it should be <2ulp
(the freebsd code had some >2ulp errors in [0.255,1])
even with the extra logic the new code produces smaller
object files
Szabolcs Nagy [Sun, 16 Dec 2012 18:49:55 +0000 (19:49 +0100)]
math: sinh.c cleanup similar to the cosh one
comments are kept in the double version of the function
Szabolcs Nagy [Sun, 16 Dec 2012 18:23:51 +0000 (19:23 +0100)]
math: finished cosh.c cleanup
changed the algorithm: large input is not special cased
(when exp(-x) is small compared to exp(x))
and the threshold values are reevaluated
(fdlibm code had a log(2)/2 cutoff for which i could not find
justification, log(2) seems to be a better threshold and this
was verified empirically)
the new code is simpler, makes smaller binaries and should be
faster for common cases
the old comments were removed as they are no longer true for the
new algorithm and the fdlibm copyright was dropped as well
because there is no common code or idea with the original anymore
except for trivial ones.
Szabolcs Nagy [Sun, 16 Dec 2012 16:30:29 +0000 (17:30 +0100)]
math: x86_64 version of expl, fixed some comments in the i386 version
Szabolcs Nagy [Sun, 16 Dec 2012 16:28:18 +0000 (17:28 +0100)]
math: move x86_64 exp2l implementation to exp2l.s from expl.s
Rich Felker [Sun, 16 Dec 2012 04:34:08 +0000 (23:34 -0500)]
fix breakage in ldd (failure to print library load address)
Rich Felker [Sat, 15 Dec 2012 05:49:09 +0000 (00:49 -0500)]
Merge remote-tracking branch 'nsz/math'
Rich Felker [Sat, 15 Dec 2012 05:43:27 +0000 (00:43 -0500)]
add some missing macros to sys/shm.h
these are not specified in the standard, but in the reserved
namespace, so there is no problem with defining them unconditionally.
Szabolcs Nagy [Fri, 14 Dec 2012 17:29:56 +0000 (18:29 +0100)]
math: fix i386/expl.s with more precise x*log2e
with naive exp2l(x*log2e) the last 12bits of the result was incorrect
for x with large absolute value
with hi + lo = x*log2e is caluclated to 128 bits precision and then
expl(x) = exp2l(hi) + exp2l(hi) * f2xm1(lo)
this gives <1.5ulp measured error everywhere in nearest rounding mode
Szabolcs Nagy [Fri, 14 Dec 2012 11:49:35 +0000 (12:49 +0100)]
fixed tgmath.h for functions with integral result
in tgmath.h the return values are casted to the appropriate
floating-point type (if the compiler supports gcc __typeof__),
this is wrong in case of ilogb, lrint, llrint, lround, llround
which do not need such cast
Rich Felker [Thu, 13 Dec 2012 19:15:11 +0000 (14:15 -0500)]
add missing flags in sys/timerfd.h
Rich Felker [Wed, 12 Dec 2012 04:28:31 +0000 (23:28 -0500)]
treat invalid C as an error even if warnings aren't enabled.
Szabolcs Nagy [Wed, 12 Dec 2012 00:43:43 +0000 (01:43 +0100)]
math: add a non-dummy tgamma implementation
uses the lanczos approximation method with the usual tweaks.
same parameters were selected as in boost and python.
(avoides some extra work and special casing found in boost
so the precision is not that good: measured error is <5ulp for
positive x and <10ulp for negative)
an alternative lgamma_r implementation is also given in the same
file which is simpler and smaller than the current one, but less
precise so it's ifdefed out for now.
Szabolcs Nagy [Wed, 12 Dec 2012 00:39:23 +0000 (01:39 +0100)]
math: cosh cleanup
do fabs by hand, don't check for nan and inf separately