Don't pass around the target in order to define symbols; get it from
[platform/upstream/binutils.git] / gold / defstd.cc
1 // defstd.cc -- define standard symbols for gold.
2
3 // Copyright 2006, 2007 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 "defstd.h"
27
28 // This is a simple file which defines the standard symbols like
29 // "_end".
30
31 namespace
32 {
33
34 using namespace gold;
35
36 const Define_symbol_in_section in_section[] =
37 {
38   {
39     "__preinit_array_start",    // name
40     ".preinit_array",           // output_section
41     0,                          // value
42     0,                          // size
43     elfcpp::STT_NOTYPE,         // type
44     elfcpp::STB_GLOBAL,         // binding
45     elfcpp::STV_HIDDEN,         // visibility
46     0,                          // nonvis
47     false,                      // offset_is_from_end
48     true                        // only_if_ref
49   },
50   {
51     "__preinit_array_end",      // name
52     ".preinit_array",           // output_section
53     0,                          // value
54     0,                          // size
55     elfcpp::STT_NOTYPE,         // type
56     elfcpp::STB_GLOBAL,         // binding
57     elfcpp::STV_HIDDEN,         // visibility
58     0,                          // nonvis
59     true,                       // offset_is_from_end
60     true                        // only_if_ref
61   },
62   {
63     "__init_array_start",       // name
64     ".init_array",              // output_section
65     0,                          // value
66     0,                          // size
67     elfcpp::STT_NOTYPE,         // type
68     elfcpp::STB_GLOBAL,         // binding
69     elfcpp::STV_HIDDEN,         // visibility
70     0,                          // nonvis
71     false,                      // offset_is_from_end
72     true                        // only_if_ref
73   },
74   {
75     "__init_array_end",         // name
76     ".init_array",              // output_section
77     0,                          // value
78     0,                          // size
79     elfcpp::STT_NOTYPE,         // type
80     elfcpp::STB_GLOBAL,         // binding
81     elfcpp::STV_HIDDEN,         // visibility
82     0,                          // nonvis
83     true,                       // offset_is_from_end
84     true                        // only_if_ref
85   },
86   {
87     "__fini_array_start",       // name
88     ".fini_array",              // output_section
89     0,                          // value
90     0,                          // size
91     elfcpp::STT_NOTYPE,         // type
92     elfcpp::STB_GLOBAL,         // binding
93     elfcpp::STV_HIDDEN,         // visibility
94     0,                          // nonvis
95     false,                      // offset_is_from_end
96     true                        // only_if_ref
97   },
98   {
99     "__fini_array_end",         // name
100     ".fini_array",              // output_section
101     0,                          // value
102     0,                          // size
103     elfcpp::STT_NOTYPE,         // type
104     elfcpp::STB_GLOBAL,         // binding
105     elfcpp::STV_HIDDEN,         // visibility
106     0,                          // nonvis
107     true,                       // offset_is_from_end
108     true                        // only_if_ref
109   }
110 };
111
112 const int in_section_count = sizeof in_section / sizeof in_section[0];
113
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     "etext",                    // name
132     elfcpp::PT_LOAD,            // segment_type
133     elfcpp::PF_X,               // segment_flags_set
134     elfcpp::PF_W,               // segment_flags_clear
135     0,                          // value
136     0,                          // size
137     elfcpp::STT_NOTYPE,         // type
138     elfcpp::STB_GLOBAL,         // binding
139     elfcpp::STV_DEFAULT,        // visibility
140     0,                          // nonvis
141     Symbol::SEGMENT_END,        // 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     "_edata",                   // name
174     elfcpp::PT_LOAD,            // segment_type
175     elfcpp::PF_W,               // segment_flags_set
176     elfcpp::PF(0),              // 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_BSS,        // offset_from_base
184     false                       // 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     true                        // only_if_ref
199   },
200   {
201     "__bss_start",              // 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     false                       // only_if_ref
213   },
214   {
215     "_end",                     // 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_END,        // 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
244 const int in_segment_count = sizeof in_segment / sizeof in_segment[0];
245
246 } // End anonymous namespace.
247
248 namespace gold
249 {
250
251 void
252 define_standard_symbols(Symbol_table* symtab, const Layout* layout)
253 {
254   symtab->define_symbols(layout, in_section_count, in_section);
255   symtab->define_symbols(layout, in_segment_count, in_segment);
256 }
257
258 } // End namespace gold.