musl
8 years agohave configure check/add --gc-sections linker option
Rich Felker [Thu, 5 Nov 2015 02:40:36 +0000 (21:40 -0500)]
have configure check/add --gc-sections linker option

this allowing the linker to drop certain weak definitions that are
only used as dummies for static linking. they could be eliminated for
shared library builds using the preprocessor instead, but we are
trying to transition to using the same object files for shared and
static libc, so a link-time solution is preferable.

8 years agohave configure check/add linker options to reduce size lost to padding
Rich Felker [Thu, 5 Nov 2015 02:39:13 +0000 (21:39 -0500)]
have configure check/add linker options to reduce size lost to padding

based on patch by Denys Vlasenko. sorting sections and common data
symbols by alignment acts as an approximation for optimal packing,
which the linker does not actually support.

8 years agohave configure check/add -ffunction-sections and -fdata-sections
Rich Felker [Wed, 4 Nov 2015 18:24:11 +0000 (13:24 -0500)]
have configure check/add -ffunction-sections and -fdata-sections

based on patch by Denys Vlasenko. the original intent for using these
options was to enable linking optimizations. these are immediately
available for static linking applications to libc.a, and will also be
used for linking libc.so in a subsequent commit.

in addition to the original motives, this change works around a whole
class of toolchain bugs where the compiler generates relative address
expressions using a weak symbol and the assembler "optimizes out" the
relocation which should result by using the weak definition. (see gas
pr 18561 and gcc pr 66609, 68178, etc. for examples.) by having
different functions and data objects in their own sections, all
relative address expressions are cross-section and thus cannot be
resolved to constants until link time. this allows us to retain
support for affected compiler/assembler versions without invasive
and fragile source-level workarounds.

8 years agofix mismatched parens in CMPLX def for annex-g-conforming compilers
Rich Felker [Tue, 3 Nov 2015 02:44:57 +0000 (21:44 -0500)]
fix mismatched parens in CMPLX def for annex-g-conforming compilers

this conditional path was never tested because there are no compilers
that conform to annex g (none with _Imaginary_I).

8 years agogeneralize sh entry point asm not to assume call dests fit in 12 bits
Rich Felker [Mon, 2 Nov 2015 23:11:36 +0000 (18:11 -0500)]
generalize sh entry point asm not to assume call dests fit in 12 bits

this assumption is borderline-unsafe to begin with, and fails badly
with -ffunction-sections since the linker can move the callee
arbitrarily far away when it lies in a different section.

8 years agokeep user-provided CFLAGS/LDFLAGS separate from those added by configure
Rich Felker [Mon, 2 Nov 2015 21:58:14 +0000 (16:58 -0500)]
keep user-provided CFLAGS/LDFLAGS separate from those added by configure

this way, overriding these variables on the make command line (or just
re-passing the originally-passed values when invoking make) won't
suppress use of the flags added by configure.

8 years agofix mremap memory synchronization and use of variadic argument
Rich Felker [Mon, 2 Nov 2015 21:37:51 +0000 (16:37 -0500)]
fix mremap memory synchronization and use of variadic argument

since mremap with the MREMAP_FIXED flag is an operation that unmaps
existing mappings, it needs to use the vm lock mechanism to ensure
that any in-progress synchronization operations using vm identities
from before the call have finished.

also, the variadic argument was erroneously being read even if the
MREMAP_FIXED flag was not passed. in practice this didn't break
anything, but it's UB and in theory LTO could turn it into a hard
error.

8 years agoprevent allocs than PTRDIFF_MAX via mremap
Daniel Micay [Sat, 31 Oct 2015 09:14:45 +0000 (05:14 -0400)]
prevent allocs than PTRDIFF_MAX via mremap

It's quite feasible for this to happen via MREMAP_MAYMOVE.

8 years agouse explicit __cp_cancel label in cancellable syscall asm for all archs
Rich Felker [Mon, 2 Nov 2015 21:16:00 +0000 (16:16 -0500)]
use explicit __cp_cancel label in cancellable syscall asm for all archs

previously, only archs that needed to do stack cleanup defined a
__cp_cancel label for acting on cancellation in their syscall asm, and
a default definition was provided by a weak alias to __cancel, the C
function. this resulted in wrong codegen for arm on gcc versions
affected by pr 68178 and possibly similar issues (like pr 66609) on
other archs, and also created an inconsistency where the __cp_begin
and __cp_end labels were treated as const data but __cp_cancel was
treated as a function. this in turn caused incorrect code generation
on archs where function pointers point to function descriptors rather
than code (for now, only sh/fdpic).

8 years agoproperly access mcontext_t program counter in cancellation handler
Rich Felker [Mon, 2 Nov 2015 17:39:28 +0000 (12:39 -0500)]
properly access mcontext_t program counter in cancellation handler

using the actual mcontext_t definition rather than an overlaid pointer
array both improves correctness/readability and eliminates some ugly
hacks for archs with 64-bit registers bit 32-bit program counter.

also fix UB due to comparison of pointers not in a common array
object.

8 years agofix missing bss handling in FDPIC ELF loader
Rich Felker [Thu, 29 Oct 2015 01:45:31 +0000 (21:45 -0400)]
fix missing bss handling in FDPIC ELF loader

when a library being loaded has bss (i.e. data segment with
p_memsz>p_filesz), this region needs to be zeroed with a combination
of memset and/or mmap. the regular ELF loader always did this but the
FDPIC code path omitted it, leading to objects in bss having
uninitialized/junk contents.

8 years agogetnameinfo: make size check not fail for bigger sizes
Hauke Mehrtens [Mon, 26 Oct 2015 22:03:55 +0000 (23:03 +0100)]
getnameinfo: make size check not fail for bigger sizes

getnameinfo() compares the size of the given struct sockaddr with
sizeof(struct sockaddr_in) and sizeof(struct sockaddr_in6) depending on
the net family. When you add a sockaddr of size sizeof(struct
sockaddr_storage) this function will fail because the size of the
sockaddr is too big. Change the check that it only fails if the size is
too small, but make it work when it is too big for example when someone
calls this function with a struct sockaddr_storage and its size.
This fixes a problem with IoTivity 1.0.0 and musl.

glibc and bionic are only failing if it is smaller, net/freebsd
implemented the != check.

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
8 years agosafely handle failure to open hosts, services, resolv.conf files
Rich Felker [Mon, 26 Oct 2015 22:42:22 +0000 (18:42 -0400)]
safely handle failure to open hosts, services, resolv.conf files

