musl
10 years agofix inet_pton
Szabolcs Nagy [Wed, 23 Oct 2013 01:49:14 +0000 (01:49 +0000)]
fix inet_pton

* parse IPv4 dotted-decimal correctly (without strtoul, no leading zeros)
* disallow single leading ':' in IPv6 address
* allow at most 4 hex digits in IPv6 address (according to RFC 2373)
* have enough hex fields in IPv4 mapped IPv6 address
* disallow leading zeros in IPv4 mapped IPv6 address

10 years agofix __ipparse to parse the generic numbers-and-dots IPv4 format correctly
Szabolcs Nagy [Tue, 22 Oct 2013 12:28:17 +0000 (12:28 +0000)]
fix __ipparse to parse the generic numbers-and-dots IPv4 format correctly

* allow at most 4 parts
* bounds check the parts correctly
* disallow leading whitespace and sign
* check the address family before falling back to IPv6

10 years agofix inet_aton to accept the generic "numbers-and-dots" IPv4 address format
Szabolcs Nagy [Tue, 22 Oct 2013 12:23:17 +0000 (12:23 +0000)]
fix inet_aton to accept the generic "numbers-and-dots" IPv4 address format

10 years agosplit inet_addr and inet_ntoa back into their own files
Rich Felker [Tue, 22 Oct 2013 02:05:29 +0000 (22:05 -0400)]
split inet_addr and inet_ntoa back into their own files

despite being practically deprecated, these functions are still part
of the standard and thus cannot reside in a file that also contains
namespace pollution. this reverts some of the changes made in commit
e40f48a421a9176e3e298b5bac75f0355b219e58.

10 years agofix multiple minor namespace issues in headers
Rich Felker [Mon, 21 Oct 2013 02:01:51 +0000 (22:01 -0400)]
fix multiple minor namespace issues in headers

fcntl.h: AT_* is not a reserved namespace so extensions cannot be
exposed by default.

langinfo.h: YESSTR and NOSTR were removed from the standard.

limits.h: NL_NMAX was removed from the standard.

signal.h: the conditional for NSIG was wrongly checking _XOPEN_SOURCE
rather than _BSD_SOURCE. this was purely a mistake; it doesn't even
match the commit message from the commit that added it.

10 years agofix return value for inet_pton in ipv6 failure cases
Rich Felker [Sun, 20 Oct 2013 02:36:30 +0000 (22:36 -0400)]
fix return value for inet_pton in ipv6 failure cases

in the case of input that does not match the expected form, the
correct return value is 0, not -1.

10 years agouse consistent include guard name in arpa/ftp.h
Szabolcs Nagy [Fri, 18 Oct 2013 15:21:36 +0000 (15:21 +0000)]
use consistent include guard name in arpa/ftp.h

10 years agofix typo in socket.h (wrong macro name)
Szabolcs Nagy [Fri, 18 Oct 2013 15:19:49 +0000 (15:19 +0000)]
fix typo in socket.h (wrong macro name)

10 years agoin faccessat slow path, add close-on-exec to pipe fds
Rich Felker [Fri, 18 Oct 2013 11:12:38 +0000 (07:12 -0400)]
in faccessat slow path, add close-on-exec to pipe fds

as usual, this is needed to avoid fd leaks. as a better solution, the
use of fds could possibly be replaced with mmap and a futex.

10 years agofix uid/gid-setting error in faccessat with AT_EACCESS flag
Rich Felker [Sat, 12 Oct 2013 23:50:09 +0000 (19:50 -0400)]
fix uid/gid-setting error in faccessat with AT_EACCESS flag

this fixes an issue reported by Daniel Thau whereby faccessat with the
AT_EACCESS flag did not work in cases where the process is running
suid or sgid but without root privileges. per POSIX, when the process
does not have "appropriate privileges", setuid changes the euid, not
the real uid, and the target uid must be equal to the current real or
saved uid; if this condition is not met, EPERM results. this caused
the faccessat child process to fail.

using the setreuid syscall rather than setuid works. POSIX leaves it
unspecified whether setreuid can set the real user id to the effective
user id on processes without "appropriate privileges", but Linux
allows this; if it's not allowed, there would be no way for this
function to work.

10 years agofix errno value for getcwd when size argument is zero
Rich Felker [Tue, 8 Oct 2013 23:49:10 +0000 (19:49 -0400)]
fix errno value for getcwd when size argument is zero

based on patch by Michael Forney. at the same time, I've changed the
if branch to be more clear, avoiding the comma operator.

the underlying issue is that Linux always returns ERANGE when size is
too short, even when it's zero, rather than returning EINVAL for the
special case of zero as required by POSIX.

10 years agomath: fix rare underflow issue in fma
Szabolcs Nagy [Mon, 7 Oct 2013 18:46:43 +0000 (18:46 +0000)]
math: fix rare underflow issue in fma

the issue is described in commits 1e5eb73545ca6cfe8b918798835aaf6e07af5beb
and ffd8ac2dd50f99c3c83d7d9d845df9874ec3e7d5

10 years agomath: use sqrtl if FLT_EVAL_METHOD==2 in acosh and acoshf
Szabolcs Nagy [Mon, 7 Oct 2013 18:41:03 +0000 (18:41 +0000)]
math: use sqrtl if FLT_EVAL_METHOD==2 in acosh and acoshf

