1 /*****************************************************************************/
4 * \brief L4 compiler related defines.
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>,
10 * Frank Mehnert <fm3@os.inf.tu-dresden.de>,
11 * Jork Löser <jork@os.inf.tu-dresden.de>,
12 * Ronald Aigner <ra3@os.inf.tu-dresden.de>
13 * economic rights: Technische Universität Dresden (Germany)
15 * This file is part of TUD:OS and distributed under the terms of the
16 * GNU General Public License 2.
17 * Please see the COPYING-GPL-2 file for details.
19 * As a special exception, you may use this file as part of a free software
20 * library without restriction. Specifically, if other files instantiate
21 * templates or use macros or inline functions from this file, or you compile
22 * this file and link it with other files to produce an executable, this
23 * file does not by itself cause the resulting executable to be covered by
24 * the GNU General Public License. This exception does not however
25 * invalidate any other reasons why the executable file might be covered by
26 * the GNU General Public License.
28 /*****************************************************************************/
29 #ifndef __L4_COMPILER_H__
30 #define __L4_COMPILER_H__
32 #if !defined(__ASSEMBLY__) && !defined(__ASSEMBLER__)
35 * \addtogroup l4sys_defines
37 * <c>\#include <l4/sys/compiler.h></c>
42 * L4 Inline function attribute.
48 # define L4_INLINE_STATIC static __inline__
49 # define L4_INLINE_EXTERN extern __inline__
50 /* gcc-4.3 implements c99 inline behaviour, i.e. we use the
51 * 'extern inline' there, 4.2 and below use 'static inline' */
52 # if (__GNUC__ == 4 && __GNUC_MINOR__ <= 2) || __GNUC__ <= 3
53 # define L4_INLINE L4_INLINE_STATIC
55 # ifdef __GNUC_STDC_INLINE__
56 # define L4_INLINE L4_INLINE_STATIC
58 # define L4_INLINE L4_INLINE_EXTERN
61 # else /* ! __OPTIMIZE__ */
62 # define L4_INLINE static
63 # endif /* ! __OPTIMIZE__ */
64 #else /* __cplusplus */
65 # define L4_INLINE inline
66 #endif /* __cplusplus */
67 #endif /* L4_INLINE */
71 * \brief Handcoded version of __attribute__((constructor(xx))).
72 * \param func function declaration (prototype)
73 * \param prio the prio must be 65535 - \a gcc_prio
76 # define L4_DECLARE_CONSTRUCTOR(func, prio) \
77 static void (* func ## _ctor__)(void) __attribute__((used,section(".init_array." L4_stringify(prio)))) = &func;
79 # define L4_DECLARE_CONSTRUCTOR(func, prio) \
80 static void (* func ## _ctor__)(void) __attribute__((used,section(".ctors." L4_stringify(prio)))) = &func;
86 * Start section with C types and functions.
91 * End section with C types and functions.
96 * Start section with C types and functions.
101 * End section with C types and functions.
106 * Mark C types and functions.
114 * \brief Mark a function declaration and definition as never
115 * throwing an exception. (Also for C code).
117 * This macro shall be used to mark C and C++ functions that never
118 * throw any exception. Note that also C functions may throw exceptions
119 * according to the compilers ABI and shall be marke with L4_NOTHROW
120 * if they never do. In C++ this is equvalent to \c throw().
123 * int foo() L4_NOTHROW;
125 * int foo() L4_NOTHROW
137 * \brief Attribute to mark functions, variables, and data types as being
138 * exported from a library.
140 * All data types, functions, and global variables that shall be exported
141 * from a library shall be marked with this attribute. The default may become
142 * to hide everything that is not marked as L4_EXPORT from the users of a
143 * library and provide the possibility for aggressive optimization of all
144 * those internal functionality of a library.
148 * class L4_EXPORT My_class
153 * int L4_EXPORT function(void);
155 * int L4_EXPORT global_data; // global data is not recommended
163 * \brief Attribute to mark functions, variables, and data types as being
164 * explicitly hidden from users of a library.
166 * This attribute is intended for functions, data, and data types that
167 * shall never be visible outside of a library. In particular, for shared
168 * libraries this may result in much faster code within the library and short
172 * class L4_HIDDEN My_class
177 * int L4_HIDDEN function(void);
179 * int L4_HIDDEN global_data; // global data is not recommended
183 # define L4_NOTHROW__A __attribute__((nothrow))
185 # define EXTERN_C_BEGIN
186 # define EXTERN_C_END
188 # ifndef __BEGIN_DECLS
189 # define __BEGIN_DECLS
194 # define L4_DEFAULT_PARAM(x)
195 #else /* __cplusplus */
196 # define L4_NOTHROW throw()
197 # define EXTERN_C_BEGIN extern "C" {
198 # define EXTERN_C_END }
199 # define EXTERN_C extern "C"
200 # ifndef __BEGIN_DECLS
201 # define __BEGIN_DECLS extern "C" {
204 # define __END_DECLS }
206 # define L4_DEFAULT_PARAM(x) = x
207 #endif /* __cplusplus */
210 * Noreturn function attribute.
213 #define L4_NORETURN __attribute__((noreturn))
216 * No instrumentation function attribute.
219 #define L4_NOINSTRUMENT __attribute__((no_instrument_function))
221 # define L4_HIDDEN __attribute__((visibility("hidden")))
224 # define L4_EXPORT __attribute__((visibility("default")))
226 #define L4_STRONG_ALIAS(name, aliasname) L4__STRONG_ALIAS(name, aliasname)
227 #define L4__STRONG_ALIAS(name, aliasname) \
228 extern __typeof (name) aliasname __attribute__ ((alias (#name)));
231 #endif /* !__ASSEMBLY__ */
233 #include <l4/sys/linkage.h>
235 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
236 #define __builtin_expect(x, expected_value) (x)
239 #define EXPECT_TRUE(x) __builtin_expect((x),1) ///< Expression is likely to execute. \hideinitializer
240 #define EXPECT_FALSE(x) __builtin_expect((x),0) ///< Expression is unlikely to execute. \hideinitializer
242 #if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || __GNUC__ >= 4
243 /* Make sure that the function is not removed by optimization. Without the
244 * "used" attribute, unreferenced static functions are removed. */
245 #define L4_STICKY(x) __attribute__((used)) x ///< Mark symbol sticky (even not there) \hideinitializer
246 /* The deprecated attribute is available with 3.1 and higher (3.3 as here
248 #define L4_DEPRECATED __attribute__((deprecated)) ///< Mark symbol deprecated. \hideinitializer
250 /* The "used" attribute is not available with older gcc versions so simply
251 * make sure that gcc doesn't warn about unused functions. */
252 #define L4_STICKY(x) __attribute__((unused)) x ///< Mark symbol sticky (even not there).
253 #define L4_DEPRECATED ///< Mark symbol deprecated
256 #ifndef __GXX_EXPERIMENTAL_CXX0X__
257 #ifndef static_assert
258 #define static_assert(x, y) \
259 do { (void)sizeof(char[-(!(x))]); } while (0)
263 #define L4_stringify_helper(x) #x ///< stringify helper. \hideinitializer
264 #define L4_stringify(x) L4_stringify_helper(x) ///< stringify. \hideinitializer
266 #ifndef __ASSEMBLER__
268 * \brief Memory barrier.
270 L4_INLINE void l4_mb(void);
273 * \brief Write memory barrier.
275 L4_INLINE void l4_wmb(void);
278 /* Implementations */
279 L4_INLINE void l4_mb(void)
281 __asm__ __volatile__ ("" : : : "memory");
284 L4_INLINE void l4_wmb(void)
286 __asm__ __volatile__ ("" : : : "memory");
292 #endif /* !__L4_COMPILER_H__ */