previously, transient failures like fd exhaustion or other
resource-related errors were treated the same as non-existence of
these files, leading to fallbacks or false-negative results. in
particular:

- failure to open hosts resulted in fallback to dns, possibly yielding
  EAI_NONAME for a hostname that should be defined locally, or an
  unwanted result from dns that the hosts file was intended to
  replace.

- failure to open services resulted in EAI_SERVICE.

- failure to open resolv.conf resulted in querying localhost rather
  than the configured nameservers.

now, only permanent errors trigger the fallback behaviors above; all
other errors are reportable to the caller as EAI_SYSTEM.

8 years agofix single-byte overflow of malloc'd buffer in getdelim
Rich Felker [Sun, 25 Oct 2015 02:42:10 +0000 (22:42 -0400)]
fix single-byte overflow of malloc'd buffer in getdelim

the buffer enlargement logic here accounted for the terminating null
byte, but not for the possibility of hitting the delimiter in the
buffer-refill code path that uses getc_unlocked, in which case two
additional bytes (the delimiter and the null termination) are written
without another chance to enlarge the buffer.

this patch and the corresponding bug report are by Felix Janda.

8 years agoprevent user CFLAGS overrides from exposing executable stack
Rich Felker [Fri, 23 Oct 2015 04:01:01 +0000 (00:01 -0400)]
prevent user CFLAGS overrides from exposing executable stack

the option to suppress executable stack tagging was placed in CFLAGS,
which is treated as optional and overridable by the build system. if a
user replaces CFLAGS after configure has run, it could get lost,
resulting in a libc.so that's flagged as needing executable stack,
which would cause the kernel to map the initial stack as executable.

move -Wa,--noexecstack to CFLAGS_C99FSE, the make variable used for
mandatory compiler options.

8 years agofix breakage when user overrides CFLAGS on the make command line
Rich Felker [Fri, 23 Oct 2015 03:41:35 +0000 (23:41 -0400)]
fix breakage when user overrides CFLAGS on the make command line

these per-target CFLAGS adjustments are mandatory additions to the
command line for building the affected targets, not part of the
user-provided CFLAGS for tuning. my intent was always that the
variable append operations would take place after user settings, but
when a variable is set on the command line, it overrides all
definitions in the makefile, including target-specific ones.

based on patch by Szabolcs Nagy.

8 years agorelease 1.1.12
Rich Felker [Mon, 19 Oct 2015 23:12:57 +0000 (19:12 -0400)]
release 1.1.12

8 years agodeclare fpu usage to the assembler in arm hard-float asm files
Szabolcs Nagy [Mon, 19 Oct 2015 06:05:58 +0000 (02:05 -0400)]
declare fpu usage to the assembler in arm hard-float asm files

Some armhf gcc toolchains (built with --with-float=hard but without
--with-fpu=vfp*) do not pass -mfpu=vfp to the assembler and then
binutils rejects the UAL mnemonics for VFP unless there is an .fpu vfp
directive in the asm source.

8 years agoadd missing memory barrier to pthread_join
Bobby Bingham [Sun, 4 Oct 2015 19:55:29 +0000 (14:55 -0500)]
add missing memory barrier to pthread_join

POSIX requires pthread_join to synchronize memory on success.  The
futex wait inside __timedwait_cp cannot handle this because it's not
called in all cases.  Also, in the case of a spurious wake, tid can
become zero between the wake and when the joining thread checks it.

8 years agofix dladdr treatment of function descriptors for fdpic
Rich Felker [Fri, 16 Oct 2015 02:51:56 +0000 (22:51 -0400)]
fix dladdr treatment of function descriptors for fdpic

when determining which module an address belongs to, all function
descriptor ranges must be checked first, in case the allocated memory
falls inside another module's memory range.

dladdr itself must also check addresses against function descriptors
before doing a best-match search against the symbol table. even when
doing the latter (e.g. for code addresses obtained from mcontext_t),
also check whether the best-match was a function, and if so, replace
the result with a function descriptor address. which is the nominal
"base address" of the function and which the caller needs if it
intends to subsequently call the matching function.

8 years agofix visibility mismatch in dynamic linker stage 2 function definition
Rich Felker [Thu, 15 Oct 2015 21:38:54 +0000 (17:38 -0400)]
fix visibility mismatch in dynamic linker stage 2 function definition

since commits 2907afb8dbd4c1d34825c3c9bd2b41564baca210 and
6fc30c2493fcfedec89e45088bea87766a1e3286, __dls2 is no longer called
via symbol lookup, but instead uses relative addressing that needs to
be resolved at link time. on some linker versions, and/or if
-Bsymbolic-functions is not used, the linker may leave behind a
dynamic relocation, which is not suitable for bootstrapping the
dynamic linker, if the reference to __dls2 is marked hidden but the
definition is not actually hidden. correcting the definition to use
hidden visibility fixes the problem.

the static-PIE entry point rcrt1 was likewise affected and is also
fixed by this patch.

8 years agosuppress sh assembler rejection of instructions based on isa level
Rich Felker [Thu, 15 Oct 2015 21:21:07 +0000 (17:21 -0400)]
suppress sh assembler rejection of instructions based on isa level

we need access to all instructions in order for runtime selection of
atomic model to work correctly. without this patch, some versions of
gcc instruct gas to reject instructions outside the target isa level.

8 years agoprevent reordering of or1k and powerpc thread pointer loads
Rich Felker [Thu, 15 Oct 2015 16:08:51 +0000 (12:08 -0400)]
prevent reordering of or1k and powerpc thread pointer loads

other archs use asm for the thread pointer load, so making that asm
volatile is sufficient to inform the compiler that it has a "side
effect" (crashing or giving the wrong result if the thread pointer was
not yet initialized) that prevents reordering. however, powerpc and
or1k have dedicated general purpose registers for the thread pointer
and did not need to use any asm to access it; instead, "local register
variables with a specified register" were used. however, there is no
specification for ordering constraints on this type of usage, and
presumably use of the thread pointer could be reordered across its
initialization.

to impose an ordering, I have added empty volatile asm blocks that
produce the "local register variable with a specified register" as
an output constraint.

8 years agomark arm thread-pointer-loading inline asm as volatile
Rich Felker [Thu, 15 Oct 2015 16:04:48 +0000 (12:04 -0400)]
mark arm thread-pointer-loading inline asm as volatile