this makes acosh slightly more precise around 1.0 on i386

10 years agofix clockid macro names in time.h, reported by Paul Schutte
Szabolcs Nagy [Mon, 7 Oct 2013 13:28:03 +0000 (13:28 +0000)]
fix clockid macro names in time.h, reported by Paul Schutte

10 years agoremove errno setting from setenv, malloc sets it correctly on oom
Szabolcs Nagy [Mon, 7 Oct 2013 13:26:51 +0000 (13:26 +0000)]
remove errno setting from setenv, malloc sets it correctly on oom

10 years agofix allocation sizes in regcomp
Szabolcs Nagy [Mon, 7 Oct 2013 13:25:19 +0000 (13:25 +0000)]
fix allocation sizes in regcomp

sizeof had incorrect argument in a few places, the size was always
large enough so the issue was not critical.

10 years agoadd missing va_end in execl* for correcness and static code analyzers
Szabolcs Nagy [Mon, 7 Oct 2013 13:24:00 +0000 (13:24 +0000)]
add missing va_end in execl* for correcness and static code analyzers

10 years agominor vfprintf and vfwprintf changes to please static code analyzers
Szabolcs Nagy [Mon, 7 Oct 2013 13:22:24 +0000 (13:22 +0000)]
minor vfprintf and vfwprintf changes to please static code analyzers

add missing va_end and remove some unnecessary code.

10 years agomath: remove an unused variable from modfl
Szabolcs Nagy [Sun, 6 Oct 2013 02:09:40 +0000 (02:09 +0000)]
math: remove an unused variable from modfl

10 years agoslightly optimize __brk for size
Rich Felker [Sat, 5 Oct 2013 16:00:55 +0000 (12:00 -0400)]
slightly optimize __brk for size

there is no reason to check the return value for setting errno, since
brk never returns errors, only the new value of the brk (which may be
the same as the old, or otherwise differ from the requested brk, on
failure).

it may be beneficial to eventually just eliminate this file and make
the syscalls inline in malloc.c.

10 years agofix failure of malloc to set errno on heap (brk) exhaustion
Rich Felker [Sat, 5 Oct 2013 15:59:21 +0000 (11:59 -0400)]
fix failure of malloc to set errno on heap (brk) exhaustion

I wrongly assumed the brk syscall would set errno, but on failure it
returns the old value of the brk rather than an error code.

10 years agofix failure to check malloc result in setenv
Rich Felker [Fri, 4 Oct 2013 19:49:55 +0000 (15:49 -0400)]
fix failure to check malloc result in setenv

10 years agomath: remove code duplication in erfl found by clang analyzer
Szabolcs Nagy [Fri, 4 Oct 2013 18:10:17 +0000 (18:10 +0000)]
math: remove code duplication in erfl found by clang analyzer

erfl had some superflous code left around after the last erf cleanup.
the issue was reported by Alexander Monakov

10 years agomath: remove a useless assignment in lgammal found by clang analyzer
Szabolcs Nagy [Fri, 4 Oct 2013 18:08:16 +0000 (18:08 +0000)]
math: remove a useless assignment in lgammal found by clang analyzer

the issue was reported by Alexander Monakov

10 years agofix invalid implicit pointer conversion in pthread_key_create
Rich Felker [Fri, 4 Oct 2013 05:06:42 +0000 (01:06 -0400)]
fix invalid implicit pointer conversion in pthread_key_create

10 years agofix uninitialized variable in dladdr
Rich Felker [Fri, 4 Oct 2013 04:29:58 +0000 (00:29 -0400)]
fix uninitialized variable in dladdr

the affected branch only applies for DSOs that lack standard hash
table and only have the GNU hash table present.

10 years agoremoved unused variable in vfwprintf
Rich Felker [Fri, 4 Oct 2013 04:14:57 +0000 (00:14 -0400)]
removed unused variable in vfwprintf

10 years agofix new environment always being null with execle
Rich Felker [Thu, 3 Oct 2013 14:16:01 +0000 (10:16 -0400)]
fix new environment always being null with execle

the va_arg call for the argv[]-terminating null pointer was missing,
so this pointer was being wrongly used as the environment pointer.

issue reported by Timo Teräs. proposed patch slightly modified to
simplify the resulting code.

10 years agofix off-by-one error in getgrnam_r and getgrgid_r, clobbering gr_name
Rich Felker [Sun, 29 Sep 2013 06:52:33 +0000 (02:52 -0400)]
fix off-by-one error in getgrnam_r and getgrgid_r, clobbering gr_name

bug report and patch by Michael Forney. the terminating null pointer
at the end of the gr_mem array was overwriting the beginning of the
string data, causing the gr_name member to always be a zero-length
string.

10 years agofix buffer overflow in mbsrtowcs
Rich Felker [Fri, 27 Sep 2013 17:09:46 +0000 (13:09 -0400)]
fix buffer overflow in mbsrtowcs

issue reported by Michael Forney:

"If wn becomes 0 after processing a chunk of 4, mbsrtowcs currently
continues on, wrapping wn around to -1, causing the rest of the string
to be processed.

