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