Rich Felker [Sat, 19 Jul 2014 19:51:12 +0000 (15:51 -0400)]
fix missing barrier instructions in mips atomic asm
previously I had wrongly assumed the ll/sc instructions also provided
memory synchronization; apparently they do not. this commit adds sync
instructions before and after each atomic operation and changes the
atomic store to simply use sync before and after a plain store, rather
than a useless compare-and-swap.
(cherry picked from commit
bcad48439494820989f5867c3f8ccfa6aae2909f)
Rich Felker [Sat, 19 Jul 2014 17:51:35 +0000 (13:51 -0400)]
use memory constraints for mips atomic asm
despite lacking the semantic content that the asm accesses the
pointed-to object rather than just using its address as a value, the
mips asm was not actually broken. the asm blocks were declared
volatile, meaning that the compiler must treat them as having unknown
side effects.
however changing the asm to use memory constraints is desirable not
just from a semantic correctness and consistency standpoint, but also
produces better code. the compiler is able to use base/offset
addressing expressions for the atomic object's address rather than
having to load the address into a single register. this improves
access to global locks in static libc, and access to non-zero-offset
atomic fields in synchronization primitives, etc.
(cherry picked from commit
a294f539c78c6ba0a2786ef3c5b2a1210a33864e)
Rich Felker [Sat, 19 Jul 2014 17:43:46 +0000 (13:43 -0400)]
fix build breakage from ppc asm constraints change
due to a mistake in my testing procedure, the changes in the previous
commit were not correctly tested and wrongly assumed to be valid. the
lwarx and stwcx. instructions do not accept general ppc memory address
expressions and thus the argument associated with the memory
constraint cannot be used directly.
instead, the memory constraint can be left as an argument that the asm
does not actually use, and the address can be provided in a separate
register constraint.
(cherry picked from commit
bb3a3befeaa01531c273ef9130f3fbcaaf8a25e2)
Rich Felker [Sat, 19 Jul 2014 17:03:30 +0000 (13:03 -0400)]
remove cruft from microblaze atomic.h
(cherry picked from commit
94252dd341a7c72b31db2614abdc74142ad80562)
Rich Felker [Sat, 19 Jul 2014 16:19:20 +0000 (12:19 -0400)]
fix broken constraints for powerpc atomic cas asm
the register constraint for the address to be accessed did not convey
that the asm can access the pointed-to object. as far as the compiler
could tell, the result of the asm was just a pure function of the
address and the values passed in, and thus the asm could be hoisted
out of loops or omitted entirely if the result was not used.
(cherry picked from commit
7fdae458bd421046a300a69dcb32953ac9450136)
Rich Felker [Fri, 18 Jul 2014 18:55:30 +0000 (14:55 -0400)]
fix microblaze definition of struct stat
the erroneous definition was missed because with works with qemu
user-level emulation, which also has the wrong definition. the actual
kernel uses the asm-generic generic definition.
(cherry picked from commit
d69ab5b3686acf75fdf5db6fad19c2c6a510bb4f)
Rich Felker [Thu, 17 Jul 2014 23:56:27 +0000 (19:56 -0400)]
fix crash in regexec for nonzero nmatch argument with REG_NOSUB
per POSIX, the nmatch and pmatch arguments are ignored when the regex
was compiled with REG_NOSUB.
(cherry picked from commit
72ed3d47e567b1635a35d3c1d174c8a8b2787e30)
Rich Felker [Thu, 17 Jul 2014 01:32:06 +0000 (21:32 -0400)]
work around constant folding bug 61144 in gcc 4.9.0 and 4.9.1
previously we detected this bug in configure and issued advice for a
workaround, but this turned out not to work. since then gcc 4.9.0 has
appeared in several distributions, and now 4.9.1 has been released
without a fix despite this being a wrong code generation bug which is
supposed to be a release-blocker, per gcc policy.
since the scope of the bug seems to affect only data objects (rather
than functions) whose definitions are overridable, and there are only
a very small number of these in musl, I am just changing them from
const to volatile for the time being. simply removing the const would
be sufficient to make gcc 4.9.1 work (the non-const case was
inadvertently fixed as part of another change in gcc), and this would
also be sufficient with 4.9.0 if we forced -O0 on the affected files
or on the whole build. however it's cleaner to just remove all the
broken compiler detection and use volatile, which will ensure that
they are never constant-folded. the quality of a non-broken compiler's
output should not be affected except for the fact that these objects
are no longer const and thus possibly add a few bytes to data/bss.
this change can be reconsidered and possibly reverted at some point in
the future when the broken gcc versions are no longer relevant.
(cherry picked from commit
a6adb2bcd8145353943377d6119c1d7a4242bae1)
Rich Felker [Thu, 17 Jul 2014 00:44:22 +0000 (20:44 -0400)]
simplify __stdio_exit static linking logic
the purpose of this logic is to avoid linking __stdio_exit unless any
stdio reads (which might require repositioning the file offset at exit
time) or writes (which might require flushing at exit time) could have
been performed.
previously, exit called two wrapper functions for __stdio_exit named
__flush_on_exit and __seek_on_exit. both of these functions actually
performed both tasks (seek and flushing) by calling the underlying
__stdio_exit. in order to avoid doing this twice, an overridable data
object __towrite_used was used to cause __seek_on_exit to act as a nop
when __towrite was linked.
now, exit only makes one call, directly to __stdio_exit. this is
satisfiable by a weak dummy definition in exit.c, but the real
definition is pulled in by either __toread.c or __towrite.c through
their referencing a symbol which is defined only in __stdio_exit.c.
(cherry picked from commit
c463e11eda8326aacee2ac1d516954a9574a2dcd)
Clément Vasseur [Wed, 9 Jul 2014 12:34:18 +0000 (14:34 +0200)]
fix the %m specifier in syslog
errno must be saved upon vsyslog entry, otherwise its value could be
changed by some libc function before reaching the %m handler in
vsnprintf.
(cherry picked from commit
da27118157c2942d7652138b8d8b0056fc8f872f)
Rich Felker [Fri, 11 Jul 2014 04:26:12 +0000 (00:26 -0400)]
make dynamic linker accept colon as a separator for LD_PRELOAD
(cherry picked from commit
349381aa8c0fc385e54e1068dd5f2b27af55cd12)
Rich Felker [Tue, 8 Jul 2014 23:40:44 +0000 (19:40 -0400)]
fix typo in microblaze setjmp asm
r24 was wrongly being saved at a misaligned offset of 30 rather than
the correct offset of 40 in the jmp_buf. the exact effects of this
error have not been studied, but it's clear that the value of r24 was
lost across setjmp/longjmp and the saved values of r21 and/or r22 may
also have been corrupted.
(cherry picked from commit
729673689c3e78803ddfdac2ca6be5a5b80e124a)
Rich Felker [Sun, 6 Jul 2014 05:34:13 +0000 (01:34 -0400)]
fix multiple issues in legacy function getpass
1. failure to output a newline after the password is read
2. fd leaks via missing FD_CLOEXEC
3. fd leaks via failure-to-close when any of the standard streams are
closed at the time of the call
4. wrongful fallback to use of stdin when opening /dev/tty fails
5. wrongful use of stderr rather than /dev/tty for prompt
6. failure to report error reading password
(cherry picked from commit
ea496d6c63ecbb5ea475111808e5c0f799354450)
Rich Felker [Wed, 2 Jul 2014 16:09:48 +0000 (12:09 -0400)]
fix failure of wide printf/scanf functions to set wide orientation
in some cases, these functions internally call a byte-based input or
output function before calling getwc/putwc, so they cannot rely on the
latter to set the orientation.
(cherry picked from commit
984c25b74da085c6ae6b44a87bbd5f8afc9be331)
Rich Felker [Tue, 1 Jul 2014 22:49:54 +0000 (18:49 -0400)]
fix incorrect return value for fwide function
when the orientation of the stream was already set, fwide was
incorrectly returning its argument (the requested orientation) rather
than the actual orientation of the stream.
(cherry picked from commit
ebd8142a6ae19db1a5440d11c01afc7529eae0cd)
Rich Felker [Tue, 1 Jul 2014 22:27:19 +0000 (18:27 -0400)]
fix aliasing violations in mbtowc and mbrtowc
these functions were setting wc to point to wchar_t aliasing itself as
a "cheap" way to support null wc arguments. doing so was anything but
cheap, since even without the aliasing violation, it would limit the
compiler's ability to optimize.
making wc point to a dummy object is equally easy and does not suffer
from the above problems.
(cherry picked from commit
e89cfe51d2001af08fc2a13e5133ba8157f90beb)
Rich Felker [Sat, 21 Jun 2014 11:44:46 +0000 (07:44 -0400)]
remove hack in syslog.h that resulted in aliasing violations
this issue affected the prioritynames and facilitynames arrays which
are only provided when requested (usually by syslogd implementations)
and which are presently defined as compound literals. the aliasing
violation seems to have been introduced as a workaround for bad
behavior by gcc's -Wwrite-strings option, but it caused compilers to
completely optimize out the contents of prioritynames and
facilitynames since, under many usage cases, the aliasing rules prove
that the contents are never accessed.
(cherry picked from commit
70d9c303b3115ab0fe6060ba0f7b0e4c0a2320b7)
Rich Felker [Thu, 19 Jun 2014 04:42:28 +0000 (00:42 -0400)]
fix incorrect comparison loop condition in memmem
the logic for this loop was copied from null-terminated-string logic
in strstr without properly adapting it to work with explicit lengths.
presumably this error could result in false negatives (wrongly
comparing past the end of the needle/haystack), false positives
(stopping comparison early when the needle contains null bytes), and
crashes (from runaway reads past the end of mapped memory).
(cherry picked from commit
cef0f289f666b6c963bfd11537a6d80916ff889e)
Rich Felker [Tue, 17 Jun 2014 18:32:43 +0000 (14:32 -0400)]
fix powerpc dynamic linker thread-pointer-relative relocations
processing of R_PPC_TPREL32 was ignoring the addend provided by the
RELA-style relocation and instead using the inline value as the
addend. this presumably broke dynamic-linked access to initial TLS in
cases where the addend was nonzero.
(cherry picked from commit
94cf991bf4b18bb87a15a96e7b5e7d92fab787ba)
Clément Vasseur [Fri, 13 Jun 2014 16:27:56 +0000 (18:27 +0200)]
fix missing argument to syscall in fanotify_mark
(cherry picked from commit
4e5c7a2176773c9a1564c6603240337b3ad6b496)
Rich Felker [Mon, 28 Jul 2014 04:25:24 +0000 (00:25 -0400)]
prepare pthread_create.c for cherry-picking from master
this change is harmless and allows commit
a6adb2bcd8145353943377d6119c1d7a4242bae1 to apply without conflicts.
Rich Felker [Mon, 28 Jul 2014 04:07:37 +0000 (00:07 -0400)]
fix gethostby*_r result pointer value on error
according to the documentation in the man pages, the GNU extension
functions gethostbyaddr_r, gethostbyname_r and gethostbyname2_r are
guaranteed to set the result pointer to NULL in case of error or no
result.
corresponds to commit
fe82bb9b921be34370e6b71a1c6f062c20999ae0 in
master branch.
Rich Felker [Fri, 6 Jun 2014 22:45:24 +0000 (18:45 -0400)]
release 1.0.3
Szabolcs Nagy [Thu, 5 Jun 2014 20:32:42 +0000 (22:32 +0200)]
fix multiple validation issues in dns response label parsing
Due to an error introduced in commit
fcc522c92335783293ac19df318415cd97fbf66b,
checking of the remaining output buffer space was not performed correctly,
allowing malformed input to write past the end of the buffer.
In addition, the loop detection logic failed to account for the possibility
of infinite loops with no output, which would hang the function.
The output size is now limited more strictly so only names with valid length
are accepted.
(cherry picked from commit
b3d9e0b94ea73c68ef4169ec82c898ce59a4e30a)
Rich Felker [Wed, 4 Jun 2014 08:39:34 +0000 (04:39 -0400)]
remove some dummy "ent" function aliases that duplicated real ones
the service and protocol functions are defined also in other files,
and the protocol ones are actually non-nops elsewhere, so the weak
definitions in ent.c could have prevented the strong definitions from
getting pulled in and used in some static programs.
(cherry picked from commit
934aa1350b96461f205ad69c95e8f6f035f6b62c)
Rich Felker [Tue, 3 Jun 2014 21:53:11 +0000 (17:53 -0400)]
fix if_nametoindex return value when interface does not exist
the return value is unsigned, so negative results for "errors" do not
make sense; 0 is the value reserved for when the interface name does
not exist.
(cherry picked from commit
8041af59881219c32267c3491bee43591d3c3fe6)
Rich Felker [Mon, 2 Jun 2014 20:21:47 +0000 (16:21 -0400)]
fix incorrect end pointer in some cases when wcsrtombs stops early
when wcsrtombs stopped due to hitting zero remaining space in the
output buffer, it was wrongly clearing the position pointer as if it
had completed the conversion successfully.
this commit rearranges the code somewhat to make a clear separation
between the cases of ending due to running out of output buffer space,
and ending due to reaching the end of input or an illegal sequence in
the input. the new branches have been arranged with the hope of
optimizing more common cases, too.
(cherry picked from commit
8fba4458afb7304b32ca887e4a3990c6029131f9)
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).
(cherry picked from commit
8258014fd1e34e942a549c88c7e022a00445c352)
Rich Felker [Fri, 6 Jun 2014 21:56:36 +0000 (17:56 -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.
corresponds to commit
55f45bc7222ec50b72aa8411c61e30184d0ade23 in
master branch.
Rich Felker [Tue, 20 May 2014 21:58:42 +0000 (17:58 -0400)]
release 1.0.2
Rich Felker [Tue, 20 May 2014 19:49:21 +0000 (15:49 -0400)]
trivial formatting fix for the config.mak generated by configure
(cherry picked from commit
7c6db373a55a348b3ecc7b124dd4ea541eff63cd)
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.
(cherry picked from commit
dec66750b8ed4493d5bb40042f7a473e60fe934e)
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.
(cherry picked from commit
9ca4dae5d895cf816eb1815511aba77a90f6acd7)
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.
(cherry picked from commit
8945667fadc2eb71b7924bb4c5a69507fd362f4a)
Szabolcs Nagy [Thu, 8 May 2014 17:04:48 +0000 (19:04 +0200)]
fix strftime %s not to zero pad with default width=2
(cherry picked from commit
ac0acd569e01735fc6052d43fdf57f3a07c93f3d)
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.
(cherry picked from commit
adbf0258be4eea5f012e173de7e55a87f3093669)
Rich Felker [Wed, 30 Apr 2014 18:47:06 +0000 (14:47 -0400)]
fix missing SO_RCVBUFFORCE and SO_SNDBUFFORCE in mips socket.h
(cherry picked from commit
468bc11ed059c475f974920ac3d499e6071a6b2c)
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.
(cherry picked from commit
23d64182d8328c300b368446aad20da9cec91aa3)
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.
(cherry picked from commit
c3d9d172b1fcd56c4d356798f4e3b4653076bcc3)
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.
(cherry picked from commit
476cd1d96560aaf7f210319597556e7fbcd60469)
Rich Felker [Wed, 16 Apr 2014 08:23:31 +0000 (04:23 -0400)]
release 1.0.1
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.
(cherry picked from commit
0d0c2f40344640a2a6942dda156509593f51db5d)
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.
(cherry picked from commit
fcea534e579077e10456f6ed06c033dfaa013a24)
Rich Felker [Tue, 15 Apr 2014 03:48:40 +0000 (23:48 -0400)]
fix fallback code for old kernels in clock_gettime
(cherry picked from commit
805698401dbac7ce3079fa97eaad5ba0508377f4)
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.
(cherry picked from commit
83c98aac4c43f9571e8f92a1c795afe02c237d4b)
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.
(cherry picked from commit
73c870ed3209b68b5c8c350534508cc9d95a6bcb)
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.
(cherry picked from commit
6fbdeff0e51f6afc38fbb1476a4db81322779da4)
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.
(cherry picked from commit
e94d0692864ecf9522fd6a97610a47a2f718d3de)
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.
(cherry picked from commit
89740868c9f1c84b8ee528468d12df1fa72cd392)
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.
(cherry picked from commit
109048e031f39fbb370211fde44ababf6c04c8fb)
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.
(cherry picked from commit
91d5aa06572d2660122f9a06ed242fef0383f292)
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.
(cherry picked from commit
0a8d98285f46f721dabf38485df916c02d6a4675)
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.
(cherry picked from commit
30c1205acd73c8481ca34f0a41de1d41884d07b5)
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.
rofl0r [Mon, 17 Mar 2014 21:34:52 +0000 (22:34 +0100)]
x32: fix struct statfs
the omission of the padding was uncovered by the latest regression
statvfs regression test added to libc-test.
Rich Felker [Mon, 17 Mar 2014 04:25:23 +0000 (00:25 -0400)]
fix negated error codes from ptsname_r
the incorrect error codes also made their way into errno when
__ptsname_r was called by plain ptsname, which reports errors via
errno rather than a return value.
Bobby Bingham [Sun, 16 Mar 2014 21:17:28 +0000 (16:17 -0500)]
superh: fix dynamic linking of __fpscr_values
Applications ended up with copy relocations for this array, which
resulted in libc's references to this array pointing to the
application's copy. The dynamic linker, however, can require this array
before the application is relocated, and therefore before the
application's copy of this array is initialized. This resulted in
garbage being loaded into FPSCR before executing main, which violated
the ABI.
We fix this by putting the array in crt1 and making the libc copy
private. This prevents libc's reference to the array from pointing to
an uninitialized copy in the application.
rofl0r [Thu, 13 Mar 2014 19:27:55 +0000 (20:27 +0100)]
semctl: fix UB causing crashes on powerpc
it's UB to fetch variadic args when none are passed, and this caused
real crashes on ppc due to its calling convention, which defines that
for variadic functions aggregate types be passed as pointers.
the assignment caused that pointer to get dereferenced, resulting in
a crash.
Szabolcs Nagy [Wed, 12 Mar 2014 14:59:09 +0000 (15:59 +0100)]
fix statfs struct on mips
The mips statfs struct layout is different than on other archs, so the
statfs, fstatfs, statvfs and fstatvfs APIs were broken on mips.
Now the ordering is fixed, the types are kept consistent with other archs.
Szabolcs Nagy [Wed, 12 Mar 2014 10:46:17 +0000 (11:46 +0100)]
fix semid_ds structure on mips
This used to be broken when all archs had the same semid_ds definition:
there is no padding around the time_t members on mips.
Rich Felker [Tue, 11 Mar 2014 21:21:38 +0000 (17:21 -0400)]
fix socket.h struct msghdr member types on powerpc
these were incorrectly copied from the kernel, whose ABI matches the
POSIX requirements but with the wrong underlying types and wrong
signedness.
Rich Felker [Tue, 11 Mar 2014 21:01:34 +0000 (17:01 -0400)]
fix sysvipc structures on powerpc
these have been wrong for a long time and were never detected or
corrected. powerpc needs some gratuitous extra padding/reserved slots
in ipc_perm, big-endian ordering for the padding of time_t slots that
was intended by the kernel folks to allow a transition to 64-bit
time_t, and some minor gratuitous reordering of struct members.
Rich Felker [Tue, 11 Mar 2014 19:27:13 +0000 (15:27 -0400)]
move struct semid_ds to from shared sys/sem.h to bits
the definition was found to be incorrect at least for powerpc, and
fixing this cleanly requires making the definition arch-specific. this
will allow cleaning up the definition for other archs to make it more
specific, and reversing some of the ugliness (time_t hacks) introduced
with the x32 port.
this first commit simply copies the existing definition to each arch
without any changes. this is intentional, to make it easier to review
changes made on a per-arch basis.
Szabolcs Nagy [Sun, 9 Mar 2014 18:29:41 +0000 (19:29 +0100)]
math.h: make __FLOAT_BITS and __DOUBLE_BITS C89
Remove non-constant aggregate initializer. (Still using long long, but
that is supported by ancient compilers without __extension__ anyway).
Rich Felker [Sun, 9 Mar 2014 07:09:49 +0000 (03:09 -0400)]
fix incorrect rounding in printf floating point corner cases
the printf floating point formatting code contains an optimization to
avoid computing digits that will be thrown away by rounding at the
specified (or default) precision. while it was correctly retaining all
places up to the last decimal place to be printed, it was not
retaining enough precision to see the next nonzero decimal place in
all cases. this could cause incorrect rounding down in round-to-even
(default) rounding mode, for example, when printing 0.5+DBL_EPSILON
with "%.0f".
in the fix, LDBL_MANT_DIG/3 is a lazy (non-sharp) upper bound on the
number of zeros between any two nonzero decimal digits.
Rich Felker [Sun, 9 Mar 2014 06:38:52 +0000 (01:38 -0500)]
fix buffer overflow in printf formatting of denormals with low bit set
empirically the overflow was an off-by-one, and it did not seem to be
overwriting meaningful data. rather than simply increasing the buffer
size by one, however, I have attempted to make the size obviously
correct in terms of bounds on the number of iterations for the loops
that fill the buffer. this still results in no more than a negligible
size increase of the buffer on the stack (6-7 32-bit slots) and is a
"safer" fix unless/until somebody wants to do the proof that a smaller
buffer would suffice.
Rich Felker [Sat, 8 Mar 2014 05:50:19 +0000 (00:50 -0500)]
in sys/procfs.h, avoid using __WORDSIZE macro
this was problematic because several archs don't define __WORDSIZE. we
could add it, but I would rather phase this macro out in the long
term. in our version of the headers, UINTPTR_MAX is available here, so
just use it instead.
Rich Felker [Sat, 8 Mar 2014 05:14:33 +0000 (00:14 -0500)]
add bits/user.h for sh port
this seems to have been overlooked, and resulted in breakage in
anything including sys/user.h.
Rich Felker [Sat, 8 Mar 2014 04:56:48 +0000 (23:56 -0500)]
in fcntl, use unsigned long instead of long for variadic argument type
neither is correct; different commands take different argument types,
and some take no arguments at all. I have a much larger overhaul of
fcntl prepared to address this, but it's not appropriate to commit
during freeze.
the immediate problem being addressed affects forward-compatibility on
x32: if new commands are added and they take pointers, but the
libc-level fcntl function is not aware of them, using long would
sign-extend the pointer to 64 bits and give the kernel an invalid
pointer. on the kernel side, the argument to fcntl is always treated
as unsigned long, so no harm is done by treating possibly-signed
integer arguments as unsigned. for every command that takes an integer
argument except for F_SETOWN, large integer arguments and negative
arguments are handled identically anyway. in the case of F_SETOWN, the
kernel is responsible for converting the argument which it received as
unsigned long to int, so the sign of negative arguments is recovered.
the other problem that will be addressed later is that the type passed
to va_arg does not match the type in the caller of fcntl. an advanced
compiler doing cross-translation-unit analysis could potentially see
this mismatch and issue warnings or otherwise make trouble.
on i386, this patch was confirmed not to alter the code generated by
gcc 4.7.3. in principle the generated code should not be affected on
any arch except x32.
Rich Felker [Thu, 6 Mar 2014 23:59:51 +0000 (18:59 -0500)]
update copyright dates to 2014
rofl0r [Wed, 5 Mar 2014 23:26:03 +0000 (00:26 +0100)]
x32: fix sysinfo()
the kernel uses long longs in the struct, but the documentation
says they're long. so we need to fixup the mismatch between the
userspace and kernelspace structs.
since the struct offers a mem_unit member, we can avoid truncation
by adjusting that value.
Rich Felker [Wed, 5 Mar 2014 21:08:56 +0000 (16:08 -0500)]
fix strerror on mips: one error code is out of the 8-bit table range
if we ever encounter other targets where error codes don't fit in the
8-bit range, the table should probably just be bumped to 16-bit, but
for now I don't want to increase the table size on all archs just
because of a bug in the mips abi.
Rich Felker [Fri, 28 Feb 2014 18:12:40 +0000 (13:12 -0500)]
improve configure's target arch matching
most notably, it was failing to match sh4-*, etc., but in general the
explicit matching of hyphens for some archs was problematic because it
failed to accept simply the musl-style arch name (without a gcc-style
tuple) as an input. the original motivation of matching hyphens was to
prevent incorrectly identifying a 64-bit arch as the corresponding
32-bit arch (e.g. mips* matching mips64) but this is easily fixed by
simply checking (and for now, rejecting as unsupported) the relevant
64-bit archs.
Rich Felker [Fri, 28 Feb 2014 05:09:55 +0000 (00:09 -0500)]
fix missing CFLAGS in configure test for float on sh
Rich Felker [Fri, 28 Feb 2014 04:55:04 +0000 (23:55 -0500)]
fix copy-and-paste error in configure's IEEE double check for sh
Rich Felker [Fri, 28 Feb 2014 04:18:42 +0000 (23:18 -0500)]
add nofpu subarchs to the sh arch, and properly detect compiler's fpu config
Rich Felker [Fri, 28 Feb 2014 03:20:44 +0000 (22:20 -0500)]
fix endian subarchs for sh arch
default endianness for sh on linux is little, and while conventions
vary, "eb" seems to be the most widely used suffix for big endian.
Rich Felker [Fri, 28 Feb 2014 03:03:25 +0000 (22:03 -0500)]
rename superh port to "sh" for consistency
linux, gcc, etc. all use "sh" as the name for the superh arch. there
was already some inconsistency internally in musl: the dynamic linker
was searching for "ld-musl-sh.path" as its path file despite its own
name being "ld-musl-superh.so.1". there was some sentiment in both
directions as to how to resolve the inconsistency, but overall "sh"
was favored.
Rich Felker [Tue, 25 Feb 2014 18:05:38 +0000 (13:05 -0500)]
fix readdir not to set ENOENT when directory is removed while reading
per POSIX, ENOENT is reserved for invalid stream position; it is an
optional error and would only happen if the application performs
invalid seeks on the underlying file descriptor. however, linux's
getdents syscall also returns ENOENT if the directory was removed
between the time it was opened and the time of the read. we need to
catch this case and remap it to simple end-of-file condition (null
pointer return value like an error, but no change to errno). this
issue reportedly affects GNU make in certain corner cases.
rather than backing up and restoring errno, I've just changed the
syscall to be made in a way that doesn't affect errno (via an inline
syscall rather than a call to the __getdents function). the latter
still exists for the purpose of providing the public getdents alias
which sets errno.
Szabolcs Nagy [Mon, 24 Feb 2014 23:28:31 +0000 (00:28 +0100)]
in.h: new IP_MTU_DISCOVER mode IP_PMTUDISC_INTERFACE
introduced in linux v3.13,
482fc6094afad572a4ea1fd722e7b11ca72022a0
to mitigate dns cache poisoning via fragmentation
Szabolcs Nagy [Mon, 24 Feb 2014 23:24:05 +0000 (00:24 +0100)]
if_ether.h: new ethernet protocol type
for High-availability Seamless Redundancy (HSR) specified in IEC 62439-3
new in linux v3.13,
f421436a591d34fa5279b54a96ac07d70250cc8d
Szabolcs Nagy [Mon, 24 Feb 2014 23:22:04 +0000 (00:22 +0100)]
sys/socket.h: add the SO_MAX_PACING_RATE SOL_SOCKET option
introduced in linux v3.13,
62748f32d501f5d3712a7c372bbb92abc7c62bc7
Szabolcs Nagy [Mon, 24 Feb 2014 23:17:29 +0000 (00:17 +0100)]
elf.h: add aarch64 relocations
Szabolcs Nagy [Mon, 24 Feb 2014 23:12:39 +0000 (00:12 +0100)]
elf.h: new elf header flag to mark 2008-NaN vs legacy-NaN on mips
see glibc commit
9c21573c02446b3d5cf6a34b67c8545e5be6a600
Rich Felker [Mon, 24 Feb 2014 22:31:00 +0000 (17:31 -0500)]
add missing sub files for mipsel-sf to use softfloat code
the build system has no automatic way to know this code applies to
both big (default) and little endian variants, so explicit .sub files
are needed.
Szabolcs Nagy [Mon, 24 Feb 2014 22:16:29 +0000 (23:16 +0100)]
mips: add mips-sf subarch support (soft-float)
Userspace emulated floating-point (gcc -msoft-float) is not compatible
with the default mips abi (assumes an FPU or in kernel emulation of it).
Soft vs hard float abi should not be mixed, __mips_soft_float is checked
in musl's configure script and there is no runtime check. The -sf subarch
does not save/restore floating-point registers in setjmp/longjmp and only
provides dummy fenv implementation.