this builds on commits a603a75a72bb469c6be4963ed1b55fabe675fe15 and
0ba35d69c0e77b225ec640d2bd112ff6d9d3b2af to ensure that a compiler
cannot conclude that it's valid to reorder the asm to a point before
the thread pointer is set up, or to treat the inline function as if it
were declared with attribute((const)).

other archs already use volatile asm for thread pointer loading.

8 years agoadd comment documenting hard-coded opcode for reading mips thread pointer
Rich Felker [Thu, 15 Oct 2015 04:55:41 +0000 (00:55 -0400)]
add comment documenting hard-coded opcode for reading mips thread pointer

8 years agoremove attribute((const)) from arm __pthread_self inline function
Rich Felker [Thu, 15 Oct 2015 04:20:50 +0000 (00:20 -0400)]
remove attribute((const)) from arm __pthread_self inline function

commit a603a75a72bb469c6be4963ed1b55fabe675fe15 did this for the
public pthread_self function but not the internal inline one.

8 years agofix strftime handling of out-of-range struct tm fields
Rich Felker [Wed, 14 Oct 2015 22:58:15 +0000 (18:58 -0400)]
fix strftime handling of out-of-range struct tm fields

strftime results are unspecified in this case, but should not invoke
undefined behaviour.

tm_wday, tm_yday, tm_mon and tm_year fields were used in signed int
arithmetic that could overflow.

based on patch by Szabolcs Nagy.

8 years agoremove hand-written crt1.s and Scrt1.s files for all archs
Rich Felker [Wed, 14 Oct 2015 21:08:34 +0000 (17:08 -0400)]
remove hand-written crt1.s and Scrt1.s files for all archs

since commit c5e34dabbb47d8e97a4deccbb421e0cd93c0094b, crt1.c has
provided a "mostly-C" implementation of the crt1 start file that
avoids the need for arch-specific symbol referencing, PIC/PIE-specific
code variants, etc. but for archs that had existing hand-written
versions, the new code was initially unused, and later only used as
the dynamic linker entry point. this commit switches all archs to
using the new code.

the code being removed was a recurring source of subtle errors, and
was still broken at least on arm, where it failed to properly align
the stack pointer before calling into C code.

8 years agoadd CFI generation script for x86_64
Alex Dowad [Tue, 13 Oct 2015 11:28:52 +0000 (13:28 +0200)]
add CFI generation script for x86_64

8 years agorecognize partial register operands in i386 CFI generation
Alex Dowad [Tue, 13 Oct 2015 11:28:51 +0000 (13:28 +0200)]
recognize partial register operands in i386 CFI generation

8 years agofix misinterpretation of indexed memory operand in i386 CFI generation
Alex Dowad [Tue, 13 Oct 2015 21:58:43 +0000 (17:58 -0400)]
fix misinterpretation of indexed memory operand in i386 CFI generation

a register used as an index in the memory destination of a mov
instruction was wrongly interpreted as the destination of the mov.

8 years agofix misinterpretation of operand order in i386 CFI generation
Alex Dowad [Tue, 13 Oct 2015 11:28:50 +0000 (13:28 +0200)]
fix misinterpretation of operand order in i386 CFI generation

binary ops like ADD, AND, etc. modify the 2nd operand, not 1st.

8 years agofix integer overflows in time_t/struct tm conversion code
Rich Felker [Thu, 8 Oct 2015 23:30:42 +0000 (23:30 +0000)]
fix integer overflows in time_t/struct tm conversion code

as found and reported by Brian Mastenbrook, the expressions
400*qc_cycles and years+100 in __secs_to_tm were both subject to
integer overflow for extreme values of the input t.

this patch by Szabolcs Nagy fixes the code by switching to larger
types, and matches the original intent I had in mind when writing this
code.

8 years agofix open_[w]memstream behavior when no writes take place
Rich Felker [Thu, 8 Oct 2015 22:03:53 +0000 (22:03 +0000)]
fix open_[w]memstream behavior when no writes take place

the specification for these functions requires that the buffer/size
exposed to the caller be valid after any successful call to fflush or
fclose on the stream. the implementation's approach is to update them
only at flush time, but that misses the case where fflush or fclose is
called without any writes having taken place, in which case the write
flushing callback will not be called.

to fix both the observable bug and the desired invariant, setup empty
buffers at open time and fail the open operation if no memory is
available.

8 years agofix instruction matching errors in i386 CFI generation
Alex Dowad [Fri, 2 Oct 2015 11:32:33 +0000 (13:32 +0200)]
fix instruction matching errors in i386 CFI generation

fdiv and fmul instructions were wrongly matched by the rules for
integer div and mul instructions, leading to incorrect conclusions
about register values being clobbered.

8 years agofactor common awk functions for CFI generation scripts into new file
Alex Dowad [Fri, 2 Oct 2015 11:32:32 +0000 (13:32 +0200)]
factor common awk functions for CFI generation scripts into new file

There is a lot which could be common between i386 and x86_64, but none
of it will be useful for any other arch. These should be useful for
all archs, however.

8 years agomake nl_langinfo(CODESET) always return "ASCII" in byte-based C locale
Rich Felker [Thu, 1 Oct 2015 22:59:56 +0000 (22:59 +0000)]
make nl_langinfo(CODESET) always return "ASCII" in byte-based C locale

commit 844212d94f582c4e3c5055e0a1524931e89ebe76, which did not make it
into any releases, changed nl_langinfo(CODESET) to always return
"UTF-8", even in the byte-based C locale. this was problematic because
application software was found to use the string match for "UTF-8" to
activate its own UTF-8 processing. this both undermines the byte-based
functionality of the C locale, and if mixed with with calls to the
standard multibyte functions, which happened in practice, could result
in severe mis-handling of input.

the motive for the previous change was that, to avoid widespread
compatibility problems, the string returned by nl_langinfo(CODESET)
needs to be accepted by iconv and by third-party character conversion
code. thus, the only remaining choice is "ASCII". this choice
accurately represents the intent that high bytes do not have
individual meaning in the C locale, but it does mean that iconv, when
passed nl_langinfo(CODESET) in the C locale, will produce errors in
cases where mbrtowc would have succeeded. for reference, glibc behaves
similarly in this regard, so I don't think it will be a problem.

8 years agofix mips fesetround failure to write back resulting mode
Rich Felker [Thu, 1 Oct 2015 05:10:54 +0000 (05:10 +0000)]
fix mips fesetround failure to write back resulting mode

patch by Anand Takale.

