musl
11 years agomath: more correct tgmath.h type cast logic
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

11 years agomath: new type cast logic in tgmath.h
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

11 years agomath: use 0x1p-120f and 0x1p120f for tiny and huge values
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)

11 years agomath: tgammal.c fixes
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

11 years agomath: tanh.c cleanup similar to sinh, cosh
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

11 years agomath: sinh.c cleanup similar to the cosh one
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

11 years agomath: finished cosh.c cleanup
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.

11 years agomath: x86_64 version of expl, fixed some comments in the i386 version
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

11 years agomath: move x86_64 exp2l implementation to exp2l.s from expl.s
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

11 years agofix breakage in ldd (failure to print library load address)
Rich Felker [Sun, 16 Dec 2012 04:34:08 +0000 (23:34 -0500)]
fix breakage in ldd (failure to print library load address)

11 years agoMerge remote-tracking branch 'nsz/math'
Rich Felker [Sat, 15 Dec 2012 05:49:09 +0000 (00:49 -0500)]
Merge remote-tracking branch 'nsz/math'

11 years agoadd some missing macros to sys/shm.h
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.

11 years agomath: fix i386/expl.s with more precise x*log2e
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

11 years agofixed tgmath.h for functions with integral result
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

11 years agoadd missing flags in sys/timerfd.h
Rich Felker [Thu, 13 Dec 2012 19:15:11 +0000 (14:15 -0500)]
add missing flags in sys/timerfd.h

11 years agotreat invalid C as an error even if warnings aren't enabled.
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.

11 years agomath: add a non-dummy tgamma implementation
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.

11 years agomath: cosh cleanup
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

11 years agomath: fix comment in __rem_pio2f.c
Szabolcs Nagy [Wed, 12 Dec 2012 00:28:22 +0000 (01:28 +0100)]
math: fix comment in __rem_pio2f.c

11 years agomath: add empty __invtrigl.s to i386 and x86_64
Szabolcs Nagy [Tue, 11 Dec 2012 23:16:32 +0000 (00:16 +0100)]
math: add empty __invtrigl.s to i386 and x86_64

__invtrigl is not needed when acosl, asinl, atanl have asm
implementations

11 years agomath: clean up inverse trigonometric functions
Szabolcs Nagy [Tue, 11 Dec 2012 22:56:59 +0000 (23:56 +0100)]
math: clean up inverse trigonometric functions

modifications:
* avoid unsigned->signed conversions
* removed various volatile hacks
* use FORCE_EVAL when evaluating only for side-effects
* factor out R() rational approximation instead of manual inline
* __invtrigl.h now only provides __invtrigl_R, __pio2_hi and __pio2_lo
* use 2*pio2_hi, 2*pio2_lo instead of pi_hi, pi_lo

otherwise the logic is not changed, long double versions will
need a revisit when a genaral long double cleanup happens

11 years agomath: rewrite inverse hyperbolic functions to be simpler/smaller
Szabolcs Nagy [Tue, 11 Dec 2012 22:06:20 +0000 (23:06 +0100)]
math: rewrite inverse hyperbolic functions to be simpler/smaller

modifications:
* avoid unsigned->signed integer conversion
* do not handle special cases when they work correctly anyway
* more strict threshold values (0x1p26 instead of 0x1p28 etc)
* smaller code, cleaner branching logic
* same precision as the old code:
    acosh(x) has up to 2ulp error in [1,1.125]
    asinh(x) has up to 1.6ulp error in [0.125,0.5], [-0.5,-0.125]
    atanh(x) has up to 1.7ulp error in [0.125,0.5], [-0.5,-0.125]

11 years agomath: remove long double version of bessel functions from math.h
Szabolcs Nagy [Tue, 11 Dec 2012 21:57:39 +0000 (22:57 +0100)]
math: remove long double version of bessel functions from math.h

j0l,j1l,jnl,y0l,j1l,jnl are gnu extensions, bsd and posix do not
have them.
noone seems to use them and there is no plan to implement them any
time soon so we shouldn't declare them in math.h.

