Commit Graph

283 Commits

Author SHA1 Message Date
Adhemerval Zanella 1f14d0c3dd posix: Fix mmap for m68k and ia64 (BZ#21908)
Default semantic for mmap2 syscall is to take the offset in 4096-byte
units.  However m68k and ia64 mmap2 implementation take in the
configured pageunit units and for both architecture it can be
different values.

This patch fixes the m68k runtime discover of mmap2 offset unit
and adds the ia64 definition to find it at runtime.

Checked the basic tst-mmap and tst-mmap-offset on m68k (the system
is configured with 4k, so current code is already passing on this
system) and a sanity check on x86_64-linux-gnu (which should not be
affected by this change).  Sergei also states that ia64 loader now
work correctly with this change.

	Adhemerval Zanella  <adhemerval.zanella@linaro.org>
	Sergei Trofimovich  <slyfox@inbox.ru>

	* sysdeps/unix/sysv/linux/m68k/mmap_internal.h (MMAP2_PAGE_SHIFT):
	Rename to MMAP2_PAGE_UNIT.
	* sysdeps/unix/sysv/linux/mmap.c: Include mmap_internal iff
	__OFF_T_MATCHES_OFF64_T is not defined.
	* sysdeps/unix/sysv/linux/mmap_internal.h (page_unit): Declare as
	uint64_t.
	(MMAP2_PAGE_UNIT) [MMAP2_PAGE_UNIT == -1]: Redefine to page_unit.
	(page_unit) [MMAP2_PAGE_UNIT != -1]: Remove definition.
2017-08-14 10:35:14 -03:00
Florian Weimer 2449ae7b2d ld.so: Introduce struct dl_exception
This commit separates allocating and raising exceptions.  This
simplifies catching and re-raising them because it is no longer
necessary to make a temporary, on-stack copy of the exception message.
2017-08-10 16:54:57 +02:00
Joseph Myers 3d452dabd1 Fix uc_* namespace (bug 21457).
The standard members of ucontext_t, in all standard versions with that
type, are uc_link, uc_sigmask, uc_stack and uc_mcontext.

The uc_* namespace is mostly reserved for additions to the structure.
However, in XPG4.2, it's only reserved when <ucontext.h> is included,
not when <signal.h> is included, while <signal.h> is required to
define ucontext_t (but not allowed to make visible other symbols from
<ucontext.h>).  Thus, nonstandard members should avoid uc_* names.
Some already do use __uc_*, but others don't; most architectures (all
except ia64, I think) have a member uc_flags and some have additional
members beyond that.

This patch makes nonstandard members have an __ prefix unless
__USE_MISC is defined.  Members whose names indicate they are solely
padding / reserved for future use are renamed unconditionally to use
the __glibc_reserved1 naming convention.

This is part of the preparation for a revised version of the
mcontext_t / sigcontext patch to be able to eliminate all 13 of the
miscellaneous XFAILs in conform/Makefile, rather than only 11 of them
as at present (at least one further fix on top of this one will be
needed for that as well).