This resulted in buffer overruns if there was only space in ws for wn
wide characters."

the original patch submitted added an additional check for !wn after
the loop; to avoid extra branching, I instead just changed the wn>=4
check to wn>=5 to ensure that at least one slot remains after the
word-at-a-time loop runs. this should not slow down the tail
processing on real-world usage, since an extra slot that can't be
processed in the word-at-a-time loop is needed for the null
termination anyway.

10 years agomath: fix comparision macros (isless etc) when FLT_EVAL_METHOD!=0
Szabolcs Nagy [Fri, 27 Sep 2013 13:55:29 +0000 (13:55 +0000)]
math: fix comparision macros (isless etc) when FLT_EVAL_METHOD!=0

This is a change in ISO C11 annex F (F.10.11p1), comparision macros
can't round their arguments to their semantic type when the evaluation
format has wider range and precision. (ie. they must be consistent with
the builtin relational operators)

10 years agoadd missing i386 syscall numbers
Rich Felker [Thu, 26 Sep 2013 18:17:36 +0000 (14:17 -0400)]
add missing i386 syscall numbers

somehow the range 335-339 was missed when updating the file.

10 years agoremove duplicate lines from mips bits/syscall.h
Rich Felker [Thu, 26 Sep 2013 18:11:18 +0000 (14:11 -0400)]
remove duplicate lines from mips bits/syscall.h

10 years agorelease notes for 0.9.14
Rich Felker [Mon, 23 Sep 2013 21:00:53 +0000 (17:00 -0400)]
release notes for 0.9.14

10 years agofix arm atomic store and generate simpler/less-bloated/faster code
Rich Felker [Sun, 22 Sep 2013 07:06:17 +0000 (03:06 -0400)]
fix arm atomic store and generate simpler/less-bloated/faster code

atomic store was lacking a barrier, which was fine for legacy arm with
no real smp and kernel-emulated cas, but unsuitable for more modern
systems. the kernel provides another "kuser" function, at 0xffff0fa0,
which could be used for the barrier, but using that would drop support
for kernels 2.6.12 through 2.6.14 unless an extra conditional were
added to check for barrier availability. just using the barrier in the
kernel cas is easier, and, based on my reading of the assembly code in
the kernel, does not appear to be significantly slower.

at the same time, other atomic operations are adapted to call the
kernel cas function directly rather than using a_cas; due to small
differences in their interface contracts, this makes the generated
code much simpler.

10 years agofix potential deadlock bug in libc-internal locking logic
Rich Felker [Fri, 20 Sep 2013 06:00:27 +0000 (02:00 -0400)]
fix potential deadlock bug in libc-internal locking logic

if a multithreaded program became non-multithreaded (i.e. all other
threads exited) while one thread held an internal lock, the remaining
thread would fail to release the lock. the the program then became
multithreaded again at a later time, any further attempts to obtain
the lock would deadlock permanently.

the underlying cause is that the value of libc.threads_minus_1 at
unlock time might not match the value at lock time. one solution would
be returning a flag to the caller indicating whether the lock was
taken and needs to be unlocked, but there is a simpler solution: using
the lock itself as such a flag.

note that this flag is not needed anyway for correctness; if the lock
is not held, the unlock code is harmless. however, the memory
synchronization properties associated with a_store are costly on some
archs, so it's best to avoid executing the unlock code when it is
unnecessary.

10 years agocorrect the sysconf value for RTSIG_MAX
Rich Felker [Fri, 20 Sep 2013 05:49:03 +0000 (01:49 -0400)]
correct the sysconf value for RTSIG_MAX

this is the number of realtime signals available, not the maximum
signal number or total number of signals.

10 years agofix sigemptyset and sigfillset for mips
Rich Felker [Mon, 16 Sep 2013 16:58:51 +0000 (12:58 -0400)]
fix sigemptyset and sigfillset for mips

they were leaving junk in the upper bits.

10 years agofix clobbering of caller's stack in mips __clone function
Rich Felker [Mon, 16 Sep 2013 15:52:39 +0000 (11:52 -0400)]
fix clobbering of caller's stack in mips __clone function

this was resulting in crashes in posix_spawn on mips, and would have
affected applications calling clone too. since the prototype for
__clone has it as a variadic function, it may not assume that 16($sp)
is writable for use in making the syscall. instead, it needs to
allocate additional stack space, and then adjust the stack pointer
back in both of the code paths for the parent process/thread.

10 years agosys/resource.h: add PRIO_MIN and PRIO_MAX for getpriority and setpriority
Szabolcs Nagy [Sun, 15 Sep 2013 15:32:07 +0000 (15:32 +0000)]
sys/resource.h: add PRIO_MIN and PRIO_MAX for getpriority and setpriority

These constants are not specified by POSIX, but they are in the reserved
namespace, glibc and bsd systems seem to provide them as well.
(Note that POSIX specifies -NZERO and NZERO-1 to be the limits, but
PRIO_MAX equals NZERO)

10 years agoupdate include/elf.h following glibc changes
Szabolcs Nagy [Sun, 15 Sep 2013 14:53:34 +0000 (14:53 +0000)]
update include/elf.h following glibc changes