8 years agoeliminate protected-visibility data in libc.so with vis.h preinclude
Rich Felker [Tue, 29 Sep 2015 02:44:05 +0000 (02:44 +0000)]
eliminate protected-visibility data in libc.so with vis.h preinclude

some newer binutils versions print scary warnings about protected data
because most gcc versions fail to produce the right address
references/relocations for such data that might be subject to copy
relocations. originally vis.h explicitly assigned default visibility
to all public data symbols to avoid this issue, but commit
b8dda24fe1caa901a99580f7a52defb95aedb67c removed this treatment for
stdin/out/err to work around a gcc 3.x bug, and since they don't
actually need it (because taking their addresses is not valid C).

instead, a check for the gcc 3.x bug is added to the configure check
for vis.h preinclude support; this feature will simply be disabled
when using a buggy version of gcc.

8 years agoavoid attempting to lookup IP literals as hostnames
Rich Felker [Fri, 25 Sep 2015 01:18:42 +0000 (01:18 +0000)]
avoid attempting to lookup IP literals as hostnames

previously, __lookup_ipliteral only checked its argument against the
requested address family, so IPv4 literals passed through to
__lookup_name if the caller asked for only IPv6 results, and likewise
for IPv6 literals when the caller asked for only IPv4. this resulted
in spurious DNS lookups that reportedly even succeeded with some
nameservers.

now, __lookup_ipliteral attempts to parse its argument as both IPv4
and IPv6, and returns an error (to stop further search) rather than 0
(no results yet) if the form of the argument mismatches the requested
address family.

based on patch by Julien Ramseier.

8 years agomake getaddrinfo return error if both host and service name are null
Rich Felker [Fri, 25 Sep 2015 01:01:11 +0000 (01:01 +0000)]
make getaddrinfo return error if both host and service name are null

this case is specified as a mandatory ("shall fail") error.

based on patch by Julien Ramseier.

8 years agofix localeconv field value for unavailable values
Rich Felker [Thu, 24 Sep 2015 06:40:05 +0000 (06:40 +0000)]
fix localeconv field value for unavailable values

per ISO C, CHAR_MAX, not -1, is the value used to indicate that a char
field in struct lconv is unavailable.

patch by Julien Ramseier.

8 years agoavoid reading uninitialized memory in __map_file
Szabolcs Nagy [Wed, 23 Sep 2015 20:22:33 +0000 (20:22 +0000)]
avoid reading uninitialized memory in __map_file

The value of *size is not relevant in case of failure, but it's
better not to copy garbage from the stack into it.
(The compiler cannot see through the syscall, so optimization
was not affected by the unspecified value).

8 years agoregcomp: propagate allocation failures
Szabolcs Nagy [Wed, 23 Sep 2015 18:19:34 +0000 (18:19 +0000)]
regcomp: propagate allocation failures

The error code of an allocating function was not checked in tre_add_tag.

8 years agofix signal return for sh/fdpic
Rich Felker [Wed, 23 Sep 2015 18:33:49 +0000 (18:33 +0000)]
fix signal return for sh/fdpic

the restorer function pointer provided in the kernel sigaction
structure is interpreted by the kernel as a raw code address, not a
function descriptor.

this commit moves the declarations of the __restore and __restore_rt
symbols to ksigaction.h so that arch versions of the file can override
them, and introduces a version for sh which declares them as objects
rather than functions.

an alternate solution would have been defining SA_RESTORER to 0 so
that the functions are not used, but this both requires executable
stack (since the sh kernel does not have a vdso page with permanent
restorer functions) and crashes on qemu user-level emulation.

8 years agofix dlsym RTLD_NEXT behavior for fdpic
Rich Felker [Tue, 22 Sep 2015 23:41:41 +0000 (23:41 +0000)]
fix dlsym RTLD_NEXT behavior for fdpic

lookup the dso an address falls in based on the loadmap and not just a
base/length. fix the main app's fake loadmap used when loaded by a
non-fdpic-aware loader so that it does not cover the whole memory
space.

function descriptor addresses are also matched for future use by
dladdr, but reverse lookups of function descriptors via dladdr have
not been implemented yet. some revisions may be needed in the future
once reclaim_gaps supports fdpic, so that function descriptors
allocated in reclaimed heap space do not get detected as belonging to
the module whose gaps they were allocated in.

8 years agofix dlsym lookup of function symbols on fdpic
Rich Felker [Tue, 22 Sep 2015 22:48:21 +0000 (22:48 +0000)]
fix dlsym lookup of function symbols on fdpic

previously these resolved to the code address rather than the address
of the function descriptor.

the conditions for accepting or rejecting symbols are quite
inconsistent between the different points in the dynamic linker code
where such decisions are made. this commit attempts to be at least as
correct as anything already there, but does not improve consistency.
it has been tested to correctly avoid symbols that are merely
references to functions defined in other modules, at least in simple
usage, but at some point all symbol lookup logic should be reviewed
and refactored/unified.

8 years agohave sh/fdpic entry point set fdpic personality if needed
Rich Felker [Tue, 22 Sep 2015 20:51:59 +0000 (20:51 +0000)]
have sh/fdpic entry point set fdpic personality if needed

the entry point code supports being loaded by a loader which is not
fdpic-aware (in practice, either kernel with mmu or qemu without fdpic
support). this mostly just works, but signal handling will wrongly use
a function descriptor address as a code address if the personality is
not adjusted to fdpic.

ideally this code could be placed with sigaction so that it's not
needed except if/when a signal handler is installed. however,
personality is incorrectly maintained per-thread by the kernel, rather
than per-process, so it's necessary to correct the personality before
any threads are started. also, in order to skip the personality
syscall when an fdpic-aware loader is used, we need to be able to
detect how the program was loaded, and this information is only
readily available at the entry point.

8 years agomove calls to application init functions after crt1 entry point
Rich Felker [Tue, 22 Sep 2015 20:24:28 +0000 (20:24 +0000)]
move calls to application init functions after crt1 entry point

this change is needed to be compatible with fdpic, where some of the
main application's relocations may be performed as part of the crt1
entry point. if we call init functions before passing control, these
relocations will not yet have been performed, and the init code will
potentially make use of invalid pointers.

conceptually, no code provided by the application or third-party
libraries should run before the application entry point. the
difference is not observable to programs using the crt1 we provide,
but it could come into play if custom entry point code is used, so
it's better to be doing this right anyway.