11 years agomake CMPLX macros available in complex.h in non-c11 mode as well
Szabolcs Nagy [Tue, 11 Dec 2012 21:44:36 +0000 (22:44 +0100)]
make CMPLX macros available in complex.h in non-c11 mode as well

11 years agofix double errno-decoding in the old-kernel fallback path of pipe2
Rich Felker [Tue, 11 Dec 2012 14:38:38 +0000 (09:38 -0500)]
fix double errno-decoding in the old-kernel fallback path of pipe2

this bug seems to have caused any failure by pipe2 on such systems to
set errno to 1, rather than the proper error code.

11 years agofix regressions in app compatibility from previous sys/ipc.h changes
Rich Felker [Tue, 11 Dec 2012 02:36:12 +0000 (21:36 -0500)]
fix regressions in app compatibility from previous sys/ipc.h changes

despite glibc using __key and __seq rather than key and seq, some
applications, notably busybox, assume the names are key and seq unless
glibc is being used. and the names key and seq are really the ones
that _should_ be exposed when not attempting to present a
standards-conforming namespace; apps should not be using names that
begin with double-underscore. thus, the optimal fix is to use key and
seq as the actual names of the members when in bsd/gnu source profile,
and define macros for __key and __seq that redirect to plain key and
seq.

11 years agodocument self-synchronized destruction issue for stdio locking
Rich Felker [Mon, 10 Dec 2012 23:31:39 +0000 (18:31 -0500)]
document self-synchronized destruction issue for stdio locking

11 years agosyscall() declaration belongs in unistd.h, not sys/syscall.h
Rich Felker [Mon, 10 Dec 2012 21:40:45 +0000 (16:40 -0500)]
syscall() declaration belongs in unistd.h, not sys/syscall.h

traditionally, both BSD and GNU systems have it this way.
sys/syscall.h is purely syscall number macros. presently glibc exposes
the syscall declaration in unistd.h only with _GNU_SOURCE, but that
does not reflect historical practice.

11 years agoadd support for ctors/dtors on arm with modern gcc
Rich Felker [Sat, 8 Dec 2012 04:04:49 +0000 (23:04 -0500)]
add support for ctors/dtors on arm with modern gcc

a while back, gcc switched from using the old _init/_fini fragments
method for calling ctors and dtors on arm to the __init_array and
__fini_array method. unfortunately, on glibc this depends on ugly
hacks involving making libc.so a linker script and pulling parts of
libc into the main program binary. so I cheat a little bit, and just
write asm to iterate over the init/fini arrays from the _init/_fini
asm. the same approach could be used on any arch it's needed on, but
for now arm is the only one.

11 years agopage-align initial brk value used by malloc in shared libc
Rich Felker [Sat, 8 Dec 2012 03:33:11 +0000 (22:33 -0500)]
page-align initial brk value used by malloc in shared libc

this change fixes an obscure issue with some nonstandard kernels,
where the initial brk syscall returns a pointer just past the end of
bss rather than the beginning of a new page. in that case, the dynamic
linker has already reclaimed the space between the end of bss and the
page end for use by malloc, and memory corruption (allocating the same
memory twice) will occur when malloc again claims it on the first call
to brk.

11 years agoremove __arch_prctl alias for arch_prctl
Rich Felker [Fri, 7 Dec 2012 21:22:13 +0000 (16:22 -0500)]
remove __arch_prctl alias for arch_prctl

if there's evidence of any use for it, we can add it back later. as
far as I can tell, glibc has it only for internal use (and musl uses a
direct syscall in that case rather than a function call), not for
exposing it to applications.

11 years agomove new linux syscall wrapper functions to proper source dir
Rich Felker [Fri, 7 Dec 2012 21:17:16 +0000 (16:17 -0500)]
move new linux syscall wrapper functions to proper source dir

11 years agofix trailing whitespace issues that crept in here and there
Rich Felker [Fri, 7 Dec 2012 21:16:44 +0000 (16:16 -0500)]
fix trailing whitespace issues that crept in here and there

