musl
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'

11 years agofcntl.h: O_SEARCH was missing for powerpc
rofl0r [Sun, 18 Nov 2012 04:14:40 +0000 (05:14 +0100)]
fcntl.h: O_SEARCH was missing for powerpc

put some macros that do not differ between architectures in the
main header and remove from bits.
restructure mips header so it has the same structure as the others.

11 years agomath: use float constants in exp10f.c
Szabolcs Nagy [Sun, 18 Nov 2012 02:52:29 +0000 (03:52 +0100)]
math: use float constants in exp10f.c

use the 'f' suffix when a float constant is not representable

11 years agomath: expl.c cleanup
Szabolcs Nagy [Sun, 18 Nov 2012 02:49:16 +0000 (03:49 +0100)]
math: expl.c cleanup

raise overflow and underflow when necessary, fix various comments.

11 years agomath: expf.c cleanup
Szabolcs Nagy [Sun, 18 Nov 2012 02:42:09 +0000 (03:42 +0100)]
math: expf.c cleanup

similar to exp.c cleanup: use scalbnf, don't return excess precision,
drop some optimizatoins.
exp.c was changed to be more consistent with expf.c code.

11 years agoppc socket.h: add forgotten cmsghdr
rofl0r [Sun, 18 Nov 2012 01:38:41 +0000 (02:38 +0100)]
ppc socket.h: add forgotten cmsghdr

11 years agofix typo in dynamic linker path file loading code
Rich Felker [Sun, 18 Nov 2012 01:04:36 +0000 (20:04 -0500)]
fix typo in dynamic linker path file loading code

fortunately the memory corruption could not hurt anything, but it
prevented clearing the final newline and thus prevented the last path
element from working.

11 years agoadd cleaned-up sys/mtio.h
Rich Felker [Sun, 18 Nov 2012 00:51:49 +0000 (19:51 -0500)]
add cleaned-up sys/mtio.h

this is mostly junk, but a few programs with tape-drive support
unconditionally include it, and it might be useful.

11 years agoadd stub versions of some missing optional pthread interfaces
Rich Felker [Sat, 17 Nov 2012 23:42:16 +0000 (18:42 -0500)]
add stub versions of some missing optional pthread interfaces

