compiler-gcc4.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #ifndef __LINUX_COMPILER_H
  2. #error "Please don't include <linux/compiler-gcc4.h> directly, include <linux/compiler.h> instead."
  3. #endif
  4. /* GCC 4.1.[01] miscompiles __weak */
  5. #ifdef __KERNEL__
  6. # if __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ <= 1
  7. # error Your version of gcc miscompiles the __weak directive
  8. # endif
  9. #endif
  10. #define __used __attribute__((__used__))
  11. #define __must_check __attribute__((warn_unused_result))
  12. #define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
  13. #if __GNUC_MINOR__ >= 3
  14. /* Mark functions as cold. gcc will assume any path leading to a call
  15. to them will be unlikely. This means a lot of manual unlikely()s
  16. are unnecessary now for any paths leading to the usual suspects
  17. like BUG(), printk(), panic() etc. [but let's keep them for now for
  18. older compilers]
  19. Early snapshots of gcc 4.3 don't support this and we can't detect this
  20. in the preprocessor, but we can live with this because they're unreleased.
  21. Maketime probing would be overkill here.
  22. gcc also has a __attribute__((__hot__)) to move hot functions into
  23. a special section, but I don't see any sense in this right now in
  24. the kernel context */
  25. #define __cold __attribute__((__cold__))
  26. #define __linktime_error(message) __attribute__((__error__(message)))
  27. /*
  28. * GCC 'asm goto' miscompiles certain code sequences:
  29. *
  30. * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
  31. *
  32. * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
  33. * Fixed in GCC 4.8.2 and later versions.
  34. *
  35. * (asm goto is automatically volatile - the naming reflects this.)
  36. */
  37. #if GCC_VERSION <= 40801
  38. # define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
  39. #else
  40. # define asm_volatile_goto(x...) do { asm goto(x); } while (0)
  41. #endif
  42. #if __GNUC_MINOR__ >= 5
  43. /*
  44. * Mark a position in code as unreachable. This can be used to
  45. * suppress control flow warnings after asm blocks that transfer
  46. * control elsewhere.
  47. *
  48. * Early snapshots of gcc 4.5 don't support this and we can't detect
  49. * this in the preprocessor, but we can live with this because they're
  50. * unreleased. Really, we need to have autoconf for the kernel.
  51. */
  52. #define unreachable() __builtin_unreachable()
  53. /* Mark a function definition as prohibited from being cloned. */
  54. #define __noclone __attribute__((__noclone__))
  55. #endif
  56. #endif
  57. #if __GNUC_MINOR__ > 0
  58. #define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
  59. #endif
  60. #if __GNUC_MINOR__ >= 4 && !defined(__CHECKER__)
  61. #define __compiletime_warning(message) __attribute__((warning(message)))
  62. #define __compiletime_error(message) __attribute__((error(message)))
  63. #endif