From cb54252075282ed6ed171a5b0d8eb372c2b06522 Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Tue, 28 May 2019 13:59:08 -0400 Subject: Add bits/types/ wrappers for stddef.h and stdarg.h types. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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. * debug/wcpcpy_chk.c, iconv/loop.c, iconv/skeleton.c * signal/sighold.c, signal/sigrelse.c, stdio-common/tempname.c * sysdeps/generic/ldsodefs.h, sysdeps/nptl/libc-lock.h * sysdeps/nptl/libc-lockP.h, sysdeps/posix/waitid.c * wcsmbs/wcstol_l.c, wcsmbs/wcstoll_l.c, wcsmbs/wcstoul_l.c * wcsmbs/wcstoull_l.c, sysdeps/posix/sigignore.c * sysdeps/posix/sigset.c: Don’t define __need macros before including stddef.h. * bits/socket.h, bits/types/stack_t.h, dirent/dirent.h * dlfcn/dlfcn.h, gmon/sys/profil.h, grp/grp.h, gshadow/gshadow.h * hurd/hurd/signal.h, hurd/hurd/sigpreempt.h, iconv/gconv.h * include/set-hooks.h, include/stdio.h, inet/aliases.h * io/sys/sendfile.h, libio/stdio.h, misc/bits/types/struct_iovec.h * misc/search.h, misc/sys/mman.h, misc/syslog.h, posix/glob.h * posix/sched.h, posix/sys/types.h, posix/unistd.h * posix/wordexp.h, pwd/pwd.h, shadow/shadow.h, signal/signal.h * socket/sys/socket.h, stdlib/alloca.h, stdlib/monetary.h * stdlib/stdlib.h, stdlib/sys/random.h, string/string.h * string/strings.h, sunrpc/rpc/netdb.h * sysdeps/htl/bits/types/struct___pthread_attr.h * sysdeps/mach/hurd/bits/socket.h * sysdeps/unix/sysv/linux/bits/socket.h * sysdeps/unix/sysv/linux/bits/types/stack_t.h * sysdeps/unix/sysv/linux/ia64/bits/sigcontext.h * sysdeps/unix/sysv/linux/mips/bits/types/stack_t.h * sysdeps/unix/sysv/linux/scsi/sg.h * sysdeps/unix/sysv/linux/sys/sysctl.h * sysvipc/sys/msg.h, sysvipc/sys/sem.h, sysvipc/sys/shm.h * time/time.h, wcsmbs/uchar.h, wcsmbs/wchar.h: Use bits/types/size_t.h instead of __need_size_t. * 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/aarch64/sys/user.h * sysdeps/unix/sysv/linux/arm/sys/user.h * sysdeps/unix/sysv/linux/m68k/sys/user.h * sysdeps/unix/sysv/linux/microblaze/sys/user.h * sysdeps/unix/sysv/linux/nios2/sys/user.h * sysdeps/unix/sysv/linux/s390/sys/user.h * sysdeps/unix/sysv/linux/x86/sys/user.h Include features.h. * 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. --- scripts/check-obsolete-constructs.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'scripts/check-obsolete-constructs.py') diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py index 8b52463cfb..5d4faac0f0 100755 --- a/scripts/check-obsolete-constructs.py +++ b/scripts/check-obsolete-constructs.py @@ -491,14 +491,6 @@ def ObsoleteTypedefChecker(reporter, fname): # but we are not ready to enforce that yet. UNIVERSAL_ALLOWED_INCLUDES = { "features.h", - - # Technically these should only ever be included with __need - # macros active, but some headers deliberately break this rule - # when they think they're dealing with freestanding headers from a - # non-GNU compiler, so enforcing it would be more trouble than - # it's worth. - "stddef.h", - "stdarg.h", } # Specific headers are allowed to include specific other headers. @@ -575,7 +567,7 @@ HEADER_ALLOWED_INCLUDES = { "link.h": [ "dlfcn.h", "elf.h", "sys/types.h" ], "mntent.h": [ "paths.h" ], "nss.h": [ "stdint.h" ], - "obstack.h": [ "string.h" ], + "obstack.h": [ "stddef.h", "string.h" ], "proc_service.h": [ "sys/procfs.h" ], "pty.h": [ "sys/ioctl.h", "termios.h" ], "sgtty.h": [ "sys/ioctl.h" ], @@ -619,7 +611,6 @@ HEADER_ALLOWED_INCLUDES = { "sys/timex.h": [ "sys/time.h" ], "sys/ttychars.h": [ "sys/ttydefaults.h" ], "sys/ucontext.h": [ "sys/procfs.h" ], - "sys/user.h": [ "sys/types.h" ], "sys/vfs.h": [ "sys/statfs.h" ], "sys/xattr.h": [ "sys/types.h" ], @@ -696,6 +687,12 @@ HEADER_ALLOWED_INCLUDES = { "bits/types/res_state.h": [ "netinet/in.h", "sys/types.h" ], "bits/utmp.h": [ "paths.h", "sys/time.h", "sys/types.h" ], "bits/utmpx.h": [ "paths.h", "sys/time.h" ], + + "bits/types/__va_list.h": [ "stdarg.h" ], + "bits/types/ptrdiff_t.h": [ "stddef.h" ], + "bits/types/size_t.h": [ "stddef.h" ], + "bits/types/wchar_t.h": [ "stddef.h" ], + "bits/NULL.h": [ "stddef.h" ], } # As above, but each group of whitelist entries is only used for -- cgit 1.4.1