priority inheritance is not yet supported, and priority protection
probably will not be supported ever unless there's serious demand for
it (it's a fairly heavy-weight feature).

per-thread cpu clocks would be nice to have, but to my knowledge linux
is still not capable of supporting them. glibc fakes them by using the
_process_ cpu-time clock and subtracting the thread creation time,
which gives seriously incorrect semantics (worse than not supporting
the feature at all), so until there's a way to do it right, it will
remain as a stub that always fails.

11 years agomath: cleanup exp2.c exp2f.c and exp2l.c
Szabolcs Nagy [Sat, 17 Nov 2012 22:39:39 +0000 (23:39 +0100)]
math: cleanup exp2.c exp2f.c and exp2l.c

* old code relied on sign extension on right shift
* exp2l ld64 wrapper was wrong
* use scalbn instead of bithacks

11 years agoarg-skipping code for powerpc dynamic linker
Rich Felker [Sat, 17 Nov 2012 22:25:17 +0000 (17:25 -0500)]
arg-skipping code for powerpc dynamic linker

this allows using the dynamic linker as a command to load programs.

11 years agomath: exp.c clean up
Szabolcs Nagy [Sat, 17 Nov 2012 22:22:41 +0000 (23:22 +0100)]
math: exp.c clean up

overflow and underflow was incorrect when the result was not stored.
an optimization for the 0.5*ln2 < |x| < 1.5*ln2 domain was removed.
did various cleanups around static constants and made the comments
consistent with the code.

11 years agodynamic linking support for powerpc
Rich Felker [Sat, 17 Nov 2012 03:22:34 +0000 (22:22 -0500)]
dynamic linking support for powerpc

incomplete but at least partly working. requires all files to be
compiled in the new "secure" plt model, not the old one that put plt
code in the data segment. TLS is untested but may work. invoking the
dynamic linker explicitly to load a program does not yet handle argv
correctly.

11 years agofix ppc stat structure definition
Rich Felker [Fri, 16 Nov 2012 06:19:42 +0000 (01:19 -0500)]
fix ppc stat structure definition

11 years agofix powerpc termios.h and ioctl.h
rofl0r [Fri, 16 Nov 2012 01:17:02 +0000 (02:17 +0100)]
fix powerpc termios.h and ioctl.h

11 years agodisable SO_REUSEPORT in sys/socket.h
Rich Felker [Fri, 16 Nov 2012 00:16:10 +0000 (19:16 -0500)]
disable SO_REUSEPORT in sys/socket.h

although a number is reserved for it, this option is not implemented
on Linux and does not work. defining it causes some applications to
use it, and subsequently break due to its failure.

11 years agoppc wchar_t is long, not int
Rich Felker [Thu, 15 Nov 2012 21:01:54 +0000 (16:01 -0500)]
ppc wchar_t is long, not int

11 years agoMerge remote-tracking branch 'nsz/math'
Rich Felker [Thu, 15 Nov 2012 13:37:58 +0000 (08:37 -0500)]
Merge remote-tracking branch 'nsz/math'

11 years agoupdate copyright file for recent contributions
Rich Felker [Thu, 15 Nov 2012 01:24:46 +0000 (20:24 -0500)]
update copyright file for recent contributions

11 years agofix indention with spaces in powerpc asm
Rich Felker [Wed, 14 Nov 2012 19:27:51 +0000 (14:27 -0500)]
fix indention with spaces in powerpc asm

11 years agofix powerpc atomic compare-and-swap function
Rich Felker [Wed, 14 Nov 2012 19:24:22 +0000 (14:24 -0500)]
fix powerpc atomic compare-and-swap function

previous version did not compare at all; it was just a fancy atomic
write. untested. further atomic fixes may be needed.

11 years agoupdate ppc atomic code to match the endian-agnostic version on other archs
Rich Felker [Wed, 14 Nov 2012 19:08:33 +0000 (14:08 -0500)]
update ppc atomic code to match the endian-agnostic version on other archs

11 years agofix wchar limits mistakenly copied from arm
Rich Felker [Wed, 14 Nov 2012 19:04:10 +0000 (14:04 -0500)]
fix wchar limits mistakenly copied from arm

11 years agoMerge remote-tracking branch 'ppc-port/ppc-squashed'
Rich Felker [Wed, 14 Nov 2012 19:01:39 +0000 (14:01 -0500)]
Merge remote-tracking branch 'ppc-port/ppc-squashed'

11 years agofenv: return FE_TONEAREST in dummy fegetround
Szabolcs Nagy [Wed, 14 Nov 2012 08:27:54 +0000 (09:27 +0100)]
fenv: return FE_TONEAREST in dummy fegetround

11 years agomath: ld80 invtrig cleanups
Szabolcs Nagy [Wed, 14 Nov 2012 00:01:38 +0000 (01:01 +0100)]
math: ld80 invtrig cleanups
keeping only commonly used data in invtrigl

11 years agomath: simplify hypot and hypotf using scalbn
Szabolcs Nagy [Tue, 13 Nov 2012 20:54:32 +0000 (21:54 +0100)]
math: simplify hypot and hypotf using scalbn

this also fixes overflow/underflow raising and excess
precision issues (as those are handled well in scalbn)

11 years agomath: turn off the STRICT_ASSIGN workaround by default
Szabolcs Nagy [Tue, 13 Nov 2012 18:59:02 +0000 (19:59 +0100)]
math: turn off the STRICT_ASSIGN workaround by default

the volatile hack in STRICT_ASSIGN is only needed if
assignment is not respected and excess precision is kept.
gcc -fexcess-precision=standard and -ffloat-store both
respect assignment and musl use these flags by default.
i kept the macro for now so the workaround may be used
for bad compilers in the future.

11 years agoPPC port cleaned up, static linking works well now.
rofl0r [Fri, 9 Nov 2012 22:36:55 +0000 (23:36 +0100)]
PPC port cleaned up, static linking works well now.

11 years agoimport preliminary ppc work by rdp.
Richard Pennington [Fri, 9 Nov 2012 22:32:57 +0000 (23:32 +0100)]
import preliminary ppc work by rdp.

11 years agomath: use '#pragma STDC FENV_ACCESS ON' when fenv is accessed
Szabolcs Nagy [Tue, 13 Nov 2012 12:34:45 +0000 (13:34 +0100)]
math: use '#pragma STDC FENV_ACCESS ON' when fenv is accessed

11 years agomath: excess precision fix modf, modff, scalbn, scalbnf
Szabolcs Nagy [Tue, 13 Nov 2012 09:55:35 +0000 (10:55 +0100)]
math: excess precision fix modf, modff, scalbn, scalbnf

old code was correct only if the result was stored (without the
excess precision) or musl was compiled with -ffloat-store.
now we use STRICT_ASSIGN to work around the issue.
(see note 160 in c11 section 6.8.6.4)

11 years agomath: fix scalbn and scalbnf on overflow/underflow
Szabolcs Nagy [Tue, 13 Nov 2012 09:30:40 +0000 (10:30 +0100)]
math: fix scalbn and scalbnf on overflow/underflow

old code was correct only if the result was stored (without the
excess precision) or musl was compiled with -ffloat-store.
(see note 160 in n1570.pdf section 6.8.6.4)

11 years agomath: fix nextafter and nexttoward on maxdbl and maxflt input
Szabolcs Nagy [Tue, 13 Nov 2012 09:12:07 +0000 (10:12 +0100)]
math: fix nextafter and nexttoward on maxdbl and maxflt input

old code (return x+x;) returns correct value and raises correct
flags only if the result is stored as double (or float)

11 years agocomplex: add C11 CMPLX macros and replace cpack with them
Szabolcs Nagy [Tue, 13 Nov 2012 00:31:49 +0000 (01:31 +0100)]
complex: add C11 CMPLX macros and replace cpack with them

11 years agomath: raise flags in logl.c on <= 0 arguments
Szabolcs Nagy [Mon, 12 Nov 2012 23:49:55 +0000 (00:49 +0100)]
math: raise flags in logl.c on <= 0 arguments

11 years agomath: fix logb*.c exceptions now that ilogb raises invalid
Szabolcs Nagy [Mon, 12 Nov 2012 23:45:51 +0000 (00:45 +0100)]
math: fix logb*.c exceptions now that ilogb raises invalid

11 years agomath: raise flags in log2l.c on <= 0 arguments, and fix volatile
Szabolcs Nagy [Mon, 12 Nov 2012 23:30:06 +0000 (00:30 +0100)]
math: raise flags in log2l.c on <= 0 arguments, and fix volatile

11 years agomath: raise exception flags in log1pl.c on <= -1 arguments
Szabolcs Nagy [Mon, 12 Nov 2012 23:21:09 +0000 (00:21 +0100)]
math: raise exception flags in log1pl.c on <= -1 arguments

11 years agomath: raise invalid flag in ilogb*.c on +-0, +-inf and nan
Szabolcs Nagy [Mon, 12 Nov 2012 22:58:18 +0000 (23:58 +0100)]
math: raise invalid flag in ilogb*.c on +-0, +-inf and nan

11 years agomath: fix exception behaviour of expm1l.c on inf and nan
Szabolcs Nagy [Mon, 12 Nov 2012 22:41:48 +0000 (23:41 +0100)]
math: fix exception behaviour of expm1l.c on inf and nan

11 years agomath: fix long double constants in exp10l.c
Szabolcs Nagy [Mon, 12 Nov 2012 22:13:28 +0000 (23:13 +0100)]
math: fix long double constants in exp10l.c

11 years agodebloat src/thread tree but putting lots of junk in one file
Rich Felker [Sun, 11 Nov 2012 21:08:38 +0000 (16:08 -0500)]
debloat src/thread tree but putting lots of junk in one file

POSIX includes mostly-useless attribute-get functions for each
attribute-set function, presumably out of some object-oriented
dogmatism. the get functions are not useful with the simple idiomatic
usage of attributes. there are of course possible valid uses of them
(like writing wrappers for pthread init functions that perform special
actions on the presence of certain attributes), but considering how
tiny these functions are anyway, little is lost by putting them all in
one file, and some build-time cost and archive-file-size benefits are
achieved.

11 years agoreport support of TPS option in unistd.h and sysconf
Rich Felker [Sun, 11 Nov 2012 20:54:20 +0000 (15:54 -0500)]
report support of TPS option in unistd.h and sysconf

also update another newish feature in sysconf, stackaddr

11 years agoadd support for thread scheduling (POSIX TPS option)
Rich Felker [Sun, 11 Nov 2012 20:38:04 +0000 (15:38 -0500)]
add support for thread scheduling (POSIX TPS option)

linux's sched_* syscalls actually implement the TPS (thread
scheduling) functionality, not the PS (process scheduling)
functionality which the sched_* functions are supposed to have.
omitting support for the PS option (and having the sched_* interfaces
fail with ENOSYS rather than omitting them, since some broken software
assumes they exist) seems to be the only conforming way to do this on
linux.