the changes were verified using various sources:
linux: include/uapi/linux/elf.h
binutils: include/elf/common.h
glibc: elf/elf.h
sysv gabi: http://www.sco.com/developers/gabi/latest/contents.html
sun linker docs: http://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf
and platform specific docs

- fixed:
EF_MIPS_* E_MIPS_* e_flags: fixed accoding to glibc and binutils

- added:
ELFOSABI_GNU for EI_OSABI entry: glibc, binutils and sysv gabi
EM_* e_machine values: updated according to linux and glibc
PN_XNUM e_phnum value: from glibc and linux, see oracle docs
NT_* note types: updated according to linux and glibc
DF_1_* flags for DT_FLAGS_1 entry: following glibc and oracle docs
AT_HWCAP2 auxv entry for more hwcap bits accoding to linux and glibc
R_386_SIZE32 relocation according to glibc and binutils
EF_ARM_ABI_FLOAT_* e_flags: added following glibc and binutils
R_AARCH64_* relocs: added following glibc and aarch64 elf specs
R_ARM_* relocs: according to glibc, binutils and arm elf specs
R_X86_64_* relocs: added missing relocs following glibc

- removed:
HWCAP_SPARC_* flags were moved to arch specific header in glibc
R_ARM_SWI24 reloc is marked as obsolete in glibc, not present in binutils
  not specified in arm elf spec, R_ARM_TLS_DESC reused its number
  see http://www.codesourcery.com/publications/RFC-TLSDESC-ARM.txt

- glibc changes not pulled in:
ELFOSABI_ARM_AEABI (bare-metal system, binutils and glibc disagrees about the name)
R_68K_* relocs for unsupported platform
R_SPARC_* ditto
EF_SH* ditto (e_flags)
EF_S390* ditto (e_flags)
R_390* ditto
R_MN10300* ditto
R_TILE* ditto

10 years agoomit CLONE_PARENT flag to clone in pthread_create
Rich Felker [Mon, 16 Sep 2013 14:56:01 +0000 (10:56 -0400)]
omit CLONE_PARENT flag to clone in pthread_create

CLONE_PARENT is not necessary (CLONE_THREAD provides all the useful
parts of it) and Linux treats CLONE_PARENT as an error in certain
situations, without noticing that it would be a no-op due to
CLONE_THREAD. this error case prevents, for example, use of a
multi-threaded init process and certain usages with containers.

10 years agouse symbolic names for clone flags in pthread_create
Rich Felker [Mon, 16 Sep 2013 14:54:31 +0000 (10:54 -0400)]
use symbolic names for clone flags in pthread_create

10 years agosys/socket.h: add new SO_BUSY_POLL socket option
Szabolcs Nagy [Sun, 15 Sep 2013 04:54:19 +0000 (04:54 +0000)]
sys/socket.h: add new SO_BUSY_POLL socket option

low latency busy poll sockets are new in linux v3.11

10 years agoptrace.h: add new ptrace requests to get/set sigmask
Szabolcs Nagy [Sun, 15 Sep 2013 02:49:26 +0000 (02:49 +0000)]
ptrace.h: add new ptrace requests to get/set sigmask

PTRACE_GETSIGMASK and PTRACE_SETSIGMASK were added in linux v3.11
and used by checkpoint/restore tools

10 years agonet/if_arp.h: add missing ARP hardware identifiers from linux uapi headers
Szabolcs Nagy [Sun, 15 Sep 2013 02:42:29 +0000 (02:42 +0000)]
net/if_arp.h: add missing ARP hardware identifiers from linux uapi headers

the removed ARPHRD_IEEE802154_PHY was only present in the kernel api
in v2.6.31 (by accident), but it got into the glibc headers (in 2009)
and remained there since this header was not updated since then.

10 years agonetinet/in.h: add missing IP protocol numbers from the linux uapi headers
Szabolcs Nagy [Sun, 15 Sep 2013 02:41:36 +0000 (02:41 +0000)]
netinet/in.h: add missing IP protocol numbers from the linux uapi headers

10 years agosupport configurable page size on mips, powerpc and microblaze
Szabolcs Nagy [Sun, 15 Sep 2013 02:00:32 +0000 (02:00 +0000)]
support configurable page size on mips, powerpc and microblaze

PAGE_SIZE was hardcoded to 4096, which is historically what most
systems use, but on several archs it is a kernel config parameter,
user space can only know it at execution time from the aux vector.

PAGE_SIZE and PAGESIZE are not defined on archs where page size is
a runtime parameter, applications should use sysconf(_SC_PAGE_SIZE)
to query it. Internally libc code defines PAGE_SIZE to libc.page_size,
which is set to aux[AT_PAGESZ] in __init_libc and early in __dynlink
as well. (Note that libc.page_size can be accessed without GOT, ie.
before relocations are done)

Some fpathconf settings are hardcoded to 4096, these should be actually
queried from the filesystem using statfs.

10 years agofix overflow in sysconf for _SC_MQ_PRIO_MAX
Rich Felker [Sat, 14 Sep 2013 23:27:24 +0000 (19:27 -0400)]
fix overflow in sysconf for _SC_MQ_PRIO_MAX

the value of MQ_PRIO_MAX does not fit, so it needs to use OFLOW.

10 years agofix child stack alignment on mips clone
Rich Felker [Sat, 14 Sep 2013 23:19:11 +0000 (19:19 -0400)]
fix child stack alignment on mips clone

unlike other archs, the mips version of clone was not doing anything
to align the stack pointer. this seems to have been the cause for some
SIGBUS crashes that were observed in posix_spawn.

10 years agofix mips sysv ipc bits headers
Rich Felker [Sat, 14 Sep 2013 18:44:03 +0000 (14:44 -0400)]
fix mips sysv ipc bits headers

msg.h was wrong for big-endian (wrong endiannness padding).
shm.h was just plain wrong (mips is not supposed to have padding).

both changes were tested using libc-test on qemu-system-mips.

10 years agofix x86_64 lrintl asm, again
Rich Felker [Fri, 13 Sep 2013 05:22:13 +0000 (01:22 -0400)]
fix x86_64 lrintl asm, again

the underlying problem was not incorrect sign extension (fixed in the
previous commit to this file by nsz) but that code that treats "long"
as 32-bit was copied blindly from i386 to x86_64.

now lrintl is identical to llrintl on x86_64, as it should be.

10 years agodo not use default when dynamic linker fails to open existing path file
Rich Felker [Mon, 9 Sep 2013 17:39:08 +0000 (13:39 -0400)]
do not use default when dynamic linker fails to open existing path file

if fopen fails for a reason other than ENOENT, we must assume the
intent is that the path file be used. failure may be due to
misconfiguration or intentional resource-exhaustion attack (against
suid programs), in which case falling back to loading libraries from
an unintended path could be dangerous.

10 years agomath: remove STRICT_ASSIGN from exp2f (see previous commit)
Szabolcs Nagy [Fri, 6 Sep 2013 20:05:25 +0000 (20:05 +0000)]
math: remove STRICT_ASSIGN from exp2f (see previous commit)

10 years agomath: remove STRICT_ASSIGN macro
Szabolcs Nagy [Fri, 6 Sep 2013 18:35:55 +0000 (18:35 +0000)]
math: remove STRICT_ASSIGN macro

gcc did not always drop excess precision according to c99 at assignments
before version 4.5 even if -std=c99 was requested which caused badly
broken mathematical functions on i386 when FLT_EVAL_METHOD!=0

but STRICT_ASSIGN was not used consistently and it is worked around for
old compilers with -ffloat-store so it is no longer needed

the new convention is to get the compiler respect c99 semantics and when
excess precision is not harmful use float_t or double_t or to specialize
code using FLT_EVAL_METHOD

10 years agomath: support invalid ld80 representations in fpclassify
Szabolcs Nagy [Thu, 5 Sep 2013 18:05:07 +0000 (18:05 +0000)]
math: support invalid ld80 representations in fpclassify

apparently gnulib requires invalid long double representations
to be handled correctly in printf so we classify them according
to how the fpu treats them: bad inf is nan, bad nan is nan,
bad normal is nan and bad subnormal/zero is minimal normal

10 years agomath: fix atanh (overflow and underflow issues)
Szabolcs Nagy [Thu, 5 Sep 2013 16:57:46 +0000 (16:57 +0000)]
math: fix atanh (overflow and underflow issues)

in atanh exception handling was left to the called log functions,
but the argument to those functions could underflow or overflow.

use double_t and float_t to avoid some useless stores on x86

10 years agomath: remove libc.h include from libm.h
Szabolcs Nagy [Thu, 5 Sep 2013 14:03:10 +0000 (14:03 +0000)]
math: remove libc.h include from libm.h

libc.h is only for weak_alias so include it directly where it is used

10 years agomath: fix acoshf on negative values
Szabolcs Nagy [Thu, 5 Sep 2013 12:26:26 +0000 (12:26 +0000)]
math: fix acoshf on negative values

acosh(x) is invalid for x<1, acoshf tried to be clever using
signed comparisions to handle all x<2 the same way, but the
formula was wrong on large negative values.

10 years agomath: fix expm1l on x86_64 (avoid underflow for large negative x)
Szabolcs Nagy [Thu, 5 Sep 2013 12:23:44 +0000 (12:23 +0000)]
math: fix expm1l on x86_64 (avoid underflow for large negative x)

copy the fix from i386: return -1 instead of exp2l(x)-1 when x <= -65

10 years agomath: fix lrintl.s on x86_64 (use movslq to signextend the result)
Szabolcs Nagy [Thu, 5 Sep 2013 12:04:58 +0000 (12:04 +0000)]
math: fix lrintl.s on x86_64 (use movslq to signextend the result)

10 years agomath: fix exp2l asm on x86 (raise underflow correctly)
Szabolcs Nagy [Thu, 5 Sep 2013 10:58:48 +0000 (10:58 +0000)]
math: fix exp2l asm on x86 (raise underflow correctly)

there were two problems:
* omitted underflow on subnormal results: exp2l(-16383.5) was calculated
as sqrt(2)*2^-16384, the last bits of sqrt(2) are zero so the down scaling
does not underflow eventhough the result is in subnormal range
* spurious underflow for subnormal inputs: exp2l(0x1p-16400) was evaluated
as f2xm1(x)+1 and f2xm1 raised underflow (because inexact subnormal result)

