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.
prepare pthread_create.c for cherry-picking from master

this change is harmless and allows commit
a6adb2bcd8145353943377d6119c1d7a4242bae1 to apply without conflicts.
fix missing argument to syscall in fanotify_mark

(cherry picked from commit 4e5c7a2176773c9a1564c6603240337b3ad6b496)
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)
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)
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)
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)
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)
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)
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)
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)
make dynamic linker accept colon as a separator for LD_PRELOAD

(cherry picked from commit 349381aa8c0fc385e54e1068dd5f2b27af55cd12)
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)
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)
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)
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)
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)
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)
remove cruft from microblaze atomic.h

(cherry picked from commit 94252dd341a7c72b31db2614abdc74142ad80562)
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)