diff mbox

[RFC] Make _FILE_OFFSET_BITS=64 default.

Message ID 532A41AA.9060208@cs.ucla.edu
State New
Headers show

Commit Message

Paul Eggert March 20, 2014, 1:17 a.m. UTC
Joseph S. Myers wrote:

> I certainly don't think they should be overriding _Static_assert provided by GCC (>= 4.6)

Good point, thanks.  Revised patches attached.

> I don't think the installed glibc headers should be providing _Static_assert

It's what FreeBSD <sys/cdefs.h> does, and applications seem to be doing 
fine there.  So there's good precedent, it's not risky, and it would 
improve compatibility with FreeBSD.

> arguably assert.h should try to do something for the case
> of _ISOC11_SOURCE, non-C11 compiler

That wouldn't support one of the main attractions of _Static_assert, 
namely that it works even when <assert.h> isn't included.  Application 
writers will prefer this feature, and defining _Static_assert in cdefs.h 
gets us close enough to this goal to be reasonably useful in apps 
compiled with pre-C11 compilers.

> generally that applies to any compiler possibly providing
> _Static_assert outside C11 mode - the library shouldn't get in the way of
> the user using the compiler feature

In general that's a good principle, but here there's not much to get in 
the way of, as the glibc substitute does the job even when it takes over 
from Clang etc.  If there's consensus I could add the usual forest of 
#ifs so as to not #define _Static_assert in non-GCC pre-C11 compilers 
where _Static_assert is known to work, but that's not what we've done in 
similar situations elsewhere in glibc, and there is some virtue in 
simplicity.
From 45c96ea279e95aa499856f9062f743665fd564ee Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 19 Mar 2014 10:59:31 -0700
Subject: [PATCH 1/2] Approximate _Static_assert for pre-C11 compilers.

* misc/sys/cdefs.h (_Static_assert) [__STDC_VERSION__ < 201112L]:
New macro, for convenience with pre-C11 compilers.
---
 ChangeLog        | 6 ++++++
 misc/sys/cdefs.h | 7 +++++++
 2 files changed, 13 insertions(+)

Comments

Joseph Myers March 20, 2014, 1:46 a.m. UTC | #1
There's another problem with using such an assertion in fts.h: it's not 
the correct condition for the two ABIs to be the same.  On MIPS n64, 
struct stat and struct stat64 have different layout and so 
_FILE_OFFSET_BITS=64 is an ABI change despite __off_t and __off64_t having 
the same size (and part of the public fts interface is a pointer to struct 
stat).
Rich Felker March 20, 2014, 4:26 a.m. UTC | #2
On Thu, Mar 20, 2014 at 01:46:15AM +0000, Joseph S. Myers wrote:
> There's another problem with using such an assertion in fts.h: it's not 
> the correct condition for the two ABIs to be the same.  On MIPS n64, 
> struct stat and struct stat64 have different layout and so 
> _FILE_OFFSET_BITS=64 is an ABI change despite __off_t and __off64_t having 
> the same size (and part of the public fts interface is a pointer to struct 
> stat).

This is beyond disgusting; why was something like that ever allowed
into the ABI, rather than just using the stat64 struct/syscall (or
whichever one is saner) regardless of whether the stat or stat64
userspace function is called?

Rich
Joseph Myers March 20, 2014, 12:11 p.m. UTC | #3
On Thu, 20 Mar 2014, Rich Felker wrote:

> On Thu, Mar 20, 2014 at 01:46:15AM +0000, Joseph S. Myers wrote:
> > There's another problem with using such an assertion in fts.h: it's not 
> > the correct condition for the two ABIs to be the same.  On MIPS n64, 
> > struct stat and struct stat64 have different layout and so 
> > _FILE_OFFSET_BITS=64 is an ABI change despite __off_t and __off64_t having 
> > the same size (and part of the public fts interface is a pointer to struct 
> > stat).
> 
> This is beyond disgusting; why was something like that ever allowed
> into the ABI, rather than just using the stat64 struct/syscall (or
> whichever one is saner) regardless of whether the stat or stat64
> userspace function is called?

This predates my maintaining the MIPS port, and long predates notions of 
carefully choosing the best ABI, hopefully architecture-independent, 
rather than having an ABI that at least approximately follows some other 
Unix for that architecture.  (I don't know if this particular ABI 
peculiarity - a userspace-only peculiarity, there's only one set of n64 
syscalls - arises from an attempt to be IRIX-compatible, but some 
peculiarities do.)
diff mbox

Patch

diff --git a/ChangeLog b/ChangeLog
index f48f6bb..3d4c88d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@ 
+2014-03-19  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Approximate _Static_assert for pre-C11 compilers.
+	* misc/sys/cdefs.h (_Static_assert) [__STDC_VERSION__ < 201112L]:
+	New macro, for convenience with pre-C11 compilers.
+
 2014-03-19  Joseph Myers  <joseph@codesourcery.com>
 
 	* math/libm-test.inc (fdim_test): Use ALL_RM_TEST.
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index 4d958ea..9402520 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -382,6 +382,13 @@ 
 # define __glibc_likely(cond)	(cond)
 #endif
 
+#if ! (defined _Static_assert						\
+       || (defined __STDC_VERSION__ && 201112L <= __STDC_VERSION__)	\
+       || (__GNUC_PREREQ (4, 6) && !defined __STRICT_ANSI__))
+# define _Static_assert(e, s) extern int (*__glibc_Static_assert (void)) \
+    [sizeof (struct { unsigned int _Static_assert_failure: (e) ? 1 : -1; })]
+#endif
+
 #include <bits/wordsize.h>
 
 #if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH