module-abi-8.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* Definitions of Module Structures used by ABI version 8
  2. Copyright (C) 1993-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under the
  5. terms of the GNU General Public License as published by the Free Software
  6. Foundation; either version 3, or (at your option) any later version.
  7. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  8. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>. */
  18. #ifndef __objc_private_module_abi_8_INCLUDE_GNU
  19. #define __objc_private_module_abi_8_INCLUDE_GNU
  20. /* For every class which happens to have statically allocated instances in
  21. this module, one OBJC_STATIC_INSTANCES is allocated by the compiler.
  22. INSTANCES is NULL terminated and points to all statically allocated
  23. instances of this class. */
  24. struct objc_static_instances
  25. {
  26. char *class_name;
  27. #ifdef __cplusplus
  28. id instances[1];
  29. #else
  30. id instances[0];
  31. #endif
  32. };
  33. /* Whereas a Module (defined further down) is the root (typically) of a file,
  34. a Symtab is the root of the class and category definitions within the
  35. module.
  36. A Symtab contains a variable length array of pointers to classes and
  37. categories defined in the module. */
  38. struct objc_symtab
  39. {
  40. unsigned long sel_ref_cnt; /* Unused (always set to 0). */
  41. struct objc_selector *refs; /* The table of selectors referenced in
  42. this module. This is terminated by a
  43. selector with NULL sel_id and NULL
  44. sel_types. Note that we use the type
  45. 'struct objc_selector *' and not
  46. 'SEL' (which is 'const struct
  47. objc_selector *') because the sel_id
  48. of these selectors is patched up by
  49. the runtime when the module is
  50. loaded. */
  51. unsigned short cls_def_cnt; /* Number of classes compiled (defined)
  52. in the module. */
  53. unsigned short cat_def_cnt; /* Number of categories compiled
  54. (defined) in the module. */
  55. void *defs[1]; /* Variable array of pointers.
  56. cls_def_cnt of type Class followed by
  57. cat_def_cnt of type Category_t,
  58. followed by a NULL terminated array
  59. of objc_static_instances. */
  60. };
  61. /* The compiler generates one of these structures for each module that
  62. composes the executable (eg main.m).
  63. This data structure is the root of the definition tree for the
  64. module.
  65. A collect program runs between ld stages and creates a ObjC ctor
  66. array. That array holds a pointer to each module structure of the
  67. executable. */
  68. struct objc_module
  69. {
  70. unsigned long version; /* Version of the Module data
  71. structure. */
  72. unsigned long size; /* sizeof(Module) according to the
  73. compiler - only used to sanity check
  74. that it matches sizeof(Module)
  75. according to the runtime. */
  76. const char* name; /* Name of the file used to compile the
  77. module - not set by modern compilers
  78. for security reasons. */
  79. struct objc_symtab *symtab; /* Pointer to the Symtab of the module.
  80. The Symtab holds an array of pointers
  81. to the classes and categories defined
  82. in the module. */
  83. };
  84. /* The compiler generates one of these structures for a class that has
  85. instance variables defined in its specification. */
  86. struct objc_ivar
  87. {
  88. const char* ivar_name; /* Name of the instance variable as entered
  89. in the class definition. */
  90. const char* ivar_type; /* Description of the Ivar's type. Useful
  91. for debuggers. */
  92. int ivar_offset; /* Byte offset from the base address of the
  93. instance structure to the variable. */
  94. };
  95. struct objc_ivar_list
  96. {
  97. int ivar_count; /* Number of structures (Ivar)
  98. contained in the list. One
  99. structure per instance variable
  100. defined in the class. */
  101. struct objc_ivar ivar_list[1]; /* Variable length structure. */
  102. };
  103. /* The compiler generates one (or more) of these structures for a
  104. class that has methods defined in its specification.
  105. The implementation of a class can be broken into separate pieces in
  106. a file and categories can break them across modules. To handle this
  107. problem is a singly linked list of methods. */
  108. struct objc_method
  109. {
  110. SEL method_name; /* This variable is the method's name.
  111. The compiler puts a char* here, and
  112. it's replaced by a real SEL at runtime
  113. when the method is registered. */
  114. const char* method_types; /* Description of the method's parameter
  115. list. Used when registering the
  116. selector with the runtime. When that
  117. happens, method_name will contain the
  118. method's parameter list. */
  119. IMP method_imp; /* Address of the method in the
  120. executable. */
  121. };
  122. struct objc_method_list
  123. {
  124. struct objc_method_list* method_next; /* This variable is used to
  125. link a method list to
  126. another. It is a singly
  127. linked list. */
  128. int method_count; /* Number of methods defined
  129. in this structure. */
  130. struct objc_method method_list[1]; /* Variable length
  131. structure. */
  132. };
  133. /* Note that a 'struct objc_method_description' as embedded inside a
  134. Protocol uses the same trick as a 'struct objc_method': the
  135. method_name is a 'char *' according to the compiler, who puts the
  136. method name as a string in there. At runtime, the selectors need
  137. to be registered, and the method_name then becomes a SEL. */
  138. struct objc_method_description_list
  139. {
  140. int count;
  141. struct objc_method_description list[1];
  142. };
  143. struct objc_protocol {
  144. struct objc_class* class_pointer;
  145. char *protocol_name;
  146. struct objc_protocol_list *protocol_list;
  147. struct objc_method_description_list *instance_methods, *class_methods;
  148. };
  149. struct objc_protocol_list
  150. {
  151. struct objc_protocol_list *next;
  152. size_t count;
  153. struct objc_protocol *list[1];
  154. };
  155. /*
  156. The compiler generates one of these structures for each class.
  157. This structure is the definition for classes.
  158. This structure is generated by the compiler in the executable and
  159. used by the run-time during normal messaging operations. Therefore
  160. some members change type. The compiler generates "char* const" and
  161. places a string in the following member variables: super_class.
  162. */
  163. struct objc_class {
  164. struct objc_class* class_pointer; /* Pointer to the class's meta
  165. class. */
  166. struct objc_class* super_class; /* Pointer to the super
  167. class. NULL for class
  168. Object. */
  169. const char* name; /* Name of the class. */
  170. long version; /* Unknown. */
  171. unsigned long info; /* Bit mask. See class masks
  172. defined below. */
  173. long instance_size; /* Size in bytes of the class.
  174. The sum of the class
  175. definition and all super
  176. class definitions. */
  177. #ifdef _WIN64
  178. /* We pad the structure manually to prevent warning when -Wpadded is
  179. used. The compiler automatically pads the structures that it
  180. generates, so this manually padded structure still matches the
  181. one generated by the compiler, but if we don't pad manually,
  182. -Wpadded detects that padding is being added and generates
  183. annoying warnings. This hack is necessary as on LLP64 targets
  184. sizeof (long) isn't equal to sizeof (void *). */
  185. long pad;
  186. #endif
  187. struct objc_ivar_list* ivars; /* Pointer to a structure that
  188. describes the instance
  189. variables in the class
  190. definition. NULL indicates
  191. no instance variables.
  192. Does not include super
  193. class variables. */
  194. struct objc_method_list* methods; /* Linked list of instance
  195. methods defined for the
  196. class. */
  197. struct sarray * dtable; /* Pointer to instance method
  198. dispatch table. */
  199. struct objc_class* subclass_list; /* Subclasses */
  200. struct objc_class* sibling_class;
  201. struct objc_protocol_list *protocols; /* Protocols conformed to */
  202. void* gc_object_type;
  203. };
  204. /* This is used to assure consistent access to the info field of
  205. classes. */
  206. #ifndef HOST_BITS_PER_LONG
  207. # define HOST_BITS_PER_LONG (sizeof(long)*8)
  208. #endif
  209. #define __CLS_INFO(cls) ((cls)->info)
  210. #define __CLS_ISINFO(cls, mask) ((__CLS_INFO(cls)&mask)==mask)
  211. #define __CLS_SETINFO(cls, mask) (__CLS_INFO(cls) |= mask)
  212. #define __CLS_SETNOTINFO(cls, mask) (__CLS_INFO(cls) &= ~mask)
  213. /* The structure is of type MetaClass */
  214. #define _CLS_META 0x2L
  215. #define CLS_ISMETA(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_META))
  216. /* The structure is of type Class */
  217. #define _CLS_CLASS 0x1L
  218. #define CLS_ISCLASS(cls) ((cls)&&__CLS_ISINFO(cls, _CLS_CLASS))
  219. /* The class is initialized within the runtime. This means that it
  220. has had correct super and sublinks assigned. */
  221. #define _CLS_RESOLV 0x8L
  222. #define CLS_ISRESOLV(cls) __CLS_ISINFO(cls, _CLS_RESOLV)
  223. #define CLS_SETRESOLV(cls) __CLS_SETINFO(cls, _CLS_RESOLV)
  224. /* The class has been send a +initialize message or a such is not
  225. defined for this class. */
  226. #define _CLS_INITIALIZED 0x04L
  227. #define CLS_ISINITIALIZED(cls) __CLS_ISINFO(cls, _CLS_INITIALIZED)
  228. #define CLS_SETINITIALIZED(cls) __CLS_SETINFO(cls, _CLS_INITIALIZED)
  229. /* The class is being constructed; it has been allocated using
  230. objc_allocateClassPair(), but has not been registered yet by using
  231. objc_registerClassPair(). This means it is possible to freely add
  232. instance variables to the class, but it can't be used for anything
  233. yet. */
  234. #define _CLS_IN_CONSTRUCTION 0x10L
  235. #define CLS_IS_IN_CONSTRUCTION(cls) __CLS_ISINFO(cls, _CLS_IN_CONSTRUCTION)
  236. #define CLS_SET_IN_CONSTRUCTION(cls) __CLS_SETINFO(cls, _CLS_IN_CONSTRUCTION)
  237. #define CLS_SET_NOT_IN_CONSTRUCTION(cls) __CLS_SETNOTINFO(cls, _CLS_IN_CONSTRUCTION)
  238. /* The class number of this class. This must be the same for both the
  239. class and its meta class object. */
  240. #define CLS_GETNUMBER(cls) (__CLS_INFO(cls) >> (HOST_BITS_PER_LONG/2))
  241. #define CLS_SETNUMBER(cls, num) \
  242. ({ (cls)->info <<= (HOST_BITS_PER_LONG/2); \
  243. (cls)->info >>= (HOST_BITS_PER_LONG/2); \
  244. __CLS_SETINFO(cls, (((unsigned long)num) << (HOST_BITS_PER_LONG/2))); })
  245. /* The compiler generates one of these structures for each category.
  246. A class may have many categories and contain both instance and
  247. factory methods. */
  248. struct objc_category
  249. {
  250. const char* category_name; /* Name of the category.
  251. Name contained in the
  252. () of the category
  253. definition. */
  254. const char* class_name; /* Name of the class to
  255. which the category
  256. belongs. */
  257. struct objc_method_list *instance_methods; /* Linked list of
  258. instance methods
  259. defined in the
  260. category. NULL
  261. indicates no instance
  262. methods defined. */
  263. struct objc_method_list *class_methods; /* Linked list of
  264. factory methods
  265. defined in the
  266. category. NULL
  267. indicates no class
  268. methods defined. */
  269. struct objc_protocol_list *protocols; /* List of Protocols
  270. conformed to. */
  271. };
  272. #endif /* __objc_private_module_abi_8_INCLUDE_GNU */