the first issue is fixed by raising underflow manually if x is in
(-32768,-16382] and not integer (x-0x1p63+0x1p63 != x)

the second issue is fixed by treating x in (-0x1p64,0x1p64) specially

for these fixes the special case handling was completely rewritten

10 years agomath: cosmetic cleanup (use explicit union instead of fshape and dshape)
Szabolcs Nagy [Wed, 4 Sep 2013 17:36:00 +0000 (17:36 +0000)]
math: cosmetic cleanup (use explicit union instead of fshape and dshape)

10 years agomath: remove *_WORD64 macros from libm.h
Szabolcs Nagy [Wed, 4 Sep 2013 16:39:41 +0000 (16:39 +0000)]
math: remove *_WORD64 macros from libm.h

only fma used these macros and the explicit union is clearer

10 years agomath: remove old longdbl.h
Szabolcs Nagy [Wed, 4 Sep 2013 16:05:32 +0000 (16:05 +0000)]
math: remove old longdbl.h

10 years agomath: long double fix (use ldshape union)
Szabolcs Nagy [Wed, 4 Sep 2013 15:54:02 +0000 (15:54 +0000)]
math: long double fix (use ldshape union)

* use new ldshape union consistently
* add ld128 support to frexpl
* simplify sqrtl comment (ld64 is not just arm)

10 years agomath: use float_t and double_t in scalbnf and scalbn
Szabolcs Nagy [Wed, 4 Sep 2013 15:52:54 +0000 (15:52 +0000)]
math: use float_t and double_t in scalbnf and scalbn

remove STRICT_ASSIGN (c99 semantics is assumed) and use the conventional
union to prepare the scaling factor (so libm.h is no longer needed)

10 years agomath: fix remaining old long double code (erfl, fmal, lgammal, scalbnl)
Szabolcs Nagy [Wed, 4 Sep 2013 15:52:23 +0000 (15:52 +0000)]
math: fix remaining old long double code (erfl, fmal, lgammal, scalbnl)

in lgammal don't handle 1 and 2 specially, in fma use the new ldshape
union instead of ld80 one.

10 years agomath: cbrt cleanup and long double fix
Szabolcs Nagy [Wed, 4 Sep 2013 15:51:05 +0000 (15:51 +0000)]
math: cbrt cleanup and long double fix

* use float_t and double_t
* cleanup subnormal handling
* bithacks according to the new convention (ldshape for long double
and explicit unions for float and double)

10 years agomath: fix underflow in exp*.c and long double handling in exp2l
Szabolcs Nagy [Wed, 4 Sep 2013 07:51:11 +0000 (07:51 +0000)]
math: fix underflow in exp*.c and long double handling in exp2l

* don't care about inexact flag
* use double_t and float_t (faster, smaller, more precise on x86)
* exp: underflow when result is zero or subnormal and not -inf
* exp2: underflow when result is zero or subnormal and not exact
* expm1: underflow when result is zero or subnormal
* expl: don't underflow on -inf
* exp2: fix incorrect comment
* expm1: simplify special case handling and overflow properly
* expm1: cleanup final scaling and fix negative left shift ub (twopk)

10 years agomath: long double trigonometric cleanup (cosl, sinl, sincosl, tanl)
Szabolcs Nagy [Tue, 3 Sep 2013 18:50:58 +0000 (18:50 +0000)]
math: long double trigonometric cleanup (cosl, sinl, sincosl, tanl)

ld128 support was added to internal kernel functions (__cosl, __sinl,
__tanl, __rem_pio2l) from freebsd (not tested, but should be a good
start for when ld128 arch arrives)

__rem_pio2l had some code cleanup, the freebsd ld128 code seems to
gather the results of a large reduction with precision loss (fixed
the bug but a todo comment was added for later investigation)

the old copyright was removed from the non-kernel wrapper functions
(cosl, sinl, sincosl, tanl) since these are trivial and the interesting
parts and comments had been already rewritten.

10 years agomath: long double inverse trigonometric cleanup (acosl, asinl, atanl, atan2l)
Szabolcs Nagy [Tue, 3 Sep 2013 15:02:10 +0000 (15:02 +0000)]
math: long double inverse trigonometric cleanup (acosl, asinl, atanl, atan2l)

* added ld128 support from freebsd fdlibm (untested)
* using new ldshape union instead of IEEEl2bits
* inexact status flag is not supported

10 years agomath: rewrite hypot
Szabolcs Nagy [Tue, 3 Sep 2013 14:37:48 +0000 (14:37 +0000)]
math: rewrite hypot

method: if there is a large difference between the scale of x and y
then the larger magnitude dominates, otherwise reduce x,y so the
argument of sqrt (x*x+y*y) does not overflow or underflow and calculate
the argument precisely using exact multiplication. If the argument
has less error than 1/sqrt(2) ~ 0.7 ulp, then the result has less error
than 1 ulp in nearest rounding mode.

the original fdlibm method was the same, except it used bit hacks
instead of dekker-veltkamp algorithm, which is problematic for long
double where different representations are supported. (the new hypot
and hypotl code should be smaller and faster on 32bit cpu archs with
fast fpu), the new code behaves differently in non-nearest rounding,
but the error should be still less than 2ulps.

ld80 and ld128 are supported