11 years agofix invalid read in aligned_alloc
Rich Felker [Fri, 7 Dec 2012 02:12:28 +0000 (21:12 -0500)]
fix invalid read in aligned_alloc

in case of mmap-obtained chunks, end points past the end of the
mapping and reading it may fault. since the value is not needed until
after the conditional, move the access to prevent invalid reads.

11 years agomove signal.h REG_* macros under _GNU_SOURCE protection
Rich Felker [Thu, 6 Dec 2012 22:05:19 +0000 (17:05 -0500)]
move signal.h REG_* macros under _GNU_SOURCE protection

they were accidentally exposed under just baseline POSIX, which is a
big namespace pollution issue. thankfully glibc only exposes them
under _GNU_SOURCE, not under any of its other options, so omitting
the pollution in the default _BSD_SOURCE profile does not hurt
application compatibility at all.

11 years agofix names of ipc_perm __key/__seq elements
Rich Felker [Thu, 6 Dec 2012 21:52:09 +0000 (16:52 -0500)]
fix names of ipc_perm __key/__seq elements

previously the names were exposed as key/seq with _GNU_SOURCE and
__ipc_perm_key/__ipc_perm/seq otherwise, whereas glibc always uses
__key and __seq for the names. thus, the old behavior never matched
glibc, and the new behavior always does, regardless of feature test
macros.

for now, i'm leaving the renaming here in sys/ipc.h where it's easy to
change globally for all archs, in case something turns out to be
wrong, but eventually the names could just be incorporated directly
into the bits headers for each arch and the renaming removed.

11 years agofix sigorset/sigandset: _NSIG/8 is the size in bytes
rofl0r [Thu, 6 Dec 2012 21:48:46 +0000 (22:48 +0100)]
fix sigorset/sigandset: _NSIG/8 is the size in bytes

11 years agofix F_DUPFD_CLOEXEC being defined twice
rofl0r [Thu, 6 Dec 2012 21:45:56 +0000 (22:45 +0100)]
fix F_DUPFD_CLOEXEC being defined twice

11 years agosigandset/sigorset: do not check for NULL pointers.
rofl0r [Thu, 6 Dec 2012 21:14:37 +0000 (22:14 +0100)]
sigandset/sigorset: do not check for NULL pointers.

that way it's consistent with existing sig* functions, and saves
some code size.

11 years agofixup sigandset
rofl0r [Thu, 6 Dec 2012 20:50:37 +0000 (21:50 +0100)]
fixup sigandset

11 years agofixup for fcntl.h changes
rofl0r [Thu, 6 Dec 2012 20:43:00 +0000 (21:43 +0100)]
fixup for fcntl.h changes

11 years agoadd arch_prctl syscall (amd64/x32 only)
rofl0r [Thu, 6 Dec 2012 20:07:19 +0000 (21:07 +0100)]
add arch_prctl syscall (amd64/x32 only)

11 years agoadd personality syscall
rofl0r [Thu, 6 Dec 2012 20:01:06 +0000 (21:01 +0100)]
add personality syscall

11 years agoadd sigandset and sigorset (needed for qemu)
rofl0r [Thu, 6 Dec 2012 19:51:32 +0000 (20:51 +0100)]
add sigandset and sigorset (needed for qemu)

11 years agoadd struct msgbuf to sys/msg.h
rofl0r [Thu, 6 Dec 2012 19:03:04 +0000 (20:03 +0100)]
add struct msgbuf to sys/msg.h

11 years agounistd.h: fix wrong type for gid_t argument
rofl0r [Thu, 6 Dec 2012 18:48:14 +0000 (19:48 +0100)]
unistd.h: fix wrong type for gid_t argument

the prototype is defined with const gid_t* rather than const gid_t[].
it was already correctly defined in grp.h.

11 years agoipc.h: fix gnu aliases for key and seq in struct ipc_perm
rofl0r [Thu, 6 Dec 2012 18:39:52 +0000 (19:39 +0100)]
ipc.h: fix gnu aliases for key and seq in struct ipc_perm

