defstd.cc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. // defstd.cc -- define standard symbols for gold.
  2. // Copyright (C) 2006-2022 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. #include "gold.h"
  18. #include "symtab.h"
  19. #include "layout.h"
  20. #include "defstd.h"
  21. // This is a simple file which defines the standard symbols like
  22. // "_end".
  23. namespace
  24. {
  25. using namespace gold;
  26. const Define_symbol_in_section in_section[] =
  27. {
  28. {
  29. "__preinit_array_start", // name
  30. ".preinit_array", // output_section
  31. 0, // value
  32. 0, // size
  33. elfcpp::STT_NOTYPE, // type
  34. elfcpp::STB_GLOBAL, // binding
  35. elfcpp::STV_HIDDEN, // visibility
  36. 0, // nonvis
  37. false, // offset_is_from_end
  38. true // only_if_ref
  39. },
  40. {
  41. "__preinit_array_end", // name
  42. ".preinit_array", // output_section
  43. 0, // value
  44. 0, // size
  45. elfcpp::STT_NOTYPE, // type
  46. elfcpp::STB_GLOBAL, // binding
  47. elfcpp::STV_HIDDEN, // visibility
  48. 0, // nonvis
  49. true, // offset_is_from_end
  50. true // only_if_ref
  51. },
  52. {
  53. "__init_array_start", // name
  54. ".init_array", // output_section
  55. 0, // value
  56. 0, // size
  57. elfcpp::STT_NOTYPE, // type
  58. elfcpp::STB_GLOBAL, // binding
  59. elfcpp::STV_HIDDEN, // visibility
  60. 0, // nonvis
  61. false, // offset_is_from_end
  62. true // only_if_ref
  63. },
  64. {
  65. "__init_array_end", // name
  66. ".init_array", // output_section
  67. 0, // value
  68. 0, // size
  69. elfcpp::STT_NOTYPE, // type
  70. elfcpp::STB_GLOBAL, // binding
  71. elfcpp::STV_HIDDEN, // visibility
  72. 0, // nonvis
  73. true, // offset_is_from_end
  74. true // only_if_ref
  75. },
  76. {
  77. "__fini_array_start", // name
  78. ".fini_array", // output_section
  79. 0, // value
  80. 0, // size
  81. elfcpp::STT_NOTYPE, // type
  82. elfcpp::STB_GLOBAL, // binding
  83. elfcpp::STV_HIDDEN, // visibility
  84. 0, // nonvis
  85. false, // offset_is_from_end
  86. true // only_if_ref
  87. },
  88. {
  89. "__fini_array_end", // name
  90. ".fini_array", // output_section
  91. 0, // value
  92. 0, // size
  93. elfcpp::STT_NOTYPE, // type
  94. elfcpp::STB_GLOBAL, // binding
  95. elfcpp::STV_HIDDEN, // visibility
  96. 0, // nonvis
  97. true, // offset_is_from_end
  98. true // only_if_ref
  99. },
  100. {
  101. "__stack", // name
  102. ".stack", // output_section
  103. 0, // value
  104. 0, // size
  105. elfcpp::STT_NOTYPE, // type
  106. elfcpp::STB_GLOBAL, // binding
  107. elfcpp::STV_DEFAULT, // visibility
  108. 0, // nonvis
  109. false, // offset_is_from_end
  110. true // only_if_ref
  111. },
  112. };
  113. const int in_section_count = sizeof in_section / sizeof in_section[0];
  114. const Define_symbol_in_segment in_segment[] =
  115. {
  116. {
  117. "__executable_start", // name
  118. elfcpp::PT_LOAD, // segment_type
  119. elfcpp::PF(0), // segment_flags_set
  120. elfcpp::PF(0), // segment_flags_clear
  121. 0, // value
  122. 0, // size
  123. elfcpp::STT_NOTYPE, // type
  124. elfcpp::STB_GLOBAL, // binding
  125. elfcpp::STV_DEFAULT, // visibility
  126. 0, // nonvis
  127. Symbol::SEGMENT_START, // offset_from_base
  128. true // only_if_ref
  129. },
  130. {
  131. "__ehdr_start", // name
  132. elfcpp::PT_LOAD, // segment_type
  133. elfcpp::PF(0), // segment_flags_set
  134. elfcpp::PF(0), // segment_flags_clear
  135. 0, // value
  136. 0, // size
  137. elfcpp::STT_NOTYPE, // type
  138. elfcpp::STB_GLOBAL, // binding
  139. elfcpp::STV_HIDDEN, // visibility
  140. 0, // nonvis
  141. Symbol::SEGMENT_START, // offset_from_base
  142. true // only_if_ref
  143. },
  144. {
  145. "etext", // name
  146. elfcpp::PT_LOAD, // segment_type
  147. elfcpp::PF_X, // segment_flags_set
  148. elfcpp::PF_W, // segment_flags_clear
  149. 0, // value
  150. 0, // size
  151. elfcpp::STT_NOTYPE, // type
  152. elfcpp::STB_GLOBAL, // binding
  153. elfcpp::STV_DEFAULT, // visibility
  154. 0, // nonvis
  155. Symbol::SEGMENT_END, // offset_from_base
  156. true // only_if_ref
  157. },
  158. {
  159. "_etext", // name
  160. elfcpp::PT_LOAD, // segment_type
  161. elfcpp::PF_X, // segment_flags_set
  162. elfcpp::PF_W, // segment_flags_clear
  163. 0, // value
  164. 0, // size
  165. elfcpp::STT_NOTYPE, // type
  166. elfcpp::STB_GLOBAL, // binding
  167. elfcpp::STV_DEFAULT, // visibility
  168. 0, // nonvis
  169. Symbol::SEGMENT_END, // offset_from_base
  170. true // only_if_ref
  171. },
  172. {
  173. "__etext", // name
  174. elfcpp::PT_LOAD, // segment_type
  175. elfcpp::PF_X, // segment_flags_set
  176. elfcpp::PF_W, // segment_flags_clear
  177. 0, // value
  178. 0, // size
  179. elfcpp::STT_NOTYPE, // type
  180. elfcpp::STB_GLOBAL, // binding
  181. elfcpp::STV_DEFAULT, // visibility
  182. 0, // nonvis
  183. Symbol::SEGMENT_END, // offset_from_base
  184. true // only_if_ref
  185. },
  186. {
  187. "_edata", // name
  188. elfcpp::PT_LOAD, // segment_type
  189. elfcpp::PF_W, // segment_flags_set
  190. elfcpp::PF(0), // segment_flags_clear
  191. 0, // value
  192. 0, // size
  193. elfcpp::STT_NOTYPE, // type
  194. elfcpp::STB_GLOBAL, // binding
  195. elfcpp::STV_DEFAULT, // visibility
  196. 0, // nonvis
  197. Symbol::SEGMENT_BSS, // offset_from_base
  198. false // only_if_ref
  199. },
  200. {
  201. "edata", // name
  202. elfcpp::PT_LOAD, // segment_type
  203. elfcpp::PF_W, // segment_flags_set
  204. elfcpp::PF(0), // segment_flags_clear
  205. 0, // value
  206. 0, // size
  207. elfcpp::STT_NOTYPE, // type
  208. elfcpp::STB_GLOBAL, // binding
  209. elfcpp::STV_DEFAULT, // visibility
  210. 0, // nonvis
  211. Symbol::SEGMENT_BSS, // offset_from_base
  212. true // only_if_ref
  213. },
  214. {
  215. "__bss_start", // name
  216. elfcpp::PT_LOAD, // segment_type
  217. elfcpp::PF_W, // segment_flags_set
  218. elfcpp::PF(0), // segment_flags_clear
  219. 0, // value
  220. 0, // size
  221. elfcpp::STT_NOTYPE, // type
  222. elfcpp::STB_GLOBAL, // binding
  223. elfcpp::STV_DEFAULT, // visibility
  224. 0, // nonvis
  225. Symbol::SEGMENT_BSS, // offset_from_base
  226. false // only_if_ref
  227. },
  228. {
  229. "_end", // name
  230. elfcpp::PT_LOAD, // segment_type
  231. elfcpp::PF_W, // segment_flags_set
  232. elfcpp::PF(0), // segment_flags_clear
  233. 0, // value
  234. 0, // size
  235. elfcpp::STT_NOTYPE, // type
  236. elfcpp::STB_GLOBAL, // binding
  237. elfcpp::STV_DEFAULT, // visibility
  238. 0, // nonvis
  239. Symbol::SEGMENT_END, // offset_from_base
  240. false // only_if_ref
  241. },
  242. {
  243. "end", // name
  244. elfcpp::PT_LOAD, // segment_type
  245. elfcpp::PF_W, // segment_flags_set
  246. elfcpp::PF(0), // segment_flags_clear
  247. 0, // value
  248. 0, // size
  249. elfcpp::STT_NOTYPE, // type
  250. elfcpp::STB_GLOBAL, // binding
  251. elfcpp::STV_DEFAULT, // visibility
  252. 0, // nonvis
  253. Symbol::SEGMENT_END, // offset_from_base
  254. true // only_if_ref
  255. }
  256. };
  257. const int in_segment_count = sizeof in_segment / sizeof in_segment[0];
  258. } // End anonymous namespace.
  259. namespace gold
  260. {
  261. void
  262. define_standard_symbols(Symbol_table* symtab, const Layout* layout)
  263. {
  264. bool saw_sections_clause = layout->script_options()->saw_sections_clause();
  265. symtab->define_symbols(layout, in_section_count, in_section,
  266. saw_sections_clause);
  267. symtab->define_symbols(layout, in_segment_count, in_segment,
  268. saw_sections_clause);
  269. }
  270. } // End namespace gold.