Commit Graph

3368 Commits

Author SHA1 Message Date
Szabolcs Nagy f9c3a2e048 add missing powerpc specific PROT_SAO memory protection flag
this flag for strong access ordering was added in linux v2.6.27
commit aba46c5027cb59d98052231b36efcbbde9c77a1d
2016-01-24 19:08:40 -05:00
Szabolcs Nagy 2f6f3dccb4 fix powerpc MCL_* mlockall flags in bits/mman.h
the definitions didn't match the linux uapi headers.
2016-01-24 19:08:19 -05:00
Szabolcs Nagy 2d14fa39b0 fix aarch64 atomics to load/store 32bit only
a_ll/a_sc inline asm used 64bit register operands (%0) instead of 32bit
ones (%w0), this at least broke a_and_64 (which always cleared the top
32bit, leaking memory in malloc).
2016-01-24 19:07:35 -05:00
Rich Felker b17fbd3520 improve aarch64 atomics
aarch64 provides ll/sc variants with acquire/release memory order,
freeing us from the need to have full barriers both before and after
the ll/sc operation. previously they were not used because the a_cas
can fail without performing a_sc, in which case half of the barrier
would be omitted. instead, define a custom version of a_cas for
aarch64 which uses a_barrier explicitly when aborting the cas
operation. aside from cas, other operations built on top of ll/sc are
not affected since they never abort but rather loop until they
succeed.

a split ll/sc version of the pointer-sized a_cas_p is also introduced
using the same technique.

patch by Szabolcs Nagy.
2016-01-23 14:03:40 -05:00
Rich Felker 0f5eb3de29 add arch/abi info to dynamic linker's id/version output 2016-01-22 04:04:16 +00:00
Rich Felker 5a2e88257a remove arch/$(ARCH)/src from the build system
the files that used to come from extra src dirs under the arch dir
have all been removed or moved to appropriate places under the main
src tree.
2016-01-22 03:58:51 +00:00
Rich Felker 4de1bc1164 remove sh port's __fpscr_values source file
commit f3ddd17380, the dynamic linker
bootstrap overhaul, silently disabled the definition of __fpscr_values
in this file since libc.so's copy of __fpscr_values now comes from
crt_arch.h, the same place the public definition in the main program's
crt1.o ultimately comes from. remove this file which is no longer in
use.
2016-01-22 03:50:58 +00:00
Rich Felker 007907a93c move sh port's __shcall internal function from arch/sh/src to src tree 2016-01-22 03:50:08 +00:00
Rich Felker 230bfe1a7d move sh __unmapself code from arch/sh/src to main src tree 2016-01-22 03:46:00 +00:00
Rich Felker 66215afc2e move x32 sysinfo impl and syscall fixup code out of arch/x32/src
all such arch-specific translation units are being moved to
appropriate arch dirs under the main src tree.
2016-01-22 03:39:07 +00:00
Rich Felker 513c043694 overhaul powerpc atomics for new atomics framework
previously powerpc had a_cas defined in terms of its native ll/sc
style operations, but all other atomics were defined in terms of
a_cas. instead define a_ll and a_sc so the compiler can generate
optimized versions of all the atomic ops and perform better inlining
of a_cas.

extracting the result of the sc (stwcx.) instruction is rather awkward
because it's natively stored in a condition flag, which is not
representable in inline asm. but even with this limitation the new
code still seems significantly better.
2016-01-22 02:58:32 +00:00
Rich Felker 16b55298dc clean up x86_64 (and x32) atomics for new atomics framework
this commit mostly makes consistent things like spacing, function
ordering in atomic_arch.h, argument names, use of volatile, etc.
a_ctz_l was also removed from x86_64 since atomic.h provides it
automatically using a_ctz_64.
2016-01-22 00:53:09 +00:00
Rich Felker e24984efd5 clean up i386 atomics for new atomics framework
this commit mostly makes consistent things like spacing, function
ordering in atomic_arch.h, argument names, use of volatile, etc. the
fake 64-bit and/or atomics are also removed because the shared
atomic.h does a better job of implementing them; it avoids making two
atomic memory accesses when only one 32-bit half needs to be touched.