the macro was the wrong way round, additionally GNU defines
__ prefixed versions, which are used by qemu.

11 years agoadd obsolete futimesat()
rofl0r [Thu, 6 Dec 2012 18:29:38 +0000 (19:29 +0100)]
add obsolete futimesat()

this function is obsolete, however it's available as a syscall
and as such qemu userspace emulation tries to forward it to the
host kernel.

11 years agobits/signal.h: add register names for x86(_64)
rofl0r [Thu, 6 Dec 2012 17:14:45 +0000 (18:14 +0100)]
bits/signal.h: add register names for x86(_64)

glibc exposes them from ucontext.h.
since that header includes signal.h, it is safe to put them
into bits/signal.h, if _GNU_SOURCE is defined.

11 years agofcntl.h: add some linux-specific F_ macros
rofl0r [Thu, 6 Dec 2012 16:48:11 +0000 (17:48 +0100)]
fcntl.h: add some linux-specific F_ macros

thankfully these are all generic across archs.
the DN_ macros are for usage with F_NOTIFY.

11 years agotcp.h: add SOL_TCP, analoguous to udp.h
rofl0r [Thu, 6 Dec 2012 16:02:19 +0000 (17:02 +0100)]
tcp.h: add SOL_TCP, analoguous to udp.h

11 years agoadd more arch-specific MAP_ macros to bits/mman.h
rofl0r [Thu, 6 Dec 2012 15:57:22 +0000 (16:57 +0100)]
add more arch-specific MAP_ macros to bits/mman.h

these are also needed by qemu.

11 years agoremove MAP_32 from non-x86 archs
rofl0r [Thu, 6 Dec 2012 00:24:03 +0000 (01:24 +0100)]
remove MAP_32 from non-x86 archs

both kernel and glibc define it only on x86(_64).

11 years agoadd MAP_NORESERVE to bits/mman.h
rofl0r [Thu, 6 Dec 2012 00:20:48 +0000 (01:20 +0100)]
add MAP_NORESERVE to bits/mman.h

this is needed for qemu, and since it differs for each arch
it can't be circumvented easily by using a macro in CFLAGS.

11 years agoremove fenv saving/loading code from setjmp/longjmp on arm
Rich Felker [Thu, 6 Dec 2012 00:13:47 +0000 (19:13 -0500)]
remove fenv saving/loading code from setjmp/longjmp on arm

the issue is identical to the recent commit fixing the mips versions:
despite other implementations doing this, it conflicts with the
requirements of ISO C and it's a waste of time and code size.

11 years agofix inefficiency of math.h isless, etc. macros
Rich Felker [Wed, 5 Dec 2012 19:12:57 +0000 (14:12 -0500)]
fix inefficiency of math.h isless, etc. macros

previously, everything was going through an intermediate conversion to
long double, which caused the extern __fpclassifyl function to get
invoked, preventing virtually all optimizations of these operations.

with the new code, tests on constant float or double arguments compile
to a constant 0 or 1, and tests on non-constant expressions are
efficient. I may later add support for __builtin versions on compilers
that support them.

11 years agoremove mips setjmp/longjmp code to save/restore fenv
Rich Felker [Wed, 5 Dec 2012 17:52:40 +0000 (12:52 -0500)]
remove mips setjmp/longjmp code to save/restore fenv

nothing in the standard requires or even allows the fenv state to be
restored by longjmp. restoring the exception flags is not such a big
deal since it's probably valid to clobber them completely, but
restoring the rounding mode yields an observable side effect not
sanctioned by ISO C. saving/restoring it also wastes a few cycles and
16 bytes of code.

as for historical behavior, reportedly SGI IRIX did save/restore fenv,
and this is where glibc and uClibc got the behavior from. a few other
systems save/restore it too (on archs other than mips), even though
this is apparently wrong. further details are documented here:

http://www-personal.umich.edu/~williams/archive/computation/setjmp-fpmode.html

as musl aims for standards conformance rather than coddling historical
programs expecting non-conforming behavior, and as it's unlikely that
any historical programs actually depend on the incorrect behavior
(such programs would break on other archs, anyway), I'm making the
change not to save/restore fenv on mips.

