This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
<sys/cdefs.h> patch set overview
- From: Sebastian Huber <sebastian dot huber at embedded-brains dot de>
- To: newlib at sourceware dot org
- Date: Wed, 17 Apr 2013 15:21:42 +0200
- Subject: <sys/cdefs.h> patch set overview
- References: <1366204592-27532-1-git-send-email-sebastian dot huber at embedded-brains dot de>
Hello,
Joel Sherrill already posted something similar several months ago. This patch
series attempts to make a review easier.
http://sourceware.org/ml/newlib/2012/msg00336.html
The general objectives are explained here:
http://sourceware.org/ml/newlib/2012/msg00332.html
The main goal is to make it as easy as possible to use FreeBSD sources along
with Newlib. It is also possible to use a RTEMS specific <sys/cdefs.h>, but I
think the FreeBSD compatibility may be of general interest for Newlib users.
Attached is a difference between the FreeBSD and Newlib <sys/cdefs.h> after
these patches.
--
Sebastian Huber, embedded brains GmbH
Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail : sebastian.huber@embedded-brains.de
PGP : Public key available on request.
Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
--- cdefs.h 2013-04-16 12:53:39.748836244 +0200
+++ ./newlib/libc/include/sys/cdefs.h 2013-04-17 15:03:12.919319847 +0200
@@ -1,3 +1,7 @@
+/* libc/sys/linux/sys/cdefs.h - Helper macros for K&R vs. ANSI C compat. */
+
+/* Written 2000 by Werner Almesberger */
+
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
@@ -36,6 +40,32 @@
#ifndef _SYS_CDEFS_H_
#define _SYS_CDEFS_H_
+#include <sys/features.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#define __PMT(args) args
+#define __DOTS , ...
+#define __THROW
+
+#ifdef __GNUC__
+# define __ASMNAME(cname) __XSTRING (__USER_LABEL_PREFIX__) cname
+#endif
+
+#define __ptr_t void *
+#define __long_double_t long double
+
+#define __attribute_malloc__
+#define __attribute_pure__
+#define __attribute_format_strfmon__(a,b)
+#define __flexarr [0]
+
+#ifndef __BOUNDED_POINTERS__
+# define __bounded /* nothing */
+# define __unbounded /* nothing */
+# define __ptrvalue /* nothing */
+#endif
+
#if defined(__cplusplus)
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS }
@@ -113,12 +143,7 @@
/*
* Macro to test if we're using a specific version of gcc or later.
*/
-#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
-#define __GNUC_PREREQ__(ma, mi) \
- (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
-#else
-#define __GNUC_PREREQ__(ma, mi) 0
-#endif
+#define __GNUC_PREREQ__(ma, mi) __GNUC_PREREQ(ma, mi)
/*
* The __CONCAT macro is used to concatenate parts of symbol names, e.g.
@@ -317,21 +342,6 @@
#define __func__ NULL
#endif
-#if (defined(__INTEL_COMPILER) || (defined(__GNUC__) && __GNUC__ >= 2)) && !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901
-#define __LONG_LONG_SUPPORTED
-#endif
-
-/* C++11 exposes a load of C99 stuff */
-#if defined(__cplusplus) && __cplusplus >= 201103L
-#define __LONG_LONG_SUPPORTED
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS
-#endif
-#ifndef __STDC_CONSTANT_MACROS
-#define __STDC_CONSTANT_MACROS
-#endif
-#endif
-
/*
* GCC 2.95 provides `__restrict' as an extension to C90 to support the
* C99-specific `restrict' type qualifier. We happen to use `__restrict' as
@@ -390,23 +400,7 @@
#define __exported
#endif
-/*
- * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
- * require it.
- */
-#if __GNUC_PREREQ__(4, 1)
-#define __offsetof(type, field) __builtin_offsetof(type, field)
-#else
-#ifndef __cplusplus
-#define __offsetof(type, field) \
- ((__size_t)(__uintptr_t)((const volatile void *)&((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 __offsetof(type, field) offsetof(type, field)
#define __rangeof(type, start, end) \
(__offsetof(type, end) - __offsetof(type, start))
@@ -418,7 +412,7 @@
*/
#if __GNUC_PREREQ__(3, 1)
#define __containerof(x, s, m) ({ \
- const volatile __typeof(((s *)0)->m) *__x = (x); \
+ const volatile __typeof__(((s *)0)->m) *__x = (x); \
__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m));\
})
#else
@@ -464,6 +458,7 @@
#define __strong_reference(sym,aliassym) \
extern __typeof (sym) aliassym __attribute__ ((__alias__ (#sym)))
#endif
+#ifdef __ELF__
#ifdef __STDC__
#define __weak_reference(sym,alias) \
__asm__(".weak " #alias); \
@@ -489,79 +484,55 @@
#define __sym_default(impl,sym,verid) \
__asm__(".symver impl, sym@@verid")
#endif /* __STDC__ */
-#endif /* __GNUC__ || __INTEL_COMPILER */
-
-#define __GLOBL1(sym) __asm__(".globl " #sym)
-#define __GLOBL(sym) __GLOBL1(sym)
-
-#if defined(__GNUC__) || defined(__INTEL_COMPILER)
-#define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"")
+#else /* !__ELF__ */
+#ifdef __STDC__
+#define __weak_reference(sym,alias) \
+ __asm__(".stabs \"_" #alias "\",11,0,0,0"); \
+ __asm__(".stabs \"_" #sym "\",1,0,0,0")
+#define __warn_references(sym,msg) \
+ __asm__(".stabs \"" msg "\",30,0,0,0"); \
+ __asm__(".stabs \"_" #sym "\",1,0,0,0")
#else
-/*
- * The following definition might not work well if used in header files,
- * but it should be better than nothing. If you want a "do nothing"
- * version, then it should generate some harmless declaration, such as:
- * #define __IDSTRING(name,string) struct __hack
- */
-#define __IDSTRING(name,string) static const char name[] __unused = string
-#endif
+#define __weak_reference(sym,alias) \
+ __asm__(".stabs \"_/**/alias\",11,0,0,0"); \
+ __asm__(".stabs \"_/**/sym\",1,0,0,0")
+#define __warn_references(sym,msg) \
+ __asm__(".stabs msg,30,0,0,0"); \
+ __asm__(".stabs \"_/**/sym\",1,0,0,0")
+#endif /* __STDC__ */
+#endif /* __ELF__ */
+#endif /* __GNUC__ || __INTEL_COMPILER */
-/*
- * Embed the rcs id of a source file in the resulting library. Note that in
- * more recent ELF binutils, we use .ident allowing the ID to be stripped.
- * Usage:
- * __FBSDID("$FreeBSD$");
- */
#ifndef __FBSDID
-#if !defined(lint) && !defined(STRIP_FBSDID)
-#define __FBSDID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
-#else
#define __FBSDID(s) struct __hack
#endif
-#endif
#ifndef __RCSID
-#ifndef NO__RCSID
-#define __RCSID(s) __IDSTRING(__CONCAT(__rcsid_,__LINE__),s)
-#else
#define __RCSID(s) struct __hack
#endif
-#endif
#ifndef __RCSID_SOURCE
-#ifndef NO__RCSID_SOURCE
-#define __RCSID_SOURCE(s) __IDSTRING(__CONCAT(__rcsid_source_,__LINE__),s)
-#else
#define __RCSID_SOURCE(s) struct __hack
#endif
-#endif
#ifndef __SCCSID
-#ifndef NO__SCCSID
-#define __SCCSID(s) __IDSTRING(__CONCAT(__sccsid_,__LINE__),s)
-#else
#define __SCCSID(s) struct __hack
#endif
-#endif
#ifndef __COPYRIGHT
-#ifndef NO__COPYRIGHT
-#define __COPYRIGHT(s) __IDSTRING(__CONCAT(__copyright_,__LINE__),s)
-#else
#define __COPYRIGHT(s) struct __hack
#endif
-#endif
#ifndef __DECONST
-#define __DECONST(type, var) ((type)(__uintptr_t)(const void *)(var))
+#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
#endif
#ifndef __DEVOLATILE
-#define __DEVOLATILE(type, var) ((type)(__uintptr_t)(volatile void *)(var))
+#define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var))
#endif
#ifndef __DEQUALIFY
-#define __DEQUALIFY(type, var) ((type)(__uintptr_t)(const volatile void *)(var))
+#define __DEQUALIFY(type, var) ((type)(uintptr_t)(const volatile void *)(var))
#endif
/*-
@@ -682,21 +653,4 @@
#endif
#endif
-#ifndef __has_extension
-#define __has_extension __has_feature
-#endif
-#ifndef __has_feature
-#define __has_feature(x) 0
-#endif
-#ifndef __has_include
-#define __has_include(x) 0
-#endif
-#ifndef __has_builtin
-#define __has_builtin(x) 0
-#endif
-
-#if defined(__mips) || defined(__powerpc64__)
-#define __NO_TLS 1
-#endif
-
#endif /* !_SYS_CDEFS_H_ */