aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-03-21 16:30:53 -0400
committerZack Weinberg <zackw@panix.com>2017-06-14 08:14:34 -0400
commitfd860eaaa8757b221d9169e460c9ec41ea51f317 (patch)
tree5e5037486db89c12cd4a7dc89a545767481aff29
parent37f802f86400684c8d13403958b2c598721d6360 (diff)
downloadglibc-fd860eaaa8757b221d9169e460c9ec41ea51f317.tar.xz
glibc-fd860eaaa8757b221d9169e460c9ec41ea51f317.zip
Remove __need macros from errno.h (__need_Emath, __need_error_t).
This is fairly complicated, not because the users of __need_Emath and __need_error_t have complicated requirements, but because the core changes had a lot of fallout. __need_error_t exists for gnulib compatibility in argz.h and argp.h. error_t itself is a Hurdism, an enum containing all the E-constants, so you can do 'p (error_t) errno' in gdb and get a symbolic value. argz.h and argp.h use it for function return values, and they want to fall back to 'int' when that's not available. There is no reason why these nonstandard headers cannot just go ahead and include all of errno.h; so we do that. __need_Emath is defined only by .S files; what they _really_ need is for errno.h to avoid declaring anything other than the E-constants (e.g. 'extern int __errno_location(void);' is a syntax error in assembly language). This is replaced with a check for __ASSEMBLER__ in errno.h, plus a carefully documented requirement for bits/errno.h not to define anything other than macros. That in turn has the consequence that bits/errno.h must not define errno - fortunately, all live ports use the same definition of errno, so I've moved it to errno.h. The Hurd bits/errno.h must also take care not to define error_t when __ASSEMBLER__ is defined, which involves repeating all of the definitions twice, but it's a generated file so that's okay. * stdlib/errno.h: Remove __need_Emath and __need_error_t logic. Reorganize file. Declare errno here. When __ASSEMBLER__ is defined, don't declare anything other than the E-constants. * include/errno.h: Change conditional for exposing internal declarations to (not _ISOMAC and not __ASSEMBLER__). * bits/errno.h: Remove logic for __need_Emath. Document requirements for a port-specific bits/errno.h. * sysdeps/unix/sysv/linux/bits/errno.h * sysdeps/unix/sysv/linux/alpha/bits/errno.h * sysdeps/unix/sysv/linux/hppa/bits/errno.h * sysdeps/unix/sysv/linux/mips/bits/errno.h * sysdeps/unix/sysv/linux/sparc/bits/errno.h: Add multiple-include guard and check against improper inclusion. Remove __need_Emath logic. Don't declare errno here. Ensure all constants are defined as simple integer literals. Consistent formatting. * sysdeps/mach/hurd/errnos.awk: Likewise. Only define error_t and enum __error_t_codes if __ASSEMBLER__ is not defined. * sysdeps/mach/hurd/bits/errno.h: Regenerate. * argp/argp.h, string/argz.h: Don't define __need_error_t before including errno.h. * sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S * sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S * sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S * sysdeps/x86_64/fpu/s_cosf.S * sysdeps/x86_64/fpu/s_sincosf.S * sysdeps/x86_64/fpu/s_sinf.S: Just include errno.h; don't define __need_Emath or include bits/errno.h directly.
-rw-r--r--ChangeLog35
-rw-r--r--NEWS4
-rw-r--r--argp/argp.h10
-rw-r--r--bits/errno.h44
-rw-r--r--include/errno.h11
-rw-r--r--stdlib/errno.h62
-rw-r--r--string/argz.h10
-rw-r--r--sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S3
-rw-r--r--sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S3
-rw-r--r--sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S3
-rw-r--r--sysdeps/mach/hurd/bits/errno.h707
-rw-r--r--sysdeps/mach/hurd/errnos.awk206
-rw-r--r--sysdeps/unix/sysv/linux/alpha/bits/errno.h42
-rw-r--r--sysdeps/unix/sysv/linux/bits/errno.h43
-rw-r--r--sysdeps/unix/sysv/linux/hppa/bits/errno.h39
-rw-r--r--sysdeps/unix/sysv/linux/mips/bits/errno.h41
-rw-r--r--sysdeps/unix/sysv/linux/sparc/bits/errno.h42
-rw-r--r--sysdeps/x86_64/fpu/s_cosf.S3
-rw-r--r--sysdeps/x86_64/fpu/s_sincosf.S3
-rw-r--r--sysdeps/x86_64/fpu/s_sinf.S3
20 files changed, 713 insertions, 601 deletions
diff --git a/ChangeLog b/ChangeLog
index f7c9635aa3..0d63b39b2e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,40 @@
2017-06-14 Zack Weinberg <zackw@panix.com>
+ * stdlib/errno.h: Remove __need_Emath and __need_error_t logic.
+ Reorganize file. Declare errno here. When __ASSEMBLER__ is
+ defined, don't declare anything other than the E-constants.
+
+ * include/errno.h: Change conditional for exposing internal
+ declarations to (not _ISOMAC and not __ASSEMBLER__).
+ * bits/errno.h: Remove logic for __need_Emath. Document
+ requirements for a port-specific bits/errno.h.
+
+ * sysdeps/unix/sysv/linux/bits/errno.h
+ * sysdeps/unix/sysv/linux/alpha/bits/errno.h
+ * sysdeps/unix/sysv/linux/hppa/bits/errno.h
+ * sysdeps/unix/sysv/linux/mips/bits/errno.h
+ * sysdeps/unix/sysv/linux/sparc/bits/errno.h:
+ Add multiple-include guard and check against improper inclusion.
+ Remove __need_Emath logic. Don't declare errno here. Ensure all
+ constants are defined as simple integer literals. Consistent
+ formatting.
+ * sysdeps/mach/hurd/errnos.awk: Likewise. Only define error_t and
+ enum __error_t_codes if __ASSEMBLER__ is not defined.
+ * sysdeps/mach/hurd/bits/errno.h: Regenerate.
+
+ * argp/argp.h, string/argz.h: Don't define __need_error_t before
+ including errno.h.
+ * sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S
+ * sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S
+ * sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S
+ * sysdeps/x86_64/fpu/s_cosf.S
+ * sysdeps/x86_64/fpu/s_sincosf.S
+ * sysdeps/x86_64/fpu/s_sinf.S:
+ Just include errno.h; don't define __need_Emath or include
+ bits/errno.h directly.
+
+2017-06-14 Zack Weinberg <zackw@panix.com>
+
* bits/uio_lim.h, sysdeps/unix/sysv/linux/bits/uio_lim.h
* bits/uio-ext.h, sysdeps/unix/sysv/linux/bits/uio-ext.h: New file.
* bits/uio.h, sysdeps/unix/sysv/linux/bits/uio.h: Delete file.
diff --git a/NEWS b/NEWS
index 991ee63f7c..8d35bd6c95 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,10 @@ Version 2.26
transliteration tables are all updated to Unicode 9.0.0, using
generator scripts contributed by Mike FABIAN (Red Hat).
+* errno.h is now safe to use from C-preprocessed assembly language on all
+ supported operating systems. In this context, it will only define the
+ Exxxx constants, as preprocessor macros expanding to integer literals.
+
* The rpcgen, librpcsvc and related headers will only be built and
installed when glibc is configured with --enable-obsolete-rpc.
This allows alternative RPC implementations, like TIRPC, to be used
diff --git a/argp/argp.h b/argp/argp.h
index 86b8e5a1e9..08b48e1cf1 100644
--- a/argp/argp.h
+++ b/argp/argp.h
@@ -24,16 +24,16 @@
#include <ctype.h>
#include <getopt.h>
#include <limits.h>
-
-#define __need_error_t
#include <errno.h>
+
+__BEGIN_DECLS
+/* error_t may or may not be available from errno.h, depending on the
+ operating system. */
#ifndef __error_t_defined
+# define __error_t_defined 1
typedef int error_t;
-# define __error_t_defined
#endif
-
-__BEGIN_DECLS
/* A description of a particular option. A pointer to an array of
these is passed in the OPTIONS field of an argp structure. Each option
diff --git a/bits/errno.h b/bits/errno.h
index cd4fcfa428..11180711d7 100644
--- a/bits/errno.h
+++ b/bits/errno.h
@@ -1,4 +1,5 @@
-/* Copyright (C) 1991-2017 Free Software Foundation, Inc.
+/* Error constants. Generic version.
+ Copyright (C) 1991-2017 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -15,20 +16,35 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
-/* This file defines the `errno' constants. */
+/* This file defines the errno constants. */
-#if !defined __Emath_defined && (defined _ERRNO_H || defined __need_Emath)
-#undef __need_Emath
-#define __Emath_defined 1
+#ifndef _BITS_ERRNO_H
+#define _BITS_ERRNO_H 1
-# define EDOM XXX <--- fill in what is actually needed
-# define EILSEQ XXX <--- fill in what is actually needed
-# define ERANGE XXX <--- fill in what is actually needed
+#if !defined _ERRNO_H
+# error "Never include <bits/errno.h> directly; use <errno.h> instead."
#endif
-#ifdef _ERRNO_H
-# error "Define here all the missing error messages for the port. These"
-# error "must match the numbers of the kernel."
-# define Exxxx XXX
-...
-#endif
+#error "Generic bits/errno.h included -- port is incomplete."
+
+/* Authors of new ports of the GNU C Library must override this file
+ with their own bits/errno.h in an appropriate subdirectory of
+ sysdeps/. Its function is to define all of the error constants
+ from C2011 and POSIX.1-2008, with values appropriate to the
+ operating system, and any additional OS-specific error constants.
+
+ C2011 requires all error constants to be object-like macros that
+ expand to "integer constant expressions with type int, positive
+ values, and suitable for use in #if directives". Moreover, all of
+ their names must begin with a capital E, followed immediately by
+ either another capital letter, or a digit. It is OK to define
+ macros that are not error constants, but only in the implementation
+ namespace.
+
+ errno.h is sometimes included from assembly language. Therefore,
+ when __ASSEMBLER__ is defined, bits/errno.h may only define macros;
+ it may not make any other kind of C declaration or definition.
+ Also, the error constants should, if at all possible, expand to
+ simple decimal or hexadecimal numbers. */
+
+#endif /* bits/errno.h. */
diff --git a/include/errno.h b/include/errno.h
index f140631b31..3c3d2288c8 100644
--- a/include/errno.h
+++ b/include/errno.h
@@ -1,8 +1,6 @@
#ifndef _ERRNO_H
-
#include <stdlib/errno.h>
-
-#if defined _ERRNO_H && !defined _ISOMAC
+#if !defined _ISOMAC && !defined __ASSEMBLER__
# if IS_IN (rtld)
# include <dl-sysdep.h>
@@ -38,15 +36,12 @@ extern __thread int errno attribute_tls_model_ie;
# define __set_errno(val) (errno = (val))
-# ifndef __ASSEMBLER__
extern int *__errno_location (void) __THROW __attribute_const__
# if RTLD_PRIVATE_ERRNO
attribute_hidden
# endif
;
libc_hidden_proto (__errno_location)
-# endif
-
-#endif /* _ERRNO_H */
-#endif /* ! _ERRNO_H */
+#endif /* !_ISOMAC && !__ASSEMBLER__ */
+#endif /* !_ERRNO_H */
diff --git a/stdlib/errno.h b/stdlib/errno.h
index c42514b448..fe08365e40 100644
--- a/stdlib/errno.h
+++ b/stdlib/errno.h
@@ -20,53 +20,41 @@
*/
#ifndef _ERRNO_H
+#define _ERRNO_H 1
-/* The includer defined __need_Emath if he wants only the definitions
- of EDOM and ERANGE, and not everything else. */
-#ifndef __need_Emath
-# define _ERRNO_H 1
-# include <features.h>
-#endif
+#include <features.h>
-__BEGIN_DECLS
-
-/* Get the error number constants from the system-specific file.
- This file will test __need_Emath and _ERRNO_H. */
+/* The system-specific definitions of the E* constants, as macros. */
#include <bits/errno.h>
-#undef __need_Emath
-#ifdef _ERRNO_H
+/* When included from assembly language, this header only provides the
+ E* constants. */
+#ifndef __ASSEMBLER__
-/* Declare the `errno' variable, unless it's defined as a macro by
- bits/errno.h. This is the case in GNU, where it is a per-thread
- variable. This redeclaration using the macro still works, but it
- will be a function declaration without a prototype and may trigger
- a -Wstrict-prototypes warning. */
-#ifndef errno
-extern int errno;
-#endif
+__BEGIN_DECLS
-#ifdef __USE_GNU
+/* The error code set by various library functions. */
+extern int *__errno_location (void) __THROW __attribute_const__;
+# define errno (*__errno_location ())
+
+# ifdef __USE_GNU
/* The full and simple forms of the name with which the program was
invoked. These variables are set up automatically at startup based on
the value of argv[0]. */
-extern char *program_invocation_name, *program_invocation_short_name;
-#endif /* __USE_GNU */
-#endif /* _ERRNO_H */
+extern char *program_invocation_name;
+extern char *program_invocation_short_name;
-__END_DECLS
+/* bits/errno.h may have defined this type. If it didn't, provide a
+ fallback definition. */
+# ifndef __error_t_defined
+# define __error_t_defined 1
+typedef int error_t;
+# endif
-#endif /* _ERRNO_H */
+# endif /* __USE_GNU */
-/* The Hurd <bits/errno.h> defines `error_t' as an enumerated type so
- that printing `error_t' values in the debugger shows the names. We
- might need this definition sometimes even if this file was included
- before. */
-#if defined __USE_GNU || defined __need_error_t
-# ifndef __error_t_defined
-typedef int error_t;
-# define __error_t_defined 1
-# endif
-# undef __need_error_t
-#endif
+__END_DECLS
+
+#endif /* !__ASSEMBLER__ */
+#endif /* errno.h */
diff --git a/string/argz.h b/string/argz.h
index f9d0ac9950..e07d74208a 100644
--- a/string/argz.h
+++ b/string/argz.h
@@ -20,18 +20,18 @@
#define _ARGZ_H 1
#include <features.h>
-
-#define __need_error_t
#include <errno.h>
#include <string.h> /* Need size_t, and strchr is called below. */
+__BEGIN_DECLS
+
+/* error_t may or may not be available from errno.h, depending on the
+ operating system. */
#ifndef __error_t_defined
+# define __error_t_defined 1
typedef int error_t;
#endif
-
-__BEGIN_DECLS
-
/* Make a '\0' separated arg vector from a unix argv vector, returning it in
ARGZ, and the total length in LEN. If a memory allocation error occurs,
ENOMEM is returned, otherwise 0. The result can be destroyed using free. */
diff --git a/sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S b/sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S
index f37850d0b3..a5b76e9fb2 100644
--- a/sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S
+++ b/sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S
@@ -17,8 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
-#define __need_Emath
-#include <bits/errno.h>
+#include <errno.h>
/* Short algorithm description:
*
diff --git a/sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S b/sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S
index f31a925522..1e99ee6416 100644
--- a/sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S
+++ b/sysdeps/i386/i686/fpu/multiarch/s_sincosf-sse2.S
@@ -17,8 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
-#define __need_Emath
-#include <bits/errno.h>
+#include <errno.h>
/* Short algorithm description:
*
diff --git a/sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S b/sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S
index ee96018061..03b925491e 100644
--- a/sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S
+++ b/sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S
@@ -17,8 +17,7 @@
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
-#define __need_Emath
-#include <bits/errno.h>
+#include <errno.h>
/* Short algorithm description:
*
diff --git a/sysdeps/mach/hurd/bits/errno.h b/sysdeps/mach/hurd/bits/errno.h
index d20ffe654a..f0a11af9ea 100644
--- a/sysdeps/mach/hurd/bits/errno.h
+++ b/sysdeps/mach/hurd/bits/errno.h
@@ -1,329 +1,418 @@
-/* This file generated by errnos.awk. */
+/* This file generated by errnos.awk from
+ errno.texi
+ mach/message.h
+ mach/kern_return.h
+ mach/mig_errors.h
+ device/device_types.h
+ Do not edit this file; edit errnos.awk and regenerate it. */
-/* The Hurd uses Mach error system 0x10, currently only subsystem 0. */
-#ifndef _HURD_ERRNO
-#define _HURD_ERRNO(n) ((0x10 << 26) | ((n) & 0x3fff))
+#ifndef _BITS_ERRNO_H
+#define _BITS_ERRNO_H 1
+
+#if !defined _ERRNO_H
+# error "Never include <bits/errno.h> directly; use <errno.h> instead."
#endif
-#ifdef _ERRNO_H
+#ifndef __ASSEMBLER__
enum __error_t_codes
{
- /* The value zero always means success and it is perfectly fine for
- code to use 0 explicitly (or implicitly, e.g. via Boolean coercion).
- Having an enum entry for zero both makes the debugger print the name
- for error_t-typed zero values, and prevents the compiler from
- issuing warnings about 'case 0:' in a switch on an error_t-typed
- value. */
- ESUCCESS = 0,
+ /* The value zero always means success and it is perfectly fine
+ for code to use 0 explicitly (or implicitly, e.g. via Boolean
+ coercion.) Having an enum entry for zero both makes the
+ debugger print the name for error_t-typed zero values, and
+ prevents the compiler from issuing warnings about 'case 0:'
+ in a switch on an error_t-typed value. */
+ ESUCCESS = 0,
-#undef EDOM
-#undef ERANGE
- EPERM = _HURD_ERRNO (1),
-#define EPERM _HURD_ERRNO (1) /* Operation not permitted */
- ENOENT = _HURD_ERRNO (2),
-#define ENOENT _HURD_ERRNO (2) /* No such file or directory */
- ESRCH = _HURD_ERRNO (3),
-#define ESRCH _HURD_ERRNO (3) /* No such process */
- EINTR = _HURD_ERRNO (4),
-#define EINTR _HURD_ERRNO (4) /* Interrupted system call */
- EIO = _HURD_ERRNO (5),
-#define EIO _HURD_ERRNO (5) /* Input/output error */
- ENXIO = _HURD_ERRNO (6),
-#define ENXIO _HURD_ERRNO (6) /* No such device or address */
- E2BIG = _HURD_ERRNO (7),
-#define E2BIG _HURD_ERRNO (7) /* Argument list too long */
- ENOEXEC = _HURD_ERRNO (8),
-#define ENOEXEC _HURD_ERRNO (8) /* Exec format error */
- EBADF = _HURD_ERRNO (9),
-#define EBADF _HURD_ERRNO (9) /* Bad file descriptor */
- ECHILD = _HURD_ERRNO (10),
-#define ECHILD _HURD_ERRNO (10)/* No child processes */
- EDEADLK = _HURD_ERRNO (11),
-#define EDEADLK _HURD_ERRNO (11)/* Resource deadlock avoided */
- ENOMEM = _HURD_ERRNO (12),
-#define ENOMEM _HURD_ERRNO (12)/* Cannot allocate memory */
- EACCES = _HURD_ERRNO (13),
-#define EACCES _HURD_ERRNO (13)/* Permission denied */
- EFAULT = _HURD_ERRNO (14),
-#define EFAULT _HURD_ERRNO (14)/* Bad address */
- ENOTBLK = _HURD_ERRNO (15),
-#define ENOTBLK _HURD_ERRNO (15)/* Block device required */
- EBUSY = _HURD_ERRNO (16),
-#define EBUSY _HURD_ERRNO (16)/* Device or resource busy */
- EEXIST = _HURD_ERRNO (17),
-#define EEXIST _HURD_ERRNO (17)/* File exists */
- EXDEV = _HURD_ERRNO (18),
-#define EXDEV _HURD_ERRNO (18)/* Invalid cross-device link */
- ENODEV = _HURD_ERRNO (19),
-#define ENODEV _HURD_ERRNO (19)/* No such device */
- ENOTDIR = _HURD_ERRNO (20),
-#define ENOTDIR _HURD_ERRNO (20)/* Not a directory */
- EISDIR = _HURD_ERRNO (21),
-#define EISDIR _HURD_ERRNO (21)/* Is a directory */
- EINVAL = _HURD_ERRNO (22),
-#define EINVAL _HURD_ERRNO (22)/* Invalid argument */
- EMFILE = _HURD_ERRNO (24),
-#define EMFILE _HURD_ERRNO (24)/* Too many open files */
- ENFILE = _HURD_ERRNO (23),
-#define ENFILE _HURD_ERRNO (23)/* Too many open files in system */
- ENOTTY = _HURD_ERRNO (25),
-#define ENOTTY _HURD_ERRNO (25)/* Inappropriate ioctl for device */
- ETXTBSY = _HURD_ERRNO (26),
-#define ETXTBSY _HURD_ERRNO (26)/* Text file busy */
- EFBIG = _HURD_ERRNO (27),
-#define EFBIG _HURD_ERRNO (27)/* File too large */
- ENOSPC = _HURD_ERRNO (28),
-#define ENOSPC _HURD_ERRNO (28)/* No space left on device */
- ESPIPE = _HURD_ERRNO (29),
-#define ESPIPE _HURD_ERRNO (29)/* Illegal seek */
- EROFS = _HURD_ERRNO (30),
-#define EROFS _HURD_ERRNO (30)/* Read-only file system */
- EMLINK = _HURD_ERRNO (31),
-#define EMLINK _HURD_ERRNO (31)/* Too many links */
- EPIPE = _HURD_ERRNO (32),
-#define EPIPE _HURD_ERRNO (32)/* Broken pipe */
- EDOM = _HURD_ERRNO (33),
-#define EDOM _HURD_ERRNO (33)/* Numerical argument out of domain */
- ERANGE = _HURD_ERRNO (34),
-#define ERANGE _HURD_ERRNO (34)/* Numerical result out of range */
- EAGAIN = _HURD_ERRNO (35),
-#define EAGAIN _HURD_ERRNO (35)/* Resource temporarily unavailable */
-#define EWOULDBLOCK EAGAIN /* Operation would block */
- EINPROGRESS = _HURD_ERRNO (36),
-#define EINPROGRESS _HURD_ERRNO (36)/* Operation now in progress */
- EALREADY = _HURD_ERRNO (37),
-#define EALREADY _HURD_ERRNO (37)/* Operation already in progress */
- ENOTSOCK = _HURD_ERRNO (38),
-#define ENOTSOCK _HURD_ERRNO (38)/* Socket operation on non-socket */
- EMSGSIZE = _HURD_ERRNO (40),
-#define EMSGSIZE _HURD_ERRNO (40)/* Message too long */
- EPROTOTYPE = _HURD_ERRNO (41),
-#define EPROTOTYPE _HURD_ERRNO (41)/* Protocol wrong type for socket */