8 years agofix breakage in non-fdpic dynamic linker init/fini processing
Rich Felker [Tue, 22 Sep 2015 20:20:39 +0000 (20:20 +0000)]
fix breakage in non-fdpic dynamic linker init/fini processing

a mistaken #ifdef instead of #if caused conversion of code addresses
to function descriptors to be performed even on non-fdpic.

8 years agofix resolving interp string address on fdpic ldd command
Rich Felker [Tue, 22 Sep 2015 19:21:57 +0000 (19:21 +0000)]
fix resolving interp string address on fdpic ldd command

8 years agoadd real fdpic loading of shared libraries
Rich Felker [Tue, 22 Sep 2015 19:12:48 +0000 (19:12 +0000)]
add real fdpic loading of shared libraries

previously, the normal ELF library loading code was used even for
fdpic, so only the kernel-loaded dynamic linker and main app could
benefit from separate placement of segments and shared text.

8 years agotry to suppress linking libc.so if there are undefined symbols
Rich Felker [Tue, 22 Sep 2015 15:45:40 +0000 (15:45 +0000)]
try to suppress linking libc.so if there are undefined symbols

this is always an error and usually results from failure to find/link
the compiler runtime library, but it could also result from
implementation errors in libc, using functions that don't (yet) exist.
either way the resulting libc.so will crash mysteriously at runtime.
the crash happens too early to produce a meaningful error, so these
crashes are very confusing to users and waste a lot of debugging time.
this commit should ensure that they do not happen.

8 years agoremove configure's suppression of enable sh/fdpic shared library build
Rich Felker [Tue, 22 Sep 2015 04:35:27 +0000 (04:35 +0000)]
remove configure's suppression of enable sh/fdpic shared library build

8 years agosize-optimize sh/fdpic dynamic entry point
Rich Felker [Tue, 22 Sep 2015 04:14:07 +0000 (04:14 +0000)]
size-optimize sh/fdpic dynamic entry point

the __fdpic_fixup code is not needed for ET_DYN executables, which
instead use reloctions, so we can omit it from the dynamic linker and
static-pie entry point and save some code size.

8 years agowork around breakage in sh/fdpic __unmapself function
Rich Felker [Tue, 22 Sep 2015 04:10:42 +0000 (04:10 +0000)]
work around breakage in sh/fdpic __unmapself function

the C implementation of __unmapself used for potentially-nommu sh
assumed CRTJMP takes a function descriptor rather than a code address;
however, the actual dynamic linker needs a code address, and so commit
7a9669e977e5f750cf72ccbd2614f8b72ce02c4c changed the definition of the
macro in reloc.h. this commit puts the old macro back in a place where
it only affects __unmapself.

this is an ugly workaround and should be cleaned up at some point, but
at least it's well isolated.

8 years agoadd general fdpic support in dynamic linker and arch support for sh
Rich Felker [Tue, 22 Sep 2015 03:54:42 +0000 (03:54 +0000)]
add general fdpic support in dynamic linker and arch support for sh

at this point not all functionality is complete. the dynamic linker
itself, and main app if it is also loaded by the kernel, take
advantage of fdpic and do not need constant displacement between
segments, but additional libraries loaded by the dynamic linker follow
normal ELF semantics for mapping still. this fully works, but does not
admit shared text on nommu.

in terms of actual functional correctness, dlsym's results are
presently incorrect for function symbols, RTLD_NEXT fails to identify
the caller correctly, and dladdr fails almost entirely.

with the dynamic linker entry point working, support for static pie is
automatically included, but linking the main application as ET_DYN
(pie) probably does not make sense for fdpic anyway. ET_EXEC is
equally relocatable but more efficient at representing relocations.

8 years agofactor symbol counting out of dladdr as its own function
Rich Felker [Mon, 21 Sep 2015 21:47:50 +0000 (21:47 +0000)]
factor symbol counting out of dladdr as its own function

the fdpic code will need to count symbols, and it may be useful
elsewhere in the future too. counting is trivial as long as sysv hash
is present, but for gnu-hash-only libraries it's complex.

the behavior of the count is changed slightly: we now include symbols
that are not accessible by the gnu hash table in the count. this may
make dladdr slightly slower. if this is a problem, dladdr can subtract
out the part that should not be accessible. unlike in the old code,
subtracting this out is easy even in the fast path where sysv hash is
available too.

8 years agosimplify dlstart code by using integer type for base address
Rich Felker [Mon, 21 Sep 2015 20:42:44 +0000 (20:42 +0000)]
simplify dlstart code by using integer type for base address

8 years agorefactor some more dynamic linker load address computations
Rich Felker [Thu, 17 Sep 2015 19:45:45 +0000 (19:45 +0000)]
refactor some more dynamic linker load address computations

these were just missed in the previous commits.

8 years agoremove some useless casts in dynamic linker
Rich Felker [Thu, 17 Sep 2015 19:21:55 +0000 (19:21 +0000)]
remove some useless casts in dynamic linker

8 years agoadd fdpic structs and reloc types for dynamic linking
Rich Felker [Thu, 17 Sep 2015 18:51:57 +0000 (18:51 +0000)]
add fdpic structs and reloc types for dynamic linking

8 years agofurther refactoring of dynamic linker load address computations
Rich Felker [Thu, 17 Sep 2015 17:50:43 +0000 (17:50 +0000)]
further refactoring of dynamic linker load address computations

these are in do_relocs. the first one was omitted in commit
301335a80b85f12c018e4acf1a2c28615e119f8d because it slightly changes
code (using dso->base rather than cached local var base) and would
have prevented easy verification. the other was an oversight.

8 years agobegin refactoring load address computations in dynamic linker
Rich Felker [Thu, 17 Sep 2015 17:18:09 +0000 (17:18 +0000)]
begin refactoring load address computations in dynamic linker

for ordinary ELF with fixed segment displacements, load address
computation is simply adding the base load address. but for FDPIC,
each segment has its own load address, and virtual addresses need to
be adjusted according to the segment they fall in. abstracting this
computation is the first step to making the dynamic linker ready for
FDPIC.

for this first commit, a macro is used rather than a function in order
to facilitate correctness checking. I have verified that the generated
code does not change on my i386 build.

8 years agoremove old dlstart stage-2 symbolic lookup code; add new generic
Rich Felker [Thu, 17 Sep 2015 08:05:34 +0000 (08:05 +0000)]
remove old dlstart stage-2 symbolic lookup code; add new generic