11 years agofix clobber of edx in i386 vsyscall asm
Rich Felker [Sun, 11 Nov 2012 18:56:37 +0000 (13:56 -0500)]
fix clobber of edx in i386 vsyscall asm

this function does not obey the normal calling convention; like a
syscall instruction, it's expected not to clobber any registers except
the return value. clobbering edx could break callers that were reusing
the value cached in edx after the syscall returns.

11 years agoalways add memory streams to stdio open file list
Rich Felker [Fri, 9 Nov 2012 19:26:25 +0000 (14:26 -0500)]
always add memory streams to stdio open file list

per interpretation for austin group issue #626, fflush(0) and exit()
must block waiting for a lock if another thread has locked a memory
stream with flockfile. this adds some otherwise-unnecessary
synchronization cost to use of memory streams, but there was already a
synchronization cost calling malloc anyway.

previously the stream was only added to the open file list in
single-threaded programs, so that upon subsequent call to
pthread_create, locking could be turned on for the stream.

11 years agosupport ldso path files without final newline
Rich Felker [Fri, 9 Nov 2012 18:49:40 +0000 (13:49 -0500)]
support ldso path files without final newline

11 years agochange ldso path file logic to replace rather than add to search path
Rich Felker [Fri, 9 Nov 2012 03:41:16 +0000 (22:41 -0500)]
change ldso path file logic to replace rather than add to search path