11 years agoadd scsi headers scsi.h and sg.h
Rich Felker [Wed, 5 Dec 2012 17:35:24 +0000 (12:35 -0500)]
add scsi headers scsi.h and sg.h

due to some historical oddity, these are considered libc headers
rather than kernel headers. the kernel used to provide them too, but
it seems modern kernels do not install them, so let's just do the
easiest thing and provide them. stripped-down versions provided by
John Spencer.

11 years agouse __builtin_offsetof to implement offsetof when possible
Rich Felker [Wed, 5 Dec 2012 05:00:42 +0000 (00:00 -0500)]
use __builtin_offsetof to implement offsetof when possible

apparently recent gcc versions have intentionally broken the
traditional definition by treating it as a non-constant expression.
the traditional definition may also be problematic for c++ programs.

11 years agouse alternate argument syntax for restrict with lio_listio
Rich Felker [Wed, 5 Dec 2012 00:03:42 +0000 (19:03 -0500)]
use alternate argument syntax for restrict with lio_listio

for some reason I have not been able to determine, gcc 3.2 rejects the
array notation. this seems to be a gcc bug, but since it's easy to
work around, let's do the workaround and avoid gratuitously requiring
newer compilers.

11 years agofix regression in arm user.h that happened during big user.h changes
Rich Felker [Tue, 4 Dec 2012 14:32:45 +0000 (09:32 -0500)]
fix regression in arm user.h that happened during big user.h changes

11 years agoadd _ALL_SOURCE as an alias for _GNU_SOURCE/enable-everything
Rich Felker [Mon, 3 Dec 2012 22:02:56 +0000 (17:02 -0500)]
add _ALL_SOURCE as an alias for _GNU_SOURCE/enable-everything

reportedly this is a semi-common practice among some BSDs and a few
other systems, and will improve application compatibility.

11 years agofeature test macros: make _GNU_SOURCE enable everything
Rich Felker [Mon, 3 Dec 2012 21:57:01 +0000 (16:57 -0500)]
feature test macros: make _GNU_SOURCE enable everything

previously, a few BSD features were enabled only by _BSD_SOURCE, not
by _GNU_SOURCE. since _BSD_SOURCE is default in the absence of other
feature test macros, this made adding _GNU_SOURCE to a project not a
purely additive feature test macro; it actually caused some features
to be suppressed.

most of the changes made by this patch actually bring musl in closer
alignment with the glibc behavior for _GNU_SOURCE. the only exceptions
are the added visibility of functions like strlcpy which were BSD-only
due to being disliked/rejected by glibc maintainers. here, I feel the
consistency of having _GNU_SOURCE mean "everything", and especially
the property of it being purely additive, are more valuable than
hiding functions which glibc does not have.

11 years agofix a couple issues in the inttypes.h PRI/SCN macros
Rich Felker [Sun, 2 Dec 2012 20:18:05 +0000 (15:18 -0500)]
fix a couple issues in the inttypes.h PRI/SCN macros

most importantly, the format/scan macros for the [u]int_fast16_t and
[u]int_fast32_t types were defined incorrectly assuming these types
would match the native word/pointer size. this is incorrect on any
64-bit system; the "fast" types for 16- and 32-bit integers are simply
int.

another issue which was "only a warning" (despite being UB) is that
the choice of "l" versus "ll" was incorrect for 64-bit types on 64-bit
machines. while it would "work" to always use "long long" for 64-bit
types, we use "long" on 64-bit machines to match what glibc does and
what the ABI documents recommend. the macro definitions were probably
right in very old versions of musl, but became wrong when we aligned
most closely with the 'standard' ABI. checking UINTPTR_MAX is an easy
way to get the system wordsize without pulling in new headers.

finally, the useless __PRIPTR macro to allow the underlying type of
[u]intptr_t to vary has been removed. we are using "long" on all
targets, and thankfully this matches what glibc does, so I do not
envision ever needing to change it. thus, the "l" has just been
incorporated directly in the strings.