no major overhaul is needed or possible because x86 actually has
native versions of all the usual atomic operations, rather than using
ll/sc or needing cas loops.
2016-01-22 00:16:53 +00:00
Rich Felker 369b22f9c4 overhaul mips atomics for new atomics framework 2016-01-22 00:10:40 +00:00
Rich Felker e617b9eea9 move arm-specific translation units out of arch/arm/src, to src/*/arm
this is possible with the new build system that allows src/*/$(ARCH)/*
files which do not shadow a file in the parent directory, and yields a
more logical organization. eventually it will be possible to remove
arch/*/src from the build system.
2016-01-22 00:02:21 +00:00
Rich Felker 397f0a6a7d overhaul arm atomics for new atomics framework
switch to ll/sc model so that new atomic.h can provide optimized
versions of all the atomic primitives without needing an ll/sc loop
written in asm for each one.

all isa levels which use ldrex/strex now use the inline ll/sc model
even if the type of barrier to use is not known until runtime (v6).
the cas model is only used for arm v5 and earlier, and it has been
optimized to make the call via inline asm with custom constraints
rather than as a C function call.
2016-01-21 23:30:30 +00:00
Rich Felker aa0db4b5d0 overhaul aarch64 atomics for new atomics framework 2016-01-21 19:50:55 +00:00
Rich Felker 61b1e75f7d overhaul sh atomics for new atomics framework, add j-core cas.l backend
sh needs runtime-selected atomic backends since there are a number of
supported models that use non-forwards-compatible (non-smp-compatible)
atomic mechanisms. previously, the code paths for this were highly
inefficient since they involved C function calls with multiple
branches in the callee and heavy spills in the caller. the new code
performs calls the runtime-selected asm fragment from inline asm with
extremely minimal clobbers, rather than using a function call.

for the sh4a case where the atomic mechanism is known and there is no
forward-compatibility issue, the movli.l and movco.l instructions are
provided as a_ll and a_sc, allowing the new shared atomic.h to
generate efficient inline versions of all the basic atomic operations
without needing a cas loop.
2016-01-21 19:43:04 +00:00
Rich Felker 1315596b51 refactor internal atomic.h
rather than having each arch provide its own atomic.h, there is a new
shared atomic.h in src/internal which pulls arch-specific definitions
from arc/$(ARCH)/atomic_arch.h. the latter can be extremely minimal,
defining only a_cas or new ll/sc type primitives which the shared
atomic.h will use to construct everything else.

this commit avoids making heavy changes to the individual archs'
atomic implementations. definitions which are identical or
near-identical to what the new shared atomic.h would produce have been
removed, but otherwise the changes made are just hooking up the
arch-specific files to the new infrastructure. major changes to take
advantage of the new system will come in subsequent commits.
2016-01-21 19:08:54 +00:00
Rich Felker ce3e24eaae fix global visibility (vis.h) support for out-of-tree builds
commit 2f853dd6b9 failed to change the
test for -include vis.h support to use $srcdir, so vis.h was always
disabled by configure for out-of-tree builds.
2016-01-20 19:43:37 +00:00
Khem Raj d1b29c2a54 exclude vis.h when compiling assembly files
otherwise C declarations are included into preprocessed (.S) asm
source files, producing errors from the assembler.
2016-01-20 19:42:21 +00:00
Rich Felker 4fcc7eb51c simplify "make clean" and remove unneeded lib dir from tree
the lib dir is automatically created if needed by the out-of-tree
build logic, and now that all generated files are in obj and lib,
deleting them is much simpler. using "rm -rf" is also more thorough,
as it picks up object files that were left around from source files
that no longer exist or which are no longer to be used because an
arch-specific replacement file was added or removed.
2016-01-20 04:01:05 +00:00
Rich Felker ada4798df0 deduplicate compiler invocation command line in makefile
also clean up duplication of CFLAGS passing to assembler.
2016-01-20 02:58:29 +00:00
Rich Felker 80de11bc6b remove outdated/incorrect comment about AS_CMD from makefile 2016-01-20 02:52:39 +00:00
Rich Felker 0f814a4e57 remove support for subarch .sub files from the makefile
as of commit af21a82ccc, .sub files are
no longer in use. removing the makefile machinery to handle them not
only cleans up and simplifies the makefile, but also significantly
reduces make's startup time.
2016-01-20 02:49:32 +00:00
Rich Felker b6363bb70a fix build regression for arm pre-v7 from out-of-tree build patch
commit 2f853dd6b9 failed to replicate
the old makefile logic that caused arch/arm/src/arm/atomics.s to be
built. since this was the only .s file under arch/*/src, rather than
trying to reproduce the old logic, I'm just moving it up a level and
adjusting the glob pattern in the makefile to catch it. eventually
arch/*/src will probably be removed in favor of moving all these files
to appropriate src/*/$(ARCH) locations.
2016-01-20 02:31:06 +00:00
Rich Felker af21a82ccc switch arm, sh, and mips fenv asm from .sub system to .S files 2016-01-20 02:07:59 +00:00
Rich Felker 4b9a08f293 switch sh and mips setjmp asm from .sub system to .S files 2016-01-20 01:45:44 +00:00
Rich Felker 56764601af fix dynamic linker path file selection for arm vs armhf
the __SOFTFP__ macro which was wrongly being used does not reflect the
ABI (arm vs armhf) but just the availability of floating point
instructions/registers, so -mfloat-abi=softfp was wrongly being
treated as armhf. __ARM_PCS_VFP is the correct predefined macro to
check for the armhf EABI variant. this macro usage was corrected for
the build process in commit 4918c2bb20
but reloc.h was apparently overlooked at the time.
2016-01-20 01:16:09 +00:00
Rich Felker e4355bd6be replace armhf math asm source files with inline asm
this makes it possible to inline them with LTO, and is the simplest
approach to eliminating the use of .sub files.

this also makes VFP sqrt available for use with the standard EABI
(plain arm rather than armhf subarch) when libc is built with
-mfloat-abi=softfp. the same could have been done for fabs, but when
the argument and return value are in integer registers, moving to VFP
registers and back is almost certainly more costly than a simple
integer operation.
2016-01-20 01:09:57 +00:00
Rich Felker cb1875eb4f adapt build of arm memcpy asm not to use .sub files
this depends on commit 9f5eb77992, which
made it possible to use a .c file for arch-specific replacements, and on
commit 2f853dd6b9, the out-of-tree build
support, which made it so that src/*/$(ARCH)/* 'replacement' files get
used even if they don't match the base name of a .c file in the parent
directory.
2016-01-20 00:35:05 +00:00
Rich Felker 9514e70c60 eliminate separate static/shared CFLAGS vars in makefile
this allows the rules for .o and .lo files to be identical, with -fPIC
and -DSHARED added for .lo files via target-specific variable append.
this is arguably cleaner now and will allow more cleanup and removal
of redundant rule bodies after other prerequisite changes are made.
2016-01-19 19:08:52 -05:00
Rich Felker 9f5eb77992 add support for arch-provided replacement files as .c or .S
previously, replacement files provided in $(ARCH) dirs under src/ had
to be .s files. in order to replace a file with C source, an empty .s
file was needed there to suppress the original file, and a separate .c
file was needed in arch/$(ARCH)/src/.

support for .S is new and is aimed at short-term use eliminating .sub
files. asm source files are still expected not to make any heavy
preprocessor use, just simple conditionals on subarch. eventually most
affected files may be replaced with C source files with minimal inline
asm instead of asm source files.
2016-01-19 18:19:01 -05:00
Kylie McClain 53f41fb568 netinet/tcp: Add TCPOPT, TCPOLEN constants
Programs such as iptables depend on these constants, which can also
be found defined in other libcs.

Since only TCP_* is reserved as part of tcp.h's namespace, we hide
them behind _BSD_SOURCE (and therefore _DEFAULT_SOURCE) to expose
them by default, but keep it standard conforming.
2016-01-17 17:37:36 -05:00
Ron Yorston 3cdbfb99c3 fix if_nametoindex return value when socket open fails
The return value of if_nametoindex is unsigned; it should return 0
on error.
2016-01-17 17:33:49 -05:00
Petr Hosek 2f853dd6b9 support out-of-tree build
this change adds support for building musl outside of the source
tree. the implementation is similar to autotools where running
configure in a different directory creates config.mak in the current
working directory and symlinks the makefile, which contains the
logic for creating all necessary directories and resolving paths
relative to the source directory.

to support both in-tree and out-of-tree builds with implicit make
rules, all object files are now placed into a separate directory.
2016-01-17 16:34:43 -05:00
Timo Teräs d5f8394f6e add missing protocols to protoent lookup functions 2016-01-06 14:31:32 -05:00
Rich Felker 5e396fb996 adjust mips crt_arch entry point asm to avoid assembler bugs
apparently the .gpword directive does not work reliably with local
text labels; values produced were offset by 64k from the correct
value, resulting in incorrect computation of the got pointer at
runtime. instead, use an external label so that the assembler does not
munge the relocation; the linker will then get it right.

commit 6fef8cafbd exposed this issue by
removing the old, non-PIE-compatible handwritten crt1.s, which was not
affected. presumably mips PIE executables (using Scrt1.o produced from
crt_arch.h) were already affected at the time.
2015-12-29 13:01:29 -05:00
Rich Felker 71991a803c adjust i386 max_align_t definition to work around some broken compilers
at least gcc 4.7 claims c++11 support but does not accept the alignas
keyword, causing breakage when stddef.h is included in c++11 mode.
instead, prefer using __attribute__((__aligned__)) on any compiler
with GNU extensions, and only use the alignas keyword as a fallback
for other C++ compilers.

C code should not be affected by this patch.
2015-12-29 12:46:15 -05:00
Rich Felker c673158d91 fix overly pessimistic realloc strategy in getdelim
previously, getdelim was allocating twice the space needed every time
it expanded its buffer to implement exponential buffer growth (in
order to avoid quadratic run time). however, this doubling was
performed even when the final buffer length needed was already known,
which is the common case that occurs whenever the delimiter is in the
FILE's buffer.

this patch makes two changes to remedy the situation:

1. over-allocation is no longer performed if the delimiter has already
been found when realloc is needed.

2. growth factor is reduced from 2x to 1.5x to reduce the relative
excess allocation in cases where the delimiter is not initially in the
buffer, including unbuffered streams.

in theory these changes could lead to quadratic time if the same
buffer is reused to process a sequence of lines successively
increasing in length, but once this length exceeds the stdio buffer
size, the delimiter will not be found in the buffer right away and
exponential growth will still kick in.
2015-12-20 00:39:35 -05:00
Rich Felker d87f0a9a95 avoid updating caller's size when getdelim fails to realloc
getdelim was updating *n, the caller's stored buffer size, before
calling realloc. if getdelim then failed due to realloc failure, the
caller would see in *n a value larger than the actual size of the
allocated block, and use of that value is unsafe. in particular,
passing it again to getdelim is unsafe.

now, temporary storage is used for the desired new size, and *n is not
written until realloc succeeds.
2015-12-19 23:43:31 -05:00
Rich Felker 42216742cd fix crash when signal number 0 is passed to sigaction
this error case was overlooked in the old range checking logic. new
check is moved out of __libc_sigaction to the public wrapper in order
to unify the error path and reduce code size.
2015-12-15 23:20:36 -05:00
Rich Felker 0d58bf2d60 remove visibility suppression by SHARED macro in mips and x32 arch files
commit 8a8fdf6398 was intended to remove
all such usage, but these arch-specific files were overlooked, leading
to inconsistent declarations and definitions.
2015-12-15 23:18:38 -05:00
Szabolcs Nagy 3abb094d19 fix tsearch, tfind, tdelete to handle null pointer input
POSIX specifies the behaviour for null rootp input, but it
was not implemented correctly.
2015-12-08 18:53:18 -05:00
Szabolcs Nagy 8994908b19 tsearch code cleanup
changed the insertion method to simplify the recursion logic and
reduce code size a bit.
2015-12-08 18:53:02 -05:00
Szabolcs Nagy bc9744763a fix tsearch to avoid crash on oom
malloc failure was not properly propagated in the insertion method
which led to null pointer dereference.
2015-12-08 18:52:38 -05:00
Szabolcs Nagy e4f9d81168 fix tdelete to properly balance the tree
the tsearch data structure is an avl tree, but it did not implement
the deletion operation correctly so the tree could become unbalanced.

reported by Ed Schouten.
2015-12-08 18:52:25 -05:00
Jo-Philipp Wich 7b712844e3 properly handle point-to-point interfaces in getifaddrs()
With point-to-point interfaces, the IFA_ADDRESS netlink attribute
contains the peer address while an extra attribute IFA_LOCAL carries
the actual local interface address.

Both the glibc and uclibc implementations of getifaddrs() handle this
case by moving the ifa_addr contents to the broadcast/remote address
union and overwriting ifa_addr upon receipt of an IFA_LOCAL attribute.

This patch adds the same special treatment logic of IFA_LOCAL to
musl's implementation of getifaddrs() in order to align its behaviour
with that of uclibc and glibc.

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
2015-11-30 14:57:25 -05:00
Szabolcs Nagy 12978acb30 ldso: fix the dtv update logic in __tls_get_new
if two or more threads accessed tls in a dso that was loaded after
the threads were created, then __tls_get_new could do out-of-bound
memory access (leading to segfault).

accidentally byte count was used instead of element count when
the new dtv pointer was computed. (dso->new_dtv is (void**).)

it is rare that the same dso provides dtv for several threads,
the crash was not observed in practice, but possible to trigger.
2015-11-28 13:34:17 -05:00
Rich Felker 8eead3ef18 math: explicitly promote expressions to excess-precision types
a conforming compiler for an arch with excess precision floating point
(FLT_EVAL_METHOD!=0; presently i386 is the only such arch supported)
computes all intermediate results in the types float_t and double_t
rather than the nominal type of the expression. some incorrect
compilers, however, only keep excess precision in registers, and
convert down to the nominal type when spilling intermediate results to
memory, yielding unpredictable results that depend on the compiler's
choices of what/when to spill. in particular, this happens on old gcc
versions with -ffloat-store, which we need in order to work around
bugs where the compiler wrongly keeps explicitly-dropped excess
precision.

by explicitly converting to double_t where expressions are expected be
be evaluated in double_t precision, we can avoid depending on the
compiler to get types correct when spilling; the nominal and
intermediate precision now match. this commit should not change the
code generated by correct compilers, or by old ones on non-i386 archs
where double_t is defined as double.

this fixes a serious bug in argument reduction observed on i386 with
gcc 4.2: for values of x outside the unit circle, sin(x) was producing
results outside the interval [-1,1]. changes made in commit
0ce946cf80 were likely responsible for
breaking compatibility with this and other old gcc versions.

patch by Szabolcs Nagy.
2015-11-21 21:41:42 -05:00