this change was originally intended just to avoid repeated attempts to
open a nonexistant /etc/ls-musl-$(ARCH).path file, but I realized it
also prevents the default paths from being searched when such a path
file exists. despite the potential to break existing usage, I believe
the new behavior is the right behavior, and it's better to fix it
sooner rather than later. with the old behavior, it was impossible to
inhibit search of default paths which might contain musl-incompatible
libs (or even libs from a different cpu arch, on multi-arch machines).

11 years agofix "configure --prefix=" and improve path/arg handling in configure
Rich Felker [Thu, 8 Nov 2012 22:20:50 +0000 (17:20 -0500)]
fix "configure --prefix=" and improve path/arg handling in configure

previously, empty string was treated as "use default". this is
apparently not compatible with standard configure semantics where an
empty prefix puts everything under /. the new logic should be a lot
cleaner and not suffer from such issues.

11 years agoclean up sloppy nested inclusion from pthread_impl.h
Rich Felker [Thu, 8 Nov 2012 22:04:20 +0000 (17:04 -0500)]
clean up sloppy nested inclusion from pthread_impl.h

this mirrors the stdio_impl.h cleanup. one header which is not
strictly needed, errno.h, is left in pthread_impl.h, because since
pthread functions return their error codes rather than using errno,
nearly every single pthread function needs the errno constants.

in a few places, rather than bringing in string.h to use memset, the
memset was replaced by direct assignment. this seems to generate much
better code anyway, and makes many functions which were previously
non-leaf functions into leaf functions (possibly eliminating a great
deal of bloat on some platforms where non-leaf functions require ugly
prologue and/or epilogue).

11 years agoclean up stdio_impl.h
Rich Felker [Thu, 8 Nov 2012 21:39:41 +0000 (16:39 -0500)]
clean up stdio_impl.h

this header evolved to facilitate the extremely lazy practice of
omitting explicit includes of the necessary headers in individual
stdio source files; not only was this sloppy, but it also increased
build time.

now, stdio_impl.h is only including the headers it needs for its own
use; any further headers needed by source files are included directly
where needed.