11 years agoprovide NSIG under _BSD_SOURCE (default) as well as _GNU_SOURCE
Rich Felker [Sat, 1 Dec 2012 02:00:18 +0000 (21:00 -0500)]
provide NSIG under _BSD_SOURCE (default) as well as _GNU_SOURCE

this fixes a regression related to the changes made to bits/signal.h
between 0.9.7 and 0.9.8 that broke some (non-portable) software.

11 years agofix ordering of shared library ctors with respect to libc init
Rich Felker [Fri, 30 Nov 2012 22:56:23 +0000 (17:56 -0500)]
fix ordering of shared library ctors with respect to libc init

previously, shared library constructors were being called before
important internal things like the environment (extern char **environ)
and hwcap flags (needed for sjlj to work right with float on arm) were
initialized in __libc_start_main. rather than trying to have to
dynamic linker make sure this stuff all gets initialized right, I've
opted to just defer calling shared library constructors until after
the main program's entry point is reached. this also fixes the order
of ctors to be the exact reverse of dtors, which is a desirable
property and possibly even mandated by some languages.

the main practical effect of this change is that shared libraries
calling getenv from ctors will no longer fail.

11 years agofix some restrict-qualifier mismatches in newly added interfaces
Rich Felker [Tue, 27 Nov 2012 14:44:30 +0000 (09:44 -0500)]
fix some restrict-qualifier mismatches in newly added interfaces

these should have little/no practical impact but they're needed for
strict conformance.

11 years agoupdate readme and release notes for 0.9.8
Rich Felker [Tue, 27 Nov 2012 02:01:30 +0000 (21:01 -0500)]
update readme and release notes for 0.9.8

11 years agoremove stat member aliases from ppc-specific bits/stat.h
Rich Felker [Tue, 27 Nov 2012 01:42:20 +0000 (20:42 -0500)]
remove stat member aliases from ppc-specific bits/stat.h

if these are to be supported, they belong in the main stat.h, not
repeated for each arch.

11 years agofix eventfd and inotify nonblock/cloexec flags to match arch values
Rich Felker [Mon, 26 Nov 2012 18:00:58 +0000 (13:00 -0500)]
fix eventfd and inotify nonblock/cloexec flags to match arch values

11 years agofix missing limits when only _BSD_SOURCE is defined
Rich Felker [Mon, 26 Nov 2012 17:05:33 +0000 (12:05 -0500)]
fix missing limits when only _BSD_SOURCE is defined

the missing check did not affect the default profile, since it has
both _XOPEN_SOURCE and _BSD_SOURCE defined, but it did break programs
which explicitly define _BSD_SOURCE, causing it to be the only feature
test macro present.

11 years agofixup mcontext stuff to expost gregset_t/fpregset_t as appropriate
Rich Felker [Mon, 26 Nov 2012 04:04:23 +0000 (23:04 -0500)]
fixup mcontext stuff to expost gregset_t/fpregset_t as appropriate

11 years agomake sys/procfs.h mostly work on most archs
Rich Felker [Mon, 26 Nov 2012 03:28:18 +0000 (22:28 -0500)]
make sys/procfs.h mostly work on most archs

these structures are purely for use by trace/debug tools and tools
working with core files. the definition of fpregset_t, which was
previously here, has been removed because it was wrong; fpregset_t
should be the type used in mcontext_t, not the type used in
ptrace/core stuff.

11 years agoremove microblaze user.h incorrectly copied from arm
Rich Felker [Mon, 26 Nov 2012 02:12:34 +0000 (21:12 -0500)]
remove microblaze user.h incorrectly copied from arm

11 years agoeliminate gdb complaints about missing linux-gate.so.1
Rich Felker [Mon, 26 Nov 2012 01:56:31 +0000 (20:56 -0500)]
eliminate gdb complaints about missing linux-gate.so.1

actually, the hard-coded name should be eliminated too, and replaced
by a search for the soname in the headers, but that can be done
separately later.