this new generic version of the stage-2 function lookup should work
for any arch where static data is accessible via got-relative or
pc-relative addressing, using approximately the technique described in
the log message for commit 2907afb8dbd4c1d34825c3c9bd2b41564baca210.

since all the mips-like archs that need got slots fo access static
data have already transitioned to the new stage chaining scheme, the
old dynamic symbol lookup code is now removed.

aarch64, arm, and sh have not yet transitioned; with this commit, they
are now using the new generic code.

8 years agonew dlstart stage-2 chaining for x86_64 and x32
Rich Felker [Thu, 17 Sep 2015 07:28:44 +0000 (07:28 +0000)]
new dlstart stage-2 chaining for x86_64 and x32

8 years agonew dlstart stage-2 chaining for powerpc
Rich Felker [Thu, 17 Sep 2015 07:20:58 +0000 (07:20 +0000)]
new dlstart stage-2 chaining for powerpc

8 years agonew dlstart stage-2 chaining for or1k
Rich Felker [Thu, 17 Sep 2015 07:20:51 +0000 (07:20 +0000)]
new dlstart stage-2 chaining for or1k

8 years agonew dlstart stage-2 chaining for mips
Rich Felker [Thu, 17 Sep 2015 07:20:43 +0000 (07:20 +0000)]
new dlstart stage-2 chaining for mips

8 years agonew dlstart stage-2 chaining for microblaze
Rich Felker [Thu, 17 Sep 2015 07:20:36 +0000 (07:20 +0000)]
new dlstart stage-2 chaining for microblaze

8 years agointroduce new symbol-lookup-free rcrt1/dlstart stage chaining
Rich Felker [Thu, 17 Sep 2015 06:30:55 +0000 (06:30 +0000)]
introduce new symbol-lookup-free rcrt1/dlstart stage chaining

previously, the call into stage 2 was made by looking up the symbol
name "__dls2" (which was chosen short to be easy to look up) from the
dynamic symbol table. this was no problem for the dynamic linker,
since it always exports all its symbols. in the case of the static pie
entry point, however, the dynamic symbol table does not contain the
necessary symbol unless -rdynamic/-E was used when linking. this
linking requirement is a major obstacle both to practical use of
static-pie as a nommu binary format (since it greatly enlarges the
file) and to upstream toolchain support for static-pie (adding -E to
default linking specs is not reasonable).

this patch replaces the runtime symbolic lookup with a link-time
lookup via an inline asm fragment, which reloc.h is responsible for
providing. in this initial commit, the asm is provided only for i386,
and the old lookup code is left in place as a fallback for archs that
have not yet transitioned.

modifying crt_arch.h to pass the stage-2 function pointer as an
argument was considered as an alternative, but such an approach would
not be compatible with fdpic, where it's impossible to compute
function pointers without already having performed relocations. it was
also deemed desirable to keep crt_arch.h as simple/minimal as
possible.

in principle, archs with pc-relative or got-relative addressing of
static variables could instead load the stage-2 function pointer from
a static volatile object. that does not work for fdpic, and is not
safe against reordering on mips-like archs that use got slots even for
static functions, but it's a valid on i386 and many others, and could
provide a reasonable default implementation in the future.

8 years agoremove attribute((const)) from pthread_self and errno location decls
Rich Felker [Thu, 17 Sep 2015 04:45:01 +0000 (04:45 +0000)]
remove attribute((const)) from pthread_self and errno location decls

this attribute was applied to pthread_self and the functions providing
the locations for errno and h_errno as an optimization; however, it is
subtly incorrect. as specified, it means the return value will always
be the same, which is not true; it varies per-thread.

this attribute also implies that the function does not depend on any
state, and that calls to it can safely be reordered across any other
code. however such reordering is unsafe for these functions: they
break when reordered before initialization of the thread pointer. such
breakage was actually observed when compiled by libfirm/cparser.

to some extent the reordering problem could be solved with strong
compiler barriers between the stages of early startup code, but the
specified meaning of of attribute((const)) is sufficiently strong that
a compiler would theoretically be justified inserting gratuitous calls
to attribute((const)) const functions at random locations (e.g. to
save the value in static storage for later use).

this reverts commit cbf35978a9870fb1f5c73a852c986d4fcca6c2d4.

8 years agoadd format argument attributes to gettext function prototypes
Khem Raj [Sun, 13 Sep 2015 06:29:04 +0000 (06:29 +0000)]
add format argument attributes to gettext function prototypes

their absence completely breaks format string warnings in programs
with gettext message translations: -Wformat gives no results, and
-Wformat-nonliteral produces spurious warnings.

with gcc, the problem manifests only in standards-conforming profiles;
otherwise gcc sets these attributes by default for the gettext family.
with clang, the problem always manifests; clang has no such defaults.

8 years agoreindent powerpc's bits/termios.h to be consistent with other archs
Felix Janda [Sun, 13 Sep 2015 21:13:00 +0000 (23:13 +0200)]
reindent powerpc's bits/termios.h to be consistent with other archs

8 years agofix namespace violations in aarch64/bits/termios.h
Felix Janda [Sun, 13 Sep 2015 21:12:48 +0000 (23:12 +0200)]
fix namespace violations in aarch64/bits/termios.h

in analogy with commit a627eb35864d5c29a3c3300dfe83745ab1e7a00f

8 years agoadd sh fdpic subarch variants
Rich Felker [Sat, 12 Sep 2015 03:22:19 +0000 (03:22 +0000)]
add sh fdpic subarch variants

with this commit it should be possible to produce a working
static-linked fdpic libc and application binaries for sh.

the changes in reloc.h are largely unused at this point since dynamic
linking is not supported, but the CRTJMP macro is used one place
outside of dynamic linking, in __unmapself.

8 years agoadd fdpic version of entry point code for sh
Rich Felker [Sat, 12 Sep 2015 03:18:08 +0000 (03:18 +0000)]
add fdpic version of entry point code for sh

this version of the entry point is only suitable for static linking in
ET_EXEC form. neither dynamic linking nor pie is supported yet. at
some point in the future the fdpic and non-fdpic versions of this code
may be unified but for now it's easiest to work with them separately.

8 years agoprovide arch-generic fdpic self-relocation code for crt1 to use
Rich Felker [Sat, 12 Sep 2015 03:10:44 +0000 (03:10 +0000)]
provide arch-generic fdpic self-relocation code for crt1 to use

this file is intended to be included by crt_arch.h on fdpic-based
targets and needs to be called from the entry point asm.