11 years agofix dlsym asm for mips
Rich Felker [Thu, 8 Nov 2012 19:31:49 +0000 (14:31 -0500)]
fix dlsym asm for mips

saving the return address from the delay slot is not valid -- by the
time the instruction executes, the return address has already been
replaced.

11 years agoimprove SOCK_NONBLOCK/SOCK_CLOEXEC fallback code
Rich Felker [Mon, 5 Nov 2012 19:30:15 +0000 (14:30 -0500)]
improve SOCK_NONBLOCK/SOCK_CLOEXEC fallback code

checking for EINVAL should be sufficient, but qemu user emulation
returns EPROTONOSUPPORT in some of the failure cases, and it seems
conceivable that other kernels doing linux-emulation could make the
same mistake. since DNS lookups and other important code might break
if the fallback does not get invoked, be extra careful and check for
either error.

note that it's important NOT to perform the fallback code on other
errors such as resource-exhaustion cases, since the fallback is not
atomic and will lead to file-descriptor leaks in multi-threaded
programs that use exec. the fallback code is only "safe" to run when
the initial failure is caused by the application's choice of
arguments, not the system state.

11 years agofix numerous mips abi constant definition mismatches
Rich Felker [Mon, 5 Nov 2012 19:29:04 +0000 (14:29 -0500)]
fix numerous mips abi constant definition mismatches

11 years agomips cache flush/ctl syscall support and header
Rich Felker [Sun, 4 Nov 2012 22:06:31 +0000 (17:06 -0500)]
mips cache flush/ctl syscall support and header

11 years agoremove one unnecessary static var from dynamic linker
Rich Felker [Fri, 2 Nov 2012 03:49:57 +0000 (23:49 -0400)]
remove one unnecessary static var from dynamic linker

11 years agofix more unused variable warnings
Rich Felker [Fri, 2 Nov 2012 03:46:39 +0000 (23:46 -0400)]
fix more unused variable warnings

some of these were coming from stdio functions locking files without
unlocking them. I believe it's useful for this to throw a warning, so
I added a new macro that's self-documenting that the file will never
be unlocked to avoid the warning in the few places where it's wrong.

11 years agofix unused variable warnings
Rich Felker [Fri, 2 Nov 2012 02:58:17 +0000 (22:58 -0400)]
fix unused variable warnings

11 years agoavoid breakage if somebody wrongly defines empty feature test macros
Rich Felker [Thu, 1 Nov 2012 07:49:43 +0000 (03:49 -0400)]
avoid breakage if somebody wrongly defines empty feature test macros

11 years agoadd dl_iterate_phdr interface
Rich Felker [Thu, 1 Nov 2012 01:27:48 +0000 (21:27 -0400)]
add dl_iterate_phdr interface

patches by Alex Caudill (npx). the dynamic-linked version is almost
identical to the final submitted patch; I just added a couple missing
lines for saving the phdr address when the dynamic linker is invoked
directly to run a program, and removed a couple to avoid introducing
another unnecessary type. the static-linked version is based on npx's
draft. it could use some improvements which are contingent on the
startup code saving some additional information for later use.

11 years agosystem is a cancellation point
Rich Felker [Mon, 29 Oct 2012 01:17:45 +0000 (21:17 -0400)]
system is a cancellation point

ideally, system would also be cancellable while running the external
command, but I cannot find any way to make that work without either
leaking zombie processes or introducing behavior that is far outside
what the standard specifies. glibc handles cancellation by killing the
child process with SIGKILL, but this could be unsafe in that it could
leave the data being manipulated by the command in an inconsistent
state.

11 years agorelease notes for 0.9.7
Rich Felker [Sun, 28 Oct 2012 22:45:11 +0000 (18:45 -0400)]
release notes for 0.9.7

11 years agofix shmdt syscall calling convention on old archs
Rich Felker [Sun, 28 Oct 2012 19:04:26 +0000 (15:04 -0400)]
fix shmdt syscall calling convention on old archs

11 years agoseparate getc/putc from fgetc/fputc
Rich Felker [Sat, 27 Oct 2012 23:52:40 +0000 (19:52 -0400)]
separate getc/putc from fgetc/fputc