11 years agobegin sys/user.h and sys/reg.h fixes for ports
Rich Felker [Sat, 24 Nov 2012 01:05:43 +0000 (20:05 -0500)]
begin sys/user.h and sys/reg.h fixes for ports

aside from microblaze, these should be roughly correct for all archs
now. some misc junk macros and typedefs are missing, which should
probably be added for max compatibility with trace/debug tools.

11 years agofix powerpc ucontext, again..
Rich Felker [Sat, 24 Nov 2012 00:54:56 +0000 (19:54 -0500)]
fix powerpc ucontext, again..

it should now really match the kernel. some of the removed padding
corresponded to the difference between user and kernel sigset_t. the
space at the end was redundant with the uc_mcontext member and seems
to have been added as a result of misunderstanding glibc's definition
versus the kernel's.

11 years agofix termios constants on mips
Rich Felker [Fri, 23 Nov 2012 22:23:38 +0000 (17:23 -0500)]
fix termios constants on mips

11 years agosigcontext/mcontext cleanup for arch-specific bits
Rich Felker [Fri, 23 Nov 2012 19:35:25 +0000 (14:35 -0500)]
sigcontext/mcontext cleanup for arch-specific bits

with these changes, the members/types of mcontext_t and related stuff
should closely match the glibc definitions. unlike glibc, however, the
definitions here avoid using typedefs as much as possible and work
directly with the underlying types, to minimize namespace pollution
from signal.h in the default (_BSD_SOURCE) profile.

this is a first step in improving compatibility with applications
which poke at context/register information -- mainly debuggers, trace
utilities, etc. additional definitions in ucontext.h and other headers
may be needed later.

if feature test macros are used to request a conforming namespace,
mcontext_t is replaced with an opaque structure of the equivalent size
and alignment; conforming programs cannot examine its contents anyway.

11 years agofix powerpc sigsetjmp asm to match the new jmp_buf size/offsets
Rich Felker [Fri, 23 Nov 2012 19:34:59 +0000 (14:34 -0500)]
fix powerpc sigsetjmp asm to match the new jmp_buf size/offsets

11 years agofix powerpc setjmp/longjmp to save/restore float regs; enlarge/align jmp_buf
Rich Felker [Fri, 23 Nov 2012 19:30:58 +0000 (14:30 -0500)]
fix powerpc setjmp/longjmp to save/restore float regs; enlarge/align jmp_buf

11 years agoadd missing startfiles for powerpc
Rich Felker [Fri, 23 Nov 2012 18:31:16 +0000 (13:31 -0500)]
add missing startfiles for powerpc

11 years agofix up leftover, incorrect NSIG definitions in arch-specific signal.h
Rich Felker [Fri, 23 Nov 2012 17:20:53 +0000 (12:20 -0500)]
fix up leftover, incorrect NSIG definitions in arch-specific signal.h

11 years agoremove stuff that doesn't belong in powerpc 32-bit sigcontext
Rich Felker [Fri, 23 Nov 2012 16:27:25 +0000 (11:27 -0500)]
remove stuff that doesn't belong in powerpc 32-bit sigcontext

these fields were wrongly copied from the kernel's ppc64 struct def

11 years agomore ppc signal.h typedef order fixes
Rich Felker [Wed, 21 Nov 2012 18:51:14 +0000 (13:51 -0500)]
more ppc signal.h typedef order fixes

11 years agofix misordered typedefs in ppc signal.h
Rich Felker [Wed, 21 Nov 2012 18:50:40 +0000 (13:50 -0500)]
fix misordered typedefs in ppc signal.h

11 years agoppc signal/NSIG related fix (warning fix, redefinition)
Rich Felker [Wed, 21 Nov 2012 18:49:31 +0000 (13:49 -0500)]
ppc signal/NSIG related fix (warning fix, redefinition)

11 years agoadd back NSIG, removed from powerpc in last commit, but for all archs
Rich Felker [Wed, 21 Nov 2012 18:41:58 +0000 (13:41 -0500)]
add back NSIG, removed from powerpc in last commit, but for all archs

