c_function_attributes.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # These functions are based on the following code:
  2. # https://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_gcc_func_attribute.m4,
  3. # which is licensed under the following terms:
  4. #
  5. # Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
  6. #
  7. # Copying and distribution of this file, with or without modification, are
  8. # permitted in any medium without royalty provided the copyright notice
  9. # and this notice are preserved. This file is offered as-is, without any
  10. # warranty.
  11. #
  12. C_FUNC_ATTRIBUTES = {
  13. 'alias': '''
  14. int foo(void) { return 0; }
  15. int bar(void) __attribute__((alias("foo")));''',
  16. 'aligned':
  17. 'int foo(void) __attribute__((aligned(32)));',
  18. 'alloc_size':
  19. 'void *foo(int a) __attribute__((alloc_size(1)));',
  20. 'always_inline':
  21. 'inline __attribute__((always_inline)) int foo(void) { return 0; }',
  22. 'artificial':
  23. 'inline __attribute__((artificial)) int foo(void) { return 0; }',
  24. 'cold':
  25. 'int foo(void) __attribute__((cold));',
  26. 'const':
  27. 'int foo(void) __attribute__((const));',
  28. 'constructor':
  29. 'int foo(void) __attribute__((constructor));',
  30. 'constructor_priority':
  31. 'int foo( void ) __attribute__((__constructor__(65535/2)));',
  32. 'deprecated':
  33. 'int foo(void) __attribute__((deprecated("")));',
  34. 'destructor':
  35. 'int foo(void) __attribute__((destructor));',
  36. 'dllexport':
  37. '__declspec(dllexport) int foo(void) { return 0; }',
  38. 'dllimport':
  39. '__declspec(dllimport) int foo(void);',
  40. 'error':
  41. 'int foo(void) __attribute__((error("")));',
  42. 'externally_visible':
  43. 'int foo(void) __attribute__((externally_visible));',
  44. 'fallthrough': '''
  45. int foo( void ) {
  46. switch (0) {
  47. case 1: __attribute__((fallthrough));
  48. case 2: break;
  49. }
  50. return 0;
  51. };''',
  52. 'flatten':
  53. 'int foo(void) __attribute__((flatten));',
  54. 'format':
  55. 'int foo(const char * p, ...) __attribute__((format(printf, 1, 2)));',
  56. 'format_arg':
  57. 'char * foo(const char * p) __attribute__((format_arg(1)));',
  58. 'gnu_inline':
  59. 'inline __attribute__((gnu_inline)) int foo(void) { return 0; }',
  60. 'hot':
  61. 'int foo(void) __attribute__((hot));',
  62. 'ifunc':
  63. ('int my_foo(void) { return 0; }'
  64. 'static int (*resolve_foo(void))(void) { return my_foo; }'
  65. 'int foo(void) __attribute__((ifunc("resolve_foo")));'),
  66. 'leaf':
  67. '__attribute__((leaf)) int foo(void) { return 0; }',
  68. 'malloc':
  69. 'int *foo(void) __attribute__((malloc));',
  70. 'noclone':
  71. 'int foo(void) __attribute__((noclone));',
  72. 'noinline':
  73. '__attribute__((noinline)) int foo(void) { return 0; }',
  74. 'nonnull':
  75. 'int foo(char * p) __attribute__((nonnull(1)));',
  76. 'noreturn':
  77. 'int foo(void) __attribute__((noreturn));',
  78. 'nothrow':
  79. 'int foo(void) __attribute__((nothrow));',
  80. 'optimize':
  81. '__attribute__((optimize(3))) int foo(void) { return 0; }',
  82. 'packed':
  83. 'struct __attribute__((packed)) foo { int bar; };',
  84. 'pure':
  85. 'int foo(void) __attribute__((pure));',
  86. 'returns_nonnull':
  87. 'int *foo(void) __attribute__((returns_nonnull));',
  88. 'unused':
  89. 'int foo(void) __attribute__((unused));',
  90. 'used':
  91. 'int foo(void) __attribute__((used));',
  92. 'visibility': '''
  93. int foo_def(void) __attribute__((visibility("default")));
  94. int foo_hid(void) __attribute__((visibility("hidden")));
  95. int foo_int(void) __attribute__((visibility("internal")));''',
  96. 'visibility:default':
  97. 'int foo(void) __attribute__((visibility("default")));',
  98. 'visibility:hidden':
  99. 'int foo(void) __attribute__((visibility("hidden")));',
  100. 'visibility:internal':
  101. 'int foo(void) __attribute__((visibility("internal")));',
  102. 'visibility:protected':
  103. 'int foo(void) __attribute__((visibility("protected")));',
  104. 'warning':
  105. 'int foo(void) __attribute__((warning("")));',
  106. 'warn_unused_result':
  107. 'int foo(void) __attribute__((warn_unused_result));',
  108. 'weak':
  109. 'int foo(void) __attribute__((weak));',
  110. 'weakref': '''
  111. static int foo(void) { return 0; }
  112. static int var(void) __attribute__((weakref("foo")));''',
  113. }
  114. CXX_FUNC_ATTRIBUTES = {
  115. # Alias must be applied to the mangled name in C++
  116. 'alias':
  117. ('extern "C" {'
  118. 'int foo(void) { return 0; }'
  119. '}'
  120. 'int bar(void) __attribute__((alias("foo")));'
  121. ),
  122. 'ifunc':
  123. ('extern "C" {'
  124. 'int my_foo(void) { return 0; }'
  125. 'static int (*resolve_foo(void))(void) { return my_foo; }'
  126. '}'
  127. 'int foo(void) __attribute__((ifunc("resolve_foo")));'),
  128. }