for conformance, two functions should not have the same address. a
conforming program could use the addresses of getc and fgetc in ways
that assume they are distinct. normally i would just use a wrapper,
but these functions are so small and performance-critical that an
extra layer of function call could make the one that's a wrapper
nearly twice as slow, so I'm just duplicating the code instead.

11 years agoupdate documentation
Rich Felker [Sat, 27 Oct 2012 00:14:19 +0000 (20:14 -0400)]
update documentation

11 years agofurther pcc fixes in configure
Rich Felker [Fri, 26 Oct 2012 22:15:51 +0000 (18:15 -0400)]
further pcc fixes in configure

-lpcc only works if -nostdlib is not passed, so it's useless. instead,
use -print-file-name to look up the full pathname for libpcc.a, and
check whether that succeeds before trying to link with the result.

also, silence pcc's junk printed on stdout during tests.

11 years agoadd support for detecting pcc's compiler runtime
Rich Felker [Fri, 26 Oct 2012 20:30:07 +0000 (16:30 -0400)]
add support for detecting pcc's compiler runtime

in old versions of pcc, the directory containing libpcc.a was not in
the library path, and other options like -print-file-name may have
been needed to locate it. however, -print-file-name itself seems to
have been added around the same time that the directory was added to
the search path, and moreover, I see no evidence that older versions
of pcc are capable of building a working musl shared library. thus, it
seems reasonable to just test whether -lpcc is accepted.

11 years agouse explicit visibility to optimize a few hot-path function calls
Rich Felker [Thu, 25 Oct 2012 19:40:58 +0000 (15:40 -0400)]
use explicit visibility to optimize a few hot-path function calls

on x86 and some other archs, functions which make function calls which
might go through a PLT incur a significant overhead cost loading the
GOT register prior to making the call. this load is utterly useless in
musl, since all calls are bound at library-creation time using
-Bsymbolic-functions, but the compiler has no way of knowing this, and
attempts to set the default visibility to protected have failed due to
bugs in GCC and binutils.

this commit simply manually assigns hidden/protected visibility, as
appropriate, to a few internal-use-only functions which have many
callers, or which have callers that are hot paths like getc/putc. it
shaves about 5k off the i386 libc.so with -Os. many of the
improvements are in syscall wrappers, where the benefit is just size
and performance improvement is unmeasurable noise amid the syscall
overhead. however, stdio may be measurably faster.

if in the future there are toolchains that can do the same thing
globally without introducing linking bugs, it might be worth
considering removing these workarounds.

11 years agoconfigure: test not just compiling but linking with -march/-mtune
Rich Felker [Thu, 25 Oct 2012 18:52:12 +0000 (14:52 -0400)]
configure: test not just compiling but linking with -march/-mtune

pcc wrongly passes any option beginning with -m to the linker, and
will break at link time if these options were added to CFLAGS. testing
linking lets us catch this at configure time and skip them.

11 years agocorrect locking in stdio functions that tried to be lock-free
Rich Felker [Thu, 25 Oct 2012 03:16:41 +0000 (23:16 -0400)]
correct locking in stdio functions that tried to be lock-free

these functions must behave as if they obtain the lock via flockfile
to satisfy POSIX requirements. since another thread can provably hold
the lock when they are called, they must wait to obtain the lock
before they can return, even if the correct return value could be
obtained without locking. in the case of fclose and freopen, failure
to do so could cause correct (albeit obscure) programs to crash or
otherwise misbehave; in the case of feof, ferror, and fwide, failure
to obtain the lock could sometimes return incorrect results. in any
case, having these functions proceed and return while another thread
held the lock was wrong.

11 years agogreatly improve freopen behavior
Rich Felker [Thu, 25 Oct 2012 01:16:06 +0000 (21:16 -0400)]
greatly improve freopen behavior

1. don't open /dev/null just as a basis to copy flags; use shared
__fmodeflags function to get the right file flags for the mode.

2. handle the case (probably invalid, but whatever) case where the
original stream's file descriptor was closed; previously, the logic
re-closed it.

3. accept the "e" mode flag for close-on-exec; update dup3 to fallback
to using dup2 so we can simply call __dup3 instead of putting fallback
logic in freopen itself.