Home | History | Annotate | Download | only in klibc
      1 /*
      2  * klibc/compiler.h
      3  *
      4  * Various compiler features
      5  */
      6 
      7 #ifndef _KLIBC_COMPILER_H
      8 #define _KLIBC_COMPILER_H
      9 
     10 #define __user
     11 
     12 /* Specific calling conventions */
     13 /* __cdecl is used when we want varadic and non-varadic functions to have
     14    the same binary calling convention. */
     15 #ifdef __i386__
     16 # ifdef __GNUC__
     17 #  define __cdecl __attribute__((cdecl,regparm(0)))
     18 # else
     19   /* Most other C compilers have __cdecl as a keyword */
     20 # endif
     21 #else
     22 # define __cdecl		/* Meaningless on non-i386 */
     23 #endif
     24 
     25 /* How to declare a function that *must* be inlined */
     26 #ifdef __GNUC__
     27 # if __GNUC_MAJOR__ >= 3
     28 #  define __must_inline static __inline__ __attribute__((always_inline))
     29 # else
     30 #  define __must_inline extern __inline__
     31 # endif
     32 #else
     33 # define __must_inline inline	/* Just hope this works... */
     34 #endif
     35 
     36 /* How to declare a function that does not return */
     37 #ifdef __GNUC__
     38 # define __noreturn void __attribute__((noreturn))
     39 #else
     40 # define __noreturn void
     41 #endif
     42 
     43 /* "const" function:
     44 
     45      Many functions do not examine any values except their arguments,
     46      and have no effects except the return value.  Basically this is
     47      just slightly more strict class than the `pure' attribute above,
     48      since function is not allowed to read global memory.
     49 
     50      Note that a function that has pointer arguments and examines the
     51      data pointed to must _not_ be declared `const'.  Likewise, a
     52      function that calls a non-`const' function usually must not be
     53      `const'.  It does not make sense for a `const' function to return
     54      `void'.
     55 */
     56 #ifdef __GNUC__
     57 # define __constfunc __attribute__((const))
     58 #else
     59 # define __constfunc
     60 #endif
     61 #undef __attribute_const__
     62 #define __attribute_const__ __constfunc
     63 
     64 /* "pure" function:
     65 
     66      Many functions have no effects except the return value and their
     67      return value depends only on the parameters and/or global
     68      variables.  Such a function can be subject to common subexpression
     69      elimination and loop optimization just as an arithmetic operator
     70      would be.  These functions should be declared with the attribute
     71      `pure'.
     72 */
     73 #ifdef __GNUC__
     74 # define __purefunc __attribute__((pure))
     75 #else
     76 # define __purefunc
     77 #endif
     78 #undef __attribute_pure__
     79 #define __attribute_pure__ __purefunc
     80 
     81 /* Format attribute */
     82 #ifdef __GNUC__
     83 # define __formatfunc(t,f,a) __attribute__((format(t,f,a)))
     84 #else
     85 # define __formatfunc(t,f,a)
     86 #endif
     87 
     88 /* malloc() function (returns unaliased pointer) */
     89 #if defined(__GNUC__) && (__GNUC_MAJOR__ >= 3)
     90 # define __mallocfunc __attribute__((malloc))
     91 #else
     92 # define __mallocfunc
     93 #endif
     94 
     95 /* likely/unlikely */
     96 #if defined(__GNUC__) && (__GNUC_MAJOR__ > 2 || (__GNUC_MAJOR__ == 2 && __GNUC_MINOR__ >= 95))
     97 # define __likely(x)   __builtin_expect(!!(x), 1)
     98 # define __unlikely(x) __builtin_expect(!!(x), 0)
     99 #else
    100 # define __likely(x)   (!!(x))
    101 # define __unlikely(x) (!!(x))
    102 #endif
    103 
    104 /* Possibly unused function */
    105 #ifdef __GNUC__
    106 # define __unusedfunc	__attribute__((unused))
    107 #else
    108 # define __unusedfunc
    109 #endif
    110 
    111 /* Declare a variable or data structure as unused. */
    112 #ifdef __GNUC__
    113 # define __unused	__attribute__((unused))
    114 #else
    115 # define __unused
    116 #endif
    117 
    118 /* Used symbol */
    119 #define __used				__attribute__((used))
    120 
    121 /* Constructors and destructors */
    122 #define __constructor	__attribute__((constructor))
    123 #define __destructor	__attribute__((destructor))
    124 
    125 /* Packed structures */
    126 #define __packed	__attribute__((packed))
    127 
    128 /* Weak symbols */
    129 #define __weak          __attribute__((weak))
    130 
    131 /* Alignment */
    132 #define __aligned(x)	__attribute__((aligned(x)))
    133 #define __alignas(x)	__attribute__((aligned(__alignof__(x))))
    134 
    135 /* Handling of common (affect constructors/destructors) */
    136 #define __common	__attribute__((common))
    137 #define __nocommon	__attribute__((nocommon))
    138 
    139 /* Weak symbols */
    140 #define __weak			__attribute__((weak))
    141 
    142 #define __export		__attribute__((visibility("default")))
    143 
    144 #endif
    145