Tested for x86_64, and with build-many-glibcs.py.

	[BZ #21457]
	* sysdeps/arm/sys/ucontext.h (__ctx): Move undefine further down.
	(ucontext_t): Use __ctx with uc_flags.  Rename uc_filler to
	__glibc_reserved1.
	* sysdeps/generic/sys/ucontext.h (__ctx): New macro.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/i386/sys/ucontext.h (__ctx): Move undefine further down.
	(__ctxt): Likewise.
	(ucontext_t): Use __ctx with uc_flags.  Rename uc_filler to
	__glibc_reserved1.
	* sysdeps/m68k/sys/ucontext.h (__ctx): Move undefine further down.
	(ucontext_t): Use __ctx with uc_flags.  Rename uc_filler to
	__glibc_reserved1.
	* sysdeps/mips/sys/ucontext.h (__ctx): Move undefine further down.
	(ucontext_t): Use __ctx with uc_flags.  Rename uc_filler to
	__glibc_reserved1.
	* sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h (__ctx): New
	macro.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/unix/sysv/linux/alpha/sys/ucontext.h (__ctx): New macro.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/unix/sysv/linux/arm/sys/ucontext.h (__ctx): New macro.
	(ucontext_t): Use __ctx with uc_flags and uc_regspace.
	* sysdeps/unix/sysv/linux/hppa/sys/ucontext.h (__ctx): New macro.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h (__ctx): Move
	undefine further down.
	(ucontext_t): Use __ctx with uc_flags.  Rename uc_filler to
	__glibc_reserved1.
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h (__ctx): Move
	undefine further down.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h (__ctx): Move
	undefine further down.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h (ucontext_t): Use
	__ctx with uc_flags, uc_regs_ptr, uc_regs and uc_reg_space.
	Rename uc_pad to __glibc_reserved1.
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h (__ctx): Move
	undefine further down.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h (__ctx): Move undefine
	further down.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/unix/sysv/linux/sparc/sys/ucontext.h (ucontext_t): Use
	__ctx with uc_flags.
	* sysdeps/unix/sysv/linux/tile/sys/ucontext.h (__ctx): New macro.
	(ucontext_t): Use __ctx with uc_flags.
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h (ucontext_t): Use
	__ctx with uc_flags.
2017-08-09 17:51:26 +00:00
Adhemerval Zanella 9b8f8593e5 Consolidate Linux fcntl implementation
This patch consolidates the fcntl Linux syscall generation on
sysdeps/unix/sysv/linux/fcntl.c.  It basically removes all the
architecture specific implementations.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/arm/fcntl.c: Remove file.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/hppa/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/fcntl.c: Likewise.
	* sysdeps/unix/sysv/linux/fcntl.c: New file.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/fcntl.c: Refactor to
	use default implementation.
2017-06-30 15:17:26 -03:00
Joseph Myers d57cb31910 Miscellaneous sys/ucontext.h namespace fixes (bug 21457).
This patch fixes various miscellaneous namespace issues in
sys/ucontext.h headers.

Some struct tags are removed where the structs also have *_t typedef
names, while other struct tags without such names are renamed to start
__; the changes are noted in NEWS as they can affect C++ name mangling
(although there seems to be little if any external use of these types,
at least based on checking codesearch.debian.net).  For powerpc,
pointers to struct pt_regs (not defined in this header) are changed to
point to struct __ctx(pt_regs), so in the __USE_MISC case those struct
fields continue to point to the existing struct pt_regs type for
maximum compatibility, while when that's a namespace issue they point
to a struct __pt_regs type which is always an incomplete struct.

Tested for affected architectures with build-many-glibcs.py.

	[BZ #21457]
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h (fpregset_t): Remove
	struct tag.
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h (fpregset_t):
	Likewise.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h (mcontext_t):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h (pt_regs):
	Declare struct type with __ctx.
	[__WORDSIZE != 32] (mcontext_t): Use __ctx with pt_regs struct
	tag.
	(ucontext_t) [__WORDSIZE == 32]: Use __ctx with pt_regs struct tag
	and regs field name.
2017-06-28 10:33:23 +00:00
Joseph Myers 251287734e Rename struct ucontext tag (bug 21457).
The ucontext_t type has a tag struct ucontext.  As with previous such
issues for siginfo_t and stack_t, this tag is not permitted by POSIX
(is not in a reserved namespace), and so namespace conformance means
breaking C++ name mangling for this type.

In this case, the type does need to have some tag rather than just a
typedef name, because it includes a pointer to itself.  This patch
uses struct ucontext_t as the new tag, so the type is mangled as
ucontext_t (the POSIX *_t reservation applies in all namespaces, not
just the namespace of ordinary identifiers).  Another reserved name
such as struct __ucontext could of course be used.

Because of other namespace issues, this patch does not by itself fix
bug 21457 or allow any XFAILs to be removed.

Tested for x86_64, and with build-many-glibcs.py.

	[BZ #21457]
	* sysdeps/arm/sys/ucontext.h (struct ucontext): Rename to struct
	ucontext_t.
	* sysdeps/generic/sys/ucontext.h (struct ucontext): Likewise.
	* sysdeps/i386/sys/ucontext.h (struct ucontext): Likewise.
	* sysdeps/m68k/sys/ucontext.h (struct ucontext): Likewise.
	* sysdeps/mips/sys/ucontext.h (struct ucontext): Likewise.
	* sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h (struct
	ucontext): Likewise.
	* sysdeps/unix/sysv/linux/alpha/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/arm/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/hppa/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/ia64/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h (struct
	ucontext): Likewise.
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/sparc/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/tile/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h (struct ucontext):
	Likewise.
	* sysdeps/powerpc/powerpc32/backtrace.c (struct
	rt_signal_frame_32): Likewise.
	* sysdeps/powerpc/powerpc64/backtrace.c (struct signal_frame_64):
	Likewise.
	* sysdeps/unix/sysv/linux/aarch64/kernel_rt_sigframe.h (struct
	kernel_rt_sigframe): Likewise.
	* sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h (SIGCONTEXT):
	Likewise.
	* sysdeps/unix/sysv/linux/arm/register-dump.h (register_dump):
	Likewise.
	* sysdeps/unix/sysv/linux/arm/sigcontextinfo.h (SIGCONTEXT):
	Likewise.
	* sysdeps/unix/sysv/linux/hppa/profil-counter.h
	(__profil_counter): Likewise.
	* sysdeps/unix/sysv/linux/microblaze/sigcontextinfo.h
	(SIGCONTEXT): Likewise.
	* sysdeps/unix/sysv/linux/mips/kernel_rt_sigframe.h (struct
	kernel_rt_sigframe): Likewise.
	* sysdeps/unix/sysv/linux/nios2/kernel_rt_sigframe.h (struct
	kernel_rt_sigframe): Likewise.
	* sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h (SIGCONTEXT):
	Likewise.
	* sysdeps/unix/sysv/linux/sh/makecontext.S (__makecontext):
	Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/makecontext.c
	(__start_context): Likewise.
	* sysdeps/unix/sysv/linux/tile/sigcontextinfo.h (SIGCONTEXT):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/register-dump.h (register_dump):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/sigcontextinfo.h (SIGCONTEXT):
	Likewise.
2017-06-26 22:03:58 +00:00
Adhemerval Zanella 3f823e87cc Call exit directly in clone (BZ #21512)
On aarch64, alpha, arm, hppa, mips, nios2, powerpc, sh, sparc, tile,
and x86_64 the clone syscall jumps to _exit after the child execution
and the function ends the process execution by calling exit_group.
This behavior have a small issue where threads created with
CLONE_THREAD using clone syscall directly will eventually exit the
whole group altogether instead of just the thread created.  Also,
s390, microblaze, ia64, i386, and m68k differs by calling exit
syscall directly.

This patch changes all architectures to call the exit syscall
directly, as for s390, microblaze, ia64, i386, and m68k.  This do not
have change glibc internal behavior in any sort, since the only
usage of clone implementation in posix_spawn calls _exit directly
in the created child (fork uses a direct call to clone).

Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu,
powerpc-linux-gnu, powerpc64le-linux-gnu, sparc64-linux-gnu,
and sparcv9-linux-gnu.

	[BZ #21512]
	* sysdeps/unix/sysv/linux/aarch64/clone.S (__clone): Call exit
	syscall instead of jump to _exit.
	(CLONE_VM_BIT): Remove unused define.
	(CLONE_VM): Likewise.
	(CLONE_THREAD_BIT): Likewise.
	(CLONE_THREAD): Likewise.
	* sysdeps/unix/sysv/linux/alpha/clone.S (__clone): Likewise.
	(CLONE_VM): Remove unused define.
	* sysdeps/unix/sysv/linux/arm/clone.S (__clone): Likewise.
	(CLONE_VM): Remove unused define.
	(CLONE_THREAD): Likewise.
	* sysdeps/unix/sysv/linux/i386/clone.S (CLONE_VM): Likewise.
	* sysdeps/unix/sysv/linux/ia64/clone2.S (__clone2): Call exit
	syscall instead of jump to _exit.
	* sysdeps/unix/sysv/linux/hppa/clone.S (__clone): Likewise.
	* sysdeps/unix/sysv/linux/mips/clone.S (__clone): Likewise.
	(CLONE_VM): Remove unused define.
	(CLONE_THREAD): Likewise.
	* sysdeps/unix/sysv/linux/nios2/clone.S (__clone): Likewise.
	(CLONE_VM): Remove unused define.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S (__clone):
	Likewise.
	(CLONE_VM): Remove unused define.
	(CLONE_THREAD): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S (__clone):
	Likewise.
	(CLONE_VM): Remove unused define.
	(CLONE_THREAD): Likewise.
	* sysdeps/unix/sysv/linux/sh/clone.S  (__clone): Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/clone.S (__clone): Likewise.
	(CLONE_VM): Remove unused define.
	* sysdeps/unix/sysv/linux/sparc/sparc64/clone.S (__clone): Likewise.
	(CLONE_VM): Remove unused define.
	* sysdeps/unix/sysv/linux/tile/clone.S (__clone): Likewise.
	* sysdeps/unix/sysv/linux/x86_64/clone.S (__clone): Likewise.
	(CLONE_VM): Remove unused define.
	* sysdeps/unix/sysv/linux/Makefile (tests): Add tst-clone3.
	* sysdeps/unix/sysv/linux/tst-clone3.c: New file.

Fix
2017-06-26 17:52:20 -03:00
Stefan Liebler 12d2dd7060 Optimize generic spinlock code and use C11 like atomic macros.
This patch optimizes the generic spinlock code.

The type pthread_spinlock_t is a typedef to volatile int on all archs.
Passing a volatile pointer to the atomic macros which are not mapped to the
C11 atomic builtins can lead to extra stores and loads to stack if such
a macro creates a temporary variable by using "__typeof (*(mem)) tmp;".
Thus, those macros which are used by spinlock code - atomic_exchange_acquire,
atomic_load_relaxed, atomic_compare_exchange_weak - have to be adjusted.
According to the comment from  Szabolcs Nagy, the type of a cast expression is
unqualified (see http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_423.htm):
__typeof ((__typeof (*(mem)) *(mem)) tmp;
Thus from spinlock perspective the variable tmp is of type int instead of
type volatile int.  This patch adjusts those macros in include/atomic.h.
With this construct GCC >= 5 omits the extra stores and loads.

The atomic macros are replaced by the C11 like atomic macros and thus
the code is aligned to it.  The pthread_spin_unlock implementation is now
using release memory order instead of sequentially consistent memory order.
The issue with passed volatile int pointers applies to the C11 like atomic
macros as well as the ones used before.

I've added a glibc_likely hint to the first atomic exchange in
pthread_spin_lock in order to return immediately to the caller if the lock is
free.  Without the hint, there is an additional jump if the lock is free.

I've added the atomic_spin_nop macro within the loop of plain reads.
The plain reads are also realized by C11 like atomic_load_relaxed macro.

The new define ATOMIC_EXCHANGE_USES_CAS determines if the first try to acquire
the spinlock in pthread_spin_lock or pthread_spin_trylock is an exchange
or a CAS.  This is defined in atomic-machine.h for all architectures.

The define SPIN_LOCK_READS_BETWEEN_CMPXCHG is now removed.
There is no technical reason for throwing in a CAS every now and then,
and so far we have no evidence that it can improve performance.
If that would be the case, we have to adjust other spin-waiting loops
elsewhere, too!  Using a CAS loop without plain reads is not a good idea
on many targets and wasn't used by one.  Thus there is now no option to
do so.

Architectures are now using the generic spinlock automatically if they
do not provide an own implementation.  Thus the pthread_spin_lock.c files
in sysdeps folder are deleted.

ChangeLog:

	* NEWS: Mention new spinlock implementation.
	* include/atomic.h:
	(__atomic_val_bysize): Cast type to omit volatile qualifier.
	(atomic_exchange_acq): Likewise.
	(atomic_load_relaxed): Likewise.
	(ATOMIC_EXCHANGE_USES_CAS): Check definition.
	* nptl/pthread_spin_init.c (pthread_spin_init):
	Use atomic_store_relaxed.
	* nptl/pthread_spin_lock.c (pthread_spin_lock):
	Use C11-like atomic macros.
	* nptl/pthread_spin_trylock.c (pthread_spin_trylock):
	Likewise.
	* nptl/pthread_spin_unlock.c (pthread_spin_unlock):
	Use atomic_store_release.
	* sysdeps/aarch64/nptl/pthread_spin_lock.c: Delete File.
	* sysdeps/arm/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/hppa/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/m68k/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/microblaze/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/mips/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/nios2/nptl/pthread_spin_lock.c: Likewise.
	* sysdeps/aarch64/atomic-machine.h (ATOMIC_EXCHANGE_USES_CAS): Define.
	* sysdeps/alpha/atomic-machine.h: Likewise.
	* sysdeps/arm/atomic-machine.h: Likewise.
	* sysdeps/i386/atomic-machine.h: Likewise.
	* sysdeps/ia64/atomic-machine.h: Likewise.
	* sysdeps/m68k/coldfire/atomic-machine.h: Likewise.
	* sysdeps/m68k/m680x0/m68020/atomic-machine.h: Likewise.
	* sysdeps/microblaze/atomic-machine.h: Likewise.
	* sysdeps/mips/atomic-machine.h: Likewise.
	* sysdeps/powerpc/powerpc32/atomic-machine.h: Likewise.
	* sysdeps/powerpc/powerpc64/atomic-machine.h: Likewise.
	* sysdeps/s390/atomic-machine.h: Likewise.
	* sysdeps/sparc/sparc32/atomic-machine.h: Likewise.
	* sysdeps/sparc/sparc32/sparcv9/atomic-machine.h: Likewise.
	* sysdeps/sparc/sparc64/atomic-machine.h: Likewise.
	* sysdeps/tile/tilegx/atomic-machine.h: Likewise.
	* sysdeps/tile/tilepro/atomic-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/hppa/atomic-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/atomic-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/nios2/atomic-machine.h: Likewise.
	* sysdeps/unix/sysv/linux/sh/atomic-machine.h: Likewise.
	* sysdeps/x86_64/atomic-machine.h: Likewise.
2017-06-06 09:41:56 +02:00
Joseph Myers 7553131847 Fix struct sigaltstack namespace (bug 21517).
glibc defines the stack_t type with the tag struct sigaltstack.  This
is not permitted by POSIX; sigaltstack is only reserved with file
scope in the namespace of ordinary identifiers, not the tag namespace,
and in the case where stack_t is obtained from ucontext.h rather than
signal.h, it's not reserved with file scope at all.

This patch removes the tag accordingly and updates uses in glibc of
struct sigaltstack.  This is similar to the removal of the "struct
siginfo" tag a few years ago: C++ name mangling changes are an
unavoidable consequence.  A NEWS item is added to note the changed
mangling.  There is inevitably some risk of breaking builds of
anything that relies on the struct sigaltstack name (though the first
few hits I looked at from codesearch.debian.net generally seemed to
involve code that could use the stack_t name conditionally, so
depending on how they determine the conditionals they may work with
glibc not defining the struct tag anyway).

Tested for x86_64 and x86, and with build-many-glibcs.py.

	[BZ #21517]
	* bits/types/stack_t.h (stack_t): Remove struct tag.
	* sysdeps/unix/sysv/linux/bits/types/stack_t.h (stack_t):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h (stack_t):
	Likewise.
	* debug/segfault.c (install_handler): Use stack_t instead of
	struct sigaltstack.
	* hurd/hurd/signal.h (struct hurd_sigstate): Likewise.
	* hurd/trampoline.c (_hurd_setup_sighandler): Likewise.
	* include/signal.h (__sigaltstack): Likwise.
	* signal/sigaltstack.c (__sigaltstack): Likewise.
	* signal/signal.h (sigaltstack): Likewise.
	* sysdeps/mach/hurd/i386/signal-defines.sym
	(SIGALTSTACK__SS_SP__OFFSET): Likewise.
	(SIGALTSTACK__SS_SIZE__OFFSET): Likewise.
	(SIGALTSTACK__SS_FLAGS__OFFSET): Likewise.
	* sysdeps/mach/hurd/sigaltstack.c (__sigaltstack): Likewise.
	* sysdeps/mach/hurd/sigstack.c (sigstack): Likewise.
	* sysdeps/unix/sysv/linux/alpha/sys/procfs.h (struct
	elf_prstatus): Likewise.
	* sysdeps/unix/sysv/linux/hppa/____longjmp_chk.c (CHECK_SP):
	Likewise.
	* sysdeps/unix/sysv/linux/ia64/sys/procfs.h (struct elf_prstatus):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/____longjmp_chk.c (CHECK_SP):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sys/procfs.h (struct
	elf_prstatus): Likewise.
	* sysdeps/unix/sysv/linux/sh/sys/procfs.h (struct elf_prstatus):
	Likewise.
	* sysdeps/unix/sysv/linux/sys/procfs.h (struct elf_prstatus):
	Likewise.
2017-06-05 10:17:46 +00:00
Joseph Myers 139904b7e4 Fix more namespace issues in sys/ucontext.h (bug 21457).
Continuing the fixes for namespace issues in sys/ucontext.h, this
patch moves various symbols into the implementation namespace in the
absence of __USE_MISC.  As with previous changes, it is nonexhaustive,
just covering more straightforward cases.

Structure fields are generally changed to have a prefix __ in the
absence of __USE_MISC, via a macro __ctx (used without a space before
the open parenthesis, since the result is a single identifier).
Various macros such as NGREG also have leading __ added.  No changes
are made to structure tags (and thus to C++ name mangling), except
that in the (unused) file sysdeps/i386/sys/ucontext.h, structures
defined inside other structures as the type for a field have their
tags removed in the non-__USE_MISC case (those structure tags would
not in any case have been visible in C++, because in C++ the scope of
such a tag is limited to the containing structure).  No changes are
made to the contents of bits/sigcontext.h, or to whether it is
included.  Because of remaining namespace issues, this patch does not
yet fix the bug or allow any XFAILs to be removed.

Tested for x86_64 and x86, and with build-many-glibcs.py.

	[BZ #21457]
	* sysdeps/arm/sys/ucontext.h (NGREG): Rename to __NGREG and define
	NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(mcontext_t): Use __ctx in defining fields.
	* sysdeps/i386/sys/ucontext.h (NGREG): Rename to __NGREG and
	define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(__ctxt): Likewise.
	(fpregset_t): Use __ctx and __ctxt in defining fields.
	(mcontext_t): Likewise.
	* sysdeps/m68k/sys/ucontext.h (NGREG): Rename to __NGREG and
	define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(mcontext_t): Use __ctx in defining fields.
	* sysdeps/mips/sys/ucontext.h (NGREG): Rename to __NGREG and
	define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(fpregset_t): Use __ctx in defining fields.
	(mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/alpha/sys/ucontext.h (NGREG): Rename to
	__NGREG and define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(NFPREG): Rename to __NFPREG and define NFPREG to __NFPREG if
	[__USE_MISC].
	(fpregset_t): Define using __NFPREG.
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h (NGREG): Rename to
	__NGREG and define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(fpregset_t): Use __ctx in defining fields.
	(mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h (NGREG): Rename to
	__NGREG and define NGREG to __NGREG if [__USE_MISC].
	(NFPREG): Rename to __NFPREG and define NFPREG to __NFPREG if
	[__USE_MISC].
	(gregset_t): Define using __NGREG.
	(__ctx): New macro.
	(fpregset_t): Use __ctx in defining fields.
	(mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h (__ctx): New macro.
	(mcontext_t): Use __ctx in defining fields.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h (__ctx): New
	macro.
	[__WORDSIZE == 32] (NGREG): Rename to __NGREG and define NGREG to
	__NGREG if [__USE_MISC].
	[__WORDSIZE == 32] (gregset_t): Define using __NGREG.
	[__WORDSIZE == 32] (fpregset_t): Use __ctx in defining fields.
	(mcontext_t): Likewise.
	[__WORDSIZE != 32] (NGREG): Rename to __NGREG and define NGREG to
	__NGREG if [__USE_MISC].
	[__WORDSIZE != 32] (NFPREG): Rename to __NFPREG and define NFPREG
	to __NFPREG if [__USE_MISC].
	[__WORDSIZE != 32] (NVRREG): Rename to __NVRREG and define NVRREG
	to __NVRREG if [__USE_MISC].
	[__WORDSIZE != 32] (gregset_t): Define using __NGREG.
	[__WORDSIZE != 32] (fpregset_t): Define using __NFPREG.
	[__WORDSIZE != 32] (vscr_t): Use __ctx in defining fields.
	[__WORDSIZE != 32] (vrregset_t): Likewise.
	[__WORDSIZE != 32] (mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h (__ctx): New macro.
	(__psw_t): Use __ctx in defining fields.
	(NGREG): Rename to __NGREG and define NGREG to __NGREG if
	[__USE_MISC].
	(gregset_t): Define using __NGREG.
	(fpreg_t): Use __ctx in defining fields.
	(fpregset_t): Likewise.
	(mcontext_t): Likewise.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h (NGREG): Rename to
	__NGREG and define NGREG to __NGREG if [__USE_MISC].
	(gregset_t): Define using __NGREG.
	(NFPREG): Rename to __NFPREG and define NFPREG to __NFPREG if
	[__USE_MISC].
	(fpregset_t): Define using __NFPREG.
	(__ctx): New macro.
	(mcontext_t): Use __ctx in defining fields.
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h (__ctx): New macro.
	[__x86_64__] (NGREG): Rename to __NGREG and define NGREG to
	__NGREG if [__USE_MISC].
	[__x86_64__] (gregset_t): Define using __NGREG.
	[__x86_64__] (struct _libc_fpxreg): Use __ctx in defining fields.
	[__x86_64__] (struct _libc_fpstate): Likewise.
	[__x86_64__] (mcontext_t): Likewise.
	[!__x86_64__] (NGREG): Rename to __NGREG and define NGREG to
	__NGREG if [__USE_MISC].
	[!__x86_64__] (gregset_t): Define using __NGREG.
	[!__x86_64__] (struct _libc_fpreg): Use __ctx in defining fields.
	[!__x86_64__] (struct _libc_fpstate): Likewise.
	[!__x86_64__] (mcontext_t): Likewise.
2017-06-01 14:07:40 +00:00
Adhemerval Zanella 52bd938169 posix: Implement preadv2 and pwritev2
This patch adds support of preadv2 and pwritev2 which are similar to
preadv/pwritev but with an extra flag argument.  As for preadv/pwritev
both interfaces are added a non-standard GNU API.

For default 'posix' implementation trying to emulate the Linux supported
flags is troublesome:

   * We can not temporary change the file state of the O_DSYNC and O_SYNC
     flags to emulate RWF_{D}SYNC (attempts to change the state of using
     fcntl are silently ignored).

   * IOCB_HIPRI requires the file opened in O_DIRECT and uses an internal
     semantic not provided by any other flag (O_NONBLOCK for instance).

So default sysdeps/posix implementations fails with EOPNOTSUPP for any non
supported flag (which are none currently) calls generic preadv/pwritev.
Basically this implementation supports only preadv2 called as preadv (with
flags sets to 0).

The Linux one uses the preadv2/pwritev2 syscall if defined, otherwise it
call preadv/writev.  Instead of using the previous __ASSUME_* to
unconditionally issue the syscall (and avoid building the fallback routine),
it call pread/write if the preadv2/pwritev2 syscalls fails.  The idea
is just avoid adding another __ASSUME_* and checking each architecture
on every kernel bump and simplify code conditionals.

Checked on x86_64-linux-gnu and on i686-linux-gnu and a check with
run-built-tests=no on aarch64-linux-gnu, alpha-linux-gnu, arm-linux-gnueabihf,
ia64-linux-gnu, m68k-linux-gnu, microblaze-linux-gnu, mips{64,64n32}-linux-gnu,
nios2-linux-gnu, powerpc{64,64le}-linux-gnu, s390{x}-linux-gnu,
sparc{64,v9}-linux-gnu, tile{gx,pro}-linux-gnu, and sh4-linux-gnu (all using
gcc 6.3).

	* NEWS: Add note about pwritev2 and preadv2 inclusion.
	* misc/Makefile (routines): Add preadv2, preadv64v2, pwritev2, and
	pwritev64v2.
	(tests): Add tst-preadvwritev2 and tst-preadvwritev64v2.
	* misc/Versions (GLIBC_2.26): Add preadv2, preadv64v2, pwritev2, and
	pwritev64v2.
	* misc/preadv2.c: New file.
	* misc/preadv64v2.c: Likewise.
	* misc/pwritev2.c: Likewise.
	* misc/pwritev64v2.c: Likewise.
	* misc/tst-preadvwritev2.c: Likewise.
	* misc/tst-preadvwritev64v2.c: Likewise.
	* manual/llio.texi: Add preadv2 and pwritev2 documentation.
	* misc/sys/uio.h [__USE_GNU && !__USE_FILE_OFFSET64] (preadv2): New
	prototype.
	[__USE_GNU && !__USE_FILE_OFFSET64] (pwritev2):	Likewise.
	[__USE_GNU && __USE_FILE_OFFSET64] (preadv64v2): Likewise.
	[__USE_GNU && __USE_FILE_OFFSET64] (pwritev64v2): Likewise.
	* misc/tst-preadvwritev-common.c (PREADV): Define if not defined.
	(PWRITEV): Likewise.
	(do_test_with_offset): Use PREADV and PWRITEV macros and check for
	ENOSYS.
	* nptl/tst-cancel4.c (tf_pwritev2): New test.
	(tf_preadv2): Likewise.
	(tf_fsync): Add tf_pwritev2 and tf_preadv2.
	* sysdeps/posix/preadv2.c: Likewise.
	* sysdeps/posix/preadv64v2.c: Likewise.
	* sysdeps/posix/pwritev2.c: Likewise.
	* sysdeps/posix/pwritev64v2.c: Likewise.
	* sysdeps/unix/sysv/linux/kernel-features.h: Add comment for syscall
	support in kernel.
	* sysdeps/unix/sysv/linux/preadv2.c: Likewise.
	* sysdeps/unix/sysv/linux/preadv64v2.c: Likewise.
	* sysdeps/unix/sysv/linux/pwritev2.c: Likewise.
	* sysdeps/unix/sysv/linux/pwritev64v2.c: Likewise.
	* sysdeps/unix/sysv/linux/preadv.c (preadv): Add libc_hidden_def.
	* sysdeps/unix/sysv/linux/preadv64.c (preadv64): Likewise.
	* sysdeps/unix/sysv/linux/pwritev.c (pwritev): Likewise.
	* sysdeps/unix/sysv/linux/pwritev64.c (pwritev64): Likewise.
	* sysdeps/unix/sysv/linux/bits/uio.h: Add supported preadv2/pwritev2
	support flags on Linux.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist (GLIBC_2.26): Add
	preadv2, preadv64v2, pwritev2, pwritev64v2.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
	(GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
	(GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
	(GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist (GLIBC_2.26): Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/sysv/linux/tile/tilegx/tilegx32/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/sysv/linux/tile/tilegx/tilegx64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist (GLIBC_2.26):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist (GLIBC_2.26):
	Likewise.
2017-05-31 17:35:46 -03:00
Dennis Wölfing 2e0bbbfbf9 Add reallocarray function
The reallocarray function is an extension from OpenBSD.  It is an
integer-overflow-safe replacement for realloc(p, X*Y) and
malloc(X*Y) (realloc(NULL, X*Y)).  It can therefore help in preventing
certain security issues in code.

This is an updated version of a patch originally submitted by Rüdiger
Sonderfeld in May 2014 [1].

Checked on i686-linux-gnu and x86_64-linux-gnu.

[1] <https://sourceware.org/ml/libc-alpha/2014-05/msg00481.html>.

2017-05-30  Dennis Wölfing  <denniswoelfing@gmx.de>
            Rüdiger Sonderfeld  <ruediger@c-plusplus.de>

	* include/stdlib.h (__libc_reallocarray): New declaration.
	* malloc/Makefile (routines): Add reallocarray.
	(tests): Add tst-reallocarray.c.
	* malloc/Versions: Add reallocarray and __libc_reallocarray.
	* malloc/malloc-internal.h (check_mul_overflow_size_t): New inline
	function.
	* malloc/malloc.h (reallocarray): New declaration.
	* stdlib/stdlib.h (reallocarray): Likewise.
	* malloc/reallocarray.c: New file.
	* malloc/tst-reallocarray.c: New test file.
	* manual/memory.texi: Document reallocarray.
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist: Add reallocarray.
	* sysdeps/unix/sysv/linux/alpha/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tilepro/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist: Likewise.
2017-05-30 18:27:57 -03:00
Joseph Myers cfed8ece79 Fix sys/ucontext.h namespace from signal.h etc. inclusion (bug 21457).
The various sys/ucontext.h headers include <signal.h> and all the
headers split out of <bits/sigstack.h>.  (Except that the powerpc
version does not include <signal.h>.)

None of the standard versions defining ucontext.h require or permit
such inclusions; rather, they all say that the stack_t and sigset_t
types from signal.h are defined.  This patch fixes the headers to
include just the bits/ headers for those types (and the existing
includes of bits/sigcontext.h).  Since bits/types/sigset_t.h is now
being included instead of bits/types/__sigset_t.h, __sigset_t uses in
the headers are replaced by direct use of the public sigset_t type.
sysdeps/unix/sysv/linux/x86/bits/sigcontext.h was relying on the prior
inclusion of <signal.h> to define types such as __uint32_t, so gets a
bits/types.h include added to provide those types.

Although one could keep some or all of the includes under a __USE_MISC
conditional, that seems unnecessary to me, especially given the lack
of a <signal.h> include in the powerpc version meaning that portable
programs already cannot rely on such an include.

Tested for x86_64 and x86, and with build-many-glibcs.py.  As with
other such fixes, more namespace issues remain so this does not permit
any XFAILs to be removed or bugs to be closed.

	[BZ #21457]
	* sysdeps/arm/sys/ucontext.h: Do not include <signal.h>,
	<bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/generic/sys/ucontext.h: Do not include <signal.h>,
	<bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/i386/sys/ucontext.h: Do not include <signal.h>,
	<bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/m68k/sys/ucontext.h: Do not include <signal.h>,
	<bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/mips/sys/ucontext.h: Do not include <signal.h>,
	<bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/alpha/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/arm/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/hppa/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/ia64/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h>.
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h: Do not include
	<bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/sparc/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/tile/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
	* sysdeps/unix/sysv/linux/x86/bits/sigcontext.h: Include
	<bits/types.h>.
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h: Do not include
	<signal.h>, <bits/sigstack.h>, <bits/types/struct_sigstack.h> or
	<bits/ss_flags.h>.  Include <bits/types/sigset_t.h> instead of
	<bits/types/__sigset_t.h>.
	(ucontext_t): Use sigset_t instead of __sigset_t.
2017-05-23 11:49:48 +00:00
Zack Weinberg a992f506ff Remove __need macros from signal.h.
The types affected are __sig_atomic_t, sig_atomic_t, __sigset_t,
sigset_t, sigval_t, sigevent_t, and siginfo_t. __sig_atomic_t is a
scalar, so it's now directly available from bits/types.h.  The others
get bits/types/ headers.

Side effects include: There have been small changes to which
non-signal headers expose which subset of the signal-related types.
A couple of architectures' nested siginfo_t fields had to be renamed
to prevent undesired macro expansion.  Internal code that wants to
manipulate signal masks must now include <sigsetops.h> (which is not
installed) and should be aware that __sigaddset, __sigandset,
__sigdelset, __sigemptyset, and __sigorset no longer return a value
(unlike the public API).  Relatedly, the public signal.h no longer
declares any of those functions.  The obsolete sigmask() macro no
longer has a system-specific definition -- in the cases where it
matters, it didn't work anyway.

New Linux architectures should create bits/siginfo-arch.h and/or
bits/siginfo-consts-arch.h to customize their siginfo_t, rather than
duplicating everything in bits/siginfo.h (which no longer exists).
Add new __SI_* macros if necessary.  Ports to other operating systems
are strongly encouraged to generalize this scheme further.

	* bits/sigevent-consts.h
	* bits/siginfo-consts.h
	* bits/types/__sigset_t.h
	* bits/types/sigevent_t.h
	* bits/types/siginfo_t.h
	* sysdeps/unix/sysv/linux/bits/sigevent-consts.h
	* sysdeps/unix/sysv/linux/bits/siginfo-consts.h
	* sysdeps/unix/sysv/linux/bits/types/__sigset_t.h
	* sysdeps/unix/sysv/linux/bits/types/sigevent_t.h
	* sysdeps/unix/sysv/linux/bits/types/siginfo_t.h:
	New system-dependent bits headers.

	* sysdeps/unix/sysv/linux/bits/siginfo-arch.h
	* sysdeps/unix/sysv/linux/bits/siginfo-consts-arch.h
	* sysdeps/unix/sysv/linux/ia64/bits/siginfo-arch.h
	* sysdeps/unix/sysv/linux/ia64/bits/siginfo-consts-arch.h
	* sysdeps/unix/sysv/linux/mips/bits/siginfo-arch.h
	* sysdeps/unix/sysv/linux/sparc/bits/siginfo-arch.h
	* sysdeps/unix/sysv/linux/tile/bits/siginfo-arch.h
	* sysdeps/unix/sysv/linux/tile/bits/siginfo-consts-arch.h
	* sysdeps/unix/sysv/linux/x86/bits/siginfo-arch.h:
	New Linux-only system-dependent bits headers.

	* signal/bits/types/sig_atomic_t.h
	* signal/bits/types/sigset_t.h
	* signal/bits/types/sigval_t.h:
	New non-system-dependent bits headers.

	* sysdeps/generic/sigsetops.h
	* sysdeps/unix/sysv/linux/sigsetops.h:
	New internal headers.

	* include/bits/types/sig_atomic_t.h
	* include/bits/types/sigset_t.h
	* include/bits/types/sigval_t.h:
	New wrappers.

	* signal/sigsetops.h
	* bits/siginfo.h
	* bits/sigset.h
	* sysdeps/unix/sysv/linux/bits/siginfo.h
	* sysdeps/unix/sysv/linux/bits/sigset.h
	* sysdeps/unix/sysv/linux/ia64/bits/siginfo.h
	* sysdeps/unix/sysv/linux/mips/bits/siginfo.h
	* sysdeps/unix/sysv/linux/s390/bits/siginfo.h
	* sysdeps/unix/sysv/linux/sparc/bits/siginfo.h
	* sysdeps/unix/sysv/linux/tile/bits/siginfo.h
	* sysdeps/unix/sysv/linux/x86/bits/siginfo.h:
	Deleted.

	* signal/Makefile, sysdeps/unix/sysv/linux/Makefile:
	Update lists of installed headers.

	* posix/bits/types.h: Define __sig_atomic_t here.
	* signal/signal.h: Use the new bits headers; no need to handle
	__need_sig_atomic_t nor __need_sigset_t.  Don't use __sigmask
	to define sigmask.
	* include/signal.h: No need to handle __need_sig_atomic_t
	nor __need_sigset_t.  Don't define __sigemptyset.

	* io/sys/poll.h, setjmp/setjmp.h
	* sysdeps/arm/sys/ucontext.h, sysdeps/generic/sys/ucontext.h
	* sysdeps/i386/sys/ucontext.h, sysdeps/m68k/sys/ucontext.h
	* sysdeps/mach/hurd/i386/bits/sigcontext.h
	* sysdeps/mips/sys/ucontext.h, sysdeps/powerpc/novmxsetjmp.h
	* sysdeps/pthread/bits/sigthread.h
	* sysdeps/unix/sysv/linux/hppa/sys/ucontext.h
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h
	* sysdeps/unix/sysv/linux/sparc/sys/ucontext.h
	* sysdeps/unix/sysv/linux/tile/sys/ucontext.h
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h:
	Use bits/types/__sigset_t.h.

	* misc/sys/select.h, posix/spawn.h
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
	* sysdeps/unix/sysv/linux/sys/epoll.h
	* sysdeps/unix/sysv/linux/sys/signalfd.h:
	Use bits/types/sigset_t.h.

	* resolv/netdb.h, rt/mqueue.h: Use bits/types/sigevent_t.h.
	* rt/aio.h: Use bits/types/sigevent_t.h and bits/sigevent-consts.h.
	* socket/sys/socket.h: Don't include bits/sigset.h.

	* login/utmp_file.c, shadow/lckpwdf.c, signal/sigandset.c
	* signal/sigisempty.c, stdlib/abort.c, sysdeps/posix/profil.c
	* sysdeps/posix/sigignore.c, sysdeps/posix/sigintr.c
	* sysdeps/posix/signal.c, sysdeps/posix/sigset.c
	* sysdeps/posix/sprofil.c, sysdeps/posix/sysv_signal.c
	* sysdeps/unix/sysv/linux/nptl-signals.h:
	Include sigsetops.h.

	* signal/sigaddset.c, signal/sigandset.c, signal/sigdelset.c
	* signal/sigorset.c, stdlib/abort.c, sysdeps/posix/sigignore.c
	* sysdeps/posix/signal.c, sysdeps/posix/sigset.c:
	__sigaddset, __sigandset, __sigdelset, __sigemptyset, __sigorset
	now return no value.

	* signal/sigaddset.c, signal/sigdelset.c, signal/sigismem.c
	Include <errno.h>, <signal.h>, and <sigsetops.h> instead of
	"sigsetops.h".

	* signal/sigsetops.c: Explicitly define __sigismember,
	__sigaddset, and __sigdelset as compatibility symbols.

	* signal/Versions: Correct commentary on __sigpause,
	__sigaddset, __sigdelset, __sigismember.

	* inet/rcmd.c: Include sigsetops.h.  Convert old code using
	__sigblock/__sigsetmask to use __sigprocmask and friends.
2017-05-20 19:04:43 -04:00
Joseph Myers 0bcec5321f Split up bits/sigstack.h.
bits/sigstack.h contains four things: the legacy struct sigstack type,
the preferred stack_t type, the SS_* enum values and macros for signal
stack sizes.

These vary in different ways between glibc configurations; in
particular, the stack sizes vary much more than any of the other
pieces.  Furthermore, these pieces have different standard namespace
rules for when they should be visible (not currently visible in
conform/ results both because the relevant tests are XFAILed for
sys/ucontext.h namespace issues, and because some of the expectations
are incorrect in the same way as the headers, e.g. neither
expectations nor headers reflect that current POSIX no longer has
either the sigstack function or the sigstack structure).

To reduce duplication of identical definitions, and facilitate
namespace fixes without requiring the same feature test macro
conditions to be repeated in many versions of the same header, this
patch splits bits/sigstack.h up into four headers.  It keeps the stack
size macros, while new bits/types/struct_sigstack.h,
bits/types/stack_t.h and bits/ss_flags.h are added for the other
pieces.  bits/types/struct_sigstack.h is the same everywhere,
bits/types/stack_t.h has three variants different in the order of the
structure elements (generic = MIPS Linux, and other Linux), and
bits/ss_flags.h has generic and Linux variants.

This patch includes the new headers everywhere that included
<bits/sigstack.h>, so should cause no difference to what any public
header defines.  Subsequent namespace fixes would then remove or
condition some of those includes.

There should be no conflicts with Zack's changes to signal.h types,
beyond the trivial conflict of both making additions to
signal/Makefile's headers list; the two patches affect disjoint sets
of types and other definitions.

Tested for x86_64 and x86, and with build-many-glibcs.py.

	* bits/ss_flags.h: New file.
	* bits/types/stack_t.h: Likewise.
	* include/bits/types/struct_sigstack.h: Likewise.
	* signal/bits/types/struct_sigstack.h: Likewise.
	* sysdeps/unix/sysv/linux/bits/ss_flags.h: Likewise.
	* sysdeps/unix/sysv/linux/bits/types/stack_t.h: Likewise.
	* sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h: Likewise.
	* signal/Makefile (headers): Add bits/types/struct_sigstack.h,
	bits/types/stack_t.h and bits/ss_flags.h.
	* signal/signal.h [__USE_XOPEN_EXTENDED || __USE_XOPEN2K8]:
	Include <bits/types/struct_sigstack.h>, <bits/types/stack_t.h> and
	<bits/ss_flags.h>.
	* bits/sigstack.h (struct sigstack): Remove.
	(stack_t): Likewise.
	(SS_ONSTACK): Likewise.
	(SS_DISABLE): Likewise.
	* sysdeps/unix/sysv/linux/aarch64/bits/sigstack.h
	(struct sigstack): Likewise.
	(stack_t): Likewise.
	(SS_ONSTACK): Likewise.
	(SS_DISABLE): Likewise.
	* sysdeps/unix/sysv/linux/alpha/bits/sigstack.h (struct sigstack):
	Likewise.
	(stack_t): Likewise.
	(SS_ONSTACK): Likewise.
	(SS_DISABLE): Likewise.
	* sysdeps/unix/sysv/linux/bits/sigstack.h (struct sigstack):
	Likewise.
	(stack_t): Likewise.
	(SS_ONSTACK): Likewise.
	(SS_DISABLE): Likewise.
	* sysdeps/unix/sysv/linux/mips/bits/sigstack.h: Likewise.
	* sysdeps/unix/sysv/linux/ia64/bits/sigstack.h (struct sigstack):
	Likewise.
	(stack_t): Likewise.
	(SS_ONSTACK): Likewise.
	(SS_DISABLE): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/bits/sigstack.h
	(struct sigstack): Likewise.
	(stack_t): Likewise.
	(SS_ONSTACK): Likewise.
	(SS_DISABLE): Likewise.
	* sysdeps/unix/sysv/linux/sparc/bits/sigstack.h (struct sigstack):
	Likewise.
	(stack_t): Likewise.
	(SS_ONSTACK): Likewise.
	(SS_DISABLE): Likewise.
	* sysdeps/arm/sys/ucontext.h: Include
	<bits/types/struct_sigstack.h>, <bits/types/stack_t.h> and
	<bits/ss_flags.h>.
	* sysdeps/generic/sys/ucontext.h: Likewise.
	* sysdeps/i386/sys/ucontext.h: Likewise.
	* sysdeps/m68k/sys/ucontext.h: Likewise.
	* sysdeps/mips/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/alpha/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/arm/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/hppa/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h: Likewise.
	* sysdeps/unix/sysv/linux/ia64/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/tile/sys/ucontext.h: Likewise.
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h: Likewise.
2017-05-19 20:35:07 +00:00
Adhemerval Zanella ebfdb12bf0 posix: Consolidate Linux waitpid syscall
This patch consolidates the waitpid Linux syscall generation on
sysdeps/unix/sysv/linux/waitpid.c.  It basically removes it from
architecture auto-generation list and also remove arch specific
implementations.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
arch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/sh/syscalls.list: Remove waitpid from
	auto-generated list.
	* sysdeps/unix/sysv/linux/m68k/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/i386/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/syscalls.list: Remove file.
	* sysdeps/unix/sysv/linux/tile/waitpid.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/syscalls.list: Likewise.
2017-05-18 18:06:47 -03:00
Joseph Myers 5df4854ed2 Condition some sys/ucontext.h contents on __USE_MISC (bug 21457).
Continuing the fixes for namespace issues arising from sys/ucontext.h,
this patch conditions various definitions, that are not needed for
defining mcontext_t / ucontext_t, on __USE_MISC, so they do not appear
in strict POSIX modes.

This patch is non-exhaustive; that is, it only conditions
straightforward cases and there may be more such definitions that can
be conditioned for these and other architectures, to be dealt with
later in separate patches.  Also, using __USE_MISC is the minimum
change for these definitions where they conflict with POSIX; some
headers already have __USE_GNU conditionals on similar definitions of
names for registers.  The patch specifically does not do anything with
definitions in bits/sigcontext.h, and nor does it condition any
inclusions of bits/sigcontext.h even where in fact that is not needed
on some architectures for the definitions of mcontext_t / ucontext_t.

As other namespace issues in these headers remain, this patch does not
fix bug 21457, nor allow any XFAILs to be removed.

Tested with build-many-glibcs.py.

	[BZ #21457]
	* sysdeps/arm/sys/ucontext.h (R0): Condition on [__USE_MISC].
	(R1): Likewise.
	(R2): Likewise.
	(R3): Likewise.
	(R4): Likewise.
	(R5): Likewise.
	(R6): Likewise.
	(R7): Likewise.
	(R8): Likewise.
	(R9): Likewise.
	(R10): Likewise.
	(R11): Likewise.
	(R12): Likewise.
	(R13): Likewise.
	(R14): Likewise.
	(R15): Likewise.
	* sysdeps/i386/sys/ucontext.h (REG_GS): Likewise.
	(REG_FS): Likewise.
	(REG_ES): Likewise.
	(REG_DS): Likewise.
	(REG_EDI): Likewise.
	(REG_ESI): Likewise.
	(REG_EBP): Likewise.
	(REG_ESP): Likewise.
	(REG_EBX): Likewise.
	(REG_EDX): Likewise.
	(REG_ECX): Likewise.
	(REG_EAX): Likewise.
	(REG_TRAPNO): Likewise.
	(REG_ERR): Likewise.
	(REG_EIP): Likewise.
	(REG_CS): Likewise.
	(REG_EFL): Likewise.
	(REG_UESP): Likewise.
	(REG_SS): Likewise.
	* sysdeps/m68k/sys/ucontext.h (R_D0): Likewise.
	(R_D1): Likewise.
	(R_D2): Likewise.
	(R_D3): Likewise.
	(R_D4): Likewise.
	(R_D5): Likewise.
	(R_D6): Likewise.
	(R_D7): Likewise.
	(R_A0): Likewise.
	(R_A1): Likewise.
	(R_A2): Likewise.
	(R_A3): Likewise.
	(R_A4): Likewise.
	(R_A5): Likewise.
	(R_A6): Likewise.
	(R_A7): Likewise.
	(R_SP): Likewise.
	(R_PC): Likewise.
	(R_PS): Likewise.
	(fpregset_t): Likewise.
	(MCONTEXT_VERSION): Likewise.
	* sysdeps/mips/sys/ucontext.h (CTX_R0): Likewise.
	(CTX_AT): Likewise.
	(CTX_V0): Likewise.
	(CTX_V1): Likewise.
	(CTX_A0): Likewise.
	(CTX_A1): Likewise.
	(CTX_A2): Likewise.
	(CTX_A3): Likewise.
	(CTX_T0): Likewise.
	(CTX_T1): Likewise.
	(CTX_T2): Likewise.
	(CTX_T3): Likewise.
	(CTX_T4): Likewise.
	(CTX_T5): Likewise.
	(CTX_T6): Likewise.
	(CTX_T7): Likewise.
	(CTX_S0): Likewise.
	(CTX_S1): Likewise.
	(CTX_S2): Likewise.
	(CTX_S3): Likewise.
	(CTX_S4): Likewise.
	(CTX_S5): Likewise.
	(CTX_S6): Likewise.
	(CTX_S7): Likewise.
	(CTX_T8): Likewise.
	(CTX_T9): Likewise.
	(CTX_K0): Likewise.
	(CTX_K1): Likewise.
	(CTX_GP): Likewise.
	(CTX_SP): Likewise.
	(CTX_S8): Likewise.
	(CTX_RA): Likewise.
	(CTX_MDLO): Likewise.
	(CTX_MDHI): Likewise.
	(CTX_CAUSE): Likewise.
	(CTX_EPC): Likewise.
	* sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h: Condition
	inclusion of <sys/procfs.h> on [__USE_MISC].
	(greg_t): Condition on [__USE_MISC].
	(gregset_t): Likewise.
	(fpregset_t): Likewise.
	* sysdeps/unix/sysv/linux/arm/sys/ucontext.h (greg_t): Likewise.
	(NGREG): Likewise.
	(gregset_t): Likewise.
	(REG_R0): Likewise.
	(REG_R1): Likewise.
	(REG_R2): Likewise.
	(REG_R3): Likewise.
	(REG_R4): Likewise.
	(REG_R5): Likewise.
	(REG_R6): Likewise.
	(REG_R7): Likewise.
	(REG_R8): Likewise.
	(REG_R9): Likewise.
	(REG_R10): Likewise.
	(REG_R11): Likewise.
	(REG_R12): Likewise.
	(REG_R13): Likewise.
	(REG_R14): Likewise.
	(REG_R15): Likewise.
	(struct _libc_fpstate): Likewise.
	(fpregset_t): Likewise.
	* sysdeps/unix/sysv/linux/hppa/sys/ucontext.h (NGREG): Likewise.
	(NFPREG): Likewise.
	(gregset_t): Likewise.
	(fpregset_t): Likewise.
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h (R_D0): Likewise.
	(R_D1): Likewise.
	(R_D2): Likewise.
	(R_D3): Likewise.
	(R_D4): Likewise.
	(R_D5): Likewise.
	(R_D6): Likewise.
	(R_D7): Likewise.
	(R_A0): Likewise.
	(R_A1): Likewise.
	(R_A2): Likewise.
	(R_A3): Likewise.
	(R_A4): Likewise.
	(R_A5): Likewise.
	(R_A6): Likewise.
	(R_A7): Likewise.
	(R_SP): Likewise.
	(R_PC): Likewise.
	(R_PS): Likewise.
	(fpregset_t): Likewise.
	(MCONTEXT_VERSION): Likewise.
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h (MCONTEXT_VERSION):
	Likewise.
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h (REG_R0): Likewise.
	(REG_R1): Likewise.
	(REG_R2): Likewise.
	(REG_R3): Likewise.
	(REG_R4): Likewise.
	(REG_R5): Likewise.
	(REG_R6): Likewise.
	(REG_R7): Likewise.
	(REG_R8): Likewise.
	(REG_R9): Likewise.
	(REG_R10): Likewise.
	(REG_R11): Likewise.
	(REG_R12): Likewise.
	(REG_R13): Likewise.
	(REG_R14): Likewise.
	(REG_R15): Likewise.
	* sysdeps/unix/sysv/linux/tile/sys/ucontext.h: Condition inclusion
	of <arch/abi.h> on [__USE_MISC].
	(greg_t): Condition on [__USE_MISC].
	(NGREG): Likewise.
	(gregset_t): Likewise.
2017-05-11 14:15:26 +00:00
Adhemerval Zanella 158d5fa0e1 Consolidate Linux mmap implementation (BZ#21270)
This patch consolidates all Linux mmap implementations on default
sysdeps/unix/sysv/linux/mmap{64}.c one.  To accomodate all required
architecture specific requeriments a new internal header is created
(mmap_internal.h) where each architecture add its specific code
requirements.  Currently only x86_64 (to define MMAP_PREPARE to add
MAP_32BITS), s390 (which have a different kernel ABI for mmap), m68k
(which have variable minimum page sizes), and MIPS n32 (which zero
extend the offset to handle negative one correctly) redefine the new
header.

The patch also fixes BZ#21270 where default mmap64 on architectures
which uses mmap2 silent truncates large offsets value (larger than
1 << (page shift + 8 * sizeof (off_t)) or 1<<44 on architectures with
4096 bytes page size).  The new consolidate implementation returns
EINVAL as allowed by POSIX.

It also adds a tests for on current tst-mmap-offset one.  I have run
a full make check on x86_64, x86_64-32, i686, aarch64, armhf, powerpc,
powerpc64le, sparc64, and sparcv9 without any regressions.  I also ran
some basic tests (tst-mmap-offset) on sh4, m68k, and on qemu simulated
MIPS32 and MIPS64.

	[BZ #21270]
	* posix/tst-mmap-offset.c (do_prepare): New function.
	(do_test): Rename to do_test_bz18877 and use FAIL_RET.
	(do_test_bz21270): New function.
	* sysdeps/unix/sysv/linux/aarch64/mmap.c: Remove file.
	* sysdeps/unix/sysv/linux/arm/mmap.c: Remove file.
	* sysdeps/unix/sysv/linux/generic/wordsize-32/mmap.c: Likewise.
	* sysdeps/unix/sysv/linux/hppa/mmap.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/mmap.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/mmap.S: Likewise.
	* sysdeps/unix/sysv/linux/m68k/mmap64.c: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/mmap.S: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/mmap.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap.c: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/mmap64.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/mmap.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/mmap64.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/mmap.S: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/mmap.c: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/mmap64.c: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
	* sysdeps/unix/sysv/linux/mmap_internal.h: New file.
	* sysdeps/unix/sysv/linux/m68k/mmap_internal.h: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/mmap_internal.h: Likewise.
	* sysdeps/unix/sysv/linux/s390/mmap_internal.h: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/mmap_internal.h: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/n64/syscalls.list: Remove mmap
	from auto-generation list.
	* sysdeps/unix/sysv/linux/mips/mips64/n32/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/mmap.c: New file.
	* sysdeps/unix/sysv/linux/mmap64.c (__mmap64): Add check for invalid
	offsets and support for mmap2 syscall.
2017-04-12 11:04:28 -03:00
Adhemerval Zanella db3d848e15 Build divdi3 only for architecture that required it
As noted in [1], divdi3 object is only exported in a handful ABIs
(i386, m68k, powerpc32, s390-32, and ia64), however it is built
for all current architectures regardless.

This patch refact the make rules for this object to so only the
aforementioned architectures that actually require it builds it.

Also, to avoid internal PLT calls to the exported symbol from the
module, glibc uses an internal header (symbol-hacks.h) which is
unrequired (and in fact breaks the build for architectures that
intend to get symbol definitions from libgcc.a).  The patch also
changes it to create its own header (divdi3-symbol-hacks.h) and
adjust the architectures that require it accordingly.

I checked the build/check (with run-built-tests=no) on the
following architectures (which I think must cover all supported
ABI/builds) using GCC 6.3:

aarch64-linux-gnu
alpha-linux-gnu
arm-linux-gnueabihf
hppa-linux-gnu
ia64-linux-gnu
m68k-linux-gnu
microblaze-linux-gnu
mips64-n32-linux-gnu
mips-linux-gnu
mips64-linux-gnu
nios2-linux-gnu
powerpc-linux-gnu
powerpc-linux-gnu-power4
powerpc64-linux-gnu
powerpc64le-linux-gnu
s390x-linux-gnu
s390-linux-gnu
sh4-linux-gnu
sh4-linux-gnu-soft
sparc64-linux-gnu
sparcv9-linux-gnu
tilegx-linux-gnu
tilegx-linux-gnu-32
tilepro-linux-gnu
x86_64-linux-gnu
x86_64-linux-gnu-x32
i686-linux-gnu

I only saw one regression on sparcv9-linux-gnu (extra PLT call to
.udiv) which I address in next patch in the set.  It also correctly
build SH with GCC 7.0.1 (without any regression from c89721e25d).

[1] https://sourceware.org/ml/libc-alpha/2017-03/msg00243.html

	* sysdeps/i386/symbol-hacks.h: New file.
	* sysdeps/m68k/symbol-hacks.h: New file.
	* sysdeps/powerpc/powerpc32/symbol-hacks.h: New file.
	* sysdeps/s390/s390-32/symbol-hacks.h: New file.
	* sysdeps/unix/sysv/linux/i386/Makefile
	[$(subdir) = csu] (sysdep_routines): New rule: divdi3 object.
	[$(subdir) = csu] (sysdep-only-routines): Likewise.
	[$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
	* sysdeps/unix/sysv/linux/m68k/Makefile
	[$(subdir) = csu] (sysdep_routines): Likewise.
	[$(subdir) = csu] (sysdep-only-routines): Likewise.
	[$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
	[$(subdir) = csu] (sysdep_routines): Likewise.
	[$(subdir) = csu] (sysdep-only-routines): Likewise.
	[$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/Makefile
	[$(subdir) = csu] (sysdep_routines): Likewise.
	[$(subdir) = csu] (sysdep-only-routines): Likewise.
	[$(subdir) = csu] (CFLAGS-divdi3.c): Likewise.
	* sysdeps/wordsize-32/Makefile: Remove file.
	* sysdeps/wordsize-32/symbol-hacks.h: Definitions move to ...
	* sysdeps/wordsize-32/divdi3-symbol-hacks.h: ... here.
2017-04-06 15:14:34 -03:00
Adhemerval Zanella 2e4cf77897 Remove __ASSUME_REQUEUE_PI
The new cond var implementation (ed19993b5b) removed all the
__ASSUME_{REQUEUE_PI,FUTEX_LOCK_PI} internal usage so there is no
need to keep defining it.  This patch removes all USE_REQUEUE_PI
and __ASSUME_REQUEUE_PI.  It is as follow up from BZ#18463.

Checked with a build for x86_64-linux-gnu, arm-linux-gnueabhf,
m68-linux-gnu, mips64-linux-gnu, and sparc64-linux-gnu.

	* nptl/pthreadP.h (USE_REQUEUE_PI): Remove ununsed macro.
	* sysdeps/unix/sysv/linux/arm/kernel-features.h
	(__ASSUME_REQUEUE_PI): Likewise.
	* sysdeps/unix/sysv/linux/kernel-features.h
	(__ASSUME_REQUEUE_PI): Likewise.
	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
	(__ASSUME_REQUEUE_PI): Likewise.
	* sysdeps/unix/sysv/linux/mips/kernel-features.h
	(__ASSUME_REQUEUE_PI): Likewise.
	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
	(__ASSUME_REQUEUE_PI): Likewise.
2017-04-04 18:02:02 -03:00
Adhemerval Zanella dd5905de03 Consolidate set* Linux implementation
This patch consolidates the Linux setegid, seteuid, setgid, setgroups,
setregid, setresgid, setresuid, setreuid, and setuid implementation on
default sysdeps/unix/sysv/linux/set*.c implementation.  It basically
removes all the architecture define implementations and add support for
__NR_set*32 syscall on Linux default implementation.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/arm/setegid.c: Remove file.
	* sysdeps/unix/sysv/linux/arm/seteuid.c: Likewise.
	* sysdeps/unix/sysv/linux/arm/setgid.c: Likewise.
	* sysdeps/unix/sysv/linux/arm/setgroups.c: Likewise.
	* sysdeps/unix/sysv/linux/arm/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/arm/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/arm/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/arm/setreuid.c: Likewise.
	* sysdeps/unix/sysv/linux/arm/setuid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setegid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/seteuid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setgid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setgroups.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setreuid.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/setuid.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setegid.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/seteuid.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setgid.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setgroups.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setreuid.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/setuid.c: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/setgroups.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setegid.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/seteuid.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setgid.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setgroups.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setreuid.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/setuid.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setegid.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/seteuid.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setgid.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setgroups.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setreuid.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/setuid.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setegid.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/seteuid.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setgid.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setgroups.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setregid.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setresgid.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setresuid.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setreuid.c: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/setuid.c: Likewise.
	* sysdeps/unix/sysv/linux/setegid.c (setegid): Use
	INLINE_SYSCALL_ERROR_RETURN_VALUE.
	* sysdeps/unix/sysv/linux/seteuid.c (seteuid): Likewise.
	* sysdeps/unix/sysv/linux/setgid.c (setgid): Use __NR_setgid32 if
	defined.
	* sysdeps/unix/sysv/linux/setgroups.c (setgroups): Use
	__NR_setgroups32 if defined.
	* sysdeps/unix/sysv/linux/setregid.c (__setregid): Use __NR_setregid32
	if defined.
	* sysdeps/unix/sysv/linux/setresgid.c (__setresgid): Use
	__NR_setresgid32 is defined.
	* sysdeps/unix/sysv/linux/setresuid.c (__setresuid): Use
	__NR_setresuid32 if defined.
	* sysdeps/unix/sysv/linux/setreuid.c (__setreuid): Use
	__NR_setreuid32 if defined.
	* sysdeps/unix/sysv/linux/setuid.c (__setuid): Use __NR_setuid32 if
	defined.
2017-03-28 12:29:27 -03:00
Adhemerval Zanella 60f9423b6b Consolidate Linux send implementation
This patch consolidates the send Linux syscall implementation on
sysdeps/unix/sysv/linux/send{to}.c.  The changes are:

  1. Remove send from auto-generation syscalls.list on the architecture
     that uses __NR_send.
  2. Define __NR_send for architectures that supports it. It was done instead
     of defining in default kernel-features.h because current Linux practice
     for new ports are to implement only __NR_sendto [1] and it will
     require adding new kernel-features for ports that do not require it
     (aarch64 for instance).
  3. Remove __ASSUME_SENDTO_FOR_SEND_SYSCALL and decide to use
     __NR_sendto for send generation based on __ASSUME_SENDTO_SYSCALL.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/sysdep.h (HAVE_INTERNAL_SEND_SYMBOL):
	Define.
	* sysdeps/unix/sysv/linux/aarch64/sysdep.h
	(HAVE_INTERNAL_SEND_SYMBOL): Undefine.
	* sysdeps/unix/sysv/linux/nios2/sysdep.h
	(HAVE_INTERNAL_SEND_SYMBOL): Likewise.
	* sysdeps/unix/sysv/linux/tile/sysdep.h
	(HAVE_INTERNAL_SEND_SYMBOL): Likewise.
	* sysdeps/unix/sysv/linux/alpha/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Define.
	* sysdeps/unix/sysv/linux/arm/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/hppa/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/ia64/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/mips/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/i386/kernel-features.h
	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Remove define.
	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/s390/kernel-features.h
	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove send from
	auto-generation list.
	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewike.
	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/send.c: Simplify includes.
	(__ASSUME_SENDTO_FOR_SEND_SYSCALL): Replace by
	__ASSUME_SENDTO_SYSCALL.
	* sysdeps/unix/sysv/linux/x86_64/send.c: Remove file.
	* sysdeps/unix/sysv/linux/mips/mips64/send.c: Likewise.
	* sysdeps/unix/sysv/linux/generic/send.c: Likewise.
2017-03-09 15:22:06 +01:00
Adhemerval Zanella 06cf371e97 Consolidate Linux sendto implementation
This patch consolidates the sendto Linux syscall implementation on
sysdeps/unix/sysv/linux/sendto.c.  The changes are:

   1. Define __ASSUME_SENDTO_SYSCALL by default.
   2. Undef it for architectures that do not support __NR_sendto.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove sendto from
	auto-generation list.
	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/kernel-features.h
	(__ASSUME_SENDTO_SYSCALL): Define by default.
	* sysdeps/unix/sysv/linux/i386/kernel-features.h
	(__ASSUME_SENDTO_SYSCALL): Undef it is kernel does not support
	__NR_sendto.
	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
	(__ASSUME_SENDTO_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/s390/kernel-features.h
	(__ASSUME_SENDTO_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
	(__ASSUME_SENDTO_SYSCALL): Remove definition.
	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
	(__ASSUME_SENDTO_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/sh/kernel-features.h:
	(__ASSUME_SENDTO_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/sendto.c: Simplify includes.
2017-03-09 15:22:06 +01:00
Adhemerval Zanella df799d9eb3 Consolidate Linux recv implementation
This patch consolidates the recv Linux syscall implementation on
sysdeps/unix/sysv/linux/recv.c.  The changes are:

  1. Remove recv from auto-generation syscalls.list on the architecture
     that uses __NR_recv.
  2. Define __NR_recv for architectures that supports it.  It was done
     instead of defining in default kernel-features.h because current Linux
     practice for new ports is to implement only __NR_recvfrom [1] and it will
     require adding new kernel-features for ports that do not require it
     (aarch64 for instance).
  3. Remove __ASSUME_RECVFROM_FOR_RECV_SYSCALL and decide to use
     __NR_recvfrom for recv generation based on __ASSUME_RECVFROM_SYSCALL.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove recv from
	auto-generation list.
	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/alpha/kernel-features.h
	(__ASSUME_RECV_SYSCALL): New define.
	* sysdeps/unix/sysv/linux/arm/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/hppa/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/ia64/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/mips/kernel-features.h
	(__ASSUME_RECV_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/i386/kernel-features.h
	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Remove define.
	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Remove define.
	* sysdeps/unix/sysv/linux/s390/kernel-features.h
	(__ASSUME_RECVFROM_FOR_RECV_SYSCALL): Remove define.
	* sysdeps/unix/sysv/linux/generic/recv.c: Remove file.
	* sysdeps/unix/sysv/linux/mips/mips64/recv.c: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/recv.c: Likewise.
	* sysdeps/unix/sysv/linux/recv.c: Simplify includes.
	(__libc_recv): Use __ASSUME_RECVFROM_SYSCALL instead of
	__ASSUME_RECVFROM_FOR_RECV_SYSCALL to issue recvfrom syscall.

[1] include/asm-generic/unistd.h (__ARCH_WANT_SYSCALL_DEPRECATED)
2017-03-09 15:22:06 +01:00
Adhemerval Zanella 1f8161a801 Consolidate Linux recvfrom implementation
This patch consolidates the recvfrom Linux syscall implementation on
sysdeps/unix/sysv/linux/recvfrom.c.  The changes are:

  1. Define __ASSUME_RECVFROM_SYSCALL by default
  2. Undef it for  architectures that do not support __NR_recvfrom.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove recvfrom from
	auto-generation list.
	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/i386/kernel-features.h
	* sysdeps/unix/sysv/linux/kernel-features.h
	(__ASSUME_RECVFROM_SYSCALL): Define by default.
	(__ASSUME_RECVFROM_SYSCALL): Undef it if kernel does not support
	__NR_recvfrom.
	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
	(__ASSUME_RECVFROM_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/s390/kernel-features.h
	(__ASSUME_RECVFROM_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
	(__ASSUME_RECVFROM_SYSCALL): Remove definition.
	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
	(__ASSUME_RECVFROM_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/sh/kernel-features.h
	(__ASSUME_RECVFROM_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
	(__ASSUME_RECVFROM_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/recvfrom.c: Simplify includes.
2017-03-09 15:22:06 +01:00
Adhemerval Zanella 3e9ff426cb Consolidate Linux connect implementation
This patch consolidates the connect Linux syscall implementation on
sysdeps/unix/sysv/linux/accept.c.  The changes are:

  1. Remove connect from auto-generation syscalls.list on the architecture
     that uses __NR_connect.
  2. Define __NR_connect as default (__ASSUME_CONNECT_SYSCALL) and undef for
     architectures that do not support it.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove connect from
	auto-generation list.
	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/connect.c: Simplify include list.
	* sysdeps/unix/sysv/linux/kernel-features.h
	(__ASSUME_CONNECT_SYSCALL): Define.
	* sysdeps/unix/sysv/linux/i386/kernel-features.h
	(__ASSUME_CONNECT_SYSCALL): Undef if kernel does not support it.
	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
	(__ASSUME_CONNECT_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/s390/kernel-features.h
	(__ASSUME_CONNECT_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
	(__ASSUME_CONNECT_SYSCALL): Likewise.
2017-03-09 15:22:06 +01:00
Adhemerval Zanella 01061a7cab Consolidate Linux accept implementation
This patch consolidates the accept Linux syscall implementation on
sysdeps/unix/sysv/linux/accept.c.  The changes are:

  1. Remove accept from auto-generation syscalls.list on the architecture
     that uses __NR_accept.
  2. Define __NR_accept as default (__ASSUME_ACCEPT_SYSCALL) and undef for
     architectures that do not support it.
  3. Remove __ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL and decide to use
     __NR_accept4 for accept generation based on __ASSUME_ACCEPT4_SYSCALL.

Checked on i686-linux-gnu, x86_64-linux-gnu, x86_64-linux-gnux32,
aarch64-linux-gnu, arm-linux-gnueabihf, and powerpc64le-linux-gnu.

	* sysdeps/unix/sysv/linux/accept.c (__libc_accept): Replace
	__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL by __ASSUME_ACCEPT4_SYSCALL.
	* sysdeps/unix/sysv/linux/alpha/syscalls.list: Remove accept from
	auto-generation list.
	* sysdeps/unix/sysv/linux/arm/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/generic/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/ia64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/i386/kernel-features.h
	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
	(__ASSUME_ACCEPT_SYSCALL): Undefine.
	* sysdeps/unix/sysv/linux/kernel-features.h
	(__ASSUME_ACCEPT_SYSCALL): New define.
	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
	(__ASSUME_ACCEPT_SYSCALL): Define wheter kernel version supports.
	* sysdeps/unix/sysv/linux/microblaze/kernel-features.h
	(__ASSUME_ACCEPT_SYSCALL): Define.
	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
	(__ASSUME_ACCEPT_SYSCALL): Undefine.
	* sysdeps/unix/sysv/linux/s390/kernel-features.h
	(__ASSUME_ACCEPT4_FOR_ACCEPT_SYSCALL): Remove define.
	(__ASSUME_ACCEPT_SYSCALL): Undefine.
	* sysdeps/unix/sysv/linux/sh/kernel-features.h
	(__ASSUME_ACCEPT_SYSCALL): Undefine.
	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
	(__ASSUME_ACCEPT_SYSCALL): Undefine for 32 bits.
2017-03-09 15:22:06 +01:00
Joseph Myers bfff8b1bec Update copyright dates with scripts/update-copyrights. 2017-01-01 00:14:16 +00:00
Joseph Myers 423c2b9d08 Add fromfp functions.
TS 18661-1 defines fromfp functions (fromfp, fromfpx, ufromfp,
ufromfpx, and float and long double variants) to convert from
floating-point to an integer type with any signedness and any given
width up to that of intmax_t, in any of the five IEEE rounding modes
(the usual four for binary floating point, plus rounding to nearest
with ties rounding away from zero), with control of whether in-range
non-integer values should result in the "inexact" exception being
raised.  This patch implements these functions for glibc.

These implementations are (apart from raising exceptions) pure integer
implementations; it's entirely possible optimized versions could be
devised for some architectures.  A common math/fromfp.h header
provides various common helper code that can readily be shared between
the implementations for different types.  For each type, the bulk of
the implementation is also shared between the four functions, with
wrappers that define UNSIGNED and INEXACT macros appropriately before
including the main implementation.

As the functions return intmax_t and uintmax_t without math.h being
allowed to expose those typedef names, they are declared using
__intmax_t and __uintmax_t as obtained from <bits/types.h>.

The FP_INT_* rounding direction macros are defined as ascending
integers in the order the names are listed in the TS; I see no
significant value in allowing architectures to vary the values of
them.

The libm-test machinery is duly adapted to handle unsigned int
arguments, and intmax_t and uintmax_t results.  Because each test
input is generally tested for four functions, five rounding modes and
several different widths, the libm-test.inc additions are very large.
Thus, the diffs in the body of this message exclude the libm-test.inc
changes, with the full patch being attached gzipped.  The bulk of the
new tests were generated (expanded from a test input plus rounding
results and information about where it lies in the relevant interval
between integers, to libm-test tests for all relevant combinations of
function, rounding direction and width) by a script that's included in
the patch as math/gen-fromfp-tests.py (input data
math/gen-fromfp-tests-inputs); as an ad hoc script that's not really
expected to be rerun, it's not very polished, but it's at least
plausibly useful for adding any further tests for these functions in
future.  I may split the libm-test tests up by function in future (so
both libm-test.inc and auto-libm-test-out are split into separate
files, and the tests for each function are also built and run
separately), but not for 2.25.

For no obvious reason, adding tgmath tests for the new functions
resulted in -Wuninitialized errors from test-tgmath.c about the
variable i being used uninitialized.  Those errors were correct - the
variable is read by the frexp version in test-tgmath.c (where real
frexp would write through that pointer instead of reading it) - but I
don't know why this patch would result in the pre-existing issue being
newly detected.  The patch initializes the variable to avoid those
errors.

With these changes, glibc 2.25 should have all the library features
from TS 18661-1 other than the functions that round result to narrower
type (and constant rounding directions, but I'm considering those
mainly a compiler feature not a library one).

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(fromfp): New declaration.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (fromfpx): Likewise.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (ufromfp): Likewise.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (ufromfpx): Likewise.
	* math/tgmath.h (__TGMATH_TERNARY_FIRST_REAL_RET_ONLY): New macro.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (fromfp): Likewise.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (ufromfp): Likewise.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (fromfpx): Likewise.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (ufromfpx): Likewise.
	* math/math.h: Include <bits/types.h>.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_INT_UPWARD): New enum
	constant and macro.
	(FP_INT_DOWNWARD): Likewise.
	(FP_INT_TOWARDZERO): Likewise.
	(FP_INT_TONEARESTFROMZERO): Likewise.
	(FP_INT_TONEAREST): Likewise.
	* math/Versions (fromfp): New libm symbol at version GLIBC_2.25.
	(fromfpf): Likewise.
	(fromfpl): Likewise.
	(ufromfp): Likewise.
	(ufromfpf): Likewise.
	(ufromfpl): Likewise.
	(fromfpx): Likewise.
	(fromfpxf): Likewise.
	(fromfpxl): Likewise.
	(ufromfpx): Likewise.
	(ufromfpxf): Likewise.
	(ufromfpxl): Likewise.
	* math/Makefile (libm-calls): Add s_fromfpF, s_ufromfpF,
	s_fromfpxF and s_ufromfpxF.
	* math/gen-fromfp-tests.py: New file.
	* math/gen-fromfp-tests-inputs: Likewise.
	* math/libm-test.inc: Include <stdint.h>
	(check_intmax_t): New function.
	(check_uintmax_t): Likewise.
	(struct test_fiu_M_data): New type.
	(struct test_fiu_U_data): Likewise.
	(RUN_TEST_fiu_M): New macro.
	(RUN_TEST_LOOP_fiu_M): Likewise.
	(RUN_TEST_fiu_U): Likewise.
	(RUN_TEST_LOOP_fiu_U): Likewise.
	(fromfp_test_data): New array.
	(fromfp_test): New function.
	(fromfpx_test_data): New array.
	(fromfpx_test): New function.
	(ufromfp_test_data): New array.
	(ufromfp_test): New function.
	(ufromfpx_test_data): New array.
	(ufromfpx_test): New function.
	(main): Call fromfp_test, fromfpx_test, ufromfp_test and
	ufromfpx_test.
	* math/gen-libm-test.pl (parse_args): Handle u, M and U descriptor
	characters.
	* math/test-tgmath-ret.c: Include <stdint.h>.
	(rm): New variable.
	(width): Likewise.
	(CHECK_RET_CONST_TYPE): Take extra arguments and pass them to
	called function.
	(CHECK_RET_CONST_FLOAT): Take extra arguments and pass them to
	CHECK_RET_CONST_TYPE.
	(CHECK_RET_CONST_DOUBLE): Likewise.
	(CHECK_RET_CONST_LDOUBLE): Likewise.
	(CHECK_RET_CONST): Take extra arguments and pass them to calls
	macros.
	(fromfp): New CHECK_RET_CONST call.
	(ufromfp): Likewise.
	(fromfpx): Likewise.
	(ufromfpx): Likewise.
	(do_test): Call check_return_fromfp, check_return_ufromfp,
	check_return_fromfpx and check_return_ufromfpx.
	* math/test-tgmath.c: Include <stdint.h>
	(NCALLS): Increase to 138.
	(F(compile_test)): Initialize i.  Call fromfp functions.
	(F(fromfp)): New function.
	(F(fromfpx)): Likewise.
	(F(ufromfp)): Likewise.
	(F(ufromfpx)): Likewise.
	* manual/arith.texi (Rounding Functions): Document FP_INT_UPWARD,
	FP_INT_DOWNWARD, FP_INT_TOWARDZERO, FP_INT_TONEARESTFROMZERO,
	FP_INT_TONEAREST, fromfp, fromfpf, fromfpl, ufromfp, ufromfpf,
	ufromfpl, fromfpx, fromfpxf, fromfpxl, ufromfpx, ufromfpxf and
	ufromfpxl.
	* manual/libm-err-tab.pl (@all_functions): Add fromfp, fromfpx,
	ufromfp and ufromfpx.
	* math/fromfp.h: New file.
	* sysdeps/ieee754/dbl-64/s_fromfp.c: Likewise.
	* sysdeps/ieee754/dbl-64/s_fromfp_main.c: Likewise.
	* sysdeps/ieee754/dbl-64/s_fromfpx.c: Likewise.
	* sysdeps/ieee754/dbl-64/s_ufromfp.c: Likewise.
	* sysdeps/ieee754/dbl-64/s_ufromfpx.c: Likewise.
	* sysdeps/ieee754/flt-32/s_fromfpf.c: Likewise.
	* sysdeps/ieee754/flt-32/s_fromfpf_main.c: Likewise.
	* sysdeps/ieee754/flt-32/s_fromfpxf.c: Likewise.
	* sysdeps/ieee754/flt-32/s_ufromfpf.c: Likewise.
	* sysdeps/ieee754/flt-32/s_ufromfpxf.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_fromfpl.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_fromfpl_main.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_fromfpxl.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_ufromfpl.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_ufromfpxl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_fromfpl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_fromfpl_main.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_fromfpxl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_ufromfpl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_ufromfpxl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_fromfpl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_fromfpl_main.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_fromfpxl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_ufromfpl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_ufromfpxl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add fromfp,
	ufromfp, fromfpx and ufromfpx.
	(CFLAGS-nldbl-fromfp.c): New variable.
	(CFLAGS-nldbl-fromfpx.c): Likewise.
	(CFLAGS-nldbl-ufromfp.c): Likewise.
	(CFLAGS-nldbl-ufromfpx.c): Likewise.
	* sysdeps/ieee754/ldbl-opt/nldbl-compat.h: Include <stdint.h>.
	* sysdeps/ieee754/ldbl-opt/nldbl-fromfp.c: New file.
	* sysdeps/ieee754/ldbl-opt/nldbl-fromfpx.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/nldbl-ufromfp.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/nldbl-ufromfpx.c: Likewise.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-12-31 00:40:59 +00:00
Adhemerval Zanella 38cee35b0c Consolidate Linux semtimedop implementation
This patch consolidates the semtimedop Linux implementation in only
one default file, sysdeps/unix/sysv/linux/semtimedop.c.  If tries to use
the direct syscall if it is supported, otherwise will use the old ipc
multiplex mechanism.

Checked on x86_64, i686, powerpc64le, aarch64, and armhf.

	* sysdeps/unix/sysv/linux/alpha/syscalls.list (semtimedop): Remove.
	* sysdeps/unix/sysv/linux/arm/syscalls.list (semtimedop): Likewise.
	* sysdeps/unix/sysv/linux/generic/syscalls.list (semtimedop):
	Likewise.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list (semtimedop): Likewise.
	* sysdeps/unix/sysv/linux/ia64/syscalls.list (semtimedop): Likewise.
	* sysdeps/unix/sysv/linux/microblaze/syscalls.list (semtimedop):
	Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/syscalls.list (semtimedop):
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/syscalls.list (semtimedop): Likewise.
	* sysdeps/unix/sysv/linux/m68k/semtimedop.S: Remove file.
	* sysdeps/unix/sysv/linux/s390/semtimedop.c: Reorganize headers and
	add a comment about s390 syscall difference from default one.
	* sysdeps/unix/sysv/linux/semtimedop.c (semtimedop): Use semtimedop
	syscall if it is defined.
2016-12-28 20:31:04 -02:00
Adhemerval Zanella 63719cf1e3 Add __ASSUME_DIRECT_SYSVIPC_SYSCALL for Linux
On current minimum supported kernels, the SysV IPC on Linux is provided
by either the ipc syscalls or correspondent wire syscalls.  Also, for
architectures that supports wire syscalls all syscalls are supported
in a set (msgct, msgrcv, msgsnd, msgget, semctl, semget, semop, semtimedop,
shmctl, shmat, shmget, shmdt).

The architectures that only supports ipc syscall are:

  - i386, m68k, microblaze, mips32, powerpc (powerpc32, powerpc64, and
    powerpc64le), s390 (32 and 64 bits), sh, sparc32, and sparc64.

And the architectures that only supports wired syscalls are:

  - aarch64, alpha, hppa, ia64, mips64, mips64n32, nios2, tile
    (tilepro, tilegx, and tilegx64), and x86_64

Also arm is the only one that supports both wire syscalls and the
ipc, although the ipc one is deprecated.

This patch adds a new define, __ASSUME_DIRECT_SYSVIPC_SYSCALL, that wired
syscalls are supported on the system and the general idea is to use
it where possible.

I also checked the syscall table for all architectures on Linux 4.9
and there is no change on described support for Linux 2.6.32/3.2.

	* sysdeps/unix/sysv/linux/kernel-features.h
	(__ASSUME_DIRECT_SYSVIPC_SYSCALL): New define.
	* sysdeps/unix/sysv/linux/i386/kernel-features.h
	(__ASSUME_DIRECT_SYSVIPC_SYSCALL): Undef.
	* sysdeps/unix/sysv/linux/m68k/kernel-features.h
	(__ASSUME_DIRECT_SYSVIPC_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/mips/kernel-features.h
	(__ASSUME_DIRECT_SYSVIPC_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/kernel-features.h
	(__ASSUME_DIRECT_SYSVIPC_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/s390/kernel-features.h
	(__ASSUME_DIRECT_SYSVIPC_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/sh/kernel-features.h
	(__ASSUME_DIRECT_SYSVIPC_SYSCALL): Likewise.
	* sysdeps/unix/sysv/linux/sparc/kernel-features.h
	(__ASSUME_DIRECT_SYSVIPC_SYSCALL): Likewise.
2016-12-28 20:28:56 -02:00
Joseph Myers 41c67149b9 Add roundeven, roundevenf, roundevenl.
TS 18661-1 defines roundeven functions that round a floating-point
number to the nearest integer, in that floating-point type, with ties
rounding to even (whereas the round functions round ties away from
zero).  As with other such functions, they raise no exceptions apart
from "invalid" for signaling NaNs.  There was a previous user request
for this functionality in glibc in
<https://sourceware.org/ml/libc-help/2015-02/msg00005.html>.

This patch implements these functions for glibc.  The implementations
use integer bit-manipulation (or roundeven on the high and low parts,
in the IBM long double case).  It's possible that there may be faster
approaches on some architectures (in particular, on AArch64 the frintn
instruction should do exactly what's required); I'll leave it to
architecture maintainers or others interested to implement such
architecture-specific versions if desired.  (Where architectures have
instructions to round to nearest integer in the current rounding mode,
implementations saving and restoring the rounding mode - and dealing
with exceptions if those instructions generate "inexact" - are also
possible, though their performance depends on the cost of manipulating
exceptions / rounding mode state.)

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(roundeven): New declaration.
	* math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (roundeven): New
	macro.
	* math/Versions (roundeven): New libm symbol at version
	GLIBC_2.25.
	(roundevenf): Likewise.
	(roundevenl): Likewise.
	* math/Makefile (libm-calls): Add s_roundevenF.
	* math/libm-test.inc (roundeven_test_data): New array.
	(roundeven_test): New function.
	(main): Call roundeven_test.
	* math/test-tgmath.c (NCALLS): Increase to 134.
	(F(compile_test)): Call roundeven.
	(F(roundeven)): New function.
	* manual/arith.texi (Rounding Functions): Document roundeven,
	roundevenf and roundevenl.
	* manual/libm-err-tab.pl (@all_functions): Add roundeven.
	* include/math.h (roundeven): Use libm_hidden_proto.
	* sysdeps/ieee754/dbl-64/s_roundeven.c: New file.
	* sysdeps/ieee754/dbl-64/wordsize-64/s_roundeven.c: Likewise.
	* sysdeps/ieee754/flt-32/s_roundevenf.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_roundevenl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_roundevenl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_roundevenl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
	roundeven.
	(CFLAGS-nldbl-roundeven.c): New variable.
	* sysdeps/ieee754/ldbl-opt/nldbl-roundeven.c: New file.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-12-21 01:48:27 +00:00
Joseph Myers 525f803984 Add fmaxmag, fminmag functions.
TS 18661-1 defines fmaxmag and fminmag functions that return the
argument with maximum / minimum magnitude (acting like fmax / fmin if
the arguments have the same magnitude or either argument is a NaN).
These correspond to the IEEE 754-2008 operations maxNumMag and
minNumMag.  This patch implements these functions for glibc.  They are
implemented with type-generic templates.  Tests are based on those for
fmax and fmin.

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(fmaxmag): New declaration.
	(fminmag): Likewise.
	* math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (fmaxmag): New
	macro.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (fminmag): Likewise.
	* math/Versions (fmaxmag): New libm symbol at version GLIBC_2.25.
	(fmaxmagf): Likewise.
	(fmaxmagl): Likewise.
	(fminmag): Likewise.
	(fminmagf): Likewise.
	(fminmagl): Likewise.
	* math/Makefile (gen-libm-calls): Add s_fmaxmagF and s_fminmagF.
	* math/s_fmaxmag_template.c: New file.
	* math/s_fminmag_template.c: Likewise.
	* math/libm-test.inc (fmaxmag_test_data): New array.
	(fmaxmag_test): New function.
	(fminmag_test_data): New array.
	(fminmag_test): New function.
	(main): Call fmaxmag_test and fminmag_test.
	* math/test-tgmath.c (NCALLS): Increase to 132.
	(F(compile_test)): Call fmaxmag and fminmag.
	(F(fminmag)): New function.
	(F(fmaxmag)): Likewise.
	* manual/arith.texi (Misc FP Arithmetic): Document fminmag,
	fminmagf, fminmagl, fmaxmag, fmaxmagf and fmaxmagl.
	* manual/libm-err-tab.pl (@all_functions): Add fmaxmag and
	fminmag.
	* sysdeps/ieee754/ldbl-opt/nldbl-fmaxmag.c: New file.
	* sysdeps/ieee754/ldbl-opt/nldbl-fminmag.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/s_fmaxmagl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/s_fminmagl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add fmaxmag
	and fminmag.
	(CFLAGS-nldbl-fmaxmag.c): New variable.
	(CFLAGS-nldbl-fminmag.c): Likewise.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-12-20 00:46:53 +00:00
Zack Weinberg ea1bd74def New string function explicit_bzero (from OpenBSD).
explicit_bzero(s, n) is the same as memset(s, 0, n), except that the
compiler is not allowed to delete a call to explicit_bzero even if the
memory pointed to by 's' is dead after the call.  Right now, this effect
is achieved externally by having explicit_bzero be a function whose
semantics are unknown to the compiler, and internally, with a no-op
asm statement that clobbers memory.  This does mean that small
explicit_bzero operations cannot be expanded inline as small memset
operations can, but on the other hand, small memset operations do get
deleted by the compiler.  Hopefully full compiler support for
explicit_bzero will happen relatively soon.

There are two new tests: test-explicit_bzero.c verifies the
visible semantics in the same way as the existing test-bzero.c,
and tst-xbzero-opt.c verifies the not-being-optimized-out property.
The latter is conceptually based on a test written by Matthew Dempsky
for the OpenBSD regression suite.

The crypt() implementation has an immediate use for this new feature.
We avoid having to add a GLIBC_PRIVATE alias for explicit_bzero
by running all of libcrypt's calls through the fortified variant,
__explicit_bzero_chk, which is in the impl namespace anyway.  Currently
I'm not aware of anything in libc proper that needs this, but the
glue is all in place if it does become necessary.  The legacy DES
implementation wasn't bothering to clear its buffers, so I added that,
mostly for consistency's sake.

	* string/explicit_bzero.c: New routine.
	* string/test-explicit_bzero.c, string/tst-xbzero-opt.c: New tests.
	* string/Makefile (routines, strop-tests, tests): Add them.
	* string/test-memset.c: Add ifdeffage for testing explicit_bzero.
	* string/string.h [__USE_MISC]: Declare explicit_bzero.

	* debug/explicit_bzero_chk.c: New routine.
	* debug/Makefile (routines): Add it.
	* debug/tst-chk1.c: Test fortification of explicit_bzero.
	* string/bits/string3.h: Fortify explicit_bzero.

	* manual/string.texi: Document explicit_bzero.
	* NEWS: Mention addition of explicit_bzero.

	* crypt/crypt-entry.c (__crypt_r): Clear key-dependent intermediate
	data before returning, using explicit_bzero.
	* crypt/md5-crypt.c (__md5_crypt_r): Likewise.
	* crypt/sha256-crypt.c (__sha256_crypt_r): Likewise.
	* crypt/sha512-crypt.c (__sha512_crypt_r): Likewise.

	* include/string.h: Redirect internal uses of explicit_bzero
	to __explicit_bzero_chk[_internal].
	* string/Versions [GLIBC_2.25]: Add explicit_bzero.
	* debug/Versions [GLIBC_2.25]: Add __explicit_bzero_chk.
	* sysdeps/arm/nacl/libc.abilist
	* sysdeps/unix/sysv/linux/aarch64/libc.abilist
	* sysdeps/unix/sysv/linux/alpha/libc.abilist
	* sysdeps/unix/sysv/linux/arm/libc.abilist
	* sysdeps/unix/sysv/linux/hppa/libc.abilist
	* sysdeps/unix/sysv/linux/i386/libc.abilist
	* sysdeps/unix/sysv/linux/ia64/libc.abilist
	* sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist
	* sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist
	* sysdeps/unix/sysv/linux/microblaze/libc.abilist
	* sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist
	* sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist
	* sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist
	* sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist
	* sysdeps/unix/sysv/linux/nios2/libc.abilist
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc-le.abilist
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libc.abilist
	* sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist
	* sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist
	* sysdeps/unix/sysv/linux/sh/libc.abilist
	* sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist
	* sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libc.abilist
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libc.abilist
	* sysdeps/unix/sysv/linux/tile/tilepro/libc.abilist
	* sysdeps/unix/sysv/linux/x86_64/64/libc.abilist
	* sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist:
	Add entries for explicit_bzero and __explicit_bzero_chk.
2016-12-16 16:21:54 -05:00
Florian Weimer 92dcaa3e2f Add getentropy, getrandom, <sys/random.h> [BZ #17252] 2016-12-12 17:28:04 +01:00
Joseph Myers 55a38f8236 Add llogb, llogbf, llogbl.
TS 18661-1 defines llogb functions that are like ilogb except that
they return long int instead of int.  Corresponding FP_LLOGB* macros
are defined, whose values are required to have the obvious
correspondence to those of the FP_ILOGB* macros.

This patch implements these functions and macros for glibc.  llogb
uses the type-generic infrastructure, with an implementation similar
to the wrapper for ilogb but with additional conversion from FP_ILOGB*
to FP_LLOGB*; this approach avoids needing to modify or duplicate any
of the architecture-specific ilogb implementations.  Tests are also
based on those for ilogb.

Ideally the llogb functions would alias the ilogb ones when long is
32-bit, but such aliasing requires the associated header declarations
of the different-type alias to be hidden, typically by defining macros
before including the header (see e.g. how
sysdeps/ieee754/dbl-64/wordsize-64/s_llround.c defines lround to
__hidden_lround before including <math.h>).  The infrastructure for
type-generic function implementations does not support defining such
macros at present (since C code can't define a macro whose name is
determined by other macros).  So this patch leaves them as separate
functions (similar to e.g. scalbln and scalbn being separate in such a
case as well), but with the remapping of FP_ILOGB* to FP_LLOGB*
conditioned out in the case where it would be the identity map.

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (llogb):
	New declaration.
	* math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (llogb): New
	macro.
	* math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (__FP_LONG_MAX):
	New macro.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_LLOGB0): Likewise.
	[__GLIBC_USE (IEC_60559_BFP_EXT)] (FP_LLOGBNAN): Likewise.
	* math/Versions (llogb): New libm symbol at version GLIBC_2.25.
	(llogbf): Likewise.
	(llogbl): Likewise.
	* math/Makefile (gen-libm-calls): Add w_llogbF.
	(tests): Add test-fp-llogb-constants.
	* math/w_llogb_template.c: New file.  Based on
	math/w_ilogb_template.c.
	* math/libm-test.inc (llogb_test_data): New array.
	(llogb_test): New function.
	(main): Call llogb_test.
	* math/test-fp-llogb-constants.c: New file.  Based on
	math/test-fp-ilogb-constants.c.
	* math/test-tgmath-ret.c (llogb): New CHECK_RET_CONST call.
	(do_test): Call check_return_llogb.
	* math/test-tgmath.c (NCALLS): Increase to 126.
	(F(compile_test)): Call llogb.
	(F(llogb)): New function.
	* manual/math.texi (Exponents and Logarithms): Document llogb,
	llogbf, llogbl, FP_LLOGB0 and FP_LLOGBNAN.
	* manual/libm-err-tab.pl (@all_functions): Add llogb.
	* sysdeps/ieee754/ldbl-opt/nldbl-llogb.c: New file.
	* sysdeps/ieee754/ldbl-opt/w_llogbl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add llogb.
	(CFLAGS-nldbl-llogb.c): New variable.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-12-02 01:42:49 +00:00
Florian Weimer b04beebf07 ld.so: Remove __libc_memalign
It is no longer needed since commit 6c444ad6e9
(elf: Do not use memalign for TCB/TLS blocks allocation [BZ #17730]).
Applications do not link against ld.so and will use the definition in
libc.so, so there is no ABI impact.
2016-11-30 16:23:58 +01:00
Florian Weimer 9e78f6f6e7 Implement _dl_catch_error, _dl_signal_error in libc.so [BZ #16628]
This change moves the main implementation of _dl_catch_error,
_dl_signal_error to libc.so, where TLS variables can be used
directly.  This removes a writable function pointer from the
rtld_global variable.

For use during initial relocation, minimal implementations of these
functions are provided in ld.so.  These are eventually interposed
by the libc.so implementations.  This is implemented by compiling
elf/dl-error-skeleton.c twice, via elf/dl-error.c and
elf/dl-error-minimal.c.

As a side effect of this change, the static version of dl-error.c
no longer includes support for the
_dl_signal_cerror/_dl_receive_error mechanism because it is only
used in ld.so.
2016-11-30 15:59:57 +01:00
Joseph Myers 457663a7cd Add setpayloadsig, setpayloadsigf, setpayloadsigl.
TS 18661-1 defines functions for manipulating the payloads of NaNs.
This patch implements the setpayloadsig functions for glibc; these are
like the setpayload functions, but produce a signaling NaN instead of
a quiet NaN.

The substance of the implementation was included with the setpayload
implementation, so the new files here just need to wrap the main files
with different defines to build the new functions.

Because the functions store a signaling NaN via a pointer and the
libm-test macros choose a suitable initial value for the variable in
such a case by comparing with the expected value, the relevant macro
needs to clear exceptions after FE_INVALID may have been raised by
that comparison.

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(setpayloadsig): New declaration.
	* math/Versions (setpayloadsig): New libm symbol at version
	GLIBC_2.25.
	(setpayloadsigf): Likewise.
	(setpayloadsigl): Likewise.
	* math/Makefile (libm-calls): Add s_setpayloadsigF.
	* math/libm-test.inc (RUN_TEST_Ff_b1): Call feclearexcept
	(FE_ALL_EXCEPT) after initializing EXTRA_VAR.
	(setpayloadsig_test_data): New array.
	(setpayloadsig_test): New function.
	(main): Call setpayloadsig_test.
	* manual/arith.texi (FP Bit Twiddling): Document setpayloadsig,
	setpayloadsigf and setpayloadsigl.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/ieee754/dbl-64/s_setpayloadsig.c: New file.
	* sysdeps/ieee754/flt-32/s_setpayloadsigf.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_setpayloadsigl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_setpayloadsigl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_setpayloadsigl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/nldbl-setpayloadsig.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
	setpayloadsig.
	(CFLAGS-nldbl-setpayloadsig.c): New variable.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-11-24 23:56:48 +00:00
Adhemerval Zanella c579f48edb Remove cached PID/TID in clone
This patch remove the PID cache and usage in current GLIBC code.  Current
usage is mainly used a performance optimization to avoid the syscall,
however it adds some issues:

  - The exposed clone syscall will try to set pid/tid to make the new
    thread somewhat compatible with current GLIBC assumptions.  This cause
    a set of issue with new workloads and usecases (such as BZ#17214 and
    [1]) as well for new internal usage of clone to optimize other algorithms
    (such as clone plus CLONE_VM for posix_spawn, BZ#19957).

  - The caching complexity also added some bugs in the past [2] [3] and
    requires more effort of each port to handle such requirements (for
    both clone and vfork implementation).

  - Caching performance gain in mainly on getpid and some specific
    code paths.  The getpid performance leverage is questionable [4],
    either by the idea of getpid being a hotspot as for the getpid
    implementation itself (if it is indeed a justifiable hotspot a
    vDSO symbol could let to a much more simpler solution).

    Other usage is mainly for non usual code paths, such as pthread
    cancellation signal and handling.

For thread creation (on stack allocation) the code simplification in fact
adds some performance gain due the no need of transverse the stack cache
and invalidate each element pid.

Other thread usages will require a direct getpid syscall, such as
cancellation/setxid signal, thread cancellation, thread fail path (at
create_thread), and thread signal (pthread_kill and pthread_sigqueue).
However these are hardly usual hotspots and I think adding a syscall is
justifiable.

It also simplifies both the clone and vfork arch-specific implementation.
And by review each fork implementation there are some discrepancies that
this patch also solves:

  - microblaze clone/vfork does not set/reset the pid/tid field
  - hppa uses the default vfork implementation that fallback to fork.
    Since vfork is deprecated I do not think we should bother with it.

The patch also removes the TID caching in clone. My understanding for
such semantic is try provide some pthread usage after a user program
issue clone directly (as done by thread creation with CLONE_PARENT_SETTID
and pthread tid member).  However, as stated before in multiple discussions
threads, GLIBC provides clone syscalls without further supporting all this
semantics.

I ran a full make check on x86_64, x32, i686, armhf, aarch64, and powerpc64le.
For sparc32, sparc64, and mips I ran the basic fork and vfork tests from
posix/ folder (on a qemu system).  So it would require further testing
on alpha, hppa, ia64, m68k, nios2, s390, sh, and tile (I excluded microblaze
because it is already implementing the patch semantic regarding clone/vfork).

[1] https://codereview.chromium.org/800183004/
[2] https://sourceware.org/ml/libc-alpha/2006-07/msg00123.html
[3] https://sourceware.org/bugzilla/show_bug.cgi?id=15368
[4] http://yarchive.net/comp/linux/getpid_caching.html

	* sysdeps/nptl/fork.c (__libc_fork): Remove pid cache setting.
	* nptl/allocatestack.c (allocate_stack): Likewise.
	(__reclaim_stacks): Likewise.
	(setxid_signal_thread): Obtain pid through syscall.
	* nptl/nptl-init.c (sigcancel_handler): Likewise.
	(sighandle_setxid): Likewise.
	* nptl/pthread_cancel.c (pthread_cancel): Likewise.
	* sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Likewise.
	* sysdeps/unix/sysv/linux/pthread_sigqueue.c (pthread_sigqueue):
	Likewise.
	* sysdeps/unix/sysv/linux/createthread.c (create_thread): Likewise.
	* sysdeps/unix/sysv/linux/getpid.c: Remove file.
	* nptl/descr.h (struct pthread): Change comment about pid value.
	* nptl/pthread_getattr_np.c (pthread_getattr_np): Remove thread
	pid assert.
	* sysdeps/unix/sysv/linux/pthread-pids.h (__pthread_initialize_pids):
	Do not set pid value.
	* nptl_db/td_ta_thr_iter.c (iterate_thread_list): Remove thread
	pid cache check.
	* nptl_db/td_thr_validate.c (td_thr_validate): Likewise.
	* sysdeps/aarch64/nptl/tcb-offsets.sym: Remove pid offset.
	* sysdeps/alpha/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/arm/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/hppa/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/i386/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/ia64/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/m68k/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/microblaze/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/mips/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/nios2/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/powerpc/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/s390/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/sh/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/sparc/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/tile/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/x86_64/nptl/tcb-offsets.sym: Likewise.
	* sysdeps/unix/sysv/linux/aarch64/clone.S: Remove pid and tid caching.
	* sysdeps/unix/sysv/linux/alpha/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/arm/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/hppa/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/ia64/clone2.S: Likewise.
	* sysdeps/unix/sysv/linux/mips/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/nios2/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/sh/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/tile/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/aarch64/vfork.S: Remove pid set and reset.
	* sysdeps/unix/sysv/linux/alpha/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/arm/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/i386/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/ia64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/m68k/clone.S: Likewise.
	* sysdeps/unix/sysv/linux/m68k/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/mips/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/nios2/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/sh/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/tile/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/vfork.S: Likewise.
	* sysdeps/unix/sysv/linux/tst-clone2.c (f): Remove direct pthread
	struct access.
	(clone_test): Remove function.
	(do_test): Rewrite to take in consideration pid is not cached anymore.
2016-11-24 19:38:51 -02:00
Joseph Myers eb3c12c784 Add setpayload, setpayloadf, setpayloadl.
TS 18661-1 defines functions for manipulating the payloads of NaNs.
This patch implements the setpayload functions for glibc; these set a
number (pointed to by a function argument) to a quiet NaN with the
given payload, or to +0 if the given payload is not valid.  The
implementations are structured to allow the substance of the
implementation to be shared with the setpayloadsig functions when
those are added.

The semantics in the TS are not entirely clear in the case where the
payload passed to the function is zero (see discussion on the WG14
reflector last month).  This patch implements what seems the most
sensible interpretation, that -0 is never valid to give as the
payload, but +0 is valid in the case where the kind of NaN being
generated has its high mantissa bit set so payload 0 is actually
possible in such a NaN.

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(setpayload): New declaration.
	* math/Versions (setpayload): New libm symbol at version
	GLIBC_2.25.
	(setpayloadf): Likewise.
	(setpayloadl): Likewise.
	* math/Makefile (libm-calls): Add s_setpayloadF.
	* math/libm-test.inc (struct test_Ffp_b1_data): Rename to struct
	test_Ff_b1_data.
	(RUN_TEST_Ff_b1): New macro.
	(RUN_TEST_LOOP_Ff_b1): Likewise.
	(canonicalize_test_data): Update type.
	(setpayload_test_data): New array.
	(setpayload_test): New function.
	(main): Call setpayload_test.
	* manual/arith.texi (FP Bit Twiddling): Document setpayload,
	setpayloadf and setpayloadl.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/ieee754/dbl-64/s_setpayload.c: New file.
	* sysdeps/ieee754/dbl-64/s_setpayload_main.c: Likewise.
	* sysdeps/ieee754/dbl-64/wordsize-64/s_setpayload_main.c:
	Likewise.
	* sysdeps/ieee754/flt-32/s_setpayloadf.c: Likewise.
	* sysdeps/ieee754/flt-32/s_setpayloadf_main.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_setpayloadl.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_setpayloadl_main.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_setpayloadl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_setpayloadl_main.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_setpayloadl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_setpayloadl_main.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/nldbl-setpayload.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
	setpayload.
	(CFLAGS-nldbl-setpayload.c): New variable.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-11-19 00:16:28 +00:00
Adhemerval Zanella 045c13d185 Consolidate Linux setrlimit and getrlimit implementation
This patch consolidates all Linux setrlimit and getrlimit on the default
sysdeps/unix/sysv/linux/{set,get}rlimit{64}.c.  It contains two exceptions:

  1. mips32 and mips64n32 which requires a versioned symbol for GLIBC 2.19
     and higher due a broken RLIM64_INFINITY constant.
  2. sparc32 does not define a compat symbol for getrlimit64 for old 2GB
     limit. I am not sure if it is required, but a RLIM_INFINITY fix [1]
     change its definition without adding a compat symbol.  This patch does
     not aim to address this possible issue, it follow current symbol
     export.

The default implementation uses prlimit64 for 64 bit rlim_t ({set,get}rlimit64)
and if it fails with ENOSYS it fall back to {get,set}rlimit syscall.  This
code path is only used on kernel older than 2.6.36 (basically now only x86)
and I avoid to user __ASSUME_PRLIMTI64 to simplify the implementation.  Once
x86 moves to be on par with other architectures regarding minimum kernel
supported we can get rid of using old syscalls and default path.

A new type size define is added, __RLIM_T_MATCHES_RLIM64_T, where is set as
default for 64 bits ports.  This allows the default implementation to avoid
{get,set}rlimit building and alias {get,set}rlimit64 to {get,set}rlimit.

Checked on x86_64, i386, armhf, aarch64, and powerpc64le.  I also did a
sanity build plus check-abi on all other supported architectures.

[1] Commit 9c96ff2385

	Adhemerval Zanella  <adhemerval.zanella@linaro.org>
	Yury Norov  <ynorov@caviumnetworks.com>

	* bits/typesizes.h (__RLIM_T_MATCHES_RLIM64_T): define.
	* sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/generic/bits/typesizes.h
	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/s390/bits/typesizes.h [__s390x__]
	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
	[__arch64__ || __sparcv9] (__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/x86/bits/typesizes.h [__86_64__]
	(__RLIM_T_MATCHES_RLIM64_T): Likewise.
	* sysdeps/unix/sysv/linux/arm/Makefile [$(subdir) = resource]
	(sysdep_routines): Remove oldgetrlimit64.
	* sysdeps/unix/sysv/linux/i386/Makefile [$(subdir) = resource]
	(sysdep_routines): Likewise.
	* sysdeps/unix/sysv/linux/m68k/Makefile [$(subdir) = resource]
	(sysdep_routines): Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/Makefile
	[$(subdir) = resource] (sysdep_routines): Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/Makefile
	[$(subdir) = resource] (sysdep_routines): Likewise.
	* sysdeps/unix/sysv/linux/arm/getrlimit64.c: Remove file.
	* sysdeps/unix/sysv/linux/arm/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/hppa/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/i386/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/m68k/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/oldgetrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/sh/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/setrlimit64.c: Likewise.
	* sysdeps/sysv/linux/generic/wordsize-32/syscalls.list: Remove
	setrlimit and getrlimit.
	* sysdeps/unix/sysv/linux/hppa/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/i386/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/wordsize-64/syscalls.list: Likewise.
	* sysdeps/unix/sysv/linux/getrlimit.c: New file.
	* sysdeps/unix/sysv/linux/sparc/getrlimit64.c: Likewise.
	* sysdeps/unix/sysv/linux/setrlimit.c: Likewise.
	* sysdeps/unix/sysv/linux/getrlimit64.c (__getrlimit64): Handle
	__RLIM_T_MATCHES_RLIM64_T and add alias if defined.
	(__old_getrlimit64): Add compatibility symbol.
	* sysdeps/unix/sysv/linux/setrlimit64.c (__setrlimit): Likewise.
2016-11-17 15:54:22 -02:00
Joseph Myers eaf5ad0bc4 Add canonicalize, canonicalizef, canonicalizel.
TS 18661-1 defines canonicalize functions to produce a canonical
version of a floating-point representation.  This patch implements
these functions for glibc.

As with the iscanonical macro, these functions are oriented to the
decimal floating-point case, where some values have both canonical and
noncanonical representations.  However, the functions have a return
value that says whether they succeeded in storing a canonical result;
thus, they can fail for the case of an invalid representation (while
still not making any particular choice from among multiple equally
canonical valid representations of the same value).  Since no
floating-point formats in glibc actually have noncanonical valid
representations, a type-generic implementation of these functions can
be used that expects iscanonical to return 0 only for invalid
representations.  Now that iscanonical is used within libm.so,
libm_hidden_proto / libm_hidden_def are added for __iscanonicall.

The definition of these functions is intended to correspond to a
convertFormat operation to the same floating-point format.  Thus, they
convert signaling NaNs to quiet NaNs, raising the "invalid" exception.
Such a conversion "should" produce "the canonical version of that
signaling NaN made quiet".

libm-test.inc is made to check NaN payloads for the output of these
functions, a new feature (at some point manipulation functions such as
fabs and copysign should have tests added that verify payload
preservation for them).  As however some architectures may not follow
the recommended practice of preserving NaN payloads when converting a
signaling NaN to quiet, a new math-tests.h macro
SNAN_TESTS_PRESERVE_PAYLOAD is added, and defined to 0 for non-NAN2008
MIPS; any other architectures seeing test failures for lack of payload
preservation in this case should also define this macro to 0.  (If any
cases arise where the sign isn't preserved either, those should have a
similar macro added.)

The ldbl-96 and ldbl-128ibm tests of iscanonical are renamed and
adapted to test canonicalizel as well on the same representations.

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(canonicalize): New declaration.
	* math/Versions (canonicalize): New libm symbol at version
	GLIBC_2.25.
	(canonicalizef): Likewise.
	(canonicalizel): Likewise.
	* math/Makefile (gen-libm-calls): Add s_canonicalizeF.
	* math/s_canonicalize_template.c: New file.
	* math/libm-test.inc: Update comment on functions tested and
	testing of NaN payloads.
	(TEST_NAN_PAYLOAD): New macro.
	(NO_TEST_INLINE): Update value.
	(XFAIL_TEST): Likewise.
	(ERRNO_UNCHANGED): Likewise.
	(ERRNO_EDOM): Likewise.
	(ERRNO_ERANGE): Likewise.
	(IGNORE_RESULT): Likewise.
	(NON_FINITE): Likewise.
	(TEST_SNAN): Likewise.
	(NO_TEST_MATHVEC): Likewise.
	(TEST_NAN_PAYLOAD_CANONICALIZE): New macro.
	(check_float_internal): Check NaN payloads if TEST_NAN_PAYLOAD.
	(struct test_Ffp_b1_data): New type.
	(RUN_TEST_Ffp_b1): New macro.
	(RUN_TEST_LOOP_Ffp_b1): Likewise.
	(canonicalize_test_data): New array.
	(canonicalize_test): New function.
	(main): Call canonicalize_test.
	* manual/arith.texi (FP Bit Twiddling): Document canonicalize,
	canonicalizef and canonicalizel.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/ieee754/ldbl-opt/nldbl-canonicalize.c: New file.
	* sysdeps/ieee754/ldbl-opt/s_canonicalizel.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
	canonicalize.
	(CFLAGS-nldbl-canonicalize.c): New variable.
	* sysdeps/ieee754/ldbl-128ibm/test-iscanonical-ldbl-128ibm.c: Move
	to ...
	* sysdeps/ieee754/ldbl-128ibm/test-canonical-ldbl-128ibm.c:
	... here.
	(do_test): Also test canonicalizel.
	* sysdeps/ieee754/ldbl-128ibm/Makefile (tests): Change
	test-iscanonical-ldbl-128ibm to test-canonical-ldbl-128ibm.
	* sysdeps/ieee754/ldbl-128ibm/include/bits/iscanonical.h: New
	file.
	* sysdeps/ieee754/ldbl-128ibm/s_iscanonicall.c (__iscanonicall):
	Use libm_hidden_def.
	* sysdeps/ieee754/ldbl-96/test-iscanonical-ldbl-96.c: Move to ...
	* sysdeps/ieee754/ldbl-96/test-canonical-ldbl-96.c: ... here.
	(do_test): Also test canonicalizel.
	* sysdeps/ieee754/ldbl-96/Makefile (tests): Change
	test-iscanonical-ldbl-96 to test-canonical-ldbl-96.
	* sysdeps/ieee754/ldbl-96/include/bits/iscanonical.h: New file.
	* sysdeps/ieee754/ldbl-96/s_iscanonicall.c (__iscanonicall): Use
	libm_hidden_def.
	* sysdeps/generic/math-tests.h (SNAN_TESTS_PRESERVE_PAYLOAD): New
	macro.
	* sysdeps/mips/math-tests.h [__mips_hard_float && !__mips_nan2008]
	(SNAN_TESTS_PRESERVE_PAYLOAD): Likewise.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-10-26 23:14:31 +00:00
Gabriel F. T. Gomes 6962682ffe Add strfromd, strfromf, and strfroml functions
ISO/IEC TS 18661-1 adds several functions in the strfrom family to stdlib.
This patch adds strfromd, strfromf, and strfroml.  This is being done in
preparation for the new floating-point type, float128.  The added functions
convert a floating-point value into a string, with configurable format.
2016-10-25 17:03:54 -02:00
Joseph Myers f8e8b8ed9f Add getpayload, getpayloadf, getpayloadl.
TS 18661-1 defines functions for manipulating the payloads of NaNs.
This patch implements the getpayload functions for glibc; these
extract the NaN payload (from an argument passed as a pointer, for
which corresponding libm-test support is added) and return it in the
same floating-point type.  The return value of these functions is
unspecified for non-NaN arguments; the patch does the simplest thing
to implement, which is that the functions do not check whether the
argument is a NaN and just treat the relevant bits of the
representation as a payload regardless.  A conversion from integer to
floating-point is used to produce the required return value, except in
the ldbl-128 case; as 128-bit integers are not supported for all
configurations using ldbl-128, the code constructs the required
floating-point representation of the return value directly instead.

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(getpayload): New declaration.
	* math/Versions (getpayload): New libm symbol at version
	GLIBC_2.25.
	(getpayloadf): Likewise.
	(getpayloadl): Likewise.
	* math/Makefile (libm-calls): Add s_getpayloadF.
	* math/libm-test.inc: Include <nan-high-order-bit.h>.
	(struct test_f_f_data): Add comment.
	(RUN_TEST_fp_f): New macro.
	(RUN_TEST_LOOP_fp_f): Likewise.
	(getpayload_test_data): New array.
	(getpayload_test): New function.
	(main): Call getpayload_test.
	* math/gen-libm-test.pl (parse_args): Handle 'p' in argument
	descriptor.
	* manual/arith.texi (FP Bit Twiddling): Document getpayload,
	getpayloadf and getpayloadl.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/ieee754/dbl-64/s_getpayload.c: New file.
	* sysdeps/ieee754/dbl-64/wordsize-64/s_getpayload.c: Likewise.
	* sysdeps/ieee754/flt-32/s_getpayloadf.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_getpayloadl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_getpayloadl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_getpayloadl.c: Likewise.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-10-19 01:49:09 +00:00
Joseph Myers cc6a8d7457 Add totalordermag, totalordermagf, totalordermagl.
In addition to the totalorder functions, TS 18661-1 defines
totalordermag functions, which do the same comparison but on the
absolute values of the arguments.  This patch implements these
functions for glibc, including the type-generic macro in <tgmath.h>.
In general the implementations are similar to but simpler than those
for the totalorder functions.

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(totalordermag): New declaration.
	* math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (totalordermag):
	New macro.
	* math/Versions (totalordermag): New libm symbol at version
	GLIBC_2.25.
	(totalordermagf): Likewise.
	(totalordermagl): Likewise.
	* math/Makefile (libm-calls): Add s_totalordermagF.
	* math/libm-test.inc (totalordermag_test_data): New array.
	(totalordermag_test): New function.
	(main): Call totalordermag_test.
	* math/test-tgmath.c (NCALLS): Increase to 125.
	(F(compile_test)): Call totalordermag.
	(F(totalordermag)): New function.
	* manual/arith.texi (FP Comparison Functions): Document
	totalordermag, totalordermagf and totalordermagl.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/ieee754/dbl-64/s_totalordermag.c: New file.
	* sysdeps/ieee754/dbl-64/wordsize-64/s_totalordermag.c: Likewise.
	* sysdeps/ieee754/flt-32/s_totalordermagf.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_totalordermagl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_totalordermagl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_totalordermagl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/nldbl-totalordermag.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
	totalordermag.
	(CFLAGS-nldbl-totalordermag.c): New variable.
	* sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c
	(do_test): Also test totalordermagl.
	* sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c (do_test):
	Likewise.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-10-15 00:36:48 +00:00
Joseph Myers 5e9d98a3d9 Add totalorder, totalorderf, totalorderl.
TS 18661-1 defines totalorder functions implementing the totalOrder
comparison operation from IEEE 754-2008.  This patch implements these
functions for glibc, including the type-generic macro in <tgmath.h>.
(The totalordermag functions will be added in a separate patch.)

The description of the totalOrder operation is complicated.  However,
for IEEE interchange binary formats and the preferred quiet NaN
convention, what that complicated description means is that you
interpret the representation as a sign-magnitude integer (with -0
coming before +0) and do a <= comparison on that interpretation.  For
finite values and infinities the ordering of the sign-magnitude
integers is just the same as the ordering of floating-point values, so
this extends that to all representations.  (Different representations
of the same floating-point value - which includes same quantum in the
decimal case - must still be considered equal by this operation, but
that issue doesn't arise for IEEE interchange binary formats.)  So the
complications are:

* When MIPS quiet NaN conventions are in use, the representation of
  NaNs needs adjusting before making such an integer comparison.  This
  patch does this adjustment only when both arguments are NaNs, as
  there's no need for it if only one is a NaN, and as long as both are
  NaNs you can just flip the relevant bits without any problems from
  this turning a NaN into an infinity.

* For the m68k version of ldbl-96, where the high mantissa bit is
  "don't care" for infinities and NaNs, representations where it
  differs must compare the same.  Note: although the testcase for this
  compiles, I have not actually tested on m68k.

* For ldbl-128ibm, the low part must be ignored when the high part is
  NaN, and low parts of +0 and -0 must be considered the same whatever
  the high part.

The new tests in libm-test.inc are the first tests there specifying
particular payloads for input NaNs.  Separate tests are also added for
the ldbl-96 and ldbl-128ibm special cases where there are different
representations of the same value that must compare equal (which can't
be covered in libm-test.inc as that only specifies values, not
representations).

Tested for x86_64, x86, mips64 and powerpc.

	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(totalorder): New declaration.
	* math/tgmath.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (totalorder):
	New macro.
	* math/Versions (totalorder): New libm symbol at version
	GLIBC_2.25.
	(totalorderf): Likewise.
	(totalorderl): Likewise.
	* math/Makefile (libm-calls): Add s_totalorderF.
	* math/gen-libm-test.pl (parse_args): Escape quotes in test name
	string.
	* math/libm-test.inc (PAYLOAD_DIG): New macro.
	(qnan_value_pl): Likewise.
	(snan_value_pl): Likewise.
	(qnan_value): Define using qnan_value_pl.
	(snan_value): Define using snan_value_pl.
	(struct test_ff_i_data): Add comment about which tests use this
	structure.
	(RUN_TEST_ff_b): New macro.
	(RUN_TEST_LOOP_ff_b): Likewise.
	(totalorder_test_data): New array.
	(totalorder_test): New function.
	(main): Call totalorder_test.
	* math/test-tgmath.c (NCALLS): Increase to 122.
	(F(compile_test)): Call totalorder.
	(F(totalorder)): New function.
	* manual/arith.texi (FP Comparison Functions): Document
	totalorder, totalorderf and totalorderl.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/ieee754/dbl-64/s_totalorder.c: New file.
	* sysdeps/ieee754/dbl-64/wordsize-64/s_totalorder.c: Likewise.
	* sysdeps/ieee754/flt-32/s_totalorderf.c: Likewise.
	* sysdeps/ieee754/ldbl-128/s_totalorderl.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/s_totalorderl.c: Likewise.
	* sysdeps/ieee754/ldbl-96/s_totalorderl.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/nldbl-totalorder.c: Likewise.
	* sysdeps/ieee754/ldbl-opt/Makefile (libnldbl-calls): Add
	totalorder.
	(CFLAGS-nldbl-totalorder.c): New variable.
	* sysdeps/ieee754/ldbl-128ibm/test-totalorderl-ldbl-128ibm.c: New
	file.
	* sysdeps/ieee754/ldbl-128ibm/Makefile [$(subdir) = math] (tests):
	Add test-totalorderl-ldbl-128ibm.
	* sysdeps/ieee754/ldbl-96/test-totalorderl-ldbl-96.c: New file.
	* sysdeps/ieee754/ldbl-96/Makefile [$(subdir) = math] (tests): Add
	test-totalorderl-ldbl-96.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-10-12 01:20:30 +00:00
Joseph Myers 1e7c8fcca5 Add iseqsig.
TS 18661-1 adds an iseqsig type-generic comparison macro to <math.h>.
This macro is like the == operator except that unordered operands
result in the "invalid" exception and errno being set to EDOM.

This patch implements this macro for glibc.  Given the need to set
errno, this is implemented with out-of-line functions __iseqsigf,
__iseqsig and __iseqsigl (of which the last only exists at all if long
double is ABI-distinct from double, so no function aliases or compat
support are needed).  The present patch ignores excess precision
issues; I intend to deal with those in a followup patch.  (Like
comparison operators, type-generic comparison macros should *not*
convert operands to their semantic types but should preserve excess
range and precision, meaning that for some argument types and values
of FLT_EVAL_METHOD, an underlying function should be called for a
wider type than that of the arguments.)

The underlying functions are implemented with the type-generic
template machinery.  Comparing x <= y && x >= y is sufficient in ISO C
to achieve an equality comparison with "invalid" raised for unordered
operands (and the results of those two comparisons can also be used to
tell whether errno needs to be set).  However, some architectures have
GCC bugs meaning that unordered comparison instructions are used
instead of ordered ones.  Thus, a mechanism is provided for
architectures to use an explicit call to feraiseexcept to raise
exceptions if required.  If your architecture has such a bug you
should add a fix-fp-int-compare-invalid.h header for it, with a
comment pointing to the relevant GCC bug report; if such a GCC bug is
fixed, that header's contents should have a __GNUC_PREREQ conditional
added so that the workaround can eventually be removed for that
architecture.

Tested for x86_64, x86, mips64, arm and powerpc.

	* math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)] (iseqsig): New
	macro.
	* math/bits/mathcalls.h [__GLIBC_USE (IEC_60559_BFP_EXT)]
	(__iseqsig): New declaration.
	* math/s_iseqsig_template.c: New file.
	* math/Versions (__iseqsigf): New libm symbol at version
	GLIBC_2.25.
	(__iseqsig): Likewise.
	(__iseqsigl): Likewise.
	* math/libm-test.inc (iseqsig_test_data): New array.
	(iseqsig_test): New function.
	(main): Call iseqsig_test.
	* math/Makefile (gen-libm-calls): Add s_iseqsigF.
	* manual/arith.texi (FP Comparison Functions): Document iseqsig.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/generic/fix-fp-int-compare-invalid.h: New file.
	* sysdeps/powerpc/fpu/fix-fp-int-compare-invalid.h: Likewise.
	* sysdeps/x86/fpu/fix-fp-int-compare-invalid.h: Likewise.
	* sysdeps/nacl/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/aarch64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/alpha/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx32/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilegx/tilegx64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/tile/tilepro/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-10-06 22:19:38 +00:00
Joseph Myers 29cb929332 Add iscanonical.
TS 18661-1 adds an iscanonical classification macro to <math.h>.

The motivation for this is decimal floating-point, where some values
have both canonical and noncanonical encodings.  For IEEE binary
interchange formats, all encodings are canonical.  For x86/m68k
ldbl-96, and for ldbl-128ibm, there are encodings that do not
represent any valid value of the type; although formally iscanonical
does not need to handle trap representations (and so could just always
return 1), it seems useful, and in line with the description in the TS
of "representations that are extraneous to the floating-point model"
as being non-canonical (as well as "redundant representations of some
or all of its values"), for it to detect those representations and
return 0 for them.

This patch adds iscanonical to glibc.  It goes in a header
<bits/iscanonical.h>, included under appropriate conditions in
<math.h>.  The default header version just evaluates the argument
(converted to its semantic type, though current GCC will probably
discard that conversion and any exceptions resulting from it) and
returns 1.  ldbl-96 and ldbl-128ibm then have versions of the header
that call a function __iscanonicall for long double (the sizeof-based
tests will of course need updating for float128 support, like other
such type-generic macro implementations).  The ldbl-96 version of
__iscanonicall has appropriate conditionals to reflect the differences
in the m68k version of that format (where the high mantissa bit may be
either 0 or 1 when the exponent is 0 or 0x7fff).  Corresponding tests
for those formats are added as well.  Other architectures do not have
any new functions added because just returning 1 is correct for all
their floating-point formats.

Tested for x86_64, x86, mips64 (to test the default macro version) and
powerpc.

	* math/math.h [__GLIBC_USE (IEC_60559_BFP_EXT)]: Include
	<bits/iscanonical.h>.
	* bits/iscanonical.h: New file.
	* math/s_iscanonicall.c: Likewise.
	* math/Versions (__iscanonicall): New libm symbol at version
	GLIBC_2.25.
	* math/libm-test.inc (iscanonical_test_data): New array.
	(iscanonical_test): New function.
	(main): Call iscanonical_test.
	* math/Makefile (headers): Add bits/iscanonical.h.
	(type-ldouble-routines): Add s_iscanonicall.
	* manual/arith.texi (Floating Point Classes): Document
	iscanonical.
	* manual/libm-err-tab.pl: Update comment on interfaces without
	ulps tabulated.
	* sysdeps/ieee754/ldbl-128ibm/bits/iscanonical.h: New file.
	* sysdeps/ieee754/ldbl-128ibm/s_iscanonicall.c: Likewise.
	* sysdeps/ieee754/ldbl-128ibm/test-iscanonical-ldbl-128ibm.c:
	Likewise.
	* sysdeps/ieee754/ldbl-128ibm/Makefile (tests): Add
	test-iscanonical-ldbl-128ibm.
	* sysdeps/ieee754/ldbl-96/bits/iscanonical.h: New file.
	* sysdeps/ieee754/ldbl-96/s_iscanonicall.c: Likewise.
	* sysdeps/ieee754/ldbl-96/test-iscanonical-ldbl-96.c: Likewise.
	* sysdeps/ieee754/ldbl-96/Makefile: Likewise.
	* sysdeps/unix/sysv/linux/i386/libm.abilist: Update.
	* sysdeps/unix/sysv/linux/ia64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm-le.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libm.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libm.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libm.abilist: Likewise.
2016-09-30 00:27:50 +00:00
Zack Weinberg c66b29f9cc Installed-header hygiene (BZ#20366): stack_t.
sys/ucontext.h unconditionally uses stack_t, and it does not make
sense to change that.  But signal.h only declares stack_t under
__USE_XOPEN_EXTENDED || __USE_XOPEN2K8.  The actual definition is
already in a bits header, bits/sigstack.h, but that header insists on
only being included by signal.h, so we have to change that as well as
all of the sys/ucontext.h variants.  (Some but not all variants of
bits/sigcontext.h, which sys/ucontext.h may also need, had already
received this adjustment; for consistency, I made them all the same,
even if that's not strictly necessary in some configurations.)
bits/sigcontext.h and bits/sigstack.h also all need to receive
multiple inclusion guards.

	* sysdeps/generic/sys/ucontext.h
	* sysdeps/arm/sys/ucontext.h
	* sysdeps/i386/sys/ucontext.h
	* sysdeps/m68k/sys/ucontext.h
	* sysdeps/mips/sys/ucontext.h
	* sysdeps/unix/sysv/linux/aarch64/sys/ucontext.h
	* sysdeps/unix/sysv/linux/alpha/sys/ucontext.h
	* sysdeps/unix/sysv/linux/arm/sys/ucontext.h
	* sysdeps/unix/sysv/linux/hppa/sys/ucontext.h
	* sysdeps/unix/sysv/linux/ia64/sys/ucontext.h
	* sysdeps/unix/sysv/linux/m68k/sys/ucontext.h
	* sysdeps/unix/sysv/linux/mips/sys/ucontext.h
	* sysdeps/unix/sysv/linux/nios2/sys/ucontext.h
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h
	* sysdeps/unix/sysv/linux/s390/sys/ucontext.h
	* sysdeps/unix/sysv/linux/sh/sys/ucontext.h
	* sysdeps/unix/sysv/linux/sparc/sys/ucontext.h
	* sysdeps/unix/sysv/linux/tile/sys/ucontext.h
	* sysdeps/unix/sysv/linux/x86/sys/ucontext.h:
	Include both bits/sigcontext.h and bits/sigstack.h.
	Fix grammar error in comment, if present.

	* bits/sigstack.h
	* sysdeps/unix/sysv/linux/aarch64/bits/sigstack.h
	* sysdeps/unix/sysv/linux/alpha/bits/sigstack.h
	* sysdeps/unix/sysv/linux/bits/sigstack.h
	* sysdeps/unix/sysv/linux/ia64/bits/sigstack.h
	* sysdeps/unix/sysv/linux/mips/bits/sigstack.h
	* sysdeps/unix/sysv/linux/powerpc/bits/sigstack.h
	* sysdeps/unix/sysv/linux/sparc/bits/sigstack.h
	* bits/sigcontext.h
	* sysdeps/mach/hurd/i386/bits/sigcontext.h
	* sysdeps/unix/sysv/linux/bits/sigcontext.h
	* sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
	* sysdeps/unix/sysv/linux/sparc/bits/sigcontext.h:
	Add multiple inclusion guard.  Permit inclusion by sys/ucontext.h
	as well as signal.h, if this was not already allowed.  Request
	definition of size_t if necessary.  Minimize semantically-null
	differences across files.
2016-09-23 08:43:56 -04:00