unlike the previous definition, NSIG/_NSIG is supposed to be one more
than the highest signal number. adding this will allow simplifying
libc-internal code that makes signal-related syscalls, which can be
done as a later step. some apps might use it too; while this usage is
questionable, it's at least not insane.

11 years agomake powerpc signal.h namespace-clean for posix/isoc
Rich Felker [Wed, 21 Nov 2012 18:36:01 +0000 (13:36 -0500)]
make powerpc signal.h namespace-clean for posix/isoc

also handle the non-GNUC case where alignment attribute is not available
by simply omitting it. this will not cause problems except for
inclusion of mcontex_t/ucontext_t in application-defined structures,
since the natural alignment of the uc_mcontext member relative to the
start of ucontext_t is already correct. and shame on whoever designed
this for making it impossible to satisfy the ABI requirements without
GNUC extensions.

11 years agofix powerpc types to match abi, and some feature test issues
Rich Felker [Wed, 21 Nov 2012 18:29:50 +0000 (13:29 -0500)]
fix powerpc types to match abi, and some feature test issues

11 years agofix invalid usage of mcontext_t in powerpc signal.h
rofl0r [Wed, 21 Nov 2012 05:24:05 +0000 (06:24 +0100)]
fix invalid usage of mcontext_t in powerpc signal.h

11 years agopowerpc: handle syscall error in clone.
rofl0r [Mon, 19 Nov 2012 05:21:48 +0000 (06:21 +0100)]
powerpc: handle syscall error in clone.

sigsetjmp: store temporaries in jmp_buf rather than on stack.

11 years agofix error in configure script using >/dev/null in noclobber mode
Rich Felker [Mon, 19 Nov 2012 04:15:47 +0000 (23:15 -0500)]
fix error in configure script using >/dev/null in noclobber mode

11 years agofix powerpc asm not to store data in volatile space below stack pointer
Rich Felker [Mon, 19 Nov 2012 03:57:32 +0000 (22:57 -0500)]
fix powerpc asm not to store data in volatile space below stack pointer

it's essential to decrement the stack pointer before writing to new
stack space, rather than afterwards. otherwise there is a race
condition during which asynchronous code (signals) could clobber the
data being stored.

it may be possible to optimize the code further using stwu, but I
wanted to avoid making any changes to the actual stack layout in this
commit. further improvements can be made separately if desired.

11 years agofix breakage from introducing bits header for sys/io.h
Rich Felker [Mon, 19 Nov 2012 00:58:15 +0000 (19:58 -0500)]
fix breakage from introducing bits header for sys/io.h

apparently some other archs have sys/io.h and should not break just
because they don't have the x86 port io functions. provide a blank
bits/io.h everywhere for now.

11 years agoadd port io functions to sys/io.h
Rich Felker [Mon, 19 Nov 2012 00:31:58 +0000 (19:31 -0500)]
add port io functions to sys/io.h

based on proposal by Isaac Dunham. nonexistance of bits/io.h will
cause inclusion of sys/io.h to produce an error on archs that are not
supposed to have it. this is probably the desired behavior, but the
error message may be a bit unusual.

11 years agoadd missing const on powerpc FE_DFL_ENV
Rich Felker [Sun, 18 Nov 2012 21:58:05 +0000 (16:58 -0500)]
add missing const on powerpc FE_DFL_ENV

11 years agofenv support for ppc, untested
Rich Felker [Sun, 18 Nov 2012 21:31:14 +0000 (16:31 -0500)]
fenv support for ppc, untested

based on code sent to the mailing list by nsz, with minor changes.

11 years agofix feholdexcept -- it needs to clear exceptions after saving environment
Rich Felker [Sun, 18 Nov 2012 21:10:20 +0000 (16:10 -0500)]
fix feholdexcept -- it needs to clear exceptions after saving environment

11 years agoMerge remote-tracking branch 'nsz/math'
Rich Felker [Sun, 18 Nov 2012 20:19:35 +0000 (15:19 -0500)]
Merge remote-tracking branch 'nsz/math'