ARM: Don't define _SYS_AUXV_H in sysdep.h

sysdep.h was defining _SYS_AUXV_H in order to avoid an include guard check
in hwcap.h. Unfortunately it didn't undefine it so it could leak out into
code and caused a build failure with -Wimplicit-function-declaration
building tst-auxv on ARM.

ChangeLog:

2014-09-23  Will Newton  <will.newton@linaro.org>

	* sysdeps/unix/sysv/linux/arm/bits/hwcap.h: Check for
	_LINUX_ARM_SYSDEP_H include guard too.
	* sysdeps/unix/sysv/linux/arm/sysdep.h (_SYS_AUXV_H): Remove
	define.
Move some setrlimit definitions to syscalls.list (bug 14138).

Bug 14138 is followup cleanup after removal of support for old Linux
kernel versions: moving syscalls to syscalls.list where the only
reason for using C definitions was kernel version conditionals that
are no longer present.

This patch deals with the case of setrlimit
(sysdeps/unix/sysv/linux/i386/setrlimit.c, included by various other
architectures).  Where needed (where there is also a compat symbol for
setrlimit@GLIBC_2.0), new syscalls.list entries are added.  Where not
needed (where there is no such compat symbol and the minimum symbol
version for libc is 2.2 or later), no such entries are added as that
in sysdeps/unix/syscalls.list will suffice.  Thus arm and sh need no
such entries, while m68k and powerpc need entries only in a
subdirectory syscalls.list file rather than for all configurations
that previously used setrlimit.c.