10 years agomath: rewrite remainder functions (remainder, remquo, fmod, modf)
Szabolcs Nagy [Tue, 3 Sep 2013 04:09:12 +0000 (04:09 +0000)]
math: rewrite remainder functions (remainder, remquo, fmod, modf)

* results are exact
* modfl follows truncl (raises inexact flag spuriously now)
* modf and modff only had cosmetic cleanup
* remainder is just a wrapper around remquo now
* using iterative shift+subtract for remquo and fmod
* ld80 and ld128 are supported as well

10 years agomath: rewrite rounding functions (ceil, floor, trunc, round, rint)
Szabolcs Nagy [Tue, 3 Sep 2013 03:27:02 +0000 (03:27 +0000)]
math: rewrite rounding functions (ceil, floor, trunc, round, rint)

* faster, smaller, cleaner implementation than the bit hacks of fdlibm
* use arithmetics like y=(double)(x+0x1p52)-0x1p52, which is an integer
neighbor of x in all rounding modes (0<=x<0x1p52) and only use bithacks
when that's faster and smaller (for float it usually is)
* the code assumes standard excess precision handling for casts
* long double code supports both ld80 and ld128
* nearbyint is not changed (it is a wrapper around rint)

10 years agomath: fix logb(-0.0) in downward rounding mode
Szabolcs Nagy [Mon, 2 Sep 2013 23:35:46 +0000 (23:35 +0000)]
math: fix logb(-0.0) in downward rounding mode

use -1/(x*x) instead of -1/(x+0) to return -inf, -0+0 is -0 in
downward rounding mode

10 years agomath: ilogb cleanup
Szabolcs Nagy [Mon, 2 Sep 2013 23:33:20 +0000 (23:33 +0000)]
math: ilogb cleanup

* consistent code style
* explicit union instead of typedef for double and float bit access
* turn FENV_ACCESS ON to make 0/0.0f raise invalid flag
* (untested) ld128 version of ilogbl (used by logbl which has ld128 support)

10 years agolong double cleanup, initial commit
Szabolcs Nagy [Mon, 2 Sep 2013 00:38:51 +0000 (00:38 +0000)]
long double cleanup, initial commit

new ldshape union, ld128 support is kept, code that used the old
ldshape union was rewritten (IEEEl2bits union of freebsd libm is
not touched yet)

ld80 __fpclassifyl no longer tries to handle invalid representation

10 years agofix typo in comment in __randname
Rich Felker [Wed, 4 Sep 2013 14:23:42 +0000 (10:23 -0400)]
fix typo in comment in __randname

10 years agofix mips-specific bug in synccall (too little space for signal mask)
Rich Felker [Mon, 2 Sep 2013 19:19:37 +0000 (15:19 -0400)]
fix mips-specific bug in synccall (too little space for signal mask)

switch to the new __block_all_sigs/__restore_sigs internal API to
clean up the code too.

10 years agoin synccall, ignore the signal before any threads' signal handlers return
Rich Felker [Mon, 2 Sep 2013 19:16:36 +0000 (15:16 -0400)]
in synccall, ignore the signal before any threads' signal handlers return

this protects against deadlock from spurious signals (e.g. sent by
another process) arriving after the controlling thread releases the
other threads from the sync operation.

10 years agofix invalid pointer in synccall (multithread setuid, etc.)
Rich Felker [Mon, 2 Sep 2013 19:06:46 +0000 (15:06 -0400)]
fix invalid pointer in synccall (multithread setuid, etc.)

the head pointer was not being reset between calls to synccall, so any
use of this interface more than once would build the linked list
incorrectly, keeping the (now invalid) list nodes from the previous
call.

10 years agofix special-case breakage in popen due to reversed argument order
Rich Felker [Sun, 1 Sep 2013 21:02:35 +0000 (17:02 -0400)]
fix special-case breakage in popen due to reversed argument order

10 years agoadd workaround header for wait.h remapping to sys/wait.h
Rich Felker [Sun, 1 Sep 2013 05:01:31 +0000 (01:01 -0400)]
add workaround header for wait.h remapping to sys/wait.h

10 years agofix missing return value warning in faccessat, minor cleanup
Rich Felker [Sun, 1 Sep 2013 03:15:48 +0000 (23:15 -0400)]
fix missing return value warning in faccessat, minor cleanup

clone will pass the return value of the start function to SYS_exit
anyway; there's no need to call the syscall directly.

10 years agofix invalid %m format crash in wide scanf variants
Rich Felker [Sun, 1 Sep 2013 02:52:41 +0000 (22:52 -0400)]
fix invalid %m format crash in wide scanf variants

the wide variant was missed in the previous commit.

10 years agoavoid crash in scanf when invalid %m format is encountered
Rich Felker [Sun, 1 Sep 2013 02:47:44 +0000 (22:47 -0400)]
avoid crash in scanf when invalid %m format is encountered

invalid format strings invoke undefined behavior, so this is not a
conformance issue, but it's nicer for scanf to report the error safely
instead of calling free on a potentially-uninitialized pointer or a
pointer to memory belonging to the caller.

10 years agoremove incorrect cancellation points from realpath
Rich Felker [Sat, 31 Aug 2013 20:01:01 +0000 (16:01 -0400)]
remove incorrect cancellation points from realpath