8 years agomake sh clone asm fdpic-compatible
Rich Felker [Sat, 12 Sep 2015 02:55:28 +0000 (02:55 +0000)]
make sh clone asm fdpic-compatible

clone calls back to a function pointer provided by the caller, which
will actually be a pointer to a function descriptor on fdpic. the
obvious solution is to have a separate version of clone for fdpic, but
I have taken a simpler approach to go around the problem. instead of
calling the pointed-to function from asm, a direct call is made to an
internal C function which then calls the pointed-to function. this
lets the C compiler generate the appropriate calling convention for an
indirect call with no need for ABI-specific assembly.

8 years agomake sh crti/crtn init/fini fragments setup proper stack frame
Rich Felker [Sat, 12 Sep 2015 02:50:28 +0000 (02:50 +0000)]
make sh crti/crtn init/fini fragments setup proper stack frame

for fdpic support is is essential that the got pointer be saved at a
known, ABI-dictated offset from the frame pointer, since there is no
way to recover it once it's lost.

8 years agoadd sh relocation types needed for fdpic to elf.h
Rich Felker [Sat, 12 Sep 2015 02:49:02 +0000 (02:49 +0000)]
add sh relocation types needed for fdpic to elf.h

8 years agofix uninitialized scopeid in lookups from hosts file and ip literals
Timo Teräs [Fri, 11 Sep 2015 06:15:06 +0000 (06:15 +0000)]
fix uninitialized scopeid in lookups from hosts file and ip literals

8 years agofix missing earlyclobber flag in i386 a_ctz_64 asm
Rich Felker [Wed, 9 Sep 2015 07:18:28 +0000 (07:18 +0000)]
fix missing earlyclobber flag in i386 a_ctz_64 asm

this error was only found by reading the code, but it seems to have
been causing gcc to produce wrong code in malloc: the same register
was used for the output and the high word of the input. in principle
this could have caused an infinite loop searching for an available
bin, but in practice most x86 models seem to implement the "undefined"
result of the bsf instruction as "unchanged".

8 years agoremove unused (and invalid) C version of sigsetjmp
Rich Felker [Wed, 9 Sep 2015 06:59:45 +0000 (06:59 +0000)]
remove unused (and invalid) C version of sigsetjmp

originally, the comment in this code was correct and it would likely
work if the compiler generated a tail call to setjmp. however, commit
583e55122e767b1586286a0d9c35e2a4027998ab redesigned sigsetjmp and
siglongjmp such that the old C implementation (which was not intended
to be used) is not even conceptually correct. remove it in the
interest of avoiding confusion when porting to new archs.

8 years agofix breakage in nl_langinfo from previous commit
Rich Felker [Wed, 9 Sep 2015 06:04:42 +0000 (06:04 +0000)]
fix breakage in nl_langinfo from previous commit

8 years agomake nl_langinfo(CODESET) always return "UTF-8"
Rich Felker [Wed, 9 Sep 2015 05:13:33 +0000 (05:13 +0000)]
make nl_langinfo(CODESET) always return "UTF-8"

this restores the original behavior prior to the addition of the
byte-based C locale and fixes what is effectively a regression in
musl's property of always providing working UTF-8 support.

commit 1507ebf837334e9e07cfab1ca1c2e88449069a80 introduced the codeset
name "UTF-8-CODE-UNITS" for the byte-based C locale to represent that
the semantic content is UTF-8 but that it is being processed as code
units (bytes) rather than whole multibyte characters. however, many
programs assume that the codeset name is usable with iconv and/or
comes from a set of standard/widely-used names known to the
application. such programs are likely to produce warnings or errors,
run with reduced functionality, or mangle character data when run
explicitly in the C locale.

the standard places basically no requirements for the string returned
by nl_langinfo(CODESET) and how it interacts with other interfaces, so
returning "UTF-8" is permissible. moreover, it seems like the right
thing to do, since the identity of the character encoding as "UTF-8"
is independent of whether it is being processed as bytes of characters
by the standard library functions.

8 years agofix fclose of permanent (stdin/out/err) streams
Rich Felker [Wed, 9 Sep 2015 04:31:07 +0000 (04:31 +0000)]
fix fclose of permanent (stdin/out/err) streams

this fixes a bug reported by Nuno Gonçalves. previously, calling
fclose on stdin or stdout resulted in deadlock at exit time, since
__stdio_exit attempts to lock these streams to flush/seek them, and
has no easy way of knowing that they were closed.

conceptually, leaving a FILE stream locked on fclose is valid since,
in the abstract machine, it ceases to exist. but to satisfy the
implementation-internal assumption in __stdio_exit that it can access
these streams unconditionally, we need to unlock them.

it's also necessary that fclose leaves permanent streams in a state
where __stdio_exit will not attempt any further operations on them.
fortunately, the call to fflush already yields this property.

8 years agoimplement arm eabi mem* functions
Timo Teräs [Sun, 30 Aug 2015 15:58:26 +0000 (18:58 +0300)]
implement arm eabi mem* functions

these functions are part of the ARM EABI, meaning compilers may
generate references to them. known versions of gcc do not use them,
but llvm does. they are not provided by libgcc, and the de facto
standard seems to be that libc provides them.

8 years agoremove use of buggy .SECONDARY special target in makefile
Rich Felker [Sun, 30 Aug 2015 18:44:58 +0000 (18:44 +0000)]
remove use of buggy .SECONDARY special target in makefile

this functionality is affected by GNU make bug #30653, "intermediate
files incorrectly pruned in parallel builds". on affected versions of
make, parallel builds attempt to compile source files before
alltypes.h is generated.

as noted with commit a91ebdcfac6804714a1fe39f4375e2b4ebab085b, which
added the use of .SECONDARY, suppression of removal of "intermediate"
files does not seem to be needed at present. if it is needed in the
future, it should be achievable by explicitly mentioning their names
as targets or prerequisites.

8 years agorelease 1.1.11
Rich Felker [Sun, 30 Aug 2015 04:15:56 +0000 (04:15 +0000)]
release 1.1.11

8 years agofix makefile suppression of intermediate file removal
Rich Felker [Thu, 27 Aug 2015 19:58:20 +0000 (19:58 +0000)]
fix makefile suppression of intermediate file removal