(setrlimit@@GLIBC_2.2 and setrlimit@GLIBC_2.0 are now semantically
identical - the new symbol version was about a change of types from
signed to unsigned and the former compatibility code for dealing with
large unsigned arguments on old kernels is no longer needed or
present, having been removed with support for pre-2.4 kernels.
However, making the two versions into aliases doesn't work at present:
the case of having both default and non-default symbol versions on the
same syscalls.list line results in a compat_symbol call in code built
for static libc, which doesn't compile.  I don't suppose it would be
hard to generate SHARED conditionals from make-syscalls.sh to fix
this, but in any case this patch doesn't make things any worse, as the
functions weren't aliases before the patch either.)

Tested for x86, and ran ABI tests for ARM as an example of an
architecture where the setrlimit.c file was just removed without
adding syscalls.list entries.

	[BZ #14138]
	* sysdeps/unix/sysv/linux/arm/setrlimit.c: Remove file.
	* sysdeps/unix/sysv/linux/i386/setrlimit.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setrlimit.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/setrlimit.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setrlimit.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setrlimit.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/syscalls.list (setrlimit): Add
	syscall entry for GLIBC_2.2 symbol version.
	* sysdeps/unix/sysv/linux/m68k/m680x0/syscalls.list (setrlimit):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list
	(setrlimit): Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list (setrlimit):
	Likewise.
Clean up gnu/lib-names.h generation (bug 14171).

This patch eliminates the mixture of SONAME information in
shlib-versions files and SONAME information used to generate
gnu/lib-names.h in makefiles, with the information in the makefiles
being removed so all this information comes from the shlib-versions
files.

So that gnu/lib-names.h supports multiple ABIs, it is changed to be
generated on the same basis as gnu/stubs.h: when there are multiple
ABIs, gnu/lib-names.h is a wrapper header (the same header installed
whatever ABI is being built) and separate headers such as
gnu/lib-names-64.h contain the substantive contents (only one such
header being installed by any glibc build).

The rules for building gnu/lib-names.h were moved from Makeconfig to
Makerules because they need to come after sysdeps makefiles are
included (now that "ifndef abi-variants" is a toplevel conditional on
the rules rather than $(abi-variants) being evaluated later inside the
commands for a rule).

Tested for x86_64 and x86 that the installed shared libraries are
unchanged by this patch, and examined the installed gnu/lib-names*.h
headers by hand.  Also tested the case of a single ABI (where there is
just a single header installed, again like stubs.h) by hacking
abi-variants to empty for x86_64.

	[BZ #14171]
	* Makeconfig [$(build-shared) = yes]
	($(common-objpfx)soversions.mk): Don't handle SONAMEs specified in
	makefiles.
	[$(build-shared) = yes && $(soversions.mk-done) = t]
	($(common-objpfx)gnu/lib-names.h): Remove rule.
	[$(build-shared) = yes && $(soversions.mk-done) = t]
	($(common-objpfx)gnu/lib-names.stmp): Likewise.  Split and moved
	to Makerules.
	[$(build-shared) = yes && $(soversions.mk-done) = t]
	(before-compile): Don't append $(common-objpfx)gnu/lib-names.h
	here.
	[$(build-shared) = yes && $(soversions.mk-done) = t]
	(common-generated): Don't append gnu/lib-names.h and
	gnu/lib-names.stmp here.
	* Makerules [$(build-shared) = yes && $(soversions.mk-done) = t]
	(lib-names-h-abi): New variable.
	[$(build-shared) = yes && $(soversions.mk-done) = t]
	(lib-names-stmp-abi): Likewise.
	[$(build-shared) = yes && $(soversions.mk-done) = t &&
	abi-variants] (before-compile): Append
	$(common-objpfx)$(lib-names-h-abi).
	[$(build-shared) = yes && $(soversions.mk-done) = t &&
	abi-variants] (common-generated): Append gnu/lib-names.h.
	[$(build-shared) = yes && $(soversions.mk-done) = t &&
	abi-variants] (install-others-nosubdir): Depend on
	$(inst_includedir)/$(lib-names-h-abi).
	[$(build-shared) = yes && $(soversions.mk-done) = t &&
	abi-variants] ($(common-objpfx)gnu/lib-names.h): New rule.
	[$(build-shared) = yes && $(soversions.mk-done) = t]
	($(common-objpfx)$(lib-names-h-abi)): New rule.
	[$(build-shared) = yes && $(soversions.mk-done) = t]
	($(common-objpfx)$(lib-names-stmp-abi)): Likewise.
	[$(build-shared) = yes && $(soversions.mk-done) = t]
	(common-generated): Append $(lib-names-h-abi) and
	$(lib-names-stmp-abi).
	* scripts/lib-names.awk: Do not handle multi being set.
	* sysdeps/unix/sysv/linux/aarch64/Makefile (abi-lp64-ld-soname):
	Remove variable.
	(abi-lp64_be-ld-soname): Likewise.
	* sysdeps/unix/sysv/linux/arm/Makefile (abi-soft-ld-soname):
	Likewise.
	(abi-hard-ld-soname): Likewise.
	* sysdeps/unix/sysv/linux/i386/shlib-versions: New file.
	* sysdeps/unix/sysv/linux/mips/Makefile (abi-o32_soft-ld-soname):
	Remove variable.
	(abi-o32_hard-ld-soname): Likewise.
	(abi-o32_soft_2008-ld-soname): Likewise.
	(abi-o32_hard_2008-ld-soname): Likewise.
	(abi-n32_soft-ld-soname): Likewise.
	(abi-n32_hard-ld-soname): Likewise.
	(abi-n32_soft_2008-ld-soname): Likewise.
	(abi-n32_hard_2008-ld-soname): Likewise.
	(abi-n64_soft-ld-soname): Likewise.
	(abi-n64_hard-ld-soname): Likewise.
	(abi-n64_soft_2008-ld-soname): Likewise.
	(abi-n64_hard_2008-ld-soname): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/Makefile (abi-64-v1-ld-soname):
	Likewise.
	(abi-64-v2-ld-soname): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/shlib-versions: Add
	ld.so entries.
	* sysdeps/unix/sysv/linux/s390/Makefile (abi-64-ld-soname): Remove
	variable.
	* sysdeps/unix/sysv/linux/s390/s390-64/shlib-versions: Add ld.so
	entry.
	* sysdeps/unix/sysv/linux/x86/Makefile (abi-32-ld-soname): Remove
	variable.
	(abi-64-ld-soname): Likewise.
	(abi-x32-ld-soname): Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/shlib-versions: Add ld.so
	entry.
	* sysdeps/unix/sysv/linux/x86_64/x32/shlib-versions: Likewise.
Remove shlib-versions entries redundant with DEFAULT entries.

When a shlib-versions file has a DEFAULT line, it's not necessary to
specify the same default minimum symbol version on the lines for
individual libraries.  If those lines otherwise duplicate the default
SONAME for the library in question, they can be removed completely.

This patch makes such cleanups: version entries for ld.so are removed
(leaving just the definition of the architecture-specific dynamic
linker name) and entries for libpthread are removed completely (since
the default is libpthread.so.0).

Tested for x86_64 that the installed shared libraries are unchanged by
this patch.

There are various architectures (hppa, ia64, mips, sh, sparc64) that
define minimum symbol versions (or in the case of mips, omission of
symbol versions) only for particular libraries without a DEFAULT line.
None of these are equivalent to something simpler with a DEFAULT line
because all have some other libraries, not explicitly mentioned, with
symbol versions that would be omitted were such a line used.  In the
mips case I'm pretty sure it was a mistake not to omit the 2.1 symbols
for libthread_db; for the others I don't know if it was a mistake or
deliberate that some symbols in various libraries have 2.0 or 2.1
versions despite other libraries having a 2.2 minimum.

This concludes the shlib-versions cleanups I'm aware of.

	* sysdeps/unix/sysv/linux/powerpc/powerpc64/shlib-versions: Do not
	specify symbol version for ld.so.  Do not include entry for
	libpthread.
	* sysdeps/unix/sysv/linux/s390/s390-64/shlib-versions: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/shlib-versions: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/shlib-versions: Likewise.
Use inline syscalls for non-cancellable versions

This patch uses inline calls (through INLINE_SYSCALL macro) to define
the non-cancellable functions macros to avoid use of the
syscall_nocancel entrypoint.
Function declaration cleanup

This patch changes the some function declaration from K&R style to
default ISO C.
nptl: Fix testcases for new pthread cancellation mechanism

With upcoming fix for BZ#12683, pthread cancellation does not act for:

1. If syscall is blocked but with some side effects already having taken
   place (e.g. a partial read or write)
2. After the syscall has returned.

It is because program need to act on such cases (for instance, to avoid
leak of allocated resources our handling partial read/write).

This patches fixes the NPTL testcase that assumes the old behavior and
also remove the tst-cancel-wrappers.sh test (which checks for symbols
that does not exist anymore).
nptl: x86_64: remove assembly implementation

This patch removes the x86_64 assembly implementation for
pthread_cond_timedwait, pthread_cond_wait, sem_timedwait, and sem_wait
for upcoming BZ#12683 fix.  The fix require that cancellable futex calls
to be called through __syscall_cancel.

Although it not strictly require, the remove of the x86_64 specific
implementation follows the rationale:

1. The adjustments required to this fix is extensive (parameters
   save, functions calls, etc.) and there is little gain in keep an
   alternate implementation for x86_64 in term of maintanability.
2. There is no pthread_cond benchmark that shows these implementations
   are more 'optimized' that what current compilers can produce using
   generic C code.
3. The changes required also can change the exact gains this optimized is
   intended to provide.
nptl: Fix Race conditions in pthread cancellation

This patches fixes some race conditions in NPTL cancellation code by
redefining how cancellable syscalls are defined and handled.  Current
approach is to enable asynchronous cancellation prior to making the syscall
and restore the previous cancellation type once the syscall returns.

As decribed in BZ#12683, this approach shows 2 important problems:

1. Cancellation can act after the syscall has returned from kernel, but
   before userspace saves the return value.  It might result in a resource
   leak if the syscall allocated a resource or a side effect (partial
   read/write), and there is no way to program handle it with cancellation
   handlers.

2. If a signal is handled while the thread is blocked at a cancellable
   syscall, the entire signal handler runs with asynchronous cancellation
   enabled.  This can lead to issues if the signal handler call functions
   which are async-signal-safe but not async-cancel-safe.

For cancellation to work correctly, there are 5 points at which the
cancellation signal could arrive:

1. Before the final testcancel before the syscall is made.
2. Between the testcancel and the syscall.
3. While the syscall is blocked and no side effects have yet taken place.
4. While the syscall is blocked but with some side effects already having
   taken place (e.g. a partial read or write).
5. After the syscall has returned.

And GLIBC wants to act on cancellation in cases 1, 2, and 3 but not in case
4 or 5.  The proposed solution follows:

* Handling case 1 is trivial: do a conditional branch based on whether the
  thread has received a cancellation request;
* Case 2 can be caught by the signal handler determining that the saved
  program counter (from the ucontext_t) is in some address range beginning
  just before the "testcancel" and ending with the syscall instruction.
* In this case, except for certain syscalls that ALWAYS fail with EINTR
  even for non-interrupting signals, the kernel will reset the program
  counter to point at the syscall instruction during signal handling, so
  that the syscall is restarted when the signal handler returns. So, from
  the signal handler's standpoint, this looks the same as case 2, and thus
  it's taken care of.
* In this case, the kernel cannot restart the syscall; when it's
  interrupted by a signal, the kernel must cause the syscall to return
  with whatever partial result it obtained (e.g. partial read or write).
* In this case, the saved program counter points just after the syscall
  instruction, so the signal handler won't act on cancellation.
  This one is equal to 4. since the program counter is past the syscall
  instruction already.

Another case that needs handling is syscalls that fail with EINTR even
when the signal handler is non-interrupting. In this case, the syscall
wrapper code can just check the cancellation flag when the errno result
is EINTR, and act on cancellation if it's set.

The proposed GLIBC adjustments are:

1. Remove the enable_asynccancel/disable_asynccancel function usage in
   syscall definition and instead make them call a common symbol that will
   check if cancellation is enabled, call the arch-specific cancellable
   entry-point and cancel the thread when required.
2. Provide a arch-specific symbol that contains global markers. These
   markers will be used in SIGCANCEL handler to check if the interruption
   has been called in a valid syscall and if the syscalls has been
   completed or not.
3. Rewrite SIGCANCEL asynchronous handler to check for both cancelling type
   and if current IP from signal handler falls between the global markes
   and act accordingly.
4. Adjust nptl/pthread_cancel.c to send an signal instead of acting
   directly. This avoid synchronization issues about updating the
   cancellation status and also focus the logic on signal handler and
   cancellation syscall code.
5. Adjust pthread code to replace CANCEL_ASYNC/CANCEL_RESET calls to
   appropriated cancelable futex syscalls.
6. Adjust libc code to replace LIBC_CANCEL_ASYNC/LIBC_CANCEL_RESET to
   appropriated cancelable syscalls.
7. Adjust 'lowlevellock.h' arch-specific implementations to provide
   cancelable futex calls (used in libpthread code).

This patch adds the proposed changes to NPTL and the changes required
for powerpc64.
nptl: x86_64: Fix Race conditions in pthread cancellation (BZ#12683)

This patches adds the x86_64 modification required for the BZ#12683 fix.
It basically removes the enable_asynccancel/disable_asynccancel function
usage on code used on x86_64, provide a arch-specific symbol that
contains global markers to be used in SIGCANCEL handler, and remove
x86_64 assembly pthread conditional and semaphore code to use default
one (that already contains the cancel call fixes).
nptl: ppc32: Fix Race conditions in pthread cancellation (BZ#12683)

This patches adds the ppc32 modification required for the BZ#12683
fix.  It basically removes the enable_asynccancel/disable_asynccancel
function usage on code used on ppc32.