vxworks.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* Common VxWorks target definitions for GNU compiler.
  2. Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. Contributed by CodeSourcery, Inc.
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #include "config.h"
  17. #include "system.h"
  18. #include "coretypes.h"
  19. #include "target.h"
  20. #include "diagnostic-core.h"
  21. #include "output.h"
  22. #include "tm.h"
  23. #include "hash-set.h"
  24. #include "machmode.h"
  25. #include "vec.h"
  26. #include "double-int.h"
  27. #include "input.h"
  28. #include "alias.h"
  29. #include "symtab.h"
  30. #include "wide-int.h"
  31. #include "inchash.h"
  32. #include "tree.h"
  33. #include "fold-const.h"
  34. #include "stringpool.h"
  35. /* Like default_named_section_asm_out_constructor, except that even
  36. constructors with DEFAULT_INIT_PRIORITY must go in a numbered
  37. section on VxWorks. The VxWorks runtime uses a clever trick to get
  38. the sentinel entry (-1) inserted at the beginning of the .ctors
  39. segment. This trick will not work if we ever generate any entries
  40. in plain .ctors sections; we must always use .ctors.PRIORITY. */
  41. void
  42. vxworks_asm_out_constructor (rtx symbol, int priority)
  43. {
  44. section *sec;
  45. sec = get_cdtor_priority_section (priority,
  46. /*constructor_p=*/true);
  47. assemble_addr_to_section (symbol, sec);
  48. }
  49. /* See comment for vxworks_asm_out_constructor. */
  50. void
  51. vxworks_asm_out_destructor (rtx symbol, int priority)
  52. {
  53. section *sec;
  54. sec = get_cdtor_priority_section (priority,
  55. /*constructor_p=*/false);
  56. assemble_addr_to_section (symbol, sec);
  57. }
  58. /* Return the list of FIELD_DECLs that make up an emulated TLS
  59. variable's control object. TYPE is the structure these are fields
  60. of and *NAME will be filled in with the structure tag that should
  61. be used. */
  62. static tree
  63. vxworks_emutls_var_fields (tree type, tree *name)
  64. {
  65. tree field, next_field;
  66. *name = get_identifier ("__tls_var");
  67. field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
  68. get_identifier ("size"), unsigned_type_node);
  69. DECL_CONTEXT (field) = type;
  70. next_field = field;
  71. field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
  72. get_identifier ("module_id"), unsigned_type_node);
  73. DECL_CONTEXT (field) = type;
  74. DECL_CHAIN (field) = next_field;
  75. next_field = field;
  76. field = build_decl (BUILTINS_LOCATION, FIELD_DECL,
  77. get_identifier ("offset"), unsigned_type_node);
  78. DECL_CONTEXT (field) = type;
  79. DECL_CHAIN (field) = next_field;
  80. return field;
  81. }
  82. /* Return the CONSTRUCTOR to initialize an emulated TLS control
  83. object. VAR is the control object. DECL is the TLS object itself
  84. and TMPL_ADDR is the address (an ADDR_EXPR) of the initializer for
  85. that object. */
  86. static tree
  87. vxworks_emutls_var_init (tree var, tree decl, tree tmpl_addr)
  88. {
  89. vec<constructor_elt, va_gc> *v;
  90. vec_alloc (v, 3);
  91. tree type = TREE_TYPE (var);
  92. tree field = TYPE_FIELDS (type);
  93. constructor_elt elt = {field, fold_convert (TREE_TYPE (field), tmpl_addr)};
  94. v->quick_push (elt);
  95. field = DECL_CHAIN (field);
  96. elt.index = field;
  97. elt.value = build_int_cst (TREE_TYPE (field), 0);
  98. v->quick_push (elt);
  99. field = DECL_CHAIN (field);
  100. elt.index = field;
  101. elt.value = fold_convert (TREE_TYPE (field), DECL_SIZE_UNIT (decl));
  102. v->quick_push (elt);
  103. return build_constructor (type, v);
  104. }
  105. /* Do VxWorks-specific parts of TARGET_OPTION_OVERRIDE. */
  106. void
  107. vxworks_override_options (void)
  108. {
  109. /* We don't support __thread via target hooks. */
  110. targetm.have_tls = false;
  111. targetm.emutls.get_address = "__builtin___tls_lookup";
  112. targetm.emutls.register_common = NULL;
  113. targetm.emutls.var_section = ".tls_vars";
  114. targetm.emutls.tmpl_section = ".tls_data";
  115. targetm.emutls.var_prefix = "__tls__";
  116. targetm.emutls.tmpl_prefix = "";
  117. targetm.emutls.var_fields = vxworks_emutls_var_fields;
  118. targetm.emutls.var_init = vxworks_emutls_var_init;
  119. targetm.emutls.var_align_fixed = true;
  120. targetm.emutls.debug_form_tls_address = true;
  121. /* We can use .ctors/.dtors sections only in RTP mode. */
  122. targetm.have_ctors_dtors = TARGET_VXWORKS_RTP;
  123. /* PIC is only supported for RTPs. */
  124. if (flag_pic && !TARGET_VXWORKS_RTP)
  125. error ("PIC is only supported for RTPs");
  126. /* Default to strict dwarf-2 to prevent potential difficulties observed with
  127. non-gdb debuggers on extensions > 2. */
  128. if (!global_options_set.x_dwarf_strict)
  129. dwarf_strict = 1;
  130. if (!global_options_set.x_dwarf_version)
  131. dwarf_version = 2;
  132. }