Zack Weinberg [Tue, 11 Jun 2019 17:05:02 +0000 (13:05 -0400)]
Rename sys/ucontext.h to bits/ucontext.h.
sys/ucontext.h is effectively a bits header. Its contents are
extremely system-specific, and it’s strongly associated with a
specific public header (ucontext.h) that provides a superset of its
definitions, but there are other public headers that also require some
of its definitions. This patch therefore moves it into the bits/
namespace and adjusts all the headers that refer to it. In case there
are external users, a stub is added that includes ucontext.h.
Most of the fallout changes are trivial, but aarch64, ia64 and riscv
need a little more work. aarch64 sys/ucontext.h (now bits/ucontext.h)
was including sys/procfs.h for the definition of elf_greg_t etc;
the simplest fix is to have it include bits/procfs.h instead (and then
that needs to include sys/user.h for user_regs_struct). This is not
ideal but fixing it properly would require disentangling all of the
debugger interface headers which is more than I’m up for at the moment.
ia64 bits/ptrace.h and bits/procfs.h were both including
bits/sigcontext.h, which is only licensed to be included from
signal.h. (I’m not sure how this ever worked, or why it broke with
this patch and not some previous one.) This is fixed by creating
another single-type header, bits/types/__ia64_fpreg.h, which provides
the only thing they need from bits/sigcontext.h.
s/u/s/l/riscv/makecontext.c was defining makecontext with a function
head that didn’t agree with its official prototype (in ucontext.h);
formerly that file did not include ucontext.h, only sys/ucontext.h,
so we were getting away with it, but it’s still wrong. Making the
function head match the prototype actually simplifies the code.
* stdlib/sys/ucontext.h: New backward compatibility stub header,
includes ucontext.h.
* include/sys/ucontext.h: New wrapper.
* sysdeps/unix/sysv/linux/aarch64/bits/procfs.h: Allow inclusion
by bits/ucontext.h as well as sys/procfs.h. Include sys/user.h.
* sysdeps/unix/sysv/linux/aarch64/bits/ucontext.h: Include
bits/procfs.h instead of sys/procfs.h.
* sysdeps/unix/sysv/linux/ia64/bits/types/__ia64_fpreg.h:
New file, contents factored out of ia64/bits/sigcontext.h and
ia64/bits/ucontext.h.
* sysdeps/unix/sysv/linux/ia64/Makefile:
Install bits/types/__ia64_fpreg.h. Merge subdir=misc blocks.
* sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
* sysdeps/unix/sysv/linux/ia64/bits/ucontext.h:
Include bits/types/__ia64_fpreg.h for struct ia64_fpreg.
* sysdeps/unix/sysv/linux/ia64/bits/procfs.h:
Include bits/types/__ia64_fpreg.h for struct ia64_fpreg.
Don’t include bits/sigcontext.h or bits/ucontext.h.
* sysdeps/unix/sysv/linux/ia64/sys/ptrace.h:
Don’t include bits/sigcontext.h.
* sysdeps/unix/sysv/linux/riscv/makecontext.c: Include
ucontext.h, not sys/ucontext.h. Correct function head to match
prototype in ucontext.h. Use va_arg to retrieve all arguments
past argc.
* sysdeps/unix/sysv/linux/s390/tst-ptrace-singleblock.c:
Sort list of includes.
* signal/signal.h, stdlib/ucontext.h
* sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h
* sysdeps/unix/sysv/linux/ia64/sys/ptrace.h
* sysdeps/unix/sysv/linux/riscv/bits/procfs.h
* sysdeps/unix/sysv/linux/s390/bits/procfs.h:
Include bits/ucontext.h, not sys/ucontext.h.
* sysdeps/unix/sysv/linux/aarch64/sigcontextinfo.h
* sysdeps/unix/sysv/linux/arm/sigcontextinfo.h
* sysdeps/unix/sysv/linux/nios2/sigcontextinfo.h
* sysdeps/unix/sysv/linux/riscv/sigcontextinfo.h:
Include signal.h, not sys/ucontext.h.
* sysdeps/unix/sysv/linux/arm/register-dump.h
* sysdeps/unix/sysv/linux/csky/register-dump.h:
Include ucontext.h, not sys/ucontext.h.
* sysdeps/unix/sysv/linux/aarch64/ucontext_i.sym
* sysdeps/unix/sysv/linux/alpha/ucontext-offsets.sym
* sysdeps/unix/sysv/linux/arm/ucontext_i.sym
* sysdeps/unix/sysv/linux/csky/abiv2/ucontext_i.sym
* sysdeps/unix/sysv/linux/hppa/ucontext_i.sym
* sysdeps/unix/sysv/linux/i386/ucontext_i.sym
* sysdeps/unix/sysv/linux/ia64/sigcontext-offsets.sym
* sysdeps/unix/sysv/linux/m68k/m680x0/ucontext_i.sym
* sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.sym
* sysdeps/unix/sysv/linux/powerpc/powerpc64/ucontext_i.sym
* sysdeps/unix/sysv/linux/mips/ucontext_i.sym
* sysdeps/unix/sysv/linux/nios2/ucontext_i.sym
* sysdeps/unix/sysv/linux/riscv/ucontext_i.sym
* sysdeps/unix/sysv/linux/s390/ucontext_i.sym
* sysdeps/unix/sysv/linux/sh/sh3/ucontext_i.sym
* sysdeps/unix/sysv/linux/sh/sh4/ucontext_i.sym
* sysdeps/unix/sysv/linux/sparc/sparc32/ucontext_i.sym
* sysdeps/unix/sysv/linux/x86_64/ucontext_i.sym:
Include stddef.h and signal.h; don’t include any other headers.
Zack Weinberg [Mon, 10 Jun 2019 13:07:10 +0000 (09:07 -0400)]
Minimize inclusion of netinet/in.h from public headers.
As with sys/socket.h and struct sockaddr, most of the files including
netinet/in.h just want struct sockaddr_in or a related type, so
introduce bits/types headers for these. POSIX specifically allows
arpa/inet.h to include netinet/in.h and I think it makes sense to
preserve that. The definition of struct sockaddr_in had a dependence
on the definition of struct sockaddr; to avoid that, bits/sockaddr.h
grows a new macro, __SOCKADDR_DATA_SIZE, which is the declared size of
struct sockaddr.sa_data.
On Linux, some kernel headers (notably linux/in.h and linux/in6.h)
attempt to cooperate with a C library’s headers in defining types such
as struct sockaddr_in. There is a set of macros whose names begin
with __UAPI_DEF_ that indicate that a type has already been defined.
This mechanism doesn’t actually work with the kernel headers as they
are in 5.0, as far as I can tell, but it could be made to work with
straightforward changes, so it makes sense for us to support it to the
extent we can. To do this sensibly I need to introduce a new bits
header called bits/uapi-compat.h, with a trivial definition for
non-Linux. This replaces the existing __USE_KERNEL_IPV6_DEFS macro.
* bits/sockaddr.h (__SOCKADDR_DATA_SIZE): New macro.
* sysdeps/unix/bsd/bits/sockaddr.h: Likewise.
* sysdeps/unix/sysv/linux/m68k/bits/sockaddr.h: Likewise.
* socket/bits/types/struct_sockaddr.h: Use __SOCKADDR_DATA_SIZE as
array length of sa_data.
* bits/in.h: Add multiple inclusion guard.
(__USE_KERNEL_IPV6_DEFS): Don’t define.
* sysdeps/unix/sysv/linux/bits/in.h: Similarly.
(IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP): Define when not
already defined, not conditional on __USE_KERNEL_IPV6_DEFS.
* bits/uapi-compat.h: New file, trivial generic version.
* sysdeps/unix/sysv/linux/bits/uapi-compat.h: New file,
Linux-specific version which recognizes kernel header guard macros
and defines __UAPI_DEF_* macros as appropriate.
* misc/Makefile: Install bits/uapi-compat.h.
* inet/bits/types/in_addr_t.h, inet/bits/types/in_port_t.h
* inet/bits/types/struct_in_addr.h
* inet/bits/types/struct_in6_addr.h
* inet/bits/types/struct_sockaddr_in.h
* inet/bits/types/struct_sockaddr_in6.h
New single-type headers, factored out of inet/netinet/in.h.
Add __UAPI_DEF_* conditionals where appropriate, and verify that
all conditionalized definitions agree with the relevant
OS-supplied header. Use __SOCKADDR_DATA_SIZE to set size of sin_zero.
* inet/Makefile: Install the new single-type headers.
* inet/netinet/in.h: Include bits/uapi-compat.h.
Define in_addr_t, in_port_t, struct in_addr, struct in6_addr,
struct sockaddr_in, and struct sockaddr_in6 by including the
above single-type headers, not directly. Replace all
__USE_KERNEL_IPV6_DEFS conditionals with appropriate __UAPI_DEF_*
conditionals. Add appropriate __UAPI_DEF_* conditionals around
the definitions of the IPPROTO_* constants, the IN_CLASS
macros, and struct ip_mreq. Import IN_LOOPBACK macro from
Linux 5.0 linux/in.h and verify all other conditionalized
definitions agree with the relevant linux/ header.
Define IPPORT_RESERVED only if not already defined, and make it a
macro so we can tell.
* inet/netinet/igmp.h, inet/netinet/ip.h, inet/netinet/ip_icmp.h:
Include bits/types/struct_in_addr.h, not netinet/in.h.
* inet/netinet/ip_icmp.h: Hoist all #includes to the top of the file.
* inet/netinet/icmp6.h, inet/netinet/ip6.h
* sysdeps/unix/sysv/linux/net/route.h:
Include bits/types/struct_in6_addr.h, not netinet/in.h.
* sysdeps/mach/hurd/net/route.h: Include bits/types.h and
bits/types/struct_in6_addr.h, not netinet/in.h. Use __uint16_t
and __uint32_t instead of uint16_t and uint32_t.
* resolv/bits/types/res_state.h: Include bits/types/struct_in_addr.h
and bits/types/struct_sockaddr_in.h. Forward declare struct
sockaddr_in6. Don’t include netinet/in.h.
* resolv/netdb.h: Don’t include netinet/in.h. Use socklen_t
instead of __socklen_t. Define IPPORT_RESERVED only if not
already defined, with definition matching netinet/in.h.
When __USE_MISC, include bits/sockaddr.h.
* resolv/resolv.h: Don’t include netinet/in.h.
* inet/tst-getni1.c, inet/tst-getni2.c
* nss/tst-nss-files-hosts-erange.c, nss/tst-nss-files-hosts-getent.c
* nss/tst-nss-files-hosts-multi.c, posix/tst-getaddrinfo2.c
* resolv/tst-bug18665-tcp.c, resolv/tst-resolv-ai_idn-common.c
* resolv/tst-resolv-canonname.c, resolv/tst-resolv-edns.c
* resolv/tst-resolv-network.c, resolv/tst-resolv-nondecimal.c
* resolv/tst-resolv-search.c, support/tst-support-namespace.c:
Include netinet/in.h.
* support/resolv_test.h: Include stdint.h, not sys/cdefs.h.
Zack Weinberg [Thu, 6 Jun 2019 13:49:54 +0000 (09:49 -0400)]
Don’t include sys/socket.h from public headers.
No standard public header is required to include sys/socket.h,
although some are allowed to. Several public headers need the
definitions of socklen_t, struct sockaddr, and/or struct
sockaddr_storage, but nothing else from sys/socket.h. We already have
a single-type header for socklen_t, so this patch adds single-type
headers for struct sockaddr and struct sockaddr_storage.
The definition of struct sockaddr_storage is subtly different on Linux
than on the Hurd; in order to not need two copies of
bits/types/struct_sockaddr_storage.h, bits/sockaddr.h is now
responsible for defining __ss_aligntype if ‘unsigned long int’ is not
the correct definition.
I also added a single-type header for struct linger, even though only
sys/socket.h is expected to define that, just because all three copies
of bits/socket.h were defining it exactly the same way. There would
also be a case for defining it directly in sys/socket.h but this
seemed tidier.
I did *not* create single-type headers for struct msghdr and struct
cmsghdr, because those and their helper macros are not consistent
among the three copies of bits/socket.h, and, again, only sys/socket.h
is expected to define them.
The large number of .c files that add an `#include <sys/socket.h>`
might make this look like it’s not worth doing. However, after this
change, only half of the files in the glibc source tree that include
netinet/in.h also need to include sys/socket.h, and only a third of
the files that include netdb.h need to include sys/socket.h. Before,
all of the files in both groups were getting sys/socket.h. That seems
like enough justification to me.
While I was at it I noticed that sys/socketvar.h is yet another
backward compatibility header that does nothing but include some other
header (sys/socket.h, in this case) and also doesn’t need to be
system-dependent.
* socket/bits/types/struct_linger.h
* socket/bits/types/struct_sockaddr.h
* socket/bits/types/struct_sockaddr_storage.h:
New single-type headers, factored out of the various bits/socket.h
headers.
* include/bits/types/struct_linger.h
* include/bits/types/struct_sockaddr.h
* include/bits/types/struct_sockaddr_storage.h:
New wrappers.
* socket/Makefile (headers): Add bits/types/struct_linger.h,
bits/types/struct_sockaddr.h, and bits/types/struct_sockaddr_storage.h.
Alphabetize the list.
* socket/sys/socket.h: Include bits/types/struct_linger.h,
bits/sockaddr.h, bits/types/struct_sockaddr.h, and
bits/types/struct_sockaddr_storage.h. Move inclusion of
bits/socket.h below forward declaration of struct timespec,
and update commentary.
* inet/ifaddrs.h, socket/net/if.h
* sysdeps/mach/hurd/net/if_arp.h
* sysdeps/mach/hurd/net/route.h
* sysdeps/unix/sysv/linux/errqueue.h
* sysdeps/unix/sysv/linux/net/if_arp.h
* sysdeps/unix/sysv/linux/net/route.h:
Include bits/types/struct_sockaddr.h and possibly also bits/types.h,
not sys/socket.h or sys/types.h.
* sysdeps/unix/sysv/linux/errqueue.h:
* sysdeps/unix/sysv/linux/net/route.h:
Use __uint8_t and __uint32_t instead of uint8_t and uint32_t.
* inet/arpa/inet.h: Include bits/types/size_t.h.
* inet/netinet/in.h: Include bits/sockaddr.h,
bits/types/struct_sockaddr.h, and
bits/types/struct_sockaddr_storage.h,
not sys/socket.h. Use __socklen_t instead of socklen_t.
* inet/netinet/tcp.h: Include bits/types.h and
bits/types/struct_sockaddr_storage.h, not sys/socket.h or
bits/stdint-uintn.h. Use __uint8_t, __uint16_t, and __uint32_t
instead of uint8_t, uint16_t and uint32_t.
* inet/protocols/routed.h: Include features.h and
bits/types/struct_sockaddr.h, not sys/socket.h.
* resolv/netdb.h: Include bits/types/socklen_t.h.
* sysdeps/unix/sysv/linux/netatalk/at.h: Don’t include sys/socket.h.
* include/ifaddrs.h: Include stddef.h for size_t.
* include/netdb.h: Use __socklen_t instead of socklen_t.
Zack Weinberg [Sat, 1 Jun 2019 23:32:01 +0000 (19:32 -0400)]
Minimize includes of unrelated public headers by networking headers.
Stop including sys/param.h, sys/types.h, stdint.h, inttypes.h,
stdio.h, and string.h from network-related headers. This is done
separately from earlier patches because the network headers are extra
messy, and are also more likely to contain quirks inherited verbatim
from 4.xBSD than the bulk of our public headers.
Rose and NetROM are based on AX.25 so it makes practical sense for
netrose/rose.h and netrom/netrom.h to continue including netax25/ax25.h.
The only copies of ip_icmp.h and udp.h in the source tree are moved
from sysdeps/gnu to inet (after which there are no longer any netinet/
headers in sysdeps/gnu).
Much as sys/un.h needs to duplicate the prototype for strlen,
netinet/icmp6.h needs to duplicate the prototype for memset. I am
open to better ideas on that front.
* resolv/resolv.h: Include bits/types.h, bits/types/FILE.h,
and bits/types/size_t.h; don’t include sys/param.h, sys/types.h,
or stdio.h. Use __uint16_t and __uint32_t instead of uint16_t and
uint32_t.
* resolv/arpa/nameser.h: Include features.h, bits/types.h, and
bits/types/size_t.h; don’t include sys/param.h, sys/types.h, or
stdint.h. Use __uint16_t and __uint32_t instead of uint16_t and
uint32_t.
* resolv/arpa/nameser_compat.h: Include features.h.
* sysdeps/mach/hurd/net/ethernet.h: Include bits/types.h;
don’t include sys/types.h or stdint.h. Use __uint8_t and
__uint16_t instead of uint8_t and uint16_t.
* sysdeps/unix/sysv/linux/net/ethernet.h: Include features.h and
bits/types.h; don’t include sys/types.h or stdint.h.
Use __uint8_t and __uint16_t instead of uint8_t and uint16_t.
* sysdeps/unix/sysv/linux/netinet/if_ether.h: Include features.h
and bits/types.h. Use __uint8_t instead of uint8_t.
* sysdeps/mach/hurd/net/if_arp.h: Don’t include sys/types.h or
stdint.h. Use __uint32_t instead of uint32_t.
* sysdeps/unix/sysv/linux/net/if_arp.h: Include features.h.
Don’t include sys/types.h or stdint.h. Use __uint32_t instead of
uint32_t.
* sysdeps/mach/hurd/net/route.h: Don’t include sys/types.h.
* sysdeps/unix/sysv/linux/net/route.h: Don’t include sys/types.h.
* sysdeps/unix/sysv/linux/net/if_ppp.h: Include features.h and
bits/types.h. Don’t include sys/types.h or stdint.h. Use
__uint8_t and __uint32_t instead of uint8_t and uint32_t.
* sysdeps/unix/sysv/linux/net/if_shaper.h: Include features.h and
bits/types.h. Don’t include sys/types.h or stdint.h. Use
__uint16_t and __uint32_t instead of uint16_t and uint32_t.
* sysdeps/unix/sysv/linux/netatalk/at.h: Include features.h,
bits/types.h, and sys/ioctl.h. Don’t include asm/types.h or
linux/atalk.h. Copy over all user-appropriate definitions from
linux/atalk.h with adjustments for glibc context.
* nscd/initgrcache.c, nscd/netgroupcache.c
* nss/nss_compat/compat-grp.c, nss/nss_compat/compat-pwd.c
* nss/nss_compat/compat-spwd.c, resolv/ns_print.c:
Include sys/param.h for MIN and/or MAX.
* resolv/tst-resolv-res_init-skeleton.c: Include signal.h.
* inet/protocols/rwhod.h: Include features.h and bits/types.h.
Don’t include sys/types.h. Use __int32_t instead of int32_t.
* inet/protocols/talkd.h: Include features.h and bits/types.h.
Don’t include sys/types.h, sys/socket.h, or stdint.h. Use
__int32_t and __uint32_t instead of int32_t and uint32_t.
* inet/protocols/timed.h: Include features.h, bits/types.h,
and bits/types/struct_timeval.h. Don’t include sys/types.h or
sys/time.h.
* sysdeps/unix/sysv/linux/netipx/ipx.h: Include features.h and
bits/types.h. Don’t include sys/types.h or stdint.h. Use
__uint16_t and __uint32_t instead of uint16_t and uint32_t.
* sysdeps/unix/sysv/linux/netrose/rose.h: Include features.h.
Don’t include sys/socket.h.
* inet/netinet/icmp6.h: Include features.h, bits/endian.h,
bits/types.h, and bits/types/size_t.h. Don’t include inttypes.h,
string.h, or sys/types.h. Duplicate prototype of memset here.
Use __uintN_t instead of uintN_t types.
* inet/netinet/igmp.h: Include bits/types.h. Don’t include sys/types.h.
Use __uintN_t instead of uintN_t types.
* inet/netinet/ip.h: Include bits/types.h. Don’t include
bits/stdint-uintn.h. Use __uintN_t instead of uintN_t types.
* inet/netinet/ip6.h: Include features.h, bits/endian.h, and
bits/types.h. Don’t include inttypes.h. Use __uintN_t instead of
uintN_t types.
* inet/netinet/ip_icmp.h: Include features.h and bits/types.h.
Don’t include sys/types.h or stdint.h. Use __uintN_t instead of
uintN_t types.
* inet/netinet/udp.h: Likewise.
* sysdeps/generic/netinet/if_ether.h: Likewise.
* sysdeps/unix/sysv/linux/netinet/if_ether.h: Likewise.
* sysdeps/unix/sysv/linux/netinet/if_fddi.h: Likewise.
* sysdeps/unix/sysv/linux/netinet/if_tr.h: Likewise.
* sysdeps/gnu/netinet/ip_icmp.h: Move to inet/netinet/ip_icmp.h.
* sysdeps/gnu/netinet/udp.h: Move to inet/netinet/udp.h.
* include/netinet/ip_icmp.h, include/netinet/udp.h: New wrappers.
* sysdeps/gnu/Makefile: Remove $(subdir)==inet stanza.
* inet/Makefile (headers): Add netinet/ip_icmp.h and
netinet/udp.h. Don’t use $(wildcard *.h) for arpa and protocols
headers. Sort list.
Zack Weinberg [Tue, 21 May 2019 23:05:39 +0000 (19:05 -0400)]
Don’t include sys/types.h or stdint.h from most public headers.
Many public headers include sys/types.h and/or stdint.h when they only
need and/or are supposed to define a small number of types from that
header. This patch changes as many of them as practical to include
only the single-type headers for the types they are actually specified
to define, and use the impl-namespace aliases for any types they need
but are not specified to define. In most cases, where a header has
historically used uintN_t types, I changed it to use __uintN_t types;
in a few cases I chose to have it continue to define the complete set
of those types (using <bits/stdint-uintn.h>).
After this patch, the public headers that still include sys/types.h are:
stdlib.h and sys/param.h, where removal would risk breaking far too much;
the inclusion of sys/types.h; regex.h, which is taken verbatim from
gnulib and can't include features.h directly (I'm open to better ideas);
sys/bitypes.h, which is an alternative name for sys/types.h; and
the networking headers, which will be dealt with separately. The headers
that still include stdint.h are: inttypes.h, as required by ISO C;
elf.h and thread_db.h, see discussion of debugger interface headers below;
and, again, the networking headers will be dealt with separately.
While I was at it, I moved headers out of sysdeps where possible: If
we have only a sysdeps/generic/something.h or sysdeps/gnu/something.h,
no other sysdeps variants, it is not really system-dependent and can
be moved to the directory that installs it. If we have both
sysdeps/generic/ and gnu/something.h, the generic version is never
used (since we support only GNUish systems these days) and can be
deleted, and the gnu-version can be moved to the directory that
installs it. If the only copy of a bits header is in the
top-level bits directory, it is not system-dependent.
For utmp.h and utmpx.h, I think we might be able to fold their
respective bits headers into the primary headers and make them not
system-dependent at all. The remaining variation is between
s390*-*-linux* and everything else, and it appears to me that the s390
versions of the bits headers are actually the headers that everyone
should be using. The only difference is that the s390 headers
unconditionally use 64-bit quantities for lastlog.ll_time,
utmp{,x}.ut_tv, and utmp{,x}.ut_session, whereas the generic headers
use either 64- or 32-bit quantities depending on
__WORDSIZE_TIME64_COMPAT32. I could be wrong, but I don’t think it
makes sense for programs with 64-bit and 32-bit time_t to have
different ideas of the layout of a structures that are copied directly
to and from a shared file on disk. But fixing that doesn’t belong in
this patch series.
The conform tests expect utmpx.h to define time_t and suseconds_t.
These are the public names for the types of the fields of struct
timeval, and utmpx.h is required to define struct timeval, so this is
a reasonable expectation even though POSIX doesn't _explicitly_ say
it's also required to define time_t and suseconds_t. utmp.h is not a
standard header but it makes sense for it to be as consistent with
utmpx.h as possible, especially in our implementation where
/var/log/utmp and /var/log/utmpx have the same format.
I thought I was going to need to change all of the arch-specific
bits/epoll.h headers as well as sys/epoll.h, but it turned out not to
be necessary. I still took the opportunity to give them all multiple
inclusion guards.
I suspect we do not need as many copies of bits/fcntl.h and bits/sem.h
as we have, but that’s complicated enough that it deserves its own patchset.
The debugger interface headers are a mess and I only have so much
patience for them. This does the bare minimum required for
thread_db.h, sys/procfs.h, and sys/user.h, which are at least
nominally cross-platform interfaces, to avoid including sys/types.h,
sys/time.h, and/or signal.h. Exposure of sys/ucontext.h is reduced
but not eliminated. Cross-architecture consistency should be improved.
It would be desirable to stop including stdint.h from elf.h and
thread_db.h as well, but that would involve touching dozens more
bits headers and I ran out of patience.
Git does not understand “remove file X and then rename file Y over the
top of it” very well, so the diff looks bigger than it should.
This is another partial fix for Hurd-specific bug 23088. The headers
that are still affected by that bug are aio.h, mqueue.h, regex.h,
signal.h, stdlib.h, and sys/types.h.
* io/ftw.h: Don't include sys/types.h.
* misc/sys/uio.h: Don't include sys/types.h.
Include bits/types.h, bits/types/size_t.h, and bits/types/ssize_t.h.
* posix/spawn.h: Don't include sys/types.h.
Include bits/types.h, bits/types/mode_t.h, and bits/types/pid_t.h.
* rt/aio.h: Don't include sys/types.h.
Include bits/types.h, bits/pthreadtypes.h,
bits/types/size_t.h, and bits/types/ssize_t.h.
* sysdeps/pthread/semaphore.h: Don't include sys/types.h.
* sysdeps/unix/sysv/linux/bits/uio-ext.h: Use __pid_t, not pid_t.
* sysdeps/generic/netinet/in_systm.h: Rename to
inet/netinet/in_systm.h. Include bits/stdint-uintn.h,
not sys/types.h or stdint.h.
* sysdeps/generic/netinet/ip.h: Rename to
inet/netinet/ip.h. Include bits/stdint-uintn.h and
bits/endian.h, not sys/types.h.
* sysdeps/gnu/netinet/tcp.h: Rename to
inet/netinet/tcp.h. Include bits/stdint-uintn.h and
bits/endian.h, not sys/types.h or stdint.h.
* sydeps/gnu/net/if.h: Rename to socket/net/if.h.
Don’t include sys/types.h.
* include/net/if.h: Include socket/net/if.h, rather than
whatever the next net/if.h on the include path is.
* include/netinet/in_systm.h, include/netinet/ip.h
* include/netinet/tcp.h: New trivial wrappers.
* sysdeps/generic/net/if.h: Delete, never used.
* sysdeps/generic/netinet/tcp.h: Delete, never used.
* bits/utmp.h: Delete file.
* sysdeps/gnu/bits/utmp.h: Move to bits/utmp.h.
Add multiple include guard.
Don’t include paths.h, sys/time.h, or sys/types.h.
Don’t use struct timeval.
Use __intN_t for consistency with bits/utmpx.h.
* sysdeps/unix/sysv/linux/s390/bits/utmp.h: Add multiple include guard.
Don’t include paths.h, sys/time.h, sys/types.h, or bits/wordsize.h.
Don’t use struct timeval.
Use __intN_t for consistency with bits/utmpx.h.
Use __time64_t unconditionally for lastlog.ll_time.
Use __int64_t unconditionally for utmp.ut_session.
Adjust indentation and blank lines to match bits/utmp.h.
* sysdeps/gnu/bits/utmpx.h: Move to bits/utmpx.h.
Add multiple include guard.
Don’t include paths.h, sys/time.h, bits/types.h, or bits/wordsize.h.
Don’t define _PATH_UTMPX or _PATH_WTMPX.
Don’t use struct timeval.
Use pid_t for consistency with bits/utmp.h.
* sysdeps/unix/sysv/linux/s390/bits/utmpx.h: Add multiple include guard.
Don’t define _PATH_UTMPX or _PATH_WTMPX.
Don’t include paths.h, sys/time.h, bits/types.h, or bits/wordsize.h.
Don’t define _PATH_UTMPX or _PATH_WTMPX.
Don’t use struct timeval.
Use pid_t for consistency with bits/utmp.h.
Use __int64_t unconditionally for utmpx.ut_session.
* login/utmp.h: Don’t include sys/types.h.
Do include paths.h, bits/types.h, bits/types/pid_t.h,
bits/types/suseconds_t, bits/types/time_t.h, and
bits/types/struct_timeval.h.
Move __BEGIN_DECLS to enclose only prototypes.
* sysdeps/gnu/utmpx.h: Move to login/utmpx.h.
Don’t include sys/time.h. Do include bits/types.h,
bits/types/suseconds_t, bits/types/time_t.h, and
bits/types/struct_timeval.h.
When __USE_GNU, include paths.h and define _PATH_UTMPX and _PATH_WTMPX.
* login/Makefile (headers): Add utmpx.h and bits/utmpx.h.
(routines): Add endutxent, getutmp, getutmpx, getutxent,
getutxid, getutxline, pututxline, setutxent, updwtmpx, and
utmpxname. Reorganize.
* sysdeps/gnu/Makefile: Do not add anything to sysdep_routines
or sysdep_headers when subdir == login.
* sysdeps/gnu/sys/mtio.h: Move to misc/sys/mtio.h.
Don't include sys/types.h.
* sysdeps/gnu/Makefile: Don't add anything to sysdep_headers
for the misc directory.
* misc/Makefile (headers): Add sys/mtio.h.
* include/sys/mtio.h: New wrapper.
* elf/link.h, inet/aliases.h, misc/sys/xattr.h:
Don't include sys/types.h. Include bits/types/size_t.h.
* gmon/sys/gmon.h: Don't include sys/types.h.
* gmon/sys/profil.h: Don't include sys/types.h.
Include bits/types/size_t.h and bits/types/struct_timeval.h.
* io/fts.h: Don't include sys/types.h.
Include bits/types/dev_t.h, bits/types/ino_t.h, bits/types/ino64_t.h,
and bits/types/nlink_t.h.
* io/sys/sendfile.h: Don't include sys/types.h.
Include bits/types.h, bits/types/off_t.h, bits/types/size_t.h,
and bits/types/ssize_t.h.
* stdlib/sys/random.h: Don't include sys/types.h.
Include bits/types/size_t.h and bits/types/ssize_t.h.
* gmon/tst-sprofil.h: Include sys/time.h.
* sysdeps/mach/hurd/sendfile.c: Include sys/types.h.
* sysdeps/unix/sysv/linux/sys/epoll.h: Don’t include stdint.h
or sys/types.h. Do include features.h and bits/types.h.
(union epoll_data, struct epoll_event): Use __uint32_t and
__uint64_t for field types.
* sysdeps/unix/sysv/linux/alpha/sys/acct.h: Style fix.
* sysdeps/unix/sysv/linux/sys/acct.h: Include features.h
and bits/stdint-uintn.h. Don't include sys/types.h, stdint.h,
or bits/types/time_t.h.
* sysdeps/unix/sysv/linux/sys/fsuid.h
* sysdeps/unix/sysv/linux/sys/quota.h
Include bits/types.h, not sys/types.h.
* sysdeps/nptl/sys/procfs.h: Include features.h and bits/types.h,
not sys/types.h.
* sysdeps/nptl/thread_db.h: Don’t include sys/types.h.
* sysdeps/nptl/proc_service.h: Include bits/types/pid_t.h and
bits/types/size_t.h.
* sysdeps/unix/sysv/linux/sys/procfs.h: Include bits/types.h and
bits/types/struct_timeval.h, not sys/time.h or sys/types.h.
* sysdeps/unix/sysv/linux/aarch64/bits/procfs.h: Add multiple
inclusion guard. Include bits/types.h. Correct a comment.
* sysdeps/unix/sysv/linux/alpha/bits/procfs-prregset.h:
Add multiple inclusion guard. Include sys/ucontext.h.
* sysdeps/unix/sysv/linux/alpha/bits/procfs.h
* sysdeps/unix/sysv/linux/sparc/bits/procfs.h
Add multiple inclusion guard. Don’t include signal.h or sys/ucontext.h.
* sysdeps/unix/sysv/linux/ia64/bits/procfs.h:
Add multiple inclusion guard. Include sys/ucontext.h, not signal.h.
* sysdeps/unix/sysv/linux/powerpc/bits/procfs.h:
Add multiple inclusion guard. Don’t include signal.h or
sys/ucontext.h. Include bits/wordsize.h and asm/elf.h.
Adjust conditional for whether to provide various fallback
definitions.
* sysdeps/posix/dl-fileid.h (r_file_id): Use __dev_t and __ino64_t
for field types.
* nss/nss.h
* sysdeps/powerpc/sys/platform/ppc.h
* sysdeps/unix/sysv/linux/sys/eventfd.h
* sysdeps/unix/sysv/linux/sys/fanotify.h
* sysdeps/unix/sysv/linux/sys/inotify.h
* sysdeps/unix/sysv/linux/sys/raw.h
* sysdeps/unix/sysv/linux/sys/signalfd.h:
Include bits/types.h, not stdint.h.
Include features.h where not already doing so.
Use __(u)intN_t types instead of (u)intN_t types in all
declarations.
* sysdeps/unix/sysv/linux/powerpc/bits/powerpc.h:
Use __uint64_t instead of uint64_t.
* nss/tst-nss-test4.c: Include stdint.h.
* bits/fcntl.h: Add multiple include guard. Hoist inclusion of
bits/types.h to top of file.
* sysdeps/mach/hurd/bits/fcntl.h: Add multiple include guard.
Include bits/types.h, not sys/types.h; remove redundant inclusion
of bits/types.h in middle of file.
* bits/sem.h: Add multiple include guard. Include bits/types.h,
not sys/types.h.
* sysdeps/gnu/bits/sem.h: Likewise.
* sysdeps/unix/sysv/linux/bits/sem.h: Likewise.
* sysdeps/unix/sysv/linux/ia64/bits/ipc.h: Likewise.
* sysvipc/sys/sem.h: Include bits/types/pid_t.h and
bits/types/time_t.h.
* resolv/bits/types/res_state.h: Include bits/types.h, not
sys/types.h. Use __uint32_t and __uint16_t, not uint32_t and
uint16_t.
* sysdeps/mach/hurd/bits/socket.h: Include bits/types.h, not
sys/types.h.
* sysdeps/unix/sysv/linux/bits/socket.h: Likewise. Use __pid_t,
__uid_t, and __gid_t, not pid_t, uid_t, and gid_t.
* socket/sys/socket.h: Include bits/types.h, bits/types/ssize_t.h,
and bits/types/socklen_t.h.
* inet/htonl.c, include/htons.c: Include endian.h.
* include/netinet/ether.h: Include bits/types/size_t.h.
Zack Weinberg [Fri, 31 May 2019 14:30:38 +0000 (10:30 -0400)]
Don’t include sys/time.h from sys/timex.h.
The interfaces defined in sys/timex.h only need struct timeval, not
any of the other things defined in sys/time.h.
While I was at it I moved stuff around so that sysdeps/…/linux/bits/timex.h
defines everything that uapi linux/timex.h defines (as of version 5.0;
alas, we still cannot use linux/timex.h directly) plus the
MOD_CLKA and MOD_CLKB constants. In particular, the TIME_* constants
are relevant to users of clock_adjtime as well as adjtimex (I presume—
clock_adjtime is not very well documented) so they should be visible
from time.h as well as sys/timex.h. Conversely, as far as I can tell,
struct ntptimeval was never a kernel interface on Linux, and MAXTC is
not part of the exposed API and also has the wrong value for current
kernels. Also I removed a thoroughly obsolete bug workaround from
ntp_gettime.c and ntp_gettimex.c.
* sysdeps/unix/sysv/linux/sys/timex.h: Don’t include sys/time.h.
Update commentary. Don’t define MAXTC. Move definition of
NTP_API and the TIME_* constants...
* sysdeps/unix/sysv/linux/bits/timex.h: ...here.
Allow inclusion only by sys/timex.h and bits/time.h.
Update commentary.
* sysdeps/unix/sysv/linux/ntp_gettime.c
* sysdeps/unix/sysv/linux/ntp_gettimex.c: Remove obsolete
check for MOD_OFFSET not being defined.
Zack Weinberg [Wed, 22 May 2019 16:03:57 +0000 (12:03 -0400)]
Don’t include string.h from sys/un.h.
sys/un.h needs strlen in order to define SUN_LEN, but does not need
any of the other things declared by string.h; the path of least
resistance is to prototype strlen locally.
Also, the construct being used to get the size of everything up to the
sun_path member contains a formal dereference of a null pointer and
therefore has undefined behavior. Replace with __SOCKADDR_COMMON_SIZE.
Some old RPC code was relying on sys/un.h to provide all of string.h.
* sys/un.h [__USE_MISC]: Don’t include string.h.
Include bits/types/size_t.h. Prototype strlen locally.
Use __SOCKADDR_COMMON_SIZE for size of leading members of
struct sockaddr_un.
* nis/nis_domain_of.c, nis/yp_xdr.c, sunrpc/svc.c:
Include string.h.
Zack Weinberg [Mon, 10 Jun 2019 15:34:41 +0000 (11:34 -0400)]
Don’t include signal.h from sys/wait.h or sys/param.h.
Besides the snarl of debugger/ucontext interfaces, these are the only
public headers that include signal.h.
sys/wait.h includes signal.h only for the definition of siginfo_t.
We already have a single-type header for that, so use it. siginfo_t
contains a field whose type is uid_t, but sys/wait.h is not specified
to define uid_t, so, as is already done for pid_t, the conformance
test is modified to expect that field to have type __uid_t instead.
It is not clear what subset of the definitions from signal.h are
actually expected by historical users of sys/param.h; I’ve chosen to
take the comment at face value and cut it down to bits/signum.h, which
supplies _NSIG and all of the SIG* constants. This requires adjusting
every copy of bits/signum.h to permit inclusion by sys/param.h as well
as signal.h.
While I was at it I moved the comment about sys/param.h being obsolete
from sysdeps/mach/hurd/bits/param.h, where it’s not likely to be seen,
to the top-level sys/param.h, and edited it to give more useful advice.
This patch partially fixes Hurd-specific bug 23088; sys/wait.h is now
conformant.
* posix/sys/wait.h: Include bits/types/siginfo_t.h, not signal.h.
* conform/data/sys/wait.h-data: Do not expect a definition of uid_t.
* misc/sys/param.h: Include bits/signum.h, not signal.h.
Add comment explaining that this header is obsolete, based on
a similar comment in Hurd bits/param.h.
* bits/param.h: Add multiple inclusion guard and defensive #error.
* sysdeps/mach/hurd/bits/param.h: Add multiple inclusion guard.
Remove comment explaining that this header is obsolete (see above).
* sysdeps/mach/i386/bits/mach/param.h: Add multiple inclusion guard.
* sysdeps/unix/sysv/linux/bits/param.h: Add multiple inclusion guard.
* bits/signum-generic.h, bits/signum.h
* sysdeps/unix/bsd/bits/signum.h
* sysdeps/unix/sysv/linux/alpha/bits/signum.h
* sysdeps/unix/sysv/linux/bits/signum.h
* sysdeps/unix/sysv/linux/hppa/bits/signum.h
* sysdeps/unix/sysv/linux/mips/bits/signum.h:
Allow inclusion by sys/param.h as well as signal.h.
Zack Weinberg [Sat, 16 Mar 2019 16:35:25 +0000 (12:35 -0400)]
Don’t include sys/select.h from sys/types.h.
This is supposedly present for BSD compatibility, but the current
generation of BSDs is not consistent about it: FreeBSD does, OpenBSD
doesn’t, NetBSD exposes only fd_set and the FD_* macros. Programs
that need to wait for any of multiple I/O events have several
alternatives to select nowadays, so I think it makes sense to expose
select only to programs that specifically want it.
Only a few places within our own code are affected. A few test
programs need to include sys/select.h explicitly, as does rpc/svc.h.
sysdeps/nptl/thread_db.h needs to declare sigset_t, and
sysdeps/unix/sysv/linux/pselect.c was including sys/poll.h instead of
sys/select.h, which is probably a copy-and-paste error. sys/socket.h
needs to forward-declare struct timespec under __USE_GNU, because
recvmmsg has a struct timespec * argument; I’m open to the possibility
of having it fully declare struct timespec.
I considered taking sys/select.h out of sys/time.h as well, but POSIX
not only explicitly allows this inclusion, it requires sys/time.h to
declare almost everything that sys/select.h declares. It doesn’t seem
worth creating another bits header just to prevent sys/time.h from
declaring pselect, sigset_t, and struct timespec.
Not including sys/select.h from sys/types.h means that sys/types.h
also no longer defines anything from sys/time.h, and a couple of files
were relying on that. (pthread_join_common.c should be using
clock_gettime instead of gettimeofday, but that's out of scope for
this patch series.)
* posix/sys/types.h: Don’t include sys/select.h.
* scripts/check-obsolete-constructs.py: Remove whitelist entry
for sys/types.h -> sys/select.h. Adjust commentary re
sys/time.h -> sys/select.h.
* socket/sys/socket.h: When __USE_GNU, forward-declare struct timespec.
* misc/tst-fdset.c, nptl/tst-cancel4.c, scripts/check-c++-types.sh
* sunrpc/rpc/svc.h: Include sys/select.h.
* sysdeps/nptl/thread_db.h: Include bits/types/sigset_t.h.
* sysdeps/unix/sysv/linux/pselect.c: Include sys/select.h,
not sys/poll.h.
* nptl/pthread_join_common.c, sysdeps/unix/sysv/linux/dl-vdso.h:
Include sys/time.h.
Zack Weinberg [Sun, 17 Mar 2019 01:01:12 +0000 (21:01 -0400)]
Limit the set of strings.h functions also exposed in string.h.
As someone who can remember when you might not be able to include both
string.h and strings.h at the same time, it annoys me that strings.h
still exists and is the only standard source for str(n)casecmp(_l) and
ffs. I think it’s right that we expose those functions from string.h.
However, there’s no reason we need to keep exposing the other obsolete
functions that strings.h declares from string.h.
This patch creates <bits/strings_x2k8.h>, which declares the
non-obsolete functions whose official home is strings.h. strings.h
includes it unconditionally, and string.h includes it under
__USE_MISC, instead of strings.h.
Two tests of the obsolete strings.h functions had to be adjusted.
* string/strings.h (strcasecmp, strncasecmp, strcasecmp_l)
(strncasecmp_l, ffs, ffsl, ffsll): Move declarations to...
* string/bits/strings_x2k8.h: ... this new file.
* string/Makefile: Install bits/strings_x2k8.h.
* include/bits/strings_x2k8h: New wrapper.
* string/string.h: Include bits/strings_x2k8.h instead of
strings.h.
* debug/tst-chk1.c, string/test-string.h: Include strings.h.
* scripts/check-obsolete-constructs.py: string.h is no longer
expected to include strings.h.
Zack Weinberg [Wed, 29 May 2019 18:23:32 +0000 (14:23 -0400)]
Don’t rely on stddef.h or stdarg.h for individual type definitions.
In the course of developing earlier patches in this series I
discovered that clang’s stddef.h does not implement the __need_*
convention correctly: in C++, under some circumstances __need_NULL
will also cause a definition of nullptr_t, and when the “modules”
feature is enabled, all of the __need macros are ignored and all of
stddef.h is exposed. (I’m not sure how to actually make either of
these things happen, I discovered the problem by reading the file.)
Worse, clang’s stdarg.h does not implement __need___va_list *at all*;
including its stdarg.h will always expose all of its definitions.
These are bugs in clang but it seems prudent to work around them, and
the simplest way to do so is to have the bits/types/ headers
introduced in the previous patch make definitions themselves, when
possible. For size_t, ptrdiff_t, and wchar_t, we can use the
predefined macros __SIZE_TYPE__, __PTRDIFF_TYPE__, and __WCHAR_TYPE__,
when available, falling back to the old approach. For __gnuc_va_list,
we have a whitelist of compilers known to provide __builtin_va_list,
falling back to the old approach. NULL and va_list are defined
ab initio.
An additional complication is that we must be able to tell stddef.h
and stdarg.h _not_ to define again things we have already defined. It
appears to me, based on inspection of clang, GCC, and icc stddef.h and
stdarg.h, that we can use the macros _SIZE_T, _PTRDIFF_T, _WCHAR_T,
_VA_LIST, and __GNUC_VA_LIST to accomplish this.
Since we are no longer relying on stdarg.h to define an
implementation-namespace alias for us, I thought it would make sense
also to stop calling it __gnuc_va_list. The bulk of this patch is
a mechanical substitution of __va_list for __gnuc_va_list throughout
our headers.
Copyright boilerplate is added to stdlib/bits/NULL.h and stdlib/bits/types/*.h
because they now contain enough commentary and code that they could
plausibly be copyrightable.
* stdlib/bits/NULL.h: Do not use stddef.h to define NULL.
Define NULL ab initio if not already defined, as `((void *)0)` for C,
and either `__null` or 0 for C++, depending on compiler support.
* stdlib/bits/types/__va_list.h: If __builtin_va_list is known to
be available, use it to define __va_list without including
stdarg.h. Otherwise use __need___va_list to request a definition
of __gnuc_va_list and nothing else from stdarg.h, then use that to
define __va_list.
* stdlib/bits/types/va_list.h: Use __va_list, not __gnuc_va_list,
to define va_list. Improve commentary.
* stdlib/bits/types/ptrdiff_t.h: If __PTRDIFF_TYPE__ is defined,
use it to define ptrdiff_t without including stddef.h. Otherwise
use __need_ptrdiff_t to request a definition of ptrdiff_t and
nothing else from stddef.h. Use _PTRDIFF_T as guard macro to
match behavior of common stddef.h implementations.
* stdlib/bits/types/size_t.h: Similarly for size_t, with
__SIZE_TYPE__, __need_size_t, and _SIZE_T.
* stdlib/bits/types/wchar_t.h: Similarly for wchar_t, with
__WCHAR_TYPE__, __need_wchar_t, and _WCHAR_T. If __cplusplus
is defined, do nothing; wchar_t is built-in in C++.
Zack Weinberg [Tue, 28 May 2019 17:59:08 +0000 (13:59 -0400)]
Add bits/types/ wrappers for stddef.h and stdarg.h types.
We rely on the compiler's stddef.h and stdarg.h to define size_t,
ptrdiff_t, wchar_t, NULL, and __gnuc_va_list, and to implement a
convention that allows us to request the definition of a specific one:
for instance
#define __need_size_t
#include <stddef.h>
is expected to define size_t but not any of the other things stddef.h
defines.
This patch hides that convention behind a set of bits/types/ headers,
which allows check-obsolete-constructs.py to verify that none of our
headers include these headers unconditionally. (Both of them define
at least one item in the user namespace that no other header is
supposed to expose.) It will also facilitate coping with compilers
that don’t implement the __need convention. (That scenario is not
hypothetical, see the next patch.)
Only public headers use the new bits headers. Non-public headers and
.c files in our codebase, that were formerly defining __need macros,
now just include stddef.h and/or stdarg.h without any __need macros.
A few files didn’t need to be including stddef.h / stdarg.h at all.
Uses of NULL in public headers that aren’t expected to define NULL
are changed to a bare 0. bits/NULL.h is only used by headers that
are expected to define NULL.
malloc.h and printf.h were, in fact, including stddef.h and/or
stdarg.h unconditionally; they no longer do that. This broke a few of
our test cases, which are fixed by adding appropriate inclusions to
the relevant .c files.
* stdlib/bits/NULL.h
* stdlib/bits/types/__va_list.h
* stdlib/bits/types/ptrdiff_t.h
* stdlib/bits/types/size_t.h
* stdlib/bits/types/va_list.h
* stdlib/bits/types/wchar_t.h:
New headers defining a single type or macro each.
* stdlib/Makefile: Install new headers.
* include/bits/NULL.h
* include/bits/types/__va_list.h
* include/bits/types/ptrdiff_t.h
* include/bits/types/size_t.h
* include/bits/types/va_list.h
* include/bits/types/wchar_t.h:
New wrapper headers.
* malloc/malloc.h: Don’t include stdio.h or stddef.h.
Include bits/NULL.h, bits/types/size_t.h, bits/types/ptrdiff_t.h,
and bits/types/FILE.h.
* stdio-common/printf.h: Don’t include stddef.h or stdarg.h.
Include bits/types/size_t.h, bits/types/wchar_t.h, and
bits/types/__va_list.h. Use __gnuc_va_list instead of va_list
in prototypes.
* libio/bits/types/struct_FILE.h: Include bits/types/size_t.h.
* misc/sys/param.h: Include features.h.
* sysvipc/sys/msg.h: Include bits/msq.h after all bits/types/ headers.
* sysvipc/sys/sem.h: Include bits/sem.h after all bits/types/ headers.
* sysvipc/sys/shm.h: Include bits/shm.h after all bits/types/ headers.
* hurd/hurd/signal.h: Don’t use NULL.
* hurd/hurd/ioctl.h: Don’t include stdarg.h.
* hurd/hurd/userlink.h: Don’t include stddef.h. Don’t use NULL.
* intl/libintl.h: Don’t include stddef.h. Don’t use NULL.
* intl/gettext.c, intl/ngettext.c: Include stddef.h
unconditionally. Don’t define any __need macros first.
Don’t include stdlib.h.
* sysdeps/posix/sigignore.c:, sysdeps/posix/sigset.c:
Don’t include errno.h or string.h.
* malloc/tst-malloc-thread-fail.c: Include stddef.h.
* malloc/tst-malloc_info.c: Include stdio.h.
* stdio-common/tst-vfprintf-user-type.c: Include stdarg.h.
* string/tst-cmp.c: Include stdio.h.
* iconv/gconv.h, iconv/iconv.h, libio/libio.h
* stdlib/inttypes.h, stdlib/stdlib.h, wcsmbs/wchar.h:
Use bits/types/wchar_t.h instead of __need_wchar_t.
* libio/stdio.h, locale/locale.h, misc/sys/param.h
* posix/sched.h, posix/unistd.h, stdlib/stdlib.h
* string/string.h, sysdeps/unix/sysv/linux/bits/sigcontext.h
* time/time.h, wcsmbs/wchar.h: Use bits/NULL.h instead of __need_NULL.
* libio/stdio.h, misc/err.h: Use bits/types/__va_list.h instead
of __need___va_list.
* libio/stdio.h: Use bits/types/va_list.h instead of manually
defining va_list.
* hurd/hurd/userlink.h, misc/sys/mman.h, posix/sched.h
* sysdeps/mach/hurd/bits/socket.h
* sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h
* wcsmbs/wchar.h: Reorganize includes; no semantic effect.
* stdlib/stdlib.h: Normalize format of multiple include guard.
* sysdeps/unix/sysv/linux/bits/sigcontext.h: Annotate workarounds
for kernel header bugs.
* sysdeps/unix/sysv/linux/alpha/sys/user.h
* sysdeps/unix/sysv/linux/ia64/sys/user.h
* sysdeps/unix/sysv/linux/mips/sys/user.h
* sysdeps/unix/sysv/linux/powerpc/sys/user.h
* sysdeps/unix/sysv/linux/sh/sys/user.h
* sysdeps/unix/sysv/linux/sparc/sys/user.h
Include features.h and bits/types/size_t.h, in that order.
Include kernel headers, if any, after those two.
Don’t include stddef.h or sys/types.h.
* scripts/check-obsolete-constructs.py
(UNIVERSAL_ALLOWED_INCLUDES): Remove stddef.h and stdarg.h.
(HEADER_ALLOWED_INCLUDES): Update.
Zack Weinberg [Fri, 15 Mar 2019 13:02:24 +0000 (09:02 -0400)]
Split up endian.h to minimize exposure of BYTE_ORDER.
With only two exceptions (sys/types.h and sys/param.h, both of which
historically might have defined BYTE_ORDER) the public headers that
include <endian.h> only want to be able to test __BYTE_ORDER against
__*_ENDIAN.
This patch creates a new bits/endian.h that can be included by any
header that wants to be able to test __BYTE_ORDER and/or
__FLOAT_WORD_ORDER against the __*_ENDIAN constants, or needs
__LONG_LONG_PAIR. It only defines macros in the implementation
namespace.
The existing bits/endian.h (which could not be included independently
of endian.h, and only defines __BYTE_ORDER and maybe __FLOAT_WORD_ORDER)
is renamed to bits/endianness.h. I also took the opportunity to
canonicalize the form of this header, which we are stuck with having
one copy of per architecture. Since they are so short, this means git
doesn’t understand that they were renamed from existing headers, sigh.
endian.h itself is a nonstandard header and its only remaining use
from a standard header is guarded by __USE_MISC, so I dropped the
__USE_MISC conditionals from around all of the public-namespace things
it defines. (This means, an application that requests strict library
conformance but includes endian.h will still see the definition of
BYTE_ORDER.)
A few changes to specific bits/endian(ness).h variants deserve
mention:
- sysdeps/unix/sysv/linux/ia64/bits/endian.h is moved to
sysdeps/ia64/bits/endianness.h. If I remember correctly, ia64 did
have selectable endianness, but we have assembly code in
sysdeps/ia64 that assumes it’s little-endian, so there is no reason
to treat the ia64 endianness.h as linux-specific.
- The C-SKY port does not fully support big-endian mode, but I do
not think this is sufficient reason to make csky/bits/endian(ness).h
error out if __CSKYBE__ is defined, so it now defines __BYTE_ORDER
appropriately for whichever mode the compiler is in.
- The PowerPC port had extra logic in its bits/endian.h to detect a
broken compiler, which strikes me as unnecessary, so I removed it.
- The only files that defined __FLOAT_WORD_ORDER always defined it to
the same value as __BYTE_ORDER, so I removed those definitions.
The SH bits/endian(ness).h had comments inconsistent with the
actual setting of __FLOAT_WORD_ORDER, which I also removed.
- I *removed* copyright boilerplate from the few bits/endian(ness).h
headers that had it; these files record a single fact in a fashion
dictated by an external spec, so I do not think they are copyrightable.
As long as I was changing every copy of ieee754.h in the tree, I
noticed that only the MIPS variant includes float.h, because it uses
LDBL_MANT_DIG to decide among three different versions of
ieee854_long_double. This patch makes it not include float.h when
GCC’s intrinsic __LDBL_MANT_DIG__ is available.
* string/endian.h: Unconditionally define LITTLE_ENDIAN,
BIG_ENDIAN, PDP_ENDIAN, and BYTE_ORDER. Condition byteswapping
macros only on !__ASSEMBLER__. Move the definitions of
__BIG_ENDIAN, __LITTLE_ENDIAN, __PDP_ENDIAN, __FLOAT_WORD_ORDER,
and __LONG_LONG_PAIR to...
* string/bits/endian.h: ...this new file, which includes
the renamed header bits/endianness.h for the definition of
__BYTE_ORDER and possibly __FLOAT_WORD_ORDER.
* string/Makefile: Install bits/endianness.h.
* include/bits/endian.h: New wrapper.
* bits/endian.h: Rename to bits/endianness.h.
Add multiple-include guard. Rewrite the comment explaining what
the machine-specific variants of this file should do.
* sysdeps/unix/sysv/linux/ia64/bits/endian.h:
Move to sysdeps/ia64.
* sysdeps/csky/bits/endianness.h: Do not error out if __CSKYEB__
is defined.
* sysdeps/powerpc/bits/endianness.h: Remove logic to check for
broken compilers.
* sysdeps/unix/sysv/linux/hppa/pthread.h: Don’t include endian.h.
* sysdeps/mips/ieee754/ieee754.h: Use __LDBL_MANT_DIG__
in ifdefs, instead of LDBL_MANT_DIG. Only include float.h
when __LDBL_MANT_DIG__ is not predefined, in which case
define __LDBL_MANT_DIG__ to equal LDBL_MANT_DIG.
* scripts/check-obsolete-constructs.h: Remove most of the
whitelist entries for endian.h and float.h.
Zack Weinberg [Tue, 18 Jun 2019 15:47:49 +0000 (11:47 -0400)]
Don’t include sys/cdefs.h directly from public headers.
The convention throughout glibc is that every public header includes
features.h directly, as its first action, and relies on features.h to
include sys/cdefs.h. In a few places, though, it’s been done the
other way around, usually in headers that were copied from a BSD
source (where the convention is exactly the opposite). This patch
makes all installed headers match the glibc convention.
This patch also corrects a bug in glob.h: it may declare size_t
without notifying stddef.h that it has done this, so e.g.
#define _XOPEN_SOURCE 700
#include <glob.h>
#include <stddef.h>
int dummy;
declares size_t twice, which is invalid prior to C2011. I wasn’t able
to persuade gcc 8 to issue an error, even with -std=c89 -Wsystem-headers,
but clang is not so lenient.
* posix/glob.h: Include features.h, not sys/cdefs.h.
When __USE_XOPEN || USE_XOPEN2K8, include stddef.h for size_t;
otherwise, issue an immediate #error if __SIZE_TYPE__ is not
available. Use __gsize_t, not __size_t, as an impl-namespace
alternative name for size_t.
* conform/data/glob.h-data: Adjust to match.
Zack Weinberg [Sun, 17 Mar 2019 13:50:36 +0000 (09:50 -0400)]
Swap sys/poll.h with poll.h.
Similarly to (sys/)syslog.h, poll.h is the header standardized by
POSIX, but we had all of its contents in sys/, for historical reasons.
This patch exchanges the contents of the two headers, and adds
multiple-include guards to all of poll.h’s bits headers.
* bits/poll.h, io/bits/poll2.h
* sysdeps/unix/sysv/linux/bits/poll.h
* sysdeps/unix/sysv/linux/m68k/bits/poll.h
* sysdeps/unix/sysv/linux/mips/bits/poll.h
* sysdeps/unix/sysv/linux/sparc/bits/poll.h:
Allow inclusion by poll.h, not sys/poll.h. Add multiple-
include guards where not already present.
Zack Weinberg [Tue, 18 Jun 2019 15:45:26 +0000 (11:45 -0400)]
Swap sys/syslog.h with syslog.h.
Our installed syslog.h is a trivial wrapper around sys/syslog.h, which
is where all the actual declarations are. This is backward from
POSIX, which specifies syslog.h and its contents, and does not specify
sys/syslog.h. This arrangement appears to have been inherited from
some BSD-phylum C library, and probably pre-dates any standardization
of syslog.
This patch swaps the contents of syslog.h and sys/syslog.h, so that
the actual declarations appear under the standardized name. Since it
is necessary to adjust all of syslog.h’s bits headers, I also added
multiple-include guards to those files that didn’t already have
them. (All installed headers should have multiple-include guards,
even if they are internal and only used in one public header. The
“never include this file directly” #error convention doesn’t protect
against including the internal header a second time after its parent
header has already been included.)
* bits/syslog-path.h, misc/bits/syslog-ldbl.h
* misc/bits/syslog.h: Allow inclusion by syslog.h, not sys/syslog.h.
Add multiple-include guard where not already present.
Zack Weinberg [Fri, 15 Mar 2019 01:03:23 +0000 (21:03 -0400)]
Add check-obsolete-constructs checker for nested includes.
As a first step toward minimizing the number of public headers that
include other public headers, add a checker to check-obsolete-constructs
that will error out on any such inclusion that’s not on a whitelist.
The whitelist is initialized to all of the nested inclusions that
already exist; subsequent patches will remove nested inclusions and
shrink the whitelist, hopefully to the point where we only have
nested inclusions as mandated by the relevant standards.
Hurd headers and Sun RPC headers and interface definitions are exempt
from these checks. The former is because minimizing their
cross-inclusions would require making Hurd-specific design decisions,
which I feel is best left to the Hurd maintainers. The latter is
because they are obsolete in glibc; cleanups should be done under the
auspices of TIRPC.
* scripts/check-obsolete-constructs.py
(UNIVERSAL_ALLOWED_INCLUDES, HEADER_ALLOWED_INCLUDES)
(SYSDEP_ALLOWED_INCLUDES, NESTED_INCLUDES_EXEMPT_RE)
(get_allowed_nested, NestedIncludeCheckerWhitelistOnly)
(NestedIncludeChecker): New.
(HeaderChecker): Instantiate and run a NestedIncludeChecker
for each header.
Zack Weinberg [Sun, 10 Mar 2019 02:18:56 +0000 (21:18 -0500)]
Don’t conditionalize declarations of ldiv_t, lldiv_t, __gwchar_t.
The declarations of ldiv_t, lldiv_t, and __gwchar_t are all wrapped in
__foo_t_defined conditionals, despite there being only one header in
glibc that declares them. I checked codesearch.debian.net and only
found one other program that refers to the __foo_t_defined
conditionals: u-boot provides its own definition of ldiv_t if
__ldiv_t_defined is not defined by stdlib.h. I conclude that the
conditionals are not necessary, but the definitions of
__ldiv_t_defined and __lldiv_t_defined should be preserved.
* stdlib/inttypes.h: Unconditionally define __gwchar_t.
Don’t define ____gwchar_t_defined.
* stdlib/stdlib.h: Unconditionally define ldiv_t.
Condition lldiv_t only on __USE_ISOC99.
Zack Weinberg [Sun, 10 Mar 2019 01:54:02 +0000 (20:54 -0500)]
Create bits/types headers for most remaining __T_defined macros.
This doesn't exactly fit the theme but as long as I'm tinkering with
sys/types.h it makes sense to go through and create single-declaration
bits/types/ headers for all of the remaining cases where we have
two or more headers declaring a public type.
The remaining uses of the original __T_defined idiom are:
__error_t_defined in files shared with gnulib, which probably has to
remain as is; ____gwchar_t_defined in inttypes.h, which may not be
necessary anymore and should be addressed separately, and
__ldiv_t_defined and __lldiv_t_defined in stdlib.h, ditto.
Our handling of LFS types is a little inconsistent: some headers
declare both off_t and off64_t (for instance) when
_LARGEFILE64_SOURCE, others will only declare off_t regardless of
_LARGEFILE64_SOURCE. I don't know if this was intentional or not.
I am tempted to centralize responsibility for _LARGEFILE64_SOURCE as
well as _FILE_OFFSET_BITS=64 in bits/types/off_t.h (etc) so that any
header that declares off_t will automatically also declare off64_t
when _LARGEFILE64_SOURCE.
sunrpc/rpc/types.h is special, because it is included in files
compiled by the *build* compiler (cross-rpcgen-objs), and therefore it
cannot unconditionally assume bits/types headers are available. What
I did was have it include the appropriate bits/types headers only if
including sys/types.h did not cause __BIT_TYPES_DEFINED__ to be
defined. This will do the right thing when an installed rpc/types.h
is included by application code compiled without __USE_MISC in effect.
During the build, we rely on the fact that we compile all of our own
code with __USE_MISC in effect. This is fragile, but should be
acceptable for code that's no longer built by default anyway.
scripts/check-obsolete-constructs.py ensures that only sys/types.h and
rpc/types.h include the bits/types/ headers that define obsolete types.
* posix/bits/types/blkcnt64_t.h
* posix/bits/types/blkcnt_t.h
* posix/bits/types/blksize_t.h
* posix/bits/types/dev_t.h
* posix/bits/types/fsblkcnt64_t.h
* posix/bits/types/fsblkcnt_t.h
* posix/bits/types/fsfilcnt64_t.h
* posix/bits/types/fsfilcnt_t.h
* posix/bits/types/fsid_t.h
* posix/bits/types/gid_t.h
* posix/bits/types/id_t.h
* posix/bits/types/ino64_t.h
* posix/bits/types/ino_t.h
* posix/bits/types/intptr_t.h
* posix/bits/types/key_t.h
* posix/bits/types/loff_t.h
* posix/bits/types/mode_t.h
* posix/bits/types/nlink_t.h
* posix/bits/types/off64_t.h
* posix/bits/types/off_t.h
* posix/bits/types/pid_t.h
* posix/bits/types/socklen_t.h
* posix/bits/types/ssize_t.h
* posix/bits/types/suseconds_t.h
* posix/bits/types/uid_t.h
* posix/bits/types/useconds_t.h:
New single-declaration headers for standard types canonically
defined by sys/types.h, sys/socket.h, or inttypes.h but also
exposed by other headers under some circumstances. Code moved
from posix/sys/types.h, socket/sys/socket.h, stdlib/inttypes.h
as appropriate.
* posix/bits/types/uint.h
* posix/bits/types/u_int.h
* posix/bits/types/u_intN_t.h
* posix/bits/types/caddr_t.h
* posix/bits/types/daddr_t.h
* posix/bits/types/loff_t.h
* posix/bits/types/register_t.h:
Similarly, but for obsolete BSD-derived types whose canonical
home is sys/types.h. Some of these headers define more than
one type.
* posix/Makefile (headers): Install the above new headers.
Rewrap the list.
* posix/sys/types.h: All definitions of public types now
accomplished using the above new headers. Consolidate
groups of definitions controlled by the same feature
selection macros.
* inet/arpa/inet.h, bits/socket.h
* sysdeps/mach/hurd/bits/socket.h
* sysdeps/unix/sysv/linux/bits/socket.h:
Use bits/types/socklen_t.h.
* dirent/dirent.h: Use bits/types/ino_t.h and bits/types/ino64_t.h.
* grp/grp.h: Use bits/types/gid_t.h.
* io/fcntl.h: Use bits/types/mode_t.h, bits/types/off_t.h,
bits/types/pid_t.h, and bits/types/off64_t.h.
* io/sys/stat.h: Use bits/types/dev_t.h, bits/types/gid_t.h,
bits/types/ino_t.h, bits/types/mode_t.h, bits/types/nlink_t.h,
bits/types/off_t.h, bits/types/uid_t.h, and bits/types/blkcnt_t.h.
* libio/stdio.h: Use bits/types/off_t.h, bits/types/off64_t.h,
and bits/types/ssize_t.h.
* misc/sys/mman.h: Use bits/types/off_t.h and bits/types/mode_t.h.
* misc/sys/select.h: Use bits/types/suseconds_t.h.
* posix/sched.h: Use bits/types/pid_t.h.
* posix/sys/wait.h: Use bits/types/pid_t.h and bits/types/id_t.h.
* posix/unistd.h: Use bits/types/gid_t.h, bits/types/uid_t.h,
bits/types/off_t.h, bits/types/off64_t.h, bits/types/useconds_t.h,
bits/types/intptr_t.h, and bits/types/socklen_t.h.
* pwd/pwd.h: Use bits/types/gid_t.h and bits/types/uid_t.h.
* resource/sys/resource.h: Use bits/types/id_t.h.
* signal/signal.h: Use bits/types/pid_t.h and bits/types/uid_t.h.
* stdlib/monetary.h: Use bits/types/ssize_t.h.
* sysdeps/gnu/utmpx.h: Use bits/types/pid_t.h.
* sysvipc/sys/ipc.h: Use bits/types/uid_t.h, bits/types/gid_t.h,
bits/types/mode_t.h, and bits/types/key_t.h.
* sysvipc/sys/msg.h: Use bits/types/pid_t.h and bits/types/ssize_t.h.
* sysvipc/sys/shm.h: Use bits/types/pid_t.h.
* termios/termios.h: Use bits/types/pid_t.h.
* time/sys/time.h: Use bits/types/suseconds_t.h.
* time/time.h: Use bits/types/pid_t.h.
* sunrpc/rpc/types.h: Consolidate all #includes at the top of
the file. If __BIT_TYPES_DEFINED__ is not defined after
including sys/types.h, also include bits/types/caddr_t.h,
bits/types/daddr_t.h, bits/types/fsid_t.h, and bits/types/u_int.h.
* scripts/check-obsolete-constructs.py (OBSOLETE_TYPE_HDR_RE_): New.
(ObsoleteIndirectDefinitionsAllowed): New; allows inclusion of
bits/types/ headers that define obsolete typedefs, but not
direct definitions of those types.
(ObsoleteNotAllowed, ObsoletePrivateDefinitionsAllowed)
(ObsoletePublicDefinitionsAllowed): Do not allow inclusion of
bits/types/ headers that define obsolete typedefs.
Zack Weinberg [Sat, 9 Mar 2019 23:01:48 +0000 (18:01 -0500)]
Clean up bits/types.h.
This makes four linked changes to bits/types.h. First, we use
__(u)?int(16|32|64)_t to define __[SU](16|32|64)_TYPE. In addition
to reducing the amount of ifdeffage, this means __STD_TYPE is no longer
necessary, since gcc -std=c89 will complain about ‘typedef long long foo_t’
but not ‘typedef __int64_t foo_t’, even if the underlying type
of __int64_t is long long.
Second, we eliminate __UQUAD_TYPE and __SQUAD_TYPE from the set of
macros bits/typesizes.h should use to define __FOO_T_TYPE macros,
since they are always the same as __U64_TYPE and __S64_TYPE
respectively.
Third, we remove __u_char, __u_short, __u_int, __u_long, __u_quad_t,
and __quad_t, we add __uintptr_t, and we define __intmax_t and
__uintmax_t as __int64_t and __uint64_t.
Fourth, we reorganize the list of typedefs into groups by the
standard (if any) that defines them, and sort them alphabetically within
each group.
* posix/bits/types.h: Move #error for __WORDSIZE neither 32 nor 64
to first group of conditionals on __WORDSIZE, and make it more
explicit. Update commentary. Define all __foo_t types with
regular ‘typedef’. Reorganize all __foo_t types into the same
groups that sys/types.h uses.
(__u_char, __u_short, __u_int, __u_long, __quad_t, __u_quad_t)
(__UQUAD_TYPE, __SQUAD_TYPE, __STD_TYPE): Don’t define.
(__S16_TYPE): Define unconditionally as __int16_t.
(__U16_TYPE): Define unconditionally as __uint16_t.
(__S32_TYPE): Define unconditionally as __int32_t.
(__U32_TYPE): Define unconditionally as __uint32_t.
(__S64_TYPE): Define unconditionally as __int64_t.
(__U64_TYPE): Define unconditionally as __uint64_t.
(__intmax_t): Define unconditionally as __int64_t.
(__uintmax_t): Define unconditionally as __uint64_t.
(__uintptr_t): New typedef.
* bits/time64.h
* bits/typesizes.h
* sysdeps/mach/hurd/bits/typesizes.h
* sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
* sysdeps/unix/sysv/linux/generic/bits/typesizes.h
* sysdeps/unix/sysv/linux/mips/bits/typesizes.h
* sysdeps/unix/sysv/linux/s390/bits/typesizes.h
* sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
* sysdeps/unix/sysv/linux/x86/bits/typesizes.h:
Replace all uses of __UQUAD_TYPE with __U64_TYPE, and all
uses of __SQUAD_TYPE with __S64_TYPE.
* posix/sys/types.h, rpc/sys/types.h
(u_char): Define as unsigned char.
(u_short): Define as unsigned short.
(u_int): Define as unsigned int.
(u_long): Define as unsigned long.
(quad_t): Define as __int64_t.
(u_quad_t): Define as __uint64_t.
* stdlib/stdint.h (intptr_t): Define as __intptr_t.
(uintptr_t): Define as __uintptr_t.
* scripts/check-obsolete-constructs.py: Update allowed
definitions for the obsolete types. No longer allow
__STD_TYPE as an alias for typedef.
Zack Weinberg [Sat, 9 Mar 2019 21:01:38 +0000 (16:01 -0500)]
Simplify definition of __time64_t.
bits/time64.h always sets __TIME64_T_TYPE to be __time_t when
__TIMESIZE == 64, so we can unconditionally use __TIME64_T_TYPE to
define __time64_t; we don’t need another conditional in bits/types.h.
Also move the definition of __time64_t next to the definition of
__time_t.
* posix/bits/types.h (__time64_t): Unconditionally define
as __TIME64_T_TYPE. Move definition next to __time_t.
Zack Weinberg [Sat, 9 Mar 2019 16:59:02 +0000 (11:59 -0500)]
Add caddr_t, daddr_t, and loff_t to the set of obsolete typedefs.
caddr_t is a BSD-derived alias for ‘char *’, obsoleted by the
introduction of ‘void *’ in C89 (!) daddr_t is a “disk address,”
but it’s always defined as ‘int’, making it too small for modern
disks and tapes. loff_t is another name for off64_t, from early
drafts of LFS. All three are already only exposed by sys/types.h
under __USE_MISC.
This patch adds them to the set of types that shall not be used in
installed headers (enforced by check-obsolete-constructs.py) and
expunges all remaining uses, internally as well as in installed
headers. Since __DADDR_T_TYPE is always defined as __S32_TYPE, and
daddr_t is obsolete so there’s no need to worry about future
variation, the patch also removes __DADDR_T_TYPE from the set of
macros that bits/typesizes.h is required to define. Instead
bits/types.h always defines __daddr_t as __S32_TYPE, and the
definition is moved to a more logical location within the file, next
to __caddr_t.
It’s always safe to change (__)loff_t to the matching (__)off64_t;
in a few internal files, I removed an unnecessary __ prefix.
daddr_t is only used for struct ustat, which is obsoleted by struct
statvfs and we already don’t declare it in public headers, and for an
ioctl parameter block in sys/mtio.h (which may or may not be obsolete,
I can’t tell). In sys/mtio.h I replaced both uses with ‘int’ to match
the use of bare ‘long int’ for most of the other fields of that
structure. In misc/ustat.c, the definition of struct ustat is not
actually necessary so I removed it entirely. In
sysdeps/unix/sysv/linux/ustat.c a definition is necessary but only
because INLINE_SYSCALL_CALL doesn’t work (on at least x86) when an
argument is a pointer to an incomplete type, so I substituted a dummy
definition.
Most of the internal uses of caddr_t are in the sunrpc and nis
directories, and since most of that code is obsolete, I mechanically
replaced them with char * rather than consider whether void * might
make more sense. Because “const caddr_t foo” is semantically
different from “const char *foo” (in the first case ‘foo’ itself is
const but the memory pointed to isn’t, in the second case the memory
pointed to is const but ‘foo’ isn’t) this change exposed some
const-correctness errors in sunrpc, which I fixed minimally. Outside
of sunrpc and nis, I put a little more thought into whether uses of
caddr_t should be void * instead.
* scripts/check-obsolete-constructs.py: Add caddr_t, daddr_t,
and loff_t to the set of obsolete types forbidden in public
headers.
* posix/bits/types.h: Unconditionally define __daddr_t as
__S32_TYPE. Move definition of __daddr_t next to definition
of __caddr_t.
* bits/typesizes.h
* sysdeps/mach/hurd/bits/typesizes.h
* sysdeps/unix/sysv/linux/alpha/bits/typesizes.h
* sysdeps/unix/sysv/linux/generic/bits/typesizes.h
* sysdeps/unix/sysv/linux/mips/bits/typesizes.h
* sysdeps/unix/sysv/linux/s390/bits/typesizes.h
* sysdeps/unix/sysv/linux/sparc/bits/typesizes.h
* sysdeps/unix/sysv/linux/x86/bits/typesizes.h:
Don’t define __DADDR_T_TYPE.
* sysdeps/gnu/sys/mtio.h (struct mtget): Change all uses of
__daddr_t to int.
* misc/ustat.c: Remove definition of struct ustat; only
forward-declare it.
* sysdeps/unix/sysv/linux/ustat.c: Replace fields of
struct ustat with a size-preserving dummy field.
* hurd/Makefile (migheaderpipe): Rewrite loff_t as __off64_t.
* hurd/fd-read.c (_hurd_fd_read): Use off64_t instead of loff_t.
* hurd/fd-write.c (hurd_fd_write): Use off64_t instead of loff_t.
* hurd/hurd/fd.h (_hurd_fd_read, _hurd_fd_write): Declare
using __off64_t instead of __loff_t.
* support/xunistd.h (xcopy_file_range): Declare using off64_t
instead of loff_t.
* sysdeps/unix/sysv/linux/generic/wordsize-32/overflow.h
* sysdeps/unix/sysv/linux/lseek.c
* sysdeps/unix/sysv/linux/lseek64.c
* sysdeps/unix/sysv/linux/splice.c
Throughout, use off64_t instead of loff_t.
* sysdeps/unix/sysv/linux/sys/quota.h
(dqoff): Use __off64_t instead of __loff_t.
(quotactl): Declare using char * instead of caddr_t.
* sysdeps/unix/sysv/linux/test-errno-linux.c
(do_test): Cast to char * instead of caddr_t when calling quotactl.
* elf/dl-map-segments.h (_dl_map_segments): Cast to void *
instead of caddr_t when calling __mprotect and __mmap.
* elf/dl-minimal.c (malloc): Declare page as char *, not caddr_t.
* elf/dl-reloc.c (_dl_relocate_object): Declare textrels.start
as char *, not caddr_t. Cast to char *, not caddr_t, in
pointer arithmetic.
* intl/loadmsgcat.c: Remove two unnecessary casts to caddr_t
when calling munmap. Change a third cast to target void *
instead and add a comment explaining why this one is necessary.
* locale/loadlocale.c (_nl_load_locale): Use NULL instead of
`(caddr_t)0`, and remove an unnecessary cast to caddr_t when
calling munmap.
(_nl_unload_locale): Change casts when calling free and munmap
to target char *, and add a comment explaining why they are
necessary.
* sysdeps/gnu/net/if.h
(struct ifreq): Declare ifru_data as char *, not __caddr_t.
(struct ifconf): Declare ifcu_buf as char *, not __caddr_t.
* sunrpc/xdr_mem.c (xdrmem_create): Cast away const when
setting xdrs->x_private and xdrs->x_base.
* sunrpc/xdr_stdio.c (xdrstdio_getbytes): Correct argument
types in definition to match prototype.
Zack Weinberg [Tue, 19 Feb 2019 02:00:34 +0000 (21:00 -0500)]
sys/types.h: Don’t define u_intN_t or register_t unless __USE_MISC.
sys/types.h unconditionally defines u_int8_t, u_int16_t, u_int32_t,
u_int64_t, and register_t. These are not part of any standard. The
u_intXX_t types are superseded by C99’s uintXX_t types (defined in
stdint.h). I’m not aware of a standardized exact equivalent of
register_t, but also I’ve never seen anyone use it for anything.
I could be persuaded to leave that one alone.
sys/types.h also unconditionally defines int8_t, int16_t, int32_t, and
int64_t, which are the same as the C99 exact-width signed types in
stdint.h. POSIX doesn’t require these to appear in sys/types.h, so in
principle they ought to be brought under __USE_MISC also. But, when I
tried that it broke about two dozen files just in our own source tree,
and POSIX doesn’t *forbid* sys/types.h to define these types, so I
think we should leave them alone.
* posix/sys/types.h (u_int8_t, u_int16_t, u_int32_t, u_int64_t)
(register_t): Move under #ifdef __USE_MISC.
Consolidate adjacent #ifdef __USE_MISC blocks.
* scripts/check_obsolete_constructs.py: Add register_t to the
set of obsolete typedefs that our headers should not use
(but sys/types.h may still define).
Zack Weinberg [Tue, 19 Feb 2019 13:45:22 +0000 (08:45 -0500)]
Define register_t using bits/typesizes.h macros.
Currently register_t is, unlike all other types in sys/types.h,
defined using a GCC extension (__attribute__((mode(word)))), falling
back to ‘int’ if the extension is unavailable. This is a potential
ABI compatibility hazard for people using non-GNU compilers with
glibc. It’s also unnecessary; the bits/typesizes.h mechanism can
handle all of the existing variation in the definition. In most
cases, defining __REGISTER_T_TYPE as __SWORD_TYPE is sufficient.
Special handling is necessary for MIPS n32 and x86-64 x32, where
__SWORD_TYPE is ‘int’ and the appropriate type for register_t is
‘long long’. Unfortunately, this means we need to create a new
bits/typesizes.h variant for linux/mips. This variant is based
on the top-level bits/typesizes.h, not linux/generic/bits/typesizes.h,
to match the existing MIPS ABIs.
Tested using build-many-glibcs. The c++-types test confirms that the
physical type of register_t does not change on any supported platform.
* posix/sys/types.h: Typedef register_t as __register_t.
* posix/bits/types.h: Typedef __register_t using __REGISTER_T_TYPE.
* sysdeps/unix/sysv/linux/mips/bits/typesizes.h:
New file (copied from bits/typesizes.h).
Define __REGISTER_T_TYPE as __SWORD_TYPE for o32 and n64 ABIs.
Define __REGISTER_T_TYPE as __SQUAD_TYPE for n32.
* sysdeps/unix/sysv/linux/x86/bits/typesizes.h:
Define __REGISTER_T_TYPE as __SWORD_TYPE for o32 and 64-bit ABIs.
Define __REGISTER_T_TYPE as __SQUAD_TYPE for x32.
Zack Weinberg [Sun, 24 Feb 2019 00:08:54 +0000 (19:08 -0500)]
Move most headers installed by top-level Makefile to misc/.
The Makefile glue to run tests on installed headers is currently
duplicated between the top-level Makefile and Rules, because the
top-level Makefile doesn't read Rules but does install some headers.
This patch moves most of the headers installed by the top-level Makefile
to misc/ (chosen arbitrarily; I'm open to putting them somewhere else
if reviewers feel it would be better) and removes the duplicated logic
from the top-level Makefile. I believe this also means that none of
the headers in include/ are installed headers anymore.
gnu/lib-names*.h are still generated by code in Makerules and installed
by the top-level Makefile. I tried to move them to misc/ as well, but
that broke the generation process in a manner that didn't make any sense
so I gave up. The tests performed on installed headers are not
especially useful for gnu/lib-names*.h so I think we can live with this
for now.
* include/bits/xopen_lim.h
* include/features.h
* include/gnu-versions.h
* include/gnu/libc-version.h
* include/limits.h
* include/stdc-predef.h
* include/values.h:
Move to misc/ and replace with a trivial wrapper.
* Makefile (headers): Remove all headers moved to misc/.
Don't set a vpath for %.h.
(check-installed-headers-c.out, check-installed-headers-cxx.out)
(check-wrapper-headers.out): Remove rules.
* misc/Makefile (headers): Add all of the above headers and
sort the list.
* sysdeps/mach/hurd/bits/errno.h: Regenerate.
Samuel Thibault [Sat, 4 Jan 2020 18:37:53 +0000 (19:37 +0100)]
htl: Add __errno_location and __h_errno_location
As explained on
https://sourceware.org/ml/libc-alpha/2020-01/msg00049.html
the presence of __errno_location in libpthread.so on GNU/Linux makes
libpthread getting linked in for libstdc++. This aligns on that behavior, to
avoid issues that only GNU/Hurd would get.
Samuel Thibault [Sat, 4 Jan 2020 17:53:23 +0000 (18:53 +0100)]
htl: Move pthread_atfork to libc_nonshared.a
This follows bd60ce86520b ('nptl: Move pthread_atfork to libc_nonshared.a')
with the same rationale: there is no non-libpthread equivalent to be used
for making linking against libpthread optional.
libpthread_nonshared.a is unused after this, so remove it from the
build.
There is no ABI impact because pthread_atfork was implemented using
__register_atfork in libc even before this change.
pthread_atfork has to be a weak alias because pthread_* names are not
reserved in libc.
This patch avoid probing the __NR_clock_getttime64 syscall each time
__clock_gettime64 is issued on a kernel without 64 bit time support.
Once ENOSYS is obtained, only 32-bit clock_gettime are used.
No architecture currently defines the vDSO symbol. On archictures
with 64-bit time_t the HAVE_CLOCK_GETRES_VSYSCALL is renamed to
HAVE_CLOCK_GETRES64_VSYSCALL, it simplifies clock_gettime code.
This patch avoid probing the __NR_clock_getttime64 syscall each time
__clock_gettime64 is issued on a kernel without 64 bit time support.
Once ENOSYS is obtained, only 32-bit clock_gettime are used.
No architecture currently defines the vDSO symbol. On architectures
with 64-bit time_t the HAVE_CLOCK_GETTIME_VSYSCALL is renamed to
HAVE_CLOCK_GETTIME64_VSYSCALL, it simplifies clock_gettime code.
This patch moves the vDSO setup from libc to loader code, just after
the vDSO link_map setup. For static case the initialization
is moved to _dl_non_dynamic_init instead.
Instead of using the mangled pointer, the vDSO data is set as
attribute_relro (on _rtld_global_ro for shared or _dl_vdso_* for
static). It is read-only even with partial relro.
It fixes BZ#24967 now that the vDSO pointer is setup earlier than
malloc interposition is called.
Also, vDSO calls should not be a problem for static dlopen as
indicated by BZ#20802. The vDSO pointer would be zero-initialized
and the syscall will be issued instead.
Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu,
arm-linux-gnueabihf, powerpc64le-linux-gnu, powerpc64-linux-gnu,
powerpc-linux-gnu, s390x-linux-gnu, sparc64-linux-gnu, and
sparcv9-linux-gnu. I also run some tests on mips.
The code is similar to the one at elf/dl-reloc.c, where it checks for
the l_relro_size from the link_map (obtained from PT_GNU_RELRO header
from program headers) and calls_dl_protected_relro.
For testing I will use the ones proposed by Florian's patch
'elf: Add tests for working RELRO protection' [1].
Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
aarch64-linux-gnu, s390x-linux-gnu, and sparc64-linux-gnu. I also
check with --enable-static pie on x86_64-linux-gnu, i686-linux-gnu,
and aarch64-linux-gnu which seems the only architectures where
static PIE is actually working (as per 9d7a3741c9e, on
arm-linux-gnueabihf, powerpc64{le}-linux-gnu, and s390x-linux-gnu
I am seeing runtime issues not related to my patch).
The IFUNC bypass to vDSO is used when USE_IFUNC_TIME is set.
Currently powerpc and x86 defines it. Otherwise the generic
implementation is used, which calls clock_gettime.
Checked on powerpc64le-linux-gnu, powerpc64-linux-gnu,
powerpc-linux-gnu-power4, x86_64-linux-gnu, and i686-linux-gnu.
The IFUNC bypass to vDSO is used when USE_IFUNC_GETTIMEOFDAY is set.
Currently aarch64, powerpc*, and x86 defines it. Otherwise the
generic implementation is used, which calls clock_gettime.
Checked on aarch64-linux-gnu, powerpc64le-linux-gnu,
powerpc64-linux-gnu, powerpc-linux-gnu-power4, x86_64-linux-gnu,
and i686-linux-gnu.
- It requires sync the auto-generated C file with current glibc
implementation;
- It still uses symbol redirections hacks where libc-symbols.h
provide macros that uses compiler builtins
(libc_ifunc_redirected for instance);
- It does not handle all required compiler handling
(inhibit_stack_protector on iFUNC resolver).
- No architecure uses it.
This is the only use of auto-generation syscall which uses a vDSO
plus IFUNC and the current x86 generic implementation already covers
the expected semantic.
linux: Fix vDSO macros build with time64 interfaces
As indicated on libc-help [1] the ec138c67cb commit broke 32-bit
builds when configured with --enable-kernel=5.1 or higher. The
scenario 10 from [2] might also occur in this configuration and
INLINE_VSYSCALL will try to use the vDSO symbol and
HAVE_CLOCK_GETTIME64_VSYSCALL does not set HAVE_VSYSCALL prior its
usage.
Also, there is no easy way to just enable the code to use one
vDSO symbol since the macro INLINE_VSYSCALL is redefined if
HAVE_VSYSCALL is set.
Instead of adding more pre-processor handling and making the code
even more convoluted, this patch removes the requirement of defining
HAVE_VSYSCALL before including sysdep-vdso.h to enable vDSO usage.
The INLINE_VSYSCALL is now expected to be issued inside a
HAVE_*_VSYSCALL check, since it will try to use the internal vDSO
pointers.
Both clock_getres and clock_gettime vDSO code for time64_t were
removed since there is no vDSO setup code for the symbol (an
architecture can not set HAVE_CLOCK_GETTIME64_VSYSCALL).
Checked on i686-linux-gnu (default and with --enable-kernel=5.1),
x86_64-linux-gnu, aarch64-linux-gnu, and powerpc64le-linux-gnu.
I also checked against a build to mips64-linux-gnu and
sparc64-linux-gnu.
The result of INTERNAL_SYSCALL_CANCEL should be checked with
macros INTERNAL_SYSCALL_ERROR_P and INTERNAL_SYSCALL_ERRNO instead
of comparing the result directly.
This patch adds a new macro, libm_alias_finite, to define all _finite
symbol. It sets all _finite symbol as compat symbol based on its first
version (obtained from the definition at built generated first-versions.h).
The <fn>f128_finite symbols were introduced in GLIBC 2.26 and so need
special treatment in code that is shared between long double and float128.
It is done by adding a list, similar to internal symbol redifinition,
on sysdeps/ieee754/float128/float128_private.h.
Alpha also needs some tricky changes to ensure we still emit 2 compat
symbols for sqrt(f).
Rafał Lużyński [Mon, 30 Dec 2019 10:58:18 +0000 (11:58 +0100)]
Multiple locales: Add date_fmt (bug 24054)
It is not specified what should be the content of d_t_fmt and date_fmt
but in the built-in C locale those fields have only one difference:
date_fmt contains "%Z" (the current time zone) while d_t_fmt does not.
For most of the locales this commit does the following operation:
copy d_t_fmt to date_fmt, and then remove "%Z" from d_t_fmt.
If "%Z" was originally missing from d_t_fmt add it to date_fmt.
It also corrects comments where necessary.
Exceptions:
* In bo_CN, dz_BT, and km_KH "%Z" has not been added to date_fmt because
it was too difficult. In these locales date_fmt has been set to the
copy of d_t_fmt.
* In en_DK "%Z" has not been removed from d_t_fmt in order to preserve
the conformance with the standard mentioned in the comment.
The command to identify and initially edit the locales that need the
update was:
for i in `grep -lw d_t_fmt *`
do
if ! grep -qw date_fmt $i ; then
awk '/d_t_fmt/ { print $0; gsub("d_t_fmt", "date_fmt"); } //{ print $0 }' < $i > $i.next
mv $i.next $i
fi
done
Hurd uses an empty prefix, so the linker scripts end up in /lib, the
find command picked them up, and stripping them failed because they
are not ELF files.
Florian Weimer [Thu, 2 Jan 2020 09:18:37 +0000 (10:18 +0100)]
Linux: Remove pread/pread64, pwrite/pwrite64 kludges from <sysdep.h>
Since the switch away from auto-generated wrappers for these system
calls, the kludge is already included in the C source file of the
system call wrapper.
This command uses pre-built compilers to re-install the Linux headers
from the current sources into a temporary location and runs glibc's
“make update-syscalls-lists” against that. This updates the glibc
source tree with the current system call numbers.
The new classes GlibcPolicyForCompiler and GlibcPolicyForBuild allow
customization of the Glibc.build_glibc method, replacing the existing
for_compiler flag.
Florian Weimer [Thu, 2 Jan 2020 09:18:22 +0000 (10:18 +0100)]
Linux: Use system call tables during build
Use <arch-syscall.h> instead of <asm/unistd.h> to obtain the system
call numbers. A few direct includes of <asm/unistd.h> need to be
removed (if the system call numbers are already provided indirectly
by <sysdep.h>) or replaced with <sys/syscall.h>.
Current Linux headers for alpha define the required system call names,
so most of the _NR_* hacks are no longer needed. For the 32-bit arm
architecture, eliminate the INTERNAL_SYSCALL_ARM macro, now that we
have regular system call names for cacheflush and set_tls. There are
more such cleanup opportunities for other architectures, but these
cleanups are required to avoid macro redefinition errors during the
build.
For ia64, it is desirable to use <asm/break.h> directly to obtain
the break number for system calls (which is not a system call number
itself). This requires replacing __BREAK_SYSCALL with
__IA64_BREAK_SYSCALL because the former is defined as an alias in
<asm/unistd.h>, but not in <asm/break.h>.
Florian Weimer [Thu, 2 Jan 2020 09:18:10 +0000 (10:18 +0100)]
Linux: Add tables with system call numbers
The new tables are currently only used for consistency checks
with the installed kernel headers and the architecture-independent
system call names table. They are based on Linux 5.4.
The goal is to use these architecture-specific tables to ensure
that system call wrappers are available irrespective of the version
of the installed kernel headers.
The tables are formatted in the form of C header files so that they
can be used directly in an #include directive, without external
preprocessing. (External preprocessing of a plain table file
would introduce cross-subdirectory dependency issues.) However,
the intent is that they can still be treated as tables and can be
processed by simple tools.
The irregular system call names on 32-bit arm add a complication.
The <fixup-asm-unistd.h> header is introduced to work around that,
and the system calls are listed under regular names in the
<arch-syscall.h> file.
A make target, update-syscalls-list, is added to patch the glibc
sources with data from the current kernel headers.
Joseph Myers [Wed, 1 Jan 2020 00:21:22 +0000 (00:21 +0000)]
Update copyright dates not handled by scripts/update-copyrights.
I've updated copyright dates in glibc for 2020. This is the patch for
the changes not generated by scripts/update-copyrights and subsequent
build / regeneration of generated files. As well as the usual annual
updates, mainly dates in --version output (minus libc.texinfo which
previously had to be handled manually but is now successfully updated
by update-copyrights), there is a fix to
sysdeps/unix/sysv/linux/powerpc/bits/termios-c_lflag.h where a typo in
the copyright notice meant it failed to be updated automatically.
Please remember to include 2020 in the dates for any new files added
in future (which means updating any existing uncommitted patches you
have that add new files to use the new copyright dates in them).
Rafał Lużyński [Mon, 30 Dec 2019 10:42:46 +0000 (11:42 +0100)]
lv_LV locale: Correct the time part of d_t_fmt (bug 25324)
Currently d_t_fmt formats time as "plkst. %H un %M". A quick Google
search says that "plkst." means "o’clock" and "un" means "and".
Also this format does not display seconds.
CLDR does not mention anything like that. We have no reason to use
anything different than "%H:%M:%S".
Jeremie Koenig [Sun, 29 Dec 2019 16:59:55 +0000 (17:59 +0100)]
hurd: Global signal disposition
This adds _hurd_sigstate_set_global_rcv used by libpthread to enable
POSIX-confirming behavior of signals on a per-thread basis.
This also provides a sigstate destructor _hurd_sigstate_delete, and a
global process signal state, which needs to be locked and check when
global disposition is enabled, thus the addition of _hurd_sigstate_lock
_hurd_sigstate_actions _hurd_sigstate_pending _hurd_sigstate_unlock helpers.
This also updates all the glibc code accordingly.
This also drops support for get_int(INIT_SIGMASK), which did not make sense
any more since we do not have a single signal thread any more.
During fork/spawn, this also reinitializes the child global sigstate's
lock. That cures an issue that would very rarely cause a deadlock in the
child in fork, tries to unlock ss' critical section lock at the end of
fork. This will typically (always?) be observed in /bin/sh, which is not
surprising as that is the foremost caller of fork.
To reproduce an intermediate state, add an endless loop if
_hurd_global_sigstate is locked after __proc_dostop (cast through
volatile); that is, while still being in the fork's parent process.
When that triggers (use the libtool testsuite), the signal thread has
already locked ss (which is _hurd_global_sigstate), and is stuck at
hurdsig.c:685 in post_signal, trying to lock _hurd_siglock (which the
main thread already has locked and keeps locked until after
__task_create). This is the case that ss->thread == MACH_PORT_NULL, that
is, a global signal. In the main thread, between __proc_dostop and
__task_create is the __thread_abort call on the signal thread which would
abort any current kernel operation (but leave ss locked). Later in fork,
in the parent, when _hurd_siglock is unlocked in fork, the parent's
signal thread can proceed and will unlock eventually the global sigstate.
In the client, _hurd_siglock will likewise be unlocked, but the global
sigstate never will be, as the client's signal thread has been configured
to restart execution from _hurd_msgport_receive. Thus, when the child
tries to unlock ss' critical section lock at the end of fork, it will
first lock the global sigstate, will spin trying to lock it, which can
never be successful, and we get our deadlock.
Options seem to be:
* Move the locking of _hurd_siglock earlier in post_signal -- but that
may generally impact performance, if this locking isn't generally
needed anyway?
On the other hand, would it actually make sense to wait here until we
are not any longer in a critical section (which is meant to disable
signal delivery anyway (but not for preempted signals?))?
* Clear the global sigstate in the fork's child with the rationale that
we're anyway restarting the signal thread from a clean state. This
has now been implemented.
Why has this problem not been observed before Jérémie's patches? (Or has
it? Perhaps even more rarely?) In _S_msg_sig_post, the signal is now
posted to a *global receiver thread*, whereas previously it was posted to
the *designated signal-receiving thread*. The latter one was in a
critical section in fork, so didn't try to handle the signal until after
leaving the critical section? (Not completely analyzed and verified.)
Another question is what the signal is that is being received
during/around the time __proc_dostop executes.
Jeremie Koenig [Sun, 29 Dec 2019 16:18:04 +0000 (17:18 +0100)]
hurd: Signal code refactoring
This should not change the current behavior, although this fixes a few
minor bugs which were made apparent in the process of global signal
disposition work:
- Split into more functions
- Scope variables more restrictively
- Split out inner functions
- refactor check_pending_signals
- make sigsuspend POSIX-conformant.
- fix uninitialized act value.
Not thoroughly tested, but manual testing as well as glibc tests look fine, and
manual -lpthread testing also looks fine (within the given bounds for a new
stack to be used with makecontext).
ldbl-128ibm-compat: Do not mix -mabi=*longdouble and -mlong-double-128
Some compiler versions, e.g. GCC 7, complain when -mlong-double-128 is
used together with -mabi=ibmlongdouble or -mabi=ieeelongdouble,
producing the following error message:
ldbl-128ibm-compat: Compiler flags for stdio functions
Some of the files that provide stdio.h and wchar.h functions have a
filename prefixed with 'io', such as 'iovsprintf.c'. On platforms that
imply ldbl-128ibm-compat, these files must be compiled with the flag
-mabi=ibmlongdouble. This patch adds this flag to their compilation.
Notice that this is not required for the other files that provide
similar functions, because filenames that are not prefixed with 'io'
have ldbl-128ibm-compat counterparts in the Makefile, which already adds
-mabi=ibmlongdouble to them.
Reviewed-by: Gabriel F. T. Gomes <gabrielftg@linux.ibm.com>
Do not redirect calls to __GI_* symbols, when redirecting to *ieee128
On platforms where long double has IEEE binary128 format as a third
option (initially, only powerpc64le), many exported functions are
redirected to their __*ieee128 equivalents. This redirection is
provided by installed headers such as stdio-ldbl.h, and is supposed to
work correctly with user code.
However, during the build of glibc, similar redirections are employed,
in internal headers, such as include/stdio.h, in order to avoid extra
PLT entries. These redirections conflict with the redirections to
__*ieee128, and must be avoided during the build. This patch protects
the second redirections with a test for __LONG_DOUBLE_USES_FLOAT128, a
new macro that is defined to 1 when functions that deal with long double
typed values reuses the _Float128 implementation (this is currently only
true for powerpc64le).
Tested for powerpc64le, x86_64, and with build-many-glibcs.py.
Co-authored-by: Gabriel F. T. Gomes <gabrielftg@linux.ibm.com> Reviewed-by: Florian Weimer <fweimer@redhat.com>
The functions do not fail regardless of the argument value. Also, for
Linux the return value is not correct on some platforms due the missing
usage of INTERNAL_SYSCALL_ERROR_P / INTERNAL_SYSCALL_ERRNO macros.
Checked on x86_64-linux-gnu, i686-linux-gnu, and sparc64-linux-gnu.
Avoid compat symbols for totalorder in powerpc64le IEEE long double
On powerpc64le, the libm_alias_float128_other_r_ldbl macro is
used to create an alias between totalorderf128 and __totalorderlieee128,
as well as between the totalordermagf128 and __totalordermaglieee128.
However, the totalorder* and totalordermag* functions changed their
parameter type since commit ID 42760d764649 and got compat symbols for
their old versions. With this change, the aforementioned macro would
create two conflicting aliases for __totalorderlieee128 and
__totalordermaglieee128.
This patch avoids the creation of the alias between the IEEE long double
symbols (__totalorderl*ieee128) and the compat symbols, because the IEEE
long double functions have never been exported thus don't need such
compat symbol.
Tested for powerpc64le.
Reviewed-by: Joseph Myers <joseph@codesourcery.com>
This patch adds IEEE long double versions of q*cvt* functions for
powerpc64le. Unlike all other long double to/from string conversion
functions, these do not rely on internal functions that can take
floating-point numbers with different formats and act on them
accordingly, instead, the related files are rebuilt with the
-mabi=ieeelongdouble compiler flag set.
Having -mabi=ieeelongdouble passed to the compiler causes the object
files to be marked with a .gnu_attribute that is incompatible with the
.gnu_attribute in files built with -mabi=ibmlongdouble (the default).
The difference causes error messages similar to the following:
ld: libc_pic.a(s_isinfl.os) uses IBM long double,
libc_pic.a(ieee128-qefgcvt_r.os) uses IEEE long double.
collect2: error: ld returned 1 exit status
make[2]: *** [../Makerules:649: libc_pic.os] Error 1
Although this warning is useful in other situations, the library
actually needs to have functions with different long double formats, so
.gnu_attribute generation is explicitly disabled for these files with
the use of -mno-gnu-attribute.
Tested for powerpc64le on the branch that actually enables the
sysdeps/ieee754/ldbl-128ibm-compat for powerpc64le.
Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com>
This patch refactors the *cvt functions implementation in a way that
makes it easier to re-use them for implementing the IEEE long double on
powerpc64le. By removing the macros that generate the function names
(APPEND combined with FUNC_PREFIX), the new code makes it easier to
define new function names, such as __qecvtieee128.
Tested that installed stripped binaries for all build-many-glibcs
targets remain identical before and after this patch. Also tested for
powerpc64le and x86_64.
Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com>
This patch refactors the *cvt functions implementation in a way that
makes it easier to re-use them for implementing the IEEE long double on
powerpc64le. By splitting the implementation per se in one file
(efgcvt-template.c) and the alias definitions in others (e.g. efgcvt.c),
the new code makes it easier to define new function names, such as
__qecvtieee128.
Tested that installed stripped binaries for all build-many-glibcs
targets remain identical before and after this patch. Also tested for
powerpc64le and x86_64.
Reviewed-by: Paul E. Murphy <murphyp@linux.ibm.com>
Xuelei Zhang [Thu, 19 Dec 2019 15:26:33 +0000 (15:26 +0000)]
aarch64: Optimized memset for Kunpeng processor.
Due to the branch prediction issue of Kunpeng processor, we found
memset_generic has poor performance on middle sizes setting, and so
we reconstructed the logic, expanded the loop by 4 times in set_long
to solve the problem, even when setting below 1K sizes have benefit.
Another change is that DZ_ZVA seems no work when setting zero, so we
discarded it and used set_long to set zero instead. Fewer branches and
predictions also make the zero case have slightly improvement.
Xuelei Zhang [Thu, 19 Dec 2019 13:41:40 +0000 (13:41 +0000)]
aarch64: Optimized strlen for strlen_asimd
Optimize the strlen implementation by using vector operations and
loop unrolling in main loop.Compared to __strlen_generic,it reduces
latency of cases in bench-strlen by 7%~18% when the length of src
is greater than 128 bytes, with gains throughout the benchmark.
Xuelei Zhang [Thu, 19 Dec 2019 14:53:29 +0000 (14:53 +0000)]
aarch64: Optimized implementation of memrchr
Considering the excellent performance of memchr.S on glibc 2.30, the
same algorithm is used to find chrin. Compared to memrchr.c, this
method with memrchr.S achieves an average performance improvement
of 58% based on benchtest and its extension cases.
Xuelei Zhang [Thu, 19 Dec 2019 13:49:46 +0000 (13:49 +0000)]
aarch64: Optimized implementation of strnlen
Optimize the strlen implementation by using vector operations and
loop unrooling in main loop. Compared to aarch64/strnlen.S, it
reduces latency of cases in bench-strnlen by 11%~24% when the length
of src is greater than 64 bytes, with gains throughout the benchmark.
Xuelei Zhang [Thu, 19 Dec 2019 13:08:11 +0000 (13:08 +0000)]
aarch64: Optimized implementation of strcpy
Optimize the strcpy implementation by using vector loads and operations
in main loop.Compared to aarch64/strcpy.S, it reduces latency of cases
in bench-strlen by 5%~18% when the length of src is greater than 64
bytes, with gains throughout the benchmark.
Xuelei Zhang [Thu, 19 Dec 2019 12:31:59 +0000 (12:31 +0000)]
aarch64: Optimized implementation of memcmp
The loop body is expanded from a 16-byte comparison to a 64-byte
comparison, and the usage of ldp is replaced by the Post-index
mode to the Base plus offset mode. Hence, compare can faster 18%
around > 128 bytes in all.
linux: Use waitid on wait4 if __NR_wait4 is not defined
If the wait4 syscall is not available (such as y2038 safe 32-bit
systems) waitid should be used instead. However prior Linux 5.4
waitid is not a full superset of other wait syscalls, since it
does not include support for waiting for the current process group.
It is possible to emulate wait4 by issuing an extra syscall to get
the current process group, but it is inherent racy: after the current
process group is received and before it is passed to waitid a signal
could arrive causing the current process group to change.
So waitid is used if wait4 is not defined iff the build is
enabled with a minimum kernel if 5.4+. The new assume
__ASSUME_WAITID_PID0_P_PGID is added and an error is issued if waitid
can not be implemented by either __NR_wait4 or
__NR_waitid && __ASSUME_WAITID_PID0_P_PGID.
Checked on x86_64-linux-gnu and i686-linux-gnu.
Co-authored-by: Alistair Francis <alistair.francis@wdc.com>
The POSIX implementation is used as default and both BSD and Linux
version are removed. It simplifies the implementation for
architectures that do not provide either __NR_waitpid or
__NR_wait4.
Checked on x86_64-linux-gnu and powerpc64le-linux-gnu.
It enables and disables cancellation with pthread_setcancelstate
before calling the waitpid. It simplifies the waitpid implementation
for architectures that do not provide either __NR_waitpid or
__NR_wait4.
Florian Weimer [Thu, 19 Dec 2019 13:45:50 +0000 (14:45 +0100)]
Fix test isolation for elf/tst-ifunc-fault-lazy, elf/tst-ifunc-fault-bindnow
Previously, ld.so was invoked only with the elf subdirectory on the
library search path. Since the soname link for libc.so only exists in
the top-level build directory, this leaked the system libc into the
test.
Another possible fix is use a static const object. Although there
should not be a difference between a const compound literal and a static
const object, the gcc C99 status page [1] has a note stating that this
optimization is not implemented:
"const-qualified compound literals could share storage with each
other and with string literals, but currently don't.".
This patch fixes it by moving both sigset_t that represent the
signal sets to static const data object. It generates slight better
code where the object reference is used directly instead of a stack
allocation plus the content materialization.
Checked on x86_64-linux-gnu, i686-linux-gnu, and sparc64-linux-gnu.
Florian Weimer [Wed, 18 Dec 2019 09:27:10 +0000 (10:27 +0100)]
hurd: Do not make sigprocmask available in ld.so
After commit f7649d5780aa4682393b9daedd653e4d9c12784c ("dlopen: Do not
block signals"), the dynamic linker no longer uses sigprocmask, which
means that it does not have to be made available explicitly on hurd.