10 years agodebloat realpath's allocation strategy
Rich Felker [Sat, 31 Aug 2013 19:50:23 +0000 (15:50 -0400)]
debloat realpath's allocation strategy

rather than allocating a PATH_MAX-sized buffer when the caller does
not provide an output buffer, work first with a PATH_MAX-sized temp
buffer with automatic storage, and either copy it to the caller's
buffer or strdup it on success. this not only avoids massive memory
waste, but also avoids pulling in free (and thus the full malloc
implementation) unnecessarily in static programs.

10 years agomake realpath use O_PATH when opening the file
Rich Felker [Sat, 31 Aug 2013 19:44:58 +0000 (15:44 -0400)]
make realpath use O_PATH when opening the file

this avoids failure if the file is not readable and avoids odd
behavior for device nodes, etc. on old kernels that lack O_PATH, the
old behavior (O_RDONLY) will naturally happen as the fallback.

10 years agofix regression in creation of ldso symlink
Rich Felker [Sat, 31 Aug 2013 15:36:56 +0000 (11:36 -0400)]
fix regression in creation of ldso symlink

DESTDIR was wrongly included in the symlink contents.

10 years agofix breakage in synccall due to incorrect signal restoration in sigqueue
Rich Felker [Sat, 31 Aug 2013 05:12:00 +0000 (01:12 -0400)]
fix breakage in synccall due to incorrect signal restoration in sigqueue

commit 07827d1a82fb33262f686eda959857f0d28cd8fa seems to have
introduced this issue. sigqueue is called from the synccall core, at
which time, even implementation-internal signals are blocked. however,
pthread_sigmask removes the implementation-internal signals from the
old mask before returning, so that a process which began life with
them blocked will not be able to save a signal mask that has them
blocked, possibly causing them to become re-blocked later. however,
this was causing sigqueue to unblock the implementation-internal
signals during synccall, leading to deadlock.

10 years agofix typo in release notes
Rich Felker [Fri, 30 Aug 2013 21:30:27 +0000 (17:30 -0400)]
fix typo in release notes

10 years agorelease notes for 0.9.13
Rich Felker [Fri, 30 Aug 2013 21:24:25 +0000 (17:24 -0400)]
release notes for 0.9.13

10 years agoonly expose struct tcphdr under _GNU_SOURCE
Rich Felker [Fri, 30 Aug 2013 21:06:17 +0000 (17:06 -0400)]
only expose struct tcphdr under _GNU_SOURCE

the BSD and GNU versions of this structure differ, so exposing it in
the default _BSD_SOURCE profile is possibly problematic. both versions
could be simultaneously supported with anonymous unions if needed in
the future, but for now, just omitting it except under _GNU_SOURCE
should be safe.

10 years agoadd struct tcphdr in netinet/tcp.h
Rich Felker [Fri, 30 Aug 2013 20:50:00 +0000 (16:50 -0400)]
add struct tcphdr in netinet/tcp.h

10 years agoremove -Wcast-align from --enable-warnings
Rich Felker [Wed, 28 Aug 2013 09:08:16 +0000 (05:08 -0400)]
remove -Wcast-align from --enable-warnings

I originally added this warning option based on a misunderstanding of
how it works. it does not warn whenever the destination of the cast
has stricter alignment; it only warns in cases where misaligned
dereference could lead to a fault. thus, it's essentially a no-op for
i386, which had me wrongly believing the code was clean for this
warning level. on other archs, numerous diagnostic messages are
produced, and all of them are false-positives, so it's better just not
to use it.

10 years agooptimized C memcpy
Rich Felker [Wed, 28 Aug 2013 07:34:57 +0000 (03:34 -0400)]
optimized C memcpy

unlike the old C memcpy, this version handles word-at-a-time reads and
writes even for misaligned copies. it does not require that the cpu
support misaligned accesses; instead, it performs bit shifts to
realign the bytes for the destination.

essentially, this is the C version of the ARM assembly language
memcpy. the ideas are all the same, and it should perform well on any
arch with a decent number of general-purpose registers that has a
barrel shift operation. since the barrel shifter is an optional cpu
feature on microblaze, it may be desirable to provide an alternate asm
implementation on microblaze, but otherwise the C code provides a
competitive implementation for "generic risc-y" cpu archs that should
alleviate the urgent need for arch-specific memcpy asm.

10 years agostdbool.h should define __bool_true_false_are_defined even for C++
Rich Felker [Wed, 28 Aug 2013 04:41:00 +0000 (00:41 -0400)]
stdbool.h should define __bool_true_false_are_defined even for C++

while the incorporation of this requirement from C99 into C++11 was
likely an accident, some software expects it to be defined, and it
doesn't hurt. if the requirement is removed, then presumably
__bool_true_false_are_defined would just be in the implementation
namespace and thus defining it would still be legal.

10 years agofix invalid instruction mnemonics in powerpc fenv asm
Rich Felker [Tue, 27 Aug 2013 22:54:46 +0000 (18:54 -0400)]
fix invalid instruction mnemonics in powerpc fenv asm

there is no non-dot version of the andis instruction, but there's no
harm in updating the flags anyway, so just use the dot version.