elfos.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. /* elfos.h -- operating system specific defines to be used when
  2. targeting GCC for some generic ELF system
  3. Copyright (C) 1991-2015 Free Software Foundation, Inc.
  4. Based on svr4.h contributed by Ron Guilmette (rfg@netcom.com).
  5. This file is part of GCC.
  6. GCC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. GCC is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. Under Section 7 of GPL version 3, you are granted additional
  15. permissions described in the GCC Runtime Library Exception, version
  16. 3.1, as published by the Free Software Foundation.
  17. You should have received a copy of the GNU General Public License and
  18. a copy of the GCC Runtime Library Exception along with this program;
  19. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. <http://www.gnu.org/licenses/>. */
  21. #define TARGET_OBJFMT_CPP_BUILTINS() \
  22. do \
  23. { \
  24. builtin_define ("__ELF__"); \
  25. } \
  26. while (0)
  27. /* Define a symbol indicating that we are using elfos.h.
  28. Some CPU specific configuration files use this. */
  29. #define USING_ELFOS_H
  30. /* The prefix to add to user-visible assembler symbols.
  31. For ELF systems the convention is *not* to prepend a leading
  32. underscore onto user-level symbol names. */
  33. #undef USER_LABEL_PREFIX
  34. #define USER_LABEL_PREFIX ""
  35. /* The biggest alignment supported by ELF in bits. 32-bit ELF
  36. supports section alignment up to (0x80000000 * 8), while
  37. 64-bit ELF supports (0x8000000000000000 * 8). If this macro
  38. is not defined, the default is the largest alignment supported
  39. by 32-bit ELF and representable on a 32-bit host. Use this
  40. macro to limit the alignment which can be specified using
  41. the `__attribute__ ((aligned (N)))' construct. */
  42. #ifndef MAX_OFILE_ALIGNMENT
  43. #define MAX_OFILE_ALIGNMENT (((unsigned int) 1 << 28) * 8)
  44. #endif
  45. /* Use periods rather than dollar signs in special g++ assembler names. */
  46. #define NO_DOLLAR_IN_LABEL
  47. /* Writing `int' for a bit-field forces int alignment for the structure. */
  48. #ifndef PCC_BITFIELD_TYPE_MATTERS
  49. #define PCC_BITFIELD_TYPE_MATTERS 1
  50. #endif
  51. /* All ELF targets can support DWARF-2. */
  52. #define DWARF2_DEBUGGING_INFO 1
  53. /* The GNU tools operate better with dwarf2, and it is required by some
  54. psABI's. Since we don't have any native tools to be compatible with,
  55. default to dwarf2. */
  56. #ifndef PREFERRED_DEBUGGING_TYPE
  57. #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
  58. #endif
  59. /* All SVR4 targets use the ELF object file format. */
  60. #define OBJECT_FORMAT_ELF
  61. /* Output #ident as a .ident. */
  62. #undef TARGET_ASM_OUTPUT_IDENT
  63. #define TARGET_ASM_OUTPUT_IDENT default_asm_output_ident_directive
  64. #undef SET_ASM_OP
  65. #define SET_ASM_OP "\t.set\t"
  66. /* Most svr4 assemblers want a .file directive at the beginning of
  67. their input file. */
  68. #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
  69. /* This is how to allocate empty space in some section. The .zero
  70. pseudo-op is used for this on most svr4 assemblers. */
  71. #define SKIP_ASM_OP "\t.zero\t"
  72. #undef ASM_OUTPUT_SKIP
  73. #define ASM_OUTPUT_SKIP(FILE, SIZE) \
  74. fprintf ((FILE), "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n",\
  75. SKIP_ASM_OP, (SIZE))
  76. /* This is how to store into the string LABEL
  77. the symbol_ref name of an internal numbered label where
  78. PREFIX is the class of label and NUM is the number within the class.
  79. This is suitable for output with `assemble_name'.
  80. For most svr4 systems, the convention is that any symbol which begins
  81. with a period is not put into the linker symbol table by the assembler. */
  82. #undef ASM_GENERATE_INTERNAL_LABEL
  83. #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
  84. do \
  85. { \
  86. char *__p; \
  87. (LABEL)[0] = '*'; \
  88. (LABEL)[1] = '.'; \
  89. __p = stpcpy (&(LABEL)[2], PREFIX); \
  90. sprint_ul (__p, (unsigned long) (NUM)); \
  91. } \
  92. while (0)
  93. /* Output the label which precedes a jumptable. Note that for all svr4
  94. systems where we actually generate jumptables (which is to say every
  95. svr4 target except i386, where we use casesi instead) we put the jump-
  96. tables into the .rodata section and since other stuff could have been
  97. put into the .rodata section prior to any given jumptable, we have to
  98. make sure that the location counter for the .rodata section gets pro-
  99. perly re-aligned prior to the actual beginning of the jump table. */
  100. #undef ALIGN_ASM_OP
  101. #define ALIGN_ASM_OP "\t.align\t"
  102. #ifndef ASM_OUTPUT_BEFORE_CASE_LABEL
  103. #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE, PREFIX, NUM, TABLE) \
  104. ASM_OUTPUT_ALIGN ((FILE), 2);
  105. #endif
  106. #undef ASM_OUTPUT_CASE_LABEL
  107. #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE) \
  108. do \
  109. { \
  110. ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE) \
  111. (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); \
  112. } \
  113. while (0)
  114. /* The standard SVR4 assembler seems to require that certain builtin
  115. library routines (e.g. .udiv) be explicitly declared as .globl
  116. in each assembly file where they are referenced. */
  117. #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
  118. (*targetm.asm_out.globalize_label) (FILE, XSTR (FUN, 0))
  119. /* This says how to output assembler code to declare an
  120. uninitialized external linkage data object. Under SVR4,
  121. the linker seems to want the alignment of data objects
  122. to depend on their types. We do exactly that here. */
  123. #define COMMON_ASM_OP "\t.comm\t"
  124. #undef ASM_OUTPUT_ALIGNED_COMMON
  125. #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
  126. do \
  127. { \
  128. fprintf ((FILE), "%s", COMMON_ASM_OP); \
  129. assemble_name ((FILE), (NAME)); \
  130. fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", \
  131. (SIZE), (ALIGN) / BITS_PER_UNIT); \
  132. } \
  133. while (0)
  134. /* This says how to output assembler code to declare an
  135. uninitialized internal linkage data object. Under SVR4,
  136. the linker seems to want the alignment of data objects
  137. to depend on their types. We do exactly that here. */
  138. #define LOCAL_ASM_OP "\t.local\t"
  139. #undef ASM_OUTPUT_ALIGNED_LOCAL
  140. #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
  141. do \
  142. { \
  143. fprintf ((FILE), "%s", LOCAL_ASM_OP); \
  144. assemble_name ((FILE), (NAME)); \
  145. fprintf ((FILE), "\n"); \
  146. ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN); \
  147. } \
  148. while (0)
  149. /* This is the pseudo-op used to generate a contiguous sequence of byte
  150. values from a double-quoted string WITHOUT HAVING A TERMINATING NUL
  151. AUTOMATICALLY APPENDED. This is the same for most svr4 assemblers. */
  152. #undef ASCII_DATA_ASM_OP
  153. #define ASCII_DATA_ASM_OP "\t.ascii\t"
  154. /* Support a read-only data section. */
  155. #define READONLY_DATA_SECTION_ASM_OP "\t.section\t.rodata"
  156. /* On svr4, we *do* have support for the .init and .fini sections, and we
  157. can put stuff in there to be executed before and after `main'. We let
  158. crtstuff.c and other files know this by defining the following symbols.
  159. The definitions say how to change sections to the .init and .fini
  160. sections. This is the same for all known svr4 assemblers. */
  161. #define INIT_SECTION_ASM_OP "\t.section\t.init"
  162. #define FINI_SECTION_ASM_OP "\t.section\t.fini"
  163. /* Output assembly directive to move to the beginning of current section. */
  164. #ifdef HAVE_GAS_SUBSECTION_ORDERING
  165. # define ASM_SECTION_START_OP "\t.subsection\t-1"
  166. # define ASM_OUTPUT_SECTION_START(FILE) \
  167. fprintf ((FILE), "%s\n", ASM_SECTION_START_OP)
  168. #endif
  169. #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
  170. /* Switch into a generic section. */
  171. #define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section
  172. #undef TARGET_ASM_SELECT_RTX_SECTION
  173. #define TARGET_ASM_SELECT_RTX_SECTION default_elf_select_rtx_section
  174. #undef TARGET_ASM_SELECT_SECTION
  175. #define TARGET_ASM_SELECT_SECTION default_elf_select_section
  176. #undef TARGET_HAVE_SWITCHABLE_BSS_SECTIONS
  177. #define TARGET_HAVE_SWITCHABLE_BSS_SECTIONS true
  178. /* Define the strings used for the special svr4 .type and .size directives.
  179. These strings generally do not vary from one system running svr4 to
  180. another, but if a given system (e.g. m88k running svr) needs to use
  181. different pseudo-op names for these, they may be overridden in the
  182. file which includes this one. */
  183. #define TYPE_ASM_OP "\t.type\t"
  184. #define SIZE_ASM_OP "\t.size\t"
  185. /* This is how we tell the assembler that a symbol is weak. */
  186. #define ASM_WEAKEN_LABEL(FILE, NAME) \
  187. do \
  188. { \
  189. fputs ("\t.weak\t", (FILE)); \
  190. assemble_name ((FILE), (NAME)); \
  191. fputc ('\n', (FILE)); \
  192. } \
  193. while (0)
  194. /* The following macro defines the format used to output the second
  195. operand of the .type assembler directive. Different svr4 assemblers
  196. expect various different forms for this operand. The one given here
  197. is just a default. You may need to override it in your machine-
  198. specific tm.h file (depending upon the particulars of your assembler). */
  199. #define TYPE_OPERAND_FMT "@%s"
  200. /* Write the extra assembler code needed to declare a function's result.
  201. Most svr4 assemblers don't require any special declaration of the
  202. result value, but there are exceptions. */
  203. #ifndef ASM_DECLARE_RESULT
  204. #define ASM_DECLARE_RESULT(FILE, RESULT)
  205. #endif
  206. /* These macros generate the special .type and .size directives which
  207. are used to set the corresponding fields of the linker symbol table
  208. entries in an ELF object file under SVR4. These macros also output
  209. the starting labels for the relevant functions/objects. */
  210. /* Write the extra assembler code needed to declare a function properly.
  211. Some svr4 assemblers need to also have something extra said about the
  212. function's return value. We allow for that here. */
  213. #ifndef ASM_DECLARE_FUNCTION_NAME
  214. #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
  215. do \
  216. { \
  217. ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
  218. ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \
  219. ASM_OUTPUT_FUNCTION_LABEL (FILE, NAME, DECL); \
  220. } \
  221. while (0)
  222. #endif
  223. /* Write the extra assembler code needed to declare an object properly. */
  224. #ifdef HAVE_GAS_GNU_UNIQUE_OBJECT
  225. #define USE_GNU_UNIQUE_OBJECT flag_gnu_unique
  226. #else
  227. #define USE_GNU_UNIQUE_OBJECT 0
  228. #endif
  229. #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
  230. do \
  231. { \
  232. HOST_WIDE_INT size; \
  233. \
  234. /* For template static data member instantiations or \
  235. inline fn local statics and their guard variables, use \
  236. gnu_unique_object so that they will be combined even under \
  237. RTLD_LOCAL. Don't use gnu_unique_object for typeinfo, \
  238. vtables and other read-only artificial decls. */ \
  239. if (USE_GNU_UNIQUE_OBJECT && DECL_ONE_ONLY (DECL) \
  240. && (!DECL_ARTIFICIAL (DECL) || !TREE_READONLY (DECL))) \
  241. ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "gnu_unique_object"); \
  242. else \
  243. ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
  244. \
  245. size_directive_output = 0; \
  246. if (!flag_inhibit_size_directive \
  247. && (DECL) && DECL_SIZE (DECL)) \
  248. { \
  249. size_directive_output = 1; \
  250. size = tree_to_uhwi (DECL_SIZE_UNIT (DECL)); \
  251. ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size); \
  252. } \
  253. \
  254. ASM_OUTPUT_LABEL (FILE, NAME); \
  255. } \
  256. while (0)
  257. /* Output the size directive for a decl in rest_of_decl_compilation
  258. in the case where we did not do so before the initializer.
  259. Once we find the error_mark_node, we know that the value of
  260. size_directive_output was set
  261. by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */
  262. #undef ASM_FINISH_DECLARE_OBJECT
  263. #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)\
  264. do \
  265. { \
  266. const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \
  267. HOST_WIDE_INT size; \
  268. \
  269. if (!flag_inhibit_size_directive \
  270. && DECL_SIZE (DECL) \
  271. && ! AT_END && TOP_LEVEL \
  272. && DECL_INITIAL (DECL) == error_mark_node \
  273. && !size_directive_output) \
  274. { \
  275. size_directive_output = 1; \
  276. size = tree_to_uhwi (DECL_SIZE_UNIT (DECL)); \
  277. ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size); \
  278. } \
  279. } \
  280. while (0)
  281. /* This is how to declare the size of a function. */
  282. #ifndef ASM_DECLARE_FUNCTION_SIZE
  283. #define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \
  284. do \
  285. { \
  286. if (!flag_inhibit_size_directive) \
  287. ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME); \
  288. } \
  289. while (0)
  290. #endif
  291. /* A table of bytes codes used by the ASM_OUTPUT_ASCII and
  292. ASM_OUTPUT_LIMITED_STRING macros. Each byte in the table
  293. corresponds to a particular byte value [0..255]. For any
  294. given byte value, if the value in the corresponding table
  295. position is zero, the given character can be output directly.
  296. If the table value is 1, the byte must be output as a \ooo
  297. octal escape. If the tables value is anything else, then the
  298. byte value should be output as a \ followed by the value
  299. in the table. Note that we can use standard UN*X escape
  300. sequences for many control characters, but we don't use
  301. \a to represent BEL because some svr4 assemblers (e.g. on
  302. the i386) don't know about that. Also, we don't use \v
  303. since some versions of gas, such as 2.2 did not accept it. */
  304. #define ELF_ASCII_ESCAPES \
  305. "\1\1\1\1\1\1\1\1btn\1fr\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
  306. \0\0\"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
  307. \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\0\0\0\
  308. \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\
  309. \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
  310. \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
  311. \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\
  312. \1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"
  313. /* Some svr4 assemblers have a limit on the number of characters which
  314. can appear in the operand of a .string directive. If your assembler
  315. has such a limitation, you should define STRING_LIMIT to reflect that
  316. limit. Note that at least some svr4 assemblers have a limit on the
  317. actual number of bytes in the double-quoted string, and that they
  318. count each character in an escape sequence as one byte. Thus, an
  319. escape sequence like \377 would count as four bytes.
  320. If your target assembler doesn't support the .string directive, you
  321. should define this to zero.
  322. */
  323. #define ELF_STRING_LIMIT ((unsigned) 256)
  324. #define STRING_ASM_OP "\t.string\t"
  325. /* The routine used to output NUL terminated strings. We use a special
  326. version of this for most svr4 targets because doing so makes the
  327. generated assembly code more compact (and thus faster to assemble)
  328. as well as more readable, especially for targets like the i386
  329. (where the only alternative is to output character sequences as
  330. comma separated lists of numbers). */
  331. #define ASM_OUTPUT_LIMITED_STRING(FILE, STR) \
  332. default_elf_asm_output_limited_string ((FILE), (STR))
  333. /* The routine used to output sequences of byte values. We use a special
  334. version of this for most svr4 targets because doing so makes the
  335. generated assembly code more compact (and thus faster to assemble)
  336. as well as more readable. Note that if we find subparts of the
  337. character sequence which end with NUL (and which are shorter than
  338. STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING. */
  339. #undef ASM_OUTPUT_ASCII
  340. #define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \
  341. default_elf_asm_output_ascii ((FILE), (STR), (LENGTH));
  342. /* Allow the use of the -frecord-gcc-switches switch via the
  343. elf_record_gcc_switches function defined in varasm.c. */
  344. #undef TARGET_ASM_RECORD_GCC_SWITCHES
  345. #define TARGET_ASM_RECORD_GCC_SWITCHES elf_record_gcc_switches
  346. /* A C statement (sans semicolon) to output to the stdio stream STREAM
  347. any text necessary for declaring the name of an external symbol
  348. named NAME which is referenced in this compilation but not defined.
  349. It is needed to properly support non-default visibility. */
  350. #ifndef ASM_OUTPUT_EXTERNAL
  351. #define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \
  352. default_elf_asm_output_external (FILE, DECL, NAME)
  353. #endif
  354. #undef TARGET_LIBC_HAS_FUNCTION
  355. #define TARGET_LIBC_HAS_FUNCTION no_c99_libc_has_function