Opened 11 years ago

Closed 8 years ago

#207 closed defect (fixed)

include/sys/cdefs.h needs updating for GCC 4.x

Reported by: psmedley Owned by: bird
Priority: normal Milestone: libc-0.6.4
Component: libc Version: 0.6.2
Severity: normal Keywords:
Cc:

Description (last modified by bird)

With the included cdefs.h, GCC 4.x breaks when building the JS code in mozilla with an error 'error: array bound is not an integer constant'

The problem comes from mozilla includes that use offsetof

cdefs.h needs to be updated for GCC 4.x, the following diff based on updated BSD headers fixes the problem:

--- u:\usr\include\sys\cdefs.h	2009-01-18 18:54:06.000000000 +0945
+++ u:\usr\local432\include\sys\cdefs.h	2009-01-18 18:55:24.000000000 +0945
@@ -251,9 +251,21 @@
  * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
  * require it.
  */
-#define	__offsetof(type, field)	((size_t)(&((type *)0)->field))
-#define	__rangeof(type, start, end) \
-	(__offsetof(type, end) - __offsetof(type, start))
+#if __GNUC_PREREQ__(4, 1)
+#define __offsetof(type, field)  __builtin_offsetof(type, field)
+#else
+#ifndef __cplusplus
+#define __offsetof(type, field) ((size_t)(&((type *)0)->field))
+#else
+#define __offsetof(type, field)                                 \
+  (__offsetof__ (reinterpret_cast <size_t>                      \
+                 (&reinterpret_cast <const volatile char &>     \
+                  (static_cast<type *> (0)->field))))
+#endif
+#endif
+#define __rangeof(type, start, end) \
+         (__offsetof(type, end) - __offsetof(type, start))
+
 
 /*
  * Compiler-dependent macros to declare that functions take printf-like

Attachments (1)

cdefs.h.diff (1.1 KB) - added by psmedley 11 years ago.
cdefs.h diff

Download all attachments as: .zip

Change History (5)

Changed 11 years ago by psmedley

cdefs.h diff

comment:1 Changed 11 years ago by psmedley

Diff got screwed up so added it as an attachment

comment:2 Changed 9 years ago by bird

  • Description modified (diff)
  • Status changed from new to assigned

comment:3 Changed 8 years ago by bird

(In [3717]) sys/cdefs.h: Updated to FreeBSD 9.0 (?) rev 1.114. References #207, #212.

comment:4 Changed 8 years ago by bird

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [3718]) 0.6: Backported r3717: sys/cdefs.h: Updated to FreeBSD 9.0 (?) rev 1.114. Fixes #207. References #212.

Note: See TracTickets for help on using tickets.