at one point, GNU make was removing crt/*.o after producing the copies
in lib/ due to an arcane misfeature for handling "intermediate" files.
the circumstances that caused this are no longer present in our
makefile, but the previous workaround using .PRECIOUS was wrong and
could result in corrupt/partial files being left behind during an
interrupted build. using .SECONDARY is the correct, documented fix
that will prevent deletion of "intermediate" files from ever
resurfacing.

8 years agoBuild process uses script to add CFI directives to x86 asm
Alex Dowad [Fri, 10 Jul 2015 13:03:24 +0000 (15:03 +0200)]
Build process uses script to add CFI directives to x86 asm

Some functions implemented in asm need to use EBP for purposes other
than acting as a frame pointer. (Notably, it is used for the 6th
argument to syscalls with 6 arguments.) Without frame pointers, GDB
can only show backtraces if it gets CFI information from a
.debug_frame or .eh_frame ELF section.

Rather than littering our asm with ugly .cfi directives, use an awk
script to insert them in the right places during the build process, so
GDB can keep track of where the current stack frame is relative to the
stack pointer. This means GDB can produce beautiful stack traces at
any given point when single-stepping through asm functions.

Additionally, when registers are saved on the stack and later
overwritten, emit ..cfi directives so GDB will know where they were
saved relative to the stack pointer. This way, when you look back up
the stack from within an asm function, you can still reliably print
the values of local variables in the caller.

If this awk script were to understand every possible wild and crazy
contortion that an asm programmer can do with the stack and registers,
and always emit the exact ..cfi directives needed for GDB to know what
the register values were in the preceding stack frame, it would
necessarily be as complex as a full x86 emulator. That way lies
madness.

Hence, we assume that the stack pointer will _only_ ever be adjusted
using push/pop or else add/sub with a constant. We do not attempt to
detect every possible way that a register value could be saved for
later use, just the simple and common ways.

Thanks to Szabolcs Nagy for suggesting numerous improvements to this
code.

8 years agogetsubopt: don't include leading = in value string
Steven Barth [Tue, 18 Aug 2015 09:06:04 +0000 (11:06 +0200)]
getsubopt: don't include leading = in value string

getsubopt incorrectly returns the delimiting = in the value string,
this patch fixes it by increasing the pointer position by one.

Signed-off-by: Steven Barth <cyrus@openwrt.org>
8 years agomitigate performance regression in libc-internal locks on x86_64
Rich Felker [Sun, 16 Aug 2015 18:15:18 +0000 (18:15 +0000)]
mitigate performance regression in libc-internal locks on x86_64

commit 3c43c0761e1725fd5f89a9c028cbf43250abb913 fixed missing
synchronization in the atomic store operation for i386 and x86_64, but
opted to use mfence for the barrier on x86_64 where it's always
available. however, in practice mfence is significantly slower than
the barrier approach used on i386 (a nop-like lock orl operation).
this commit changes x86_64 (and x32) to use the faster barrier.

8 years agomatch historical behavior for tm_gmtoff member of struct tm
Natanael Copa [Thu, 13 Aug 2015 15:28:39 +0000 (17:28 +0200)]
match historical behavior for tm_gmtoff member of struct tm

tm_gmtoff is a nonstandard field, but on historical systems which have
this field, it stores the offset of the local time zone from GMT or
UTC. this is the opposite of the POSIX extern long timezone object and
the offsets used in POSIX-form TZ strings, which represent the offset
from local time to UTC. previously we were storing these negated
offsets in tm_gmtoff too.

programs which only used this field indirectly via strftime were not
affected since strftime performed the negation for presentation.
however, some programs and libraries accesse tm_gmtoff directly and
were obtaining negated time zone offsets.

8 years agoaarch64: fix 64-bit syscall argument passing
Szabolcs Nagy [Tue, 11 Aug 2015 20:55:18 +0000 (20:55 +0000)]
aarch64: fix 64-bit syscall argument passing

On 32bit systems long long arguments are passed in a special way
to some syscalls; this accidentally got copied to the AArch64 port.

The following interfaces were broken: fallocate, fanotify, ftruncate,
posix_fadvise, posix_fallocate, pread, pwrite, readahead,
sync_file_range, truncate.

8 years agofix failure of tempnam to null-terminate result
Rich Felker [Sun, 9 Aug 2015 22:51:09 +0000 (22:51 +0000)]
fix failure of tempnam to null-terminate result

tempnam uses an uninitialized buffer which is filled using memcpy and
__randname. It is therefore necessary to explicitly null-terminate it.

based on patch by Felix Janda.

8 years agomitigate blow-up of heap size under malloc/free contention
Rich Felker [Fri, 7 Aug 2015 19:19:49 +0000 (19:19 +0000)]
mitigate blow-up of heap size under malloc/free contention

during calls to free, any free chunks adjacent to the chunk being
freed are momentarily held in allocated state for the purpose of
merging, possibly leaving little or no available free memory for other
threads to allocate. under this condition, other threads will attempt
to expand the heap rather than waiting to use memory that will soon be
available. the race window where this happens is normally very small,
but became huge when free chooses to use madvise to release unused
physical memory, causing unbounded heap size growth.

this patch drastically shrinks the race window for unwanted heap
expansion by performing madvise with the bin lock held and marking the
bin non-empty in the binmask before making the expensive madvise
syscall. testing by Timo Teräs has shown this approach to be a
suitable mitigation.

more invasive changes to the synchronization between malloc and free
would be needed to completely eliminate the problem. it's not clear
whether such changes would improve or worsen typical-case performance,
or whether this would be a worthwhile direction to take malloc
development.

8 years agofix missing synchronization in atomic store on i386 and x86_64
Rich Felker [Tue, 28 Jul 2015 18:40:18 +0000 (18:40 +0000)]
fix missing synchronization in atomic store on i386 and x86_64

despite being strongly ordered, the x86 memory model does not preclude
reordering of loads across earlier stores. while a plain store
suffices as a release barrier, we actually need a full barrier, since
users of a_store subsequently load a waiter count to determine whether
to issue a futex wait, and using a stale count will result in soft
(fail-to-wake) deadlocks. these deadlocks were observed in malloc and
possible with stdio locks and other libc-internal locking.

on i386, an atomic operation on the caller's stack is used as the
barrier rather than performing the store itself using xchg; this
avoids the need to read the cache line on which the store is being
performed. mfence is used on x86_64 where it's always available, and
could be used on i386 with the appropriate cpu model checks if it's
shown to perform better.

8 years agofix undefined left-shift of negative values in utf-8 state table
Rich Felker [Sat, 25 Jul 2015 03:15:45 +0000 (03:15 +0000)]
fix undefined left-shift of negative values in utf-8 state table