Rich Felker [Mon, 2 Jun 2014 08:27:54 +0000 (04:27 -0400)]
fix uninitialized variable in new __res_msend dns function
Rich Felker [Mon, 2 Jun 2014 06:13:57 +0000 (02:13 -0400)]
implement new dns backend, res_send and other legacy resolver functions
this is the second phase of the "resolver overhaul" project.
the key additions in this commit are the __res_msend and __res_mkquery
functions, which have been factored so as to provide a backend for
both the legacy res_* functions and the standard getaddrinfo and
getnameinfo functions. the latter however are still using the old
backend code; there is code duplication which still needs to be
removed, and this will be the next phase of the resolver overhaul.
__res_msend is derived from the old __dns_doqueries function, but
generalized to send arbitrary caller-provided packets in parallel
rather than producing the parallel queries itself. this allows it to
be used (completely trivially) as a backend for res_send. the
factored-out query generation code, with slightly more generality, is
now part of __res_mkquery.
Timo Teräs [Mon, 2 Jun 2014 05:16:08 +0000 (08:16 +0300)]
add ipsec and tunneling protocols to getprotoent-family functions
iptables and ipsec-tools among others require these to function
properly.
Rich Felker [Mon, 2 Jun 2014 05:31:28 +0000 (01:31 -0400)]
fix off-by-one in checking hostname length in new resolver backend
this bug was introduced in the recent resolver overhaul commits. it
likely had visible symptoms. these were probably limited to wrongly
accepting truncated versions of over-long names (vs rejecting them),
as opposed to stack-based overflows or anything more severe, but no
extensive checks were made. there have been no releases where this bug
was present.
Rich Felker [Sun, 1 Jun 2014 04:45:04 +0000 (00:45 -0400)]
improve getservbyname_r using new resolver backend
now that host and service lookup have been separated in the backend,
there's no need for service lookup functions to pull in the host
lookup code. moreover, dynamic allocation is no longer needed, so this
function should now be async-signal-safe. it's also significantly
smaller.
one change in getservbyname is also made: knowing that getservbyname_r
needs only two character pointers in the caller-provided buffer, some
wasted bss can be avoided.
Rich Felker [Sun, 1 Jun 2014 04:09:28 +0000 (00:09 -0400)]
improve gethostbyname2_r using new resolver backend
these changes reduce the size of the function somewhat and remove many
of its dependencies, including free. in principle it should now be
async-signal-safe, but this has not been verified in detail.
minor changes to error handling are also made.
Rich Felker [Sun, 1 Jun 2014 00:57:54 +0000 (20:57 -0400)]
refactor getaddrinfo and add support for most remaining features
this is the first phase of the "resolver overhaul" project.
conceptually, the results of getaddrinfo are a direct product of a
list of address results and a list of service results. the new code
makes this explicit by computing these lists separately and combining
the results. this adds support for services that have both tcp and udp
versions, where the caller has not specified which it wants, and
eliminates a number of duplicate code paths which were all producing
the final output addrinfo structures, but in subtly different ways,
making it difficult to implement any of the features which were
missing.
in addition to the above benefits, the refactoring allows for legacy
functions like gethostbyname to be implemented without using the
getaddrinfo function itself. such changes to the legacy functions have
not yet been made, however.
further improvements include matching of service alias names from
/etc/services (previously only the primary name was supported),
returning multiple results from /etc/hosts (previously only the first
matching line was honored), and support for the AI_V4MAPPED and AI_ALL
flags.
features which remain unimplemented are IDN translations (encoding
non-ASCII hostnames for DNS lookup) and the AI_ADDRCONFIG flag.
at this point, the DNS-based name resolving code is still based on the
old interfaces in __dns.c, albeit somewhat simpler in its use of them.
there may be some dead code which could already be removed, but
changes to this layer will be a later phase of the resolver overhaul.
Szabolcs Nagy [Fri, 30 May 2014 15:57:16 +0000 (17:57 +0200)]
fix POSIX namespace pollution in sys/types.h
int8_t, u_int8_t, etc types are moved under _BSD_SOURCE
Szabolcs Nagy [Fri, 30 May 2014 15:09:53 +0000 (17:09 +0200)]
use cleaner code for handling float rounding in vfprintf
CONCAT(0x1p,LDBL_MANT_DIG) is not safe outside of libc,
use 2/LDBL_EPSILON instead.
fix was proposed by Morten Welinder.
Szabolcs Nagy [Fri, 30 May 2014 12:15:48 +0000 (14:15 +0200)]
update netinet/in.h to match the current kernel uapi
from linux/in.h and linux/in6.h uapi headers the following
missing socket options were added:
IP_NODEFRAG - used with customized ipv4 headers
IPV6_RECVPATHMTU - for ipv6 path mtu
IPV6_PATHMTU - for ipv6 path mtu
IPV6_DONTFRAG - for ipv6 path mtu
IPV6_ADDR_PREFERENCES - RFC5014 Source Address Selection
IPV6_MINHOPCOUNT - RFC5082 Generalized TTL Security Mechanism
IPV6_ORIGDSTADDR - used by tproxy
IPV6_RECVORIGDSTADDR - used by tproxy
IPV6_TRANSPARENT - used by tproxy
IPV6_UNICAST_IF - ipv6 version of IP_UNICAST_IF
and socket option values:
IP_PMTUDISC_OMIT - value for IP_MTU_DISCOVER option, new in linux 3.14
IPV6_PMTUDISC_OMIT - same for IPV6_MTU_DISCOVER
IPV6_PMTUDISC_INTERFACE - ipv6 version of IP_PMTUDISC_INTERFACE
IPV6_PREFER_* - flags for IPV6_ADDR_PREFERENCES
not added: ipv6 flow info and flow label related definitions.
(it's unclear if libc should define these and namespace polluting
type name is involved so they are not provided for now)
Szabolcs Nagy [Fri, 30 May 2014 12:07:59 +0000 (14:07 +0200)]
add SO_BPF_EXTENSIONS socket option
this was introduced to query BPF extension support with getsockopt
in linux 3.14, commit
ea02f9411d9faa3553ed09ce0ec9f00ceae9885e
Szabolcs Nagy [Fri, 30 May 2014 11:47:44 +0000 (13:47 +0200)]
add sched_{get,set}attr syscall numbers and SCHED_DEADLINE macro
linux 3.14 introduced sched_getattr and sched_setattr syscalls in
commit
d50dde5a10f305253cbc3855307f608f8a3c5f73
and the related SCHED_DEADLINE scheduling policy in
commit
aab03e05e8f7e26f51dee792beddcb5cca9215a5
but struct sched_attr "extended scheduling parameters data structure"
is not yet exported to userspace (necessary for using the syscalls)
so related uapi definitions are not added yet.
Rich Felker [Fri, 30 May 2014 16:59:36 +0000 (12:59 -0400)]
fix breakage from recent syscall commits due to missing errno macros
Szabolcs Nagy [Fri, 30 May 2014 06:47:35 +0000 (08:47 +0200)]
fix for broken kernel side RLIM_INFINITY on mips
On 32 bit mips the kernel uses -1UL/2 to mark RLIM_INFINITY (and
this is the definition in the userspace api), but since it is in
the middle of the valid range of limits and limits are often
compared with relational operators, various kernel side logic is
broken if larger than -1UL/2 limits are used. So we truncate the
limits to -1UL/2 in get/setrlimit and prlimit.
Even if the kernel side logic consistently treated -1UL/2 as greater
than any other limit value, there wouldn't be any clean workaround
that allowed using large limits:
* using -1UL/2 as RLIM_INFINITY in userspace would mean different
infinity value for get/setrlimt and prlimit (where infinity is always
-1ULL) and userspace logic could break easily (just like the kernel
is broken now) and more special case code would be needed for mips.
* translating -1UL/2 kernel side value to -1ULL in userspace would
mean that -1UL/2 limit cannot be set (eg. -1UL/2+1 had to be passed
to the kernel instead).
Rich Felker [Fri, 30 May 2014 06:05:59 +0000 (02:05 -0400)]
break down coarse-grained 64-bit-off_t syscall remappings
using the existence of SYS_stat64 as the condition for remapping other
related syscalls is no longer valid, since new archs that omit the old
syscalls will not have SYS_stat or SYS_stat64, but still potentially
need SYS_fstat and others remapped. it would probably be possible to
get by with just one or two extra conditionals, but just breaking them
all down into separate conditions is robust and not significantly
heavier for the preprocessor.
Rich Felker [Fri, 30 May 2014 05:51:23 +0000 (01:51 -0400)]
additional fixes for linux kernel apis with old syscalls removed
Rich Felker [Fri, 30 May 2014 05:12:42 +0000 (01:12 -0400)]
fix sendfile syscall to use 64-bit off_t
somehow the remapping of this syscall to the 64-bit version was
overlooked. the issue was found, and patch provided, by Stefan
Kristiansson. presumably the reason this bug was not caught earlier is
that the syscall takes a pointer to off_t rather than a value, so on
little-endian systems, everything appears to work as long as the
offset value fits in the low 31 bits. on big-endian systems, though,
sendfile was presumably completely non-functional.
Rich Felker [Fri, 30 May 2014 01:01:32 +0000 (21:01 -0400)]
support linux kernel apis (new archs) with old syscalls removed
such archs are expected to omit definitions of the SYS_* macros for
syscalls their kernels lack from arch/$ARCH/bits/syscall.h. the
preprocessor is then able to select the an appropriate implementation
for affected functions. two basic strategies are used on a
case-by-case basis:
where the old syscalls correspond to deprecated library-level
functions, the deprecated functions have been converted to wrappers
for the modern function, and the modern function has fallback code
(omitted at the preprocessor level on new archs) to make use of the
old syscalls if the new syscall fails with ENOSYS. this also improves
functionality on older kernels and eliminates the incentive to program
with deprecated library-level functions for the sake of compatibility
with older kernels.
in other situations where the old syscalls correspond to library-level
functions which are not deprecated but merely lack some new features,
such as the *at functions, the old syscalls are still used on archs
which support them. this may change at some point in the future if or
when fallback code is added to the new functions to make them usable
(possibly with reduced functionality) on old kernels.
Rich Felker [Thu, 29 May 2014 20:35:09 +0000 (16:35 -0400)]
remove useless synchronization in exit and quick_exit
calling exit more than once invokes undefined behavior. in some cases
it's desirable to detect undefined behavior and diagnose it via a
predictable crash, but the code here was silently covering up an
uncommon case (exit from more than one thread) and turning a much more
common case (recursive calls to exit) into a permanent hang.
Rich Felker [Tue, 27 May 2014 18:21:46 +0000 (14:21 -0400)]
fix missing declaration of strcpy in implementation of tmpnam
Rich Felker [Tue, 27 May 2014 04:44:23 +0000 (00:44 -0400)]
overhaul tmpfile, tmpnam, and tempnam functions
these all now use the shared __randname function internally, rather
than duplicating logic for producing a random name. incorrect usage of
the access syscall (which works with real uid/gid, not effective) has
been removed, along with unnecessary heavy dependencies like snprintf.
Rich Felker [Tue, 27 May 2014 04:11:37 +0000 (00:11 -0400)]
fix sys_open macro for archs without the plain open syscall
Rich Felker [Tue, 27 May 2014 04:09:05 +0000 (00:09 -0400)]
fix placement of multiple inclusion guard endif in internal syscall.h
this was messed up during a recent commit when the socketcall macros
were moved to the common internal/syscall.h, and the following commit
expanded the problem by adding more new content outside the guard.
Rich Felker [Tue, 27 May 2014 01:26:46 +0000 (21:26 -0400)]
fix type of extended argument array to pselect6 syscall
this only matters on x32 (and perhaps future 32-on-64 abis for other
archs); otherwise the type is long anyway. the cast through uintptr_t
prevents nonsensical "sign extension" of pointers, and follows the
principle that uintptr_t is the canonical integer type to which
pointer conversion is safe.
Rich Felker [Sun, 25 May 2014 02:54:05 +0000 (22:54 -0400)]
support kernels with no SYS_open syscall, only SYS_openat
open is handled specially because it is used from so many places, in
so many variants (2 or 3 arguments, setting errno or not, and
cancellable or not). trying to do it as a function would not only
increase bloat, but would also risk subtle breakage.
this is the first step towards supporting "new" archs where linux
lacks "old" syscalls.
Rich Felker [Sun, 25 May 2014 00:39:46 +0000 (20:39 -0400)]
overhaul siginfo_t definition in signal.h
the main motivation for this change is that, with the previous
definition, it was arguably illegal, in standard C, to initialize both
si_value and si_pid/si_uid with designated initializers, due to the
rule that only one member of a union can have an initializer. whether
or not this affected real-world application code, it affected some
internal code, and clang was producing warnings (and possibly
generating incorrect code).
the new definition uses a more complex hierarchy of structs and unions
to avoid the need to initialize more than one member of a single union
in usage cases that make sense. further work would be needed to
eliminate even the ones with no practical applications.
at the same time, some fixes are made to the exposed names for
nonstandard fields, to match what software using them expects.
Rich Felker [Tue, 20 May 2014 22:19:53 +0000 (18:19 -0400)]
release 1.1.1
Rich Felker [Tue, 20 May 2014 19:49:21 +0000 (15:49 -0400)]
trivial formatting fix for the config.mak generated by configure
Rich Felker [Tue, 20 May 2014 02:14:09 +0000 (22:14 -0400)]
fix unhandled cases in strptime
%C, %U, %W, and %y handling were completely missing; %C wrongly
fell-through to unrelated cases, and the rest returned failure. for
now, they all parse numbers in the proper forms and range-check the
values, but they do not store the value anywhere.
it's not clear to me whether, as "derived" fields, %U and %W should
produce any result. they certainly cannot produce a result unless the
year and weekday are also converted, but in this case it might be
desirable for them to do so. clarification is needed on the intended
behavior of strptime in cases like this.
%C and %y have well-defined behavior as long as they are used together
(and %y is defined by itself but may change in the future).
implementing them (including their correct interaction) is left as a
later change to be made.
finally, strptime now rejects unknown/invalid format characters
instead of ignoring them.
Rich Felker [Mon, 19 May 2014 16:18:16 +0000 (12:18 -0400)]
remove unsupported nonstandard sysconf macros and their table entries
some of these may have been from ancient (pre-SUSv2) POSIX versions;
more likely, they were from POSIX drafts or glibc interpretations of
what ancient versions of POSIX should have added (instead they made
they described functionality mandatory and/or dropped it completely).
others are purely glibc-isms, many of them ill-thought-out, like
providing ways to lookup the min/max values of types at runtime
(despite the impossibility of them changing at runtime and the
impossibility of representing ULONG_MAX in a return value of type
long).
since our sysconf implementation does not support or return meaningful
values for any of these, it's harmful to have the macros around;
applications' build scripts may detect and attempt to use them, only
to get -1/EINVAL as a result.
if removing them does break some applications, and it's determined
that the usage was reasonable, some of these could be added back on an
as-needed basis, but they should return actual meaningful values, not
junk like they were returning before.
Rich Felker [Mon, 19 May 2014 15:19:49 +0000 (11:19 -0400)]
rework sysconf table to treat zero entries as invalid
based on patch by Timo Teräs. previously, the value zero was used as a
literal zero, meaning that all invalid sysconf "names", which should
result in sysconf returning -1, had to be explicitly listed. (in
addition, it was not possible for sysconf to set errno to EINVAL, as
there was no distinction between -1 as an error and -1 as a valid
result.)
now, the value 0 is used for invalid/undefined slots in the table and
a new switch table entry is used for returning literal zeros.
in addition, an off-by-one error in checking against the table size is
fixed.
Rich Felker [Mon, 19 May 2014 14:33:28 +0000 (10:33 -0400)]
add configure check for broken gcc 4.9.0 and possibly other versions
this is gcc bug #61144. the broken compiler is detected, but the user
must manually work around it. this is partly to avoid complex logic
for adding workaround CFLAGS and attempting to recheck with them, and
partly for the sake of letting the user know the compiler is broken
(since the workaround will result in less-efficient code production).
some refactoring was also needed to move the check for gcc outside of
the check for whether to build the compiler wrapper.
Rich Felker [Tue, 13 May 2014 23:24:48 +0000 (19:24 -0400)]
add cp437 and cp850 to available iconv conversions
perhaps some additional legacy DOS-era codepages would also be useful
to have, but these are the ones for which there has been demand. the
size of the diff is due to the fact that legacychars.h is updated in
such a way that new characters are inserted into the table in unicode
codepoint order; thus other mappings in codepages.h have changed to
reflect the new table indices of their characters.
Rich Felker [Mon, 12 May 2014 18:22:57 +0000 (14:22 -0400)]
add configure check for working compiler
without this, broken choices of CC/CPPFLAGS/CFLAGS don't show up until
late in the configure process where they are confusingly reported as a
different failure such as incorrect long double type.
Szabolcs Nagy [Thu, 8 May 2014 17:04:48 +0000 (19:04 +0200)]
fix strftime %s not to zero pad with default width=2
Rich Felker [Sun, 4 May 2014 17:15:27 +0000 (13:15 -0400)]
remove useless __yield alias for sched_yield
this is no longer used for anything, and reportedly clashed with a
builtin on certain compilers.
Rich Felker [Wed, 30 Apr 2014 19:32:11 +0000 (15:32 -0400)]
fix arm thread-pointer/atomic asm when compiling to thumb code
armv7/thumb2 provides a way to do atomics in thumb mode, but for armv6
we need a call to arm mode.
this commit is based on a patch by Stephen Thomas which fixed the
armv7 cases but not the armv6 ones.
all of this should be revisited if/when runtime selection of thread
pointer access and atomics are added.
Rich Felker [Wed, 30 Apr 2014 18:47:06 +0000 (14:47 -0400)]
fix missing SO_RCVBUFFORCE and SO_SNDBUFFORCE in mips socket.h
Bobby Bingham [Mon, 28 Apr 2014 02:13:59 +0000 (21:13 -0500)]
fix superh nofpu check on old gcc versions
As far as gcc3 knows, sh4 is the only processor version that can have an
FPU, so it indicates the FPU's presence by defining __SH4__. This is not
defined if there is no FPU, even if the processor really is an SH4.
Starting with gcc4, there is support for the sh2a processor, which has an
FPU but is not an SH4. gcc4 therefore additionally defines __SH_FPU_ANY__
when there is an FPU, but still doesn't define __SH4__ for an FPU-less sh4.
Therefore, to support all gcc versions, we must look at both preprocessor
symbols.
Rich Felker [Wed, 23 Apr 2014 00:09:56 +0000 (20:09 -0400)]
perform minimal sanity checks on zoneinfo files loaded via TZ variable
previously, setting TZ to the pathname of a file which was not a valid
zoneinfo file would usually cause programs using local time zone based
operations to crash. the new code checks the file size and magic at
the beginning of the file, which seems sufficient to prevent
accidental misconfiguration from causing crashes. attempting to make
fully-robust validation would be futile unless we wanted to drop use
of mmap (shared zoneinfo) and instead read it into a local buffer,
since such validation would be subject to race conditions with
modification of the file.
Timo Teräs [Tue, 22 Apr 2014 18:55:20 +0000 (21:55 +0300)]
do not try to interpret implementation specific strings as tz definition
Rich Felker [Tue, 22 Apr 2014 00:10:08 +0000 (20:10 -0400)]
make __init_libc static for non-shared libc
being static allows it to be inlined in __libc_start_main; inlining
should take place at all levels since the function is called exactly
once. this further reduces mandatory startup code size for static
binaries.
Rich Felker [Mon, 21 Apr 2014 23:52:24 +0000 (19:52 -0400)]
further micro-optimize startup code for size
there is no reason (and seemingly there never was any) for
__init_security to be its own function. it's linked unconditionally
so it can just be placed inline in __init_libc.
Rich Felker [Mon, 21 Apr 2014 23:31:35 +0000 (19:31 -0400)]
micro-optimize some startup code for size
moving the call to __init_ssp from __init_security to __init_libc
makes __init_security a leaf function, which allows the compiler to
make it smaller. __init_libc is already non-leaf, and the additional
call makes no difference to the amount of register spillage.
in addition, it really made no sense for the call to __init_ssp to be
buried inside __init_security rather than parallel with other init
functions.
Rich Felker [Mon, 21 Apr 2014 22:11:42 +0000 (18:11 -0400)]
allow zoneinfo-path-relative filenames with no slashes in TZ variable
since the form TZ=name is reserved for POSIX-form time zone strings,
TZ=:name needs to be used when the zoneinfo filename is in the
top-level zoneinfo directory and therefore does not contain a slash.
previously the leading colon was merely dropped, making it impossible
to access such zones without a full absolute pathname.
changes based on patch by Timo Teräs.
M Farkas-Dyck [Sat, 19 Apr 2014 03:40:28 +0000 (22:40 -0500)]
expose public execvpe interface
Rich Felker [Fri, 18 Apr 2014 21:38:35 +0000 (17:38 -0400)]
fix false negatives with periodic needles in strstr, wcsstr, and memmem
in cases where the memorized match range from the right factor
exceeded the length of the left factor, it was wrongly treated as a
mismatch rather than a match.
issue reported by Yves Bastide.
Timo Teräs [Thu, 17 Apr 2014 17:58:17 +0000 (20:58 +0300)]
make socketcall types common as they are same for all architectures
Rich Felker [Wed, 16 Apr 2014 16:45:36 +0000 (12:45 -0400)]
add options when explicitly invoking dynamic loader
so far the options are --library-path and --preload which override the
corresponding environment variables, and --list which forces the
behavior of ldd even if the invocation name is not ldd. both the
two-arg form and the one-arg form using an equals sign are supported.
based loosely on a patch proposed by Rune.
Rich Felker [Wed, 16 Apr 2014 08:30:58 +0000 (04:30 -0400)]
release 1.1.0
Rich Felker [Wed, 16 Apr 2014 06:33:29 +0000 (02:33 -0400)]
add working vdso clock_gettime support, including static linking
the vdso symbol lookup code is based on the original 2011 patch by
Nicholas J. Kain, with some streamlining, pointer arithmetic fixes,
and one symbol version matching fix.
on the consumer side (clock_gettime), per-arch macros for the
particular symbol name and version to lookup are added in
syscall_arch.h, and no vdso code is pulled in on archs which do not
define these macros. at this time, vdso is enabled only on x86_64.
the vdso support at the dynamic linker level is no longer useful to
libc, but is left in place for the sake of debuggers (which may need
the vdso in the link map to find its functions) and possibly use with
dlsym.
Rich Felker [Wed, 16 Apr 2014 00:42:39 +0000 (20:42 -0400)]
fix deadlock race in pthread_once
at the end of successful pthread_once, there was a race window during
which another thread calling pthread_once would momentarily change the
state back from 2 (finished) to 1 (in-progress). in this case, the
status was immediately changed back, but with no wake call, meaning
that waiters which arrived during this short window could block
forever. there are two possible fixes. one would be adding the wake to
the code path where it was missing. but it's better just to avoid
reverting the status at all, by using compare-and-swap instead of
swap.
Szabolcs Nagy [Mon, 14 Apr 2014 15:42:49 +0000 (17:42 +0200)]
fix RLIMIT_ constants for mips
The mips arch is special in that it uses different RLIMIT_
numbers than other archs, so allow bits/resource.h to override
the default RLIMIT_ numbers (empty on all archs except mips).
Reported by orc.
Rich Felker [Tue, 15 Apr 2014 22:45:21 +0000 (18:45 -0400)]
add _SC_PHYS_PAGES and _SC_AVPHYS_PAGES extentions to sysconf
Rich Felker [Tue, 15 Apr 2014 22:16:37 +0000 (18:16 -0400)]
add namespace-protected name for sysinfo function
it will be needed to implement some things in sysconf, and the syscall
can't easily be used directly because the x32 syscall uses the wrong
structure layout. the l (uncreative, for "linux") prefix is used since
the symbol name __sysinfo is already taken for AT_SYSINFO from the aux
vector.
the way the x32 override of this function works is also changed to be
simpler and avoid the useless jump instruction.
Rich Felker [Tue, 15 Apr 2014 22:05:30 +0000 (18:05 -0400)]
in sysconf, use getrlimit function rather than raw syscall for rlimits
the syscall is deprecated (replaced by prlimit64) and does not work
correctly on x32. this change mildly increases size, but is likely
needed anyway for newer archs that might omit deprecated syscalls.
Rich Felker [Tue, 15 Apr 2014 17:30:20 +0000 (13:30 -0400)]
avoid linear-time if/else special cases in sysconf
the previous handling of cases that could not fit in the 16-bit table
or which required non-constant results was extremely ugly and could
not scale. the new code remaps these keys into a contiguous range
that's efficient for a switch statement.
Rich Felker [Tue, 15 Apr 2014 03:48:40 +0000 (23:48 -0400)]
fix fallback code for old kernels in clock_gettime
Rich Felker [Tue, 15 Apr 2014 03:41:49 +0000 (23:41 -0400)]
use dmb barrier instruction for atomics on arm v7
aside from potentially offering better performance, this change is
needed since the old coprocessor-based approach to barriers is
deprecated in arm v7, and some compilers/assemblers issue errors when
using the deprecated instruction for v7 targets.
Rich Felker [Sat, 12 Apr 2014 04:16:19 +0000 (00:16 -0400)]
use hidden visibility rather than protected for syscall internals
the use of visibility at all is purely an optimization to avoid the
need for the caller to load the GOT register or similar to prepare for
a call via the PLT. there is no reason for these symbols to be
externally visible, so hidden works just as well as protected, and
using protected visibility is undesirable due to toolchain bugs and
the lack of testing it receives.
in particular, GCC's microblaze target is known to generate symbolic
relocations in the GOT for functions with protected visibility. this
in turn results in a dynamic linker which crashes under any nontrivial
usage that requires making a syscall before symbolic relocations are
processed.
Szabolcs Nagy [Fri, 11 Apr 2014 15:57:30 +0000 (17:57 +0200)]
math: fix aliasing violation in long double wrappers
modfl and sincosl were passing long double* instead of double*
to the wrapped double precision functions (on archs where long
double and double have the same size).
This is fixed now by using temporaries (this is not optimized
to a single branch so the generated code is a bit bigger).
Found by Morten Welinder.
Timo Teräs [Thu, 10 Apr 2014 01:06:17 +0000 (21:06 -0400)]
fix search past the end of haystack in memmem
to optimize the search, memchr is used to find the first occurrence of
the first character of the needle in the haystack before switching to
a search for the full needle. however, the number of characters
skipped by this first step were not subtracted from the haystack
length, causing memmem to search past the end of the haystack.
Rich Felker [Mon, 7 Apr 2014 17:50:05 +0000 (13:50 -0400)]
fix printf rounding with %g for some corner case midpoints
the subsequent rounding code assumes the end pointer (z) accurately
reflects the end of significance in the decimal expansion, but for
certain large integers, spurious trailing zero slots were left behind
when applying the binary exponent.
issue reported by Morten Welinder; the analysis of the cause was
performed by nsz, who also proposed this change.
Rich Felker [Mon, 7 Apr 2014 08:28:12 +0000 (04:28 -0400)]
fix arm atomic asm register constraint
the "m" constraint could give a memory reference with an offset that's
not compatible with ldrex/strex, so the arm-specific "Q" constraint is
needed instead.
Rich Felker [Mon, 7 Apr 2014 08:03:18 +0000 (04:03 -0400)]
use inline atomics and thread pointer on arm models supporting them
this is perhaps not the optimal implementation; a_cas still compiles
to nested loops due to the different interface contracts of the kuser
helper cas function (whose contract this patch implements) and the
a_cas function (whose contract mimics the x86 cmpxchg). fixing this
may be possible, but it's more complicated and thus deferred until a
later time.
aside from improving performance and code size, this patch also
provides a means of producing binaries which can run on hardened
kernels where the kuser helpers have been disabled. however, at
present this requires producing binaries for armv6k or later, which
will not run on older cpus. a real solution to the problem of kernels
that omit the kuser helpers would be runtime detection, so that
universal binaries which run on all arm cpu models can also be
compatible with all kernel hardening profiles. robust detection
however is a much harder problem, and will be addressed at a later
time.
Rich Felker [Mon, 7 Apr 2014 06:46:15 +0000 (02:46 -0400)]
add getauxval function
in a sense this implementation is incomplete since it doesn't provide
the HWCAP_* macros for use with AT_HWCAP, which is perhaps the most
important intended usage case for getauxval. they will be added at a
later time.
Rich Felker [Mon, 7 Apr 2014 06:05:20 +0000 (02:05 -0400)]
fix failure of printf %g to strip trailing zeros in some cases
the code to strip trailing zeros was only looking in the last slot for
up to 9 zeros, assuming that the rounding code had already removed
fully-zero slots from the end. however, this ignored cases where the
rounding code did not run at all, which occur when the value being
printed is exactly representable in the requested precision.
the simplest solution is to move the code that strips trailing zero
slots to run unconditionally, immediately after rounding, rather than
as the last step of rounding.
Rich Felker [Mon, 7 Apr 2014 05:36:40 +0000 (01:36 -0400)]
fix carry into uninitialized slots during printf floating point rounding
in cases where rounding caused a carry, the slot into which the carry
was taking place was unconditionally treated as valid, despite the
possibility that it could be a new slot prior to the beginning of the
existing non-rounded number. in theory this could lead to unbounded
runaway carry, but in order for that to happen, the whole
uninitialized buffer would need to have been pre-filled with 32-bit
integer values greater than or equal to
999999999.
patch based on proposed fix by Morten Welinder, who also discovered
and reported the bug.
Rich Felker [Mon, 7 Apr 2014 05:12:31 +0000 (01:12 -0400)]
remove some cruft from libc/tls init code
Rich Felker [Sat, 5 Apr 2014 01:43:20 +0000 (21:43 -0400)]
remove cruft left behind when lazy thread pointer init was removed
the function itself was static, but the weak alias provided an
externally visible reference and thus prevented the dead code from
being omitted from the output. so this change actually reduces bloat
in mandatory static-linked code.
Rich Felker [Wed, 2 Apr 2014 23:32:57 +0000 (19:32 -0400)]
add __sigsetjmp ABI-compat alias for sigsetjmp
sin [Thu, 27 Mar 2014 11:20:17 +0000 (11:20 +0000)]
remove struct elem entirely from hsearch.c
There are two changes here, both of which make sense to be done in a
single patch:
- Remove hash from struct elem and compute it at runtime wherever
necessary.
- Eliminate struct elem and use ENTRY directly.
As a result we cut down on the memory usage as each element in the
hash table now contains only an ENTRY not an ENTRY + size_t for the
hash. The downside is that the hash needs to be computed at runtime.
sin [Tue, 25 Mar 2014 16:37:51 +0000 (16:37 +0000)]
implement hcreate_r, hdestroy_r and hsearch_r
the size and alignment of struct hsearch_data are matched to the glibc
definition for binary compatibility. the members of the structure do
not match, which should not be a problem as long as applications
correctly treat the structure as opaque.
unlike the glibc implementation, this version of hcreate_r does not
require the caller to zero-fill the structure before use.
Rich Felker [Wed, 2 Apr 2014 21:57:15 +0000 (17:57 -0400)]
avoid malloc failure for small requests when brk can't be extended
this issue mainly affects PIE binaries and execution of programs via
direct invocation of the dynamic linker binary: depending on kernel
behavior, in these cases the initial brk may be placed at at location
where it cannot be extended, due to conflicting adjacent maps.
when brk fails, mmap is used instead to expand the heap. in order to
avoid expensive bookkeeping for managing fragmentation by merging
these new heap regions, the minimum size for new heap regions
increases exponentially in the number of regions. this limits the
number of regions, and thereby the number of fixed fragmentation
points, to a quantity which is logarithmic with respect to the size of
virtual address space and thus negligible. the exponential growth is
tuned so as to avoid expanding the heap by more than approximately 50%
of its current total size.
Rich Felker [Wed, 2 Apr 2014 18:13:20 +0000 (14:13 -0400)]
fix microblaze syscall register clobbers
the kernel entry point for syscalls on microblaze nominally saves and
restores all registers, and testing on qemu always worked since qemu
behaves this way too. however, the real kernel treats r3:r4 as a
potential 64-bit return value from the syscall function, and copies
both over top of the saved registers before returning to userspace.
thus, we need to treat r4 as always-clobbered.
Timo Teräs [Tue, 25 Mar 2014 19:50:15 +0000 (21:50 +0200)]
remove lazy ssp initialization
now that thread pointer is initialized always, ssp canary
initialization can be done unconditionally. this simplifies
the ldso as it does not try to detect ssp usage, and the
init function itself as it is always called exactly once.
this also merges ssp init path for shared and static linking.
Rich Felker [Tue, 25 Mar 2014 20:23:27 +0000 (16:23 -0400)]
if dynamic linker's relro mprotect call fails, include reason in message
Rich Felker [Tue, 25 Mar 2014 20:21:50 +0000 (16:21 -0400)]
cosmetic improvements in dynamic linker cleanup
consistent use of braces in if/else structure, line length.
Timo Teräs [Tue, 25 Mar 2014 18:59:50 +0000 (20:59 +0200)]
clean up internal dynamic linker functions enumerating phdrs
record phentsize in struct dso, so the phdrs can be easily
enumerated via it. simplify all functions enumerating phdrs
to require only struct dso. also merge find_map_range and
find_dso to kernel_mapped_dso function that does both tasks
during single phdr enumeration.
Timo Teräs [Tue, 25 Mar 2014 12:13:27 +0000 (14:13 +0200)]
implement PT_GNU_RELRO support
Rich Felker [Mon, 24 Mar 2014 21:39:08 +0000 (17:39 -0400)]
fix pointer type mismatch and misplacement of const
Timo Teräs [Wed, 19 Feb 2014 07:40:35 +0000 (09:40 +0200)]
fix confstr return value
per the specification, the terminating null byte is counted.
Rich Felker [Mon, 24 Mar 2014 20:57:11 +0000 (16:57 -0400)]
always initialize thread pointer at program start
this is the first step in an overhaul aimed at greatly simplifying and
optimizing everything dealing with thread-local state.
previously, the thread pointer was initialized lazily on first access,
or at program startup if stack protector was in use, or at certain
random places where inconsistent state could be reached if it were not
initialized early. while believed to be fully correct, the logic was
fragile and non-obvious.
in the first phase of the thread pointer overhaul, support is retained
(and in some cases improved) for systems/situation where loading the
thread pointer fails, e.g. old kernels.
some notes on specific changes:
- the confusing use of libc.main_thread as an indicator that the
thread pointer is initialized is eliminated in favor of an explicit
has_thread_pointer predicate.
- sigaction no longer needs to ensure that the thread pointer is
initialized before installing a signal handler (this was needed to
prevent a situation where the signal handler caused the thread
pointer to be initialized and the subsequent sigreturn cleared it
again) but it still needs to ensure that implementation-internal
thread-related signals are not blocked.
- pthread tsd initialization for the main thread is deferred in a new
manner to minimize bloat in the static-linked __init_tp code.
- pthread_setcancelstate no longer needs special handling for the
situation before the thread pointer is initialized. it simply fails
on systems that cannot support a thread pointer, which are
non-conforming anyway.
- pthread_cleanup_push/pop now check for missing thread pointer and
nop themselves out in this case, so stdio no longer needs to avoid
the cancellable path when the thread pointer is not available.
a number of cases remain where certain interfaces may crash if the
system does not support a thread pointer. at this point, these should
be limited to pthread interfaces, and the number of such cases should
be fewer than before.
Rich Felker [Mon, 24 Mar 2014 03:19:30 +0000 (23:19 -0400)]
reduce static linking overhead from TLS support by inlining mmap syscall
the external mmap function is heavy because it has to handle error
reporting that the kernel cannot do, and has to do some locking for
arcane race-condition-avoidance purposes. for allocating initial TLS,
we do not need any of that; the raw syscall suffices.
on i386, this change shaves off 13% of the size of .text for the empty
program.
Rich Felker [Mon, 24 Mar 2014 00:42:05 +0000 (20:42 -0400)]
include header that declares __syscall_ret where it's defined
in general, we aim to always include the header that's declaring a
function before defining it so that the compiler can check that
prototypes match.
additionally, the internal syscall.h declares __syscall_ret with a
visibility attribute to improve code generation for shared libc (to
prevent gratuitous GOT-register loads). this declaration should be
visible at the point where __syscall_ret is defined, too, or the
inconsistency could theoretically lead to problems at link-time.
Rich Felker [Thu, 20 Mar 2014 08:41:15 +0000 (04:41 -0400)]
release 1.0.0
Rich Felker [Thu, 20 Mar 2014 08:15:47 +0000 (04:15 -0400)]
remove claim of XSI coverage from README
in addition to the dbm functions (which we don't intent to implement
anyway), fmtmsg is still missing too. rather than adding exceptions I
think it's best just to avoid making the claim.
Rich Felker [Thu, 20 Mar 2014 06:24:10 +0000 (02:24 -0400)]
update README in preparation for release
reduces the amount of news-like content on progress and development
direction and focuses on the present.
Rich Felker [Thu, 20 Mar 2014 04:55:28 +0000 (00:55 -0400)]
update INSTALL file with new information and better advice
the text covering an ill-advised procedure for 'bootstrapping' a new
musl-based system in-place is removed. new information on targets and
compilers is added. formatting improved. the remaining text is
adjusted to cover both usage with musl-gcc on a non-musl-based system
and upgrading a musl-based system or toolchain.
Rich Felker [Thu, 20 Mar 2014 04:34:19 +0000 (00:34 -0400)]
update COPYRIGHT file with additional contributor information
rofl0r [Wed, 19 Mar 2014 21:31:00 +0000 (22:31 +0100)]
configure: check for __ILP32__ if arch is x86_64
otherwise a multilib compiler used with -mx32 will not be detected
properly.
Rich Felker [Wed, 19 Mar 2014 03:27:45 +0000 (23:27 -0400)]
fix signal.h breakage from moving stack_t to arch-specific bits
in the previous changes, I missed the fact that both the prototype of
the sigaltstack function and the definition of ucontext_t depend on
stack_t.
Rich Felker [Wed, 19 Mar 2014 03:13:56 +0000 (23:13 -0400)]
fix mips stack_t
like almost everything on mips, this is gratuitously different.
Rich Felker [Wed, 19 Mar 2014 03:12:40 +0000 (23:12 -0400)]
move signal.h definition of stack_t to arch-specific bits
it's different at least on mips. mips version will be fixed in a
separate commit to show the change.
Rich Felker [Wed, 19 Mar 2014 02:48:22 +0000 (22:48 -0400)]
fix mips sigsetjmp asm to match fixed jmp_buf size
this was missed in the previous commit.
Rich Felker [Wed, 19 Mar 2014 02:11:14 +0000 (22:11 -0400)]
fix typo in filename used in sh port
Rich Felker [Wed, 19 Mar 2014 01:52:24 +0000 (21:52 -0400)]
fix size of mips jmp_buf
the excess space was unused and unintentional. this change does not
affect the ABI between applications and libc. while it does
theoretically affect linkage between third-party translation units
using jmp_buf as part of a structure, we've already changed jmp_buf at
least once on all archs, and problems were never observed, likely
because such usage would be very unusual. in any case it's best to get
things right now rather than making changes sometime during the 1.0.x
series or later.
Rich Felker [Wed, 19 Mar 2014 01:37:05 +0000 (21:37 -0400)]
remove useless and incorrect uc_regspace member from mips ucontext_t
this seems to have been copied erroneously from the arm version of the
file. it's fairly harmless but it's a mistake and better to fix now
than later.
Rich Felker [Tue, 18 Mar 2014 21:08:15 +0000 (17:08 -0400)]
use syscall_arg_t for arguments in public syscall() function
on x32, this change allows programs which use syscall() with pointers
or 64-bit values as arguments to work correctly, i.e. without
truncation or incorrect sign extension. on all other supported archs,
syscall_arg_t is defined as long, so this change is a no-op.
Rich Felker [Mon, 17 Mar 2014 21:38:22 +0000 (17:38 -0400)]
make configure accept alternate gcc tuples for x32
the previous pattern required "x32" to be used as the second field of
the gcc tuple, which is usually reserved for vendor use and not
appropriate as an ABI specifier. with this change, putting "x32" at
the end of the tuple, the way ABI specifiers are normally done, is
also permitted.