]>
Commit | Line | Data |
---|---|---|
a2fb1b05 ILT |
1 | // output.h -- manage the output file for gold -*- C++ -*- |
2 | ||
6cb15b7f ILT |
3 | // Copyright 2006, 2007 Free Software Foundation, Inc. |
4 | // Written by Ian Lance Taylor <[email protected]>. | |
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 | ||
a2fb1b05 ILT |
23 | #ifndef GOLD_OUTPUT_H |
24 | #define GOLD_OUTPUT_H | |
25 | ||
26 | #include <list> | |
ead1e424 | 27 | #include <vector> |
a2fb1b05 ILT |
28 | |
29 | #include "elfcpp.h" | |
54dc6425 | 30 | #include "layout.h" |
c06b7b0b | 31 | #include "reloc-types.h" |
a2fb1b05 ILT |
32 | |
33 | namespace gold | |
34 | { | |
35 | ||
61ba1cf9 | 36 | class General_options; |
a2fb1b05 | 37 | class Object; |
a3ad94ed | 38 | class Symbol; |
a2fb1b05 | 39 | class Output_file; |
c06b7b0b | 40 | class Output_section; |
6a74a719 | 41 | class Relocatable_relocs; |
a3ad94ed | 42 | class Target; |
54dc6425 ILT |
43 | template<int size, bool big_endian> |
44 | class Sized_target; | |
c06b7b0b ILT |
45 | template<int size, bool big_endian> |
46 | class Sized_relobj; | |
54dc6425 ILT |
47 | |
48 | // An abtract class for data which has to go into the output file. | |
a2fb1b05 ILT |
49 | |
50 | class Output_data | |
51 | { | |
52 | public: | |
27bc2bce ILT |
53 | explicit Output_data() |
54 | : address_(0), data_size_(0), offset_(-1), | |
55 | is_address_valid_(false), is_data_size_valid_(false), | |
56 | is_offset_valid_(false), | |
4f4c5f80 | 57 | dynamic_reloc_count_(0) |
a2fb1b05 ILT |
58 | { } |
59 | ||
60 | virtual | |
61 | ~Output_data(); | |
62 | ||
27bc2bce ILT |
63 | // Return the address. For allocated sections, this is only valid |
64 | // after Layout::finalize is finished. | |
75f65a3e ILT |
65 | uint64_t |
66 | address() const | |
27bc2bce ILT |
67 | { |
68 | gold_assert(this->is_address_valid_); | |
69 | return this->address_; | |
70 | } | |
75f65a3e | 71 | |
27bc2bce ILT |
72 | // Return the size of the data. For allocated sections, this must |
73 | // be valid after Layout::finalize calls set_address, but need not | |
74 | // be valid before then. | |
a2fb1b05 | 75 | off_t |
75f65a3e | 76 | data_size() const |
27bc2bce ILT |
77 | { |
78 | gold_assert(this->is_data_size_valid_); | |
79 | return this->data_size_; | |
80 | } | |
75f65a3e | 81 | |
ead1e424 | 82 | // Return the file offset. This is only valid after |
27bc2bce ILT |
83 | // Layout::finalize is finished. For some non-allocated sections, |
84 | // it may not be valid until near the end of the link. | |
75f65a3e ILT |
85 | off_t |
86 | offset() const | |
27bc2bce ILT |
87 | { |
88 | gold_assert(this->is_offset_valid_); | |
89 | return this->offset_; | |
90 | } | |
75f65a3e | 91 | |
a445fddf ILT |
92 | // Reset the address and file offset. This essentially disables the |
93 | // sanity testing about duplicate and unknown settings. | |
94 | void | |
95 | reset_address_and_file_offset() | |
96 | { | |
97 | this->is_address_valid_ = false; | |
98 | this->is_offset_valid_ = false; | |
99 | this->is_data_size_valid_ = false; | |
100 | this->do_reset_address_and_file_offset(); | |
101 | } | |
102 | ||
75f65a3e ILT |
103 | // Return the required alignment. |
104 | uint64_t | |
105 | addralign() const | |
106 | { return this->do_addralign(); } | |
107 | ||
a445fddf ILT |
108 | // Return whether this has a load address. |
109 | bool | |
110 | has_load_address() const | |
111 | { return this->do_has_load_address(); } | |
112 | ||
113 | // Return the load address. | |
114 | uint64_t | |
115 | load_address() const | |
116 | { return this->do_load_address(); } | |
117 | ||
75f65a3e ILT |
118 | // Return whether this is an Output_section. |
119 | bool | |
120 | is_section() const | |
121 | { return this->do_is_section(); } | |
122 | ||
123 | // Return whether this is an Output_section of the specified type. | |
124 | bool | |
125 | is_section_type(elfcpp::Elf_Word stt) const | |
126 | { return this->do_is_section_type(stt); } | |
127 | ||
128 | // Return whether this is an Output_section with the specified flag | |
129 | // set. | |
130 | bool | |
131 | is_section_flag_set(elfcpp::Elf_Xword shf) const | |
132 | { return this->do_is_section_flag_set(shf); } | |
133 | ||
77e65537 ILT |
134 | // Return the output section that this goes in, if there is one. |
135 | Output_section* | |
136 | output_section() | |
137 | { return this->do_output_section(); } | |
138 | ||
ead1e424 ILT |
139 | // Return the output section index, if there is an output section. |
140 | unsigned int | |
141 | out_shndx() const | |
142 | { return this->do_out_shndx(); } | |
143 | ||
144 | // Set the output section index, if this is an output section. | |
145 | void | |
146 | set_out_shndx(unsigned int shndx) | |
147 | { this->do_set_out_shndx(shndx); } | |
148 | ||
27bc2bce ILT |
149 | // Set the address and file offset of this data, and finalize the |
150 | // size of the data. This is called during Layout::finalize for | |
151 | // allocated sections. | |
75f65a3e | 152 | void |
27bc2bce ILT |
153 | set_address_and_file_offset(uint64_t addr, off_t off) |
154 | { | |
155 | this->set_address(addr); | |
156 | this->set_file_offset(off); | |
157 | this->finalize_data_size(); | |
158 | } | |
159 | ||
160 | // Set the address. | |
161 | void | |
162 | set_address(uint64_t addr) | |
163 | { | |
164 | gold_assert(!this->is_address_valid_); | |
165 | this->address_ = addr; | |
166 | this->is_address_valid_ = true; | |
167 | } | |
168 | ||
169 | // Set the file offset. | |
170 | void | |
171 | set_file_offset(off_t off) | |
172 | { | |
173 | gold_assert(!this->is_offset_valid_); | |
174 | this->offset_ = off; | |
175 | this->is_offset_valid_ = true; | |
176 | } | |
177 | ||
178 | // Finalize the data size. | |
179 | void | |
180 | finalize_data_size() | |
181 | { | |
182 | if (!this->is_data_size_valid_) | |
183 | { | |
184 | // Tell the child class to set the data size. | |
185 | this->set_final_data_size(); | |
186 | gold_assert(this->is_data_size_valid_); | |
187 | } | |
188 | } | |
75f65a3e | 189 | |
7bf1f802 ILT |
190 | // Set the TLS offset. Called only for SHT_TLS sections. |
191 | void | |
192 | set_tls_offset(uint64_t tls_base) | |
193 | { this->do_set_tls_offset(tls_base); } | |
194 | ||
195 | // Return the TLS offset, relative to the base of the TLS segment. | |
196 | // Valid only for SHT_TLS sections. | |
197 | uint64_t | |
198 | tls_offset() const | |
199 | { return this->do_tls_offset(); } | |
200 | ||
ead1e424 ILT |
201 | // Write the data to the output file. This is called after |
202 | // Layout::finalize is complete. | |
75f65a3e ILT |
203 | void |
204 | write(Output_file* file) | |
205 | { this->do_write(file); } | |
a2fb1b05 | 206 | |
27bc2bce ILT |
207 | // This is called by Layout::finalize to note that the sizes of |
208 | // allocated sections must now be fixed. | |
a3ad94ed ILT |
209 | static void |
210 | layout_complete() | |
27bc2bce | 211 | { Output_data::allocated_sizes_are_fixed = true; } |
a3ad94ed | 212 | |
730cdc88 ILT |
213 | // Used to check that layout has been done. |
214 | static bool | |
215 | is_layout_complete() | |
27bc2bce | 216 | { return Output_data::allocated_sizes_are_fixed; } |
730cdc88 | 217 | |
4f4c5f80 ILT |
218 | // Count the number of dynamic relocations applied to this section. |
219 | void | |
220 | add_dynamic_reloc() | |
221 | { ++this->dynamic_reloc_count_; } | |
222 | ||
223 | // Return the number of dynamic relocations applied to this section. | |
224 | unsigned int | |
225 | dynamic_reloc_count() const | |
226 | { return this->dynamic_reloc_count_; } | |
227 | ||
a9a60db6 ILT |
228 | // Whether the address is valid. |
229 | bool | |
230 | is_address_valid() const | |
231 | { return this->is_address_valid_; } | |
232 | ||
233 | // Whether the file offset is valid. | |
234 | bool | |
235 | is_offset_valid() const | |
236 | { return this->is_offset_valid_; } | |
237 | ||
238 | // Whether the data size is valid. | |
239 | bool | |
240 | is_data_size_valid() const | |
241 | { return this->is_data_size_valid_; } | |
242 | ||
75f65a3e ILT |
243 | protected: |
244 | // Functions that child classes may or in some cases must implement. | |
245 | ||
246 | // Write the data to the output file. | |
a2fb1b05 | 247 | virtual void |
75f65a3e ILT |
248 | do_write(Output_file*) = 0; |
249 | ||
250 | // Return the required alignment. | |
251 | virtual uint64_t | |
252 | do_addralign() const = 0; | |
253 | ||
a445fddf ILT |
254 | // Return whether this has a load address. |
255 | virtual bool | |
256 | do_has_load_address() const | |
257 | { return false; } | |
258 | ||
259 | // Return the load address. | |
260 | virtual uint64_t | |
261 | do_load_address() const | |
262 | { gold_unreachable(); } | |
263 | ||
75f65a3e ILT |
264 | // Return whether this is an Output_section. |
265 | virtual bool | |
266 | do_is_section() const | |
267 | { return false; } | |
a2fb1b05 | 268 | |
54dc6425 | 269 | // Return whether this is an Output_section of the specified type. |
75f65a3e | 270 | // This only needs to be implement by Output_section. |
54dc6425 | 271 | virtual bool |
75f65a3e | 272 | do_is_section_type(elfcpp::Elf_Word) const |
54dc6425 ILT |
273 | { return false; } |
274 | ||
75f65a3e ILT |
275 | // Return whether this is an Output_section with the specific flag |
276 | // set. This only needs to be implemented by Output_section. | |
54dc6425 | 277 | virtual bool |
75f65a3e | 278 | do_is_section_flag_set(elfcpp::Elf_Xword) const |
54dc6425 ILT |
279 | { return false; } |
280 | ||
77e65537 ILT |
281 | // Return the output section, if there is one. |
282 | virtual Output_section* | |
283 | do_output_section() | |
284 | { return NULL; } | |
285 | ||
ead1e424 ILT |
286 | // Return the output section index, if there is an output section. |
287 | virtual unsigned int | |
288 | do_out_shndx() const | |
a3ad94ed | 289 | { gold_unreachable(); } |
ead1e424 ILT |
290 | |
291 | // Set the output section index, if this is an output section. | |
292 | virtual void | |
293 | do_set_out_shndx(unsigned int) | |
a3ad94ed | 294 | { gold_unreachable(); } |
ead1e424 | 295 | |
27bc2bce ILT |
296 | // This is a hook for derived classes to set the data size. This is |
297 | // called by finalize_data_size, normally called during | |
298 | // Layout::finalize, when the section address is set. | |
75f65a3e | 299 | virtual void |
27bc2bce ILT |
300 | set_final_data_size() |
301 | { gold_unreachable(); } | |
75f65a3e | 302 | |
a445fddf ILT |
303 | // A hook for resetting the address and file offset. |
304 | virtual void | |
305 | do_reset_address_and_file_offset() | |
306 | { } | |
307 | ||
7bf1f802 ILT |
308 | // Set the TLS offset. Called only for SHT_TLS sections. |
309 | virtual void | |
310 | do_set_tls_offset(uint64_t) | |
311 | { gold_unreachable(); } | |
312 | ||
313 | // Return the TLS offset, relative to the base of the TLS segment. | |
314 | // Valid only for SHT_TLS sections. | |
315 | virtual uint64_t | |
316 | do_tls_offset() const | |
317 | { gold_unreachable(); } | |
318 | ||
75f65a3e ILT |
319 | // Functions that child classes may call. |
320 | ||
a2fb1b05 ILT |
321 | // Set the size of the data. |
322 | void | |
75f65a3e | 323 | set_data_size(off_t data_size) |
a3ad94ed | 324 | { |
27bc2bce ILT |
325 | gold_assert(!this->is_data_size_valid_); |
326 | this->data_size_ = data_size; | |
327 | this->is_data_size_valid_ = true; | |
328 | } | |
329 | ||
330 | // Get the current data size--this is for the convenience of | |
331 | // sections which build up their size over time. | |
332 | off_t | |
333 | current_data_size_for_child() const | |
334 | { return this->data_size_; } | |
335 | ||
336 | // Set the current data size--this is for the convenience of | |
337 | // sections which build up their size over time. | |
338 | void | |
339 | set_current_data_size_for_child(off_t data_size) | |
340 | { | |
341 | gold_assert(!this->is_data_size_valid_); | |
a3ad94ed ILT |
342 | this->data_size_ = data_size; |
343 | } | |
75f65a3e | 344 | |
730cdc88 ILT |
345 | // Return default alignment for the target size. |
346 | static uint64_t | |
347 | default_alignment(); | |
348 | ||
349 | // Return default alignment for a specified size--32 or 64. | |
75f65a3e | 350 | static uint64_t |
730cdc88 | 351 | default_alignment_for_size(int size); |
a2fb1b05 ILT |
352 | |
353 | private: | |
354 | Output_data(const Output_data&); | |
355 | Output_data& operator=(const Output_data&); | |
356 | ||
a3ad94ed | 357 | // This is used for verification, to make sure that we don't try to |
27bc2bce ILT |
358 | // change any sizes of allocated sections after we set the section |
359 | // addresses. | |
360 | static bool allocated_sizes_are_fixed; | |
a3ad94ed | 361 | |
27bc2bce | 362 | // Memory address in output file. |
75f65a3e | 363 | uint64_t address_; |
27bc2bce | 364 | // Size of data in output file. |
75f65a3e | 365 | off_t data_size_; |
27bc2bce | 366 | // File offset of contents in output file. |
75f65a3e | 367 | off_t offset_; |
27bc2bce ILT |
368 | // Whether address_ is valid. |
369 | bool is_address_valid_; | |
370 | // Whether data_size_ is valid. | |
371 | bool is_data_size_valid_; | |
372 | // Whether offset_ is valid. | |
373 | bool is_offset_valid_; | |
4f4c5f80 ILT |
374 | // Count of dynamic relocations applied to this section. |
375 | unsigned int dynamic_reloc_count_; | |
a2fb1b05 ILT |
376 | }; |
377 | ||
54dc6425 ILT |
378 | // Output the section headers. |
379 | ||
380 | class Output_section_headers : public Output_data | |
381 | { | |
382 | public: | |
9025d29d | 383 | Output_section_headers(const Layout*, |
16649710 ILT |
384 | const Layout::Segment_list*, |
385 | const Layout::Section_list*, | |
6a74a719 | 386 | const Layout::Section_list*, |
61ba1cf9 | 387 | const Stringpool*); |
54dc6425 | 388 | |
27bc2bce | 389 | protected: |
54dc6425 ILT |
390 | // Write the data to the file. |
391 | void | |
75f65a3e ILT |
392 | do_write(Output_file*); |
393 | ||
394 | // Return the required alignment. | |
395 | uint64_t | |
396 | do_addralign() const | |
730cdc88 | 397 | { return Output_data::default_alignment(); } |
54dc6425 ILT |
398 | |
399 | private: | |
61ba1cf9 ILT |
400 | // Write the data to the file with the right size and endianness. |
401 | template<int size, bool big_endian> | |
402 | void | |
403 | do_sized_write(Output_file*); | |
404 | ||
16649710 ILT |
405 | const Layout* layout_; |
406 | const Layout::Segment_list* segment_list_; | |
6a74a719 | 407 | const Layout::Section_list* section_list_; |
16649710 | 408 | const Layout::Section_list* unattached_section_list_; |
61ba1cf9 | 409 | const Stringpool* secnamepool_; |
54dc6425 ILT |
410 | }; |
411 | ||
412 | // Output the segment headers. | |
413 | ||
414 | class Output_segment_headers : public Output_data | |
415 | { | |
416 | public: | |
9025d29d | 417 | Output_segment_headers(const Layout::Segment_list& segment_list); |
54dc6425 | 418 | |
27bc2bce | 419 | protected: |
54dc6425 ILT |
420 | // Write the data to the file. |
421 | void | |
75f65a3e ILT |
422 | do_write(Output_file*); |
423 | ||
424 | // Return the required alignment. | |
425 | uint64_t | |
426 | do_addralign() const | |
730cdc88 | 427 | { return Output_data::default_alignment(); } |
54dc6425 ILT |
428 | |
429 | private: | |
61ba1cf9 ILT |
430 | // Write the data to the file with the right size and endianness. |
431 | template<int size, bool big_endian> | |
432 | void | |
433 | do_sized_write(Output_file*); | |
434 | ||
54dc6425 ILT |
435 | const Layout::Segment_list& segment_list_; |
436 | }; | |
437 | ||
438 | // Output the ELF file header. | |
439 | ||
440 | class Output_file_header : public Output_data | |
441 | { | |
442 | public: | |
9025d29d | 443 | Output_file_header(const Target*, |
54dc6425 | 444 | const Symbol_table*, |
d391083d ILT |
445 | const Output_segment_headers*, |
446 | const char* entry); | |
75f65a3e ILT |
447 | |
448 | // Add information about the section headers. We lay out the ELF | |
449 | // file header before we create the section headers. | |
450 | void set_section_info(const Output_section_headers*, | |
451 | const Output_section* shstrtab); | |
54dc6425 | 452 | |
27bc2bce | 453 | protected: |
54dc6425 ILT |
454 | // Write the data to the file. |
455 | void | |
75f65a3e ILT |
456 | do_write(Output_file*); |
457 | ||
458 | // Return the required alignment. | |
459 | uint64_t | |
460 | do_addralign() const | |
730cdc88 | 461 | { return Output_data::default_alignment(); } |
75f65a3e | 462 | |
54dc6425 | 463 | private: |
61ba1cf9 ILT |
464 | // Write the data to the file with the right size and endianness. |
465 | template<int size, bool big_endian> | |
466 | void | |
467 | do_sized_write(Output_file*); | |
468 | ||
d391083d ILT |
469 | // Return the value to use for the entry address. |
470 | template<int size> | |
471 | typename elfcpp::Elf_types<size>::Elf_Addr | |
472 | entry(); | |
473 | ||
54dc6425 ILT |
474 | const Target* target_; |
475 | const Symbol_table* symtab_; | |
61ba1cf9 | 476 | const Output_segment_headers* segment_header_; |
54dc6425 ILT |
477 | const Output_section_headers* section_header_; |
478 | const Output_section* shstrtab_; | |
d391083d | 479 | const char* entry_; |
54dc6425 ILT |
480 | }; |
481 | ||
ead1e424 ILT |
482 | // Output sections are mainly comprised of input sections. However, |
483 | // there are cases where we have data to write out which is not in an | |
484 | // input section. Output_section_data is used in such cases. This is | |
485 | // an abstract base class. | |
486 | ||
487 | class Output_section_data : public Output_data | |
488 | { | |
489 | public: | |
490 | Output_section_data(off_t data_size, uint64_t addralign) | |
27bc2bce ILT |
491 | : Output_data(), output_section_(NULL), addralign_(addralign) |
492 | { this->set_data_size(data_size); } | |
ead1e424 ILT |
493 | |
494 | Output_section_data(uint64_t addralign) | |
27bc2bce | 495 | : Output_data(), output_section_(NULL), addralign_(addralign) |
ead1e424 ILT |
496 | { } |
497 | ||
16649710 ILT |
498 | // Return the output section. |
499 | const Output_section* | |
500 | output_section() const | |
501 | { return this->output_section_; } | |
502 | ||
ead1e424 ILT |
503 | // Record the output section. |
504 | void | |
16649710 | 505 | set_output_section(Output_section* os); |
ead1e424 | 506 | |
b8e6aad9 ILT |
507 | // Add an input section, for SHF_MERGE sections. This returns true |
508 | // if the section was handled. | |
509 | bool | |
510 | add_input_section(Relobj* object, unsigned int shndx) | |
511 | { return this->do_add_input_section(object, shndx); } | |
512 | ||
513 | // Given an input OBJECT, an input section index SHNDX within that | |
514 | // object, and an OFFSET relative to the start of that input | |
730cdc88 ILT |
515 | // section, return whether or not the corresponding offset within |
516 | // the output section is known. If this function returns true, it | |
517 | // sets *POUTPUT to the output offset. The value -1 indicates that | |
518 | // this input offset is being discarded. | |
8f00aeb8 | 519 | bool |
8383303e ILT |
520 | output_offset(const Relobj* object, unsigned int shndx, |
521 | section_offset_type offset, | |
522 | section_offset_type *poutput) const | |
730cdc88 | 523 | { return this->do_output_offset(object, shndx, offset, poutput); } |
b8e6aad9 | 524 | |
a9a60db6 ILT |
525 | // Return whether this is the merge section for the input section |
526 | // SHNDX in OBJECT. This should return true when output_offset | |
527 | // would return true for some values of OFFSET. | |
528 | bool | |
529 | is_merge_section_for(const Relobj* object, unsigned int shndx) const | |
530 | { return this->do_is_merge_section_for(object, shndx); } | |
531 | ||
96803768 ILT |
532 | // Write the contents to a buffer. This is used for sections which |
533 | // require postprocessing, such as compression. | |
534 | void | |
535 | write_to_buffer(unsigned char* buffer) | |
536 | { this->do_write_to_buffer(buffer); } | |
537 | ||
38c5e8b4 ILT |
538 | // Print merge stats to stderr. This should only be called for |
539 | // SHF_MERGE sections. | |
540 | void | |
541 | print_merge_stats(const char* section_name) | |
542 | { this->do_print_merge_stats(section_name); } | |
543 | ||
ead1e424 ILT |
544 | protected: |
545 | // The child class must implement do_write. | |
546 | ||
16649710 ILT |
547 | // The child class may implement specific adjustments to the output |
548 | // section. | |
549 | virtual void | |
550 | do_adjust_output_section(Output_section*) | |
551 | { } | |
552 | ||
b8e6aad9 ILT |
553 | // May be implemented by child class. Return true if the section |
554 | // was handled. | |
555 | virtual bool | |
556 | do_add_input_section(Relobj*, unsigned int) | |
557 | { gold_unreachable(); } | |
558 | ||
730cdc88 | 559 | // The child class may implement output_offset. |
b8e6aad9 | 560 | virtual bool |
8383303e ILT |
561 | do_output_offset(const Relobj*, unsigned int, section_offset_type, |
562 | section_offset_type*) const | |
b8e6aad9 ILT |
563 | { return false; } |
564 | ||
a9a60db6 ILT |
565 | // The child class may implement is_merge_section_for. |
566 | virtual bool | |
567 | do_is_merge_section_for(const Relobj*, unsigned int) const | |
568 | { return false; } | |
569 | ||
96803768 ILT |
570 | // The child class may implement write_to_buffer. Most child |
571 | // classes can not appear in a compressed section, and they do not | |
572 | // implement this. | |
573 | virtual void | |
574 | do_write_to_buffer(unsigned char*) | |
575 | { gold_unreachable(); } | |
576 | ||
38c5e8b4 ILT |
577 | // Print merge statistics. |
578 | virtual void | |
579 | do_print_merge_stats(const char*) | |
580 | { gold_unreachable(); } | |
581 | ||
ead1e424 ILT |
582 | // Return the required alignment. |
583 | uint64_t | |
584 | do_addralign() const | |
585 | { return this->addralign_; } | |
586 | ||
77e65537 ILT |
587 | // Return the output section. |
588 | Output_section* | |
589 | do_output_section() | |
590 | { return this->output_section_; } | |
591 | ||
ead1e424 ILT |
592 | // Return the section index of the output section. |
593 | unsigned int | |
594 | do_out_shndx() const; | |
595 | ||
5a6f7e2d ILT |
596 | // Set the alignment. |
597 | void | |
598 | set_addralign(uint64_t addralign) | |
599 | { this->addralign_ = addralign; } | |
600 | ||
ead1e424 ILT |
601 | private: |
602 | // The output section for this section. | |
77e65537 | 603 | Output_section* output_section_; |
ead1e424 ILT |
604 | // The required alignment. |
605 | uint64_t addralign_; | |
606 | }; | |
607 | ||
27bc2bce ILT |
608 | // Some Output_section_data classes build up their data step by step, |
609 | // rather than all at once. This class provides an interface for | |
610 | // them. | |
611 | ||
612 | class Output_section_data_build : public Output_section_data | |
613 | { | |
614 | public: | |
615 | Output_section_data_build(uint64_t addralign) | |
616 | : Output_section_data(addralign) | |
617 | { } | |
618 | ||
619 | // Get the current data size. | |
620 | off_t | |
621 | current_data_size() const | |
622 | { return this->current_data_size_for_child(); } | |
623 | ||
624 | // Set the current data size. | |
625 | void | |
626 | set_current_data_size(off_t data_size) | |
627 | { this->set_current_data_size_for_child(data_size); } | |
628 | ||
629 | protected: | |
630 | // Set the final data size. | |
631 | virtual void | |
632 | set_final_data_size() | |
633 | { this->set_data_size(this->current_data_size_for_child()); } | |
634 | }; | |
635 | ||
dbe717ef ILT |
636 | // A simple case of Output_data in which we have constant data to |
637 | // output. | |
ead1e424 | 638 | |
dbe717ef | 639 | class Output_data_const : public Output_section_data |
ead1e424 ILT |
640 | { |
641 | public: | |
dbe717ef ILT |
642 | Output_data_const(const std::string& data, uint64_t addralign) |
643 | : Output_section_data(data.size(), addralign), data_(data) | |
644 | { } | |
645 | ||
646 | Output_data_const(const char* p, off_t len, uint64_t addralign) | |
647 | : Output_section_data(len, addralign), data_(p, len) | |
648 | { } | |
649 | ||
650 | Output_data_const(const unsigned char* p, off_t len, uint64_t addralign) | |
651 | : Output_section_data(len, addralign), | |
652 | data_(reinterpret_cast<const char*>(p), len) | |
653 | { } | |
654 | ||
27bc2bce | 655 | protected: |
a3ad94ed | 656 | // Write the data to the output file. |
dbe717ef | 657 | void |
a3ad94ed | 658 | do_write(Output_file*); |
dbe717ef | 659 | |
96803768 ILT |
660 | // Write the data to a buffer. |
661 | void | |
662 | do_write_to_buffer(unsigned char* buffer) | |
663 | { memcpy(buffer, this->data_.data(), this->data_.size()); } | |
664 | ||
dbe717ef ILT |
665 | private: |
666 | std::string data_; | |
667 | }; | |
668 | ||
a3ad94ed ILT |
669 | // Another version of Output_data with constant data, in which the |
670 | // buffer is allocated by the caller. | |
dbe717ef | 671 | |
a3ad94ed | 672 | class Output_data_const_buffer : public Output_section_data |
dbe717ef ILT |
673 | { |
674 | public: | |
a3ad94ed ILT |
675 | Output_data_const_buffer(const unsigned char* p, off_t len, |
676 | uint64_t addralign) | |
677 | : Output_section_data(len, addralign), p_(p) | |
678 | { } | |
679 | ||
27bc2bce | 680 | protected: |
a3ad94ed ILT |
681 | // Write the data the output file. |
682 | void | |
683 | do_write(Output_file*); | |
684 | ||
96803768 ILT |
685 | // Write the data to a buffer. |
686 | void | |
687 | do_write_to_buffer(unsigned char* buffer) | |
688 | { memcpy(buffer, this->p_, this->data_size()); } | |
689 | ||
a3ad94ed ILT |
690 | private: |
691 | const unsigned char* p_; | |
692 | }; | |
693 | ||
27bc2bce ILT |
694 | // A place holder for a fixed amount of data written out via some |
695 | // other mechanism. | |
a3ad94ed | 696 | |
27bc2bce | 697 | class Output_data_fixed_space : public Output_section_data |
a3ad94ed ILT |
698 | { |
699 | public: | |
27bc2bce | 700 | Output_data_fixed_space(off_t data_size, uint64_t addralign) |
a3ad94ed ILT |
701 | : Output_section_data(data_size, addralign) |
702 | { } | |
703 | ||
27bc2bce ILT |
704 | protected: |
705 | // Write out the data--the actual data must be written out | |
706 | // elsewhere. | |
707 | void | |
708 | do_write(Output_file*) | |
ead1e424 | 709 | { } |
27bc2bce | 710 | }; |
ead1e424 | 711 | |
27bc2bce ILT |
712 | // A place holder for variable sized data written out via some other |
713 | // mechanism. | |
714 | ||
715 | class Output_data_space : public Output_section_data_build | |
716 | { | |
717 | public: | |
718 | explicit Output_data_space(uint64_t addralign) | |
719 | : Output_section_data_build(addralign) | |
720 | { } | |
ead1e424 | 721 | |
5a6f7e2d ILT |
722 | // Set the alignment. |
723 | void | |
724 | set_space_alignment(uint64_t align) | |
725 | { this->set_addralign(align); } | |
726 | ||
27bc2bce ILT |
727 | protected: |
728 | // Write out the data--the actual data must be written out | |
729 | // elsewhere. | |
ead1e424 ILT |
730 | void |
731 | do_write(Output_file*) | |
732 | { } | |
733 | }; | |
734 | ||
a3ad94ed ILT |
735 | // A string table which goes into an output section. |
736 | ||
737 | class Output_data_strtab : public Output_section_data | |
738 | { | |
739 | public: | |
740 | Output_data_strtab(Stringpool* strtab) | |
741 | : Output_section_data(1), strtab_(strtab) | |
742 | { } | |
743 | ||
27bc2bce | 744 | protected: |
a3ad94ed ILT |
745 | // This is called to set the address and file offset. Here we make |
746 | // sure that the Stringpool is finalized. | |
747 | void | |
27bc2bce | 748 | set_final_data_size(); |
a3ad94ed ILT |
749 | |
750 | // Write out the data. | |
751 | void | |
752 | do_write(Output_file*); | |
753 | ||
96803768 ILT |
754 | // Write the data to a buffer. |
755 | void | |
756 | do_write_to_buffer(unsigned char* buffer) | |
757 | { this->strtab_->write_to_buffer(buffer, this->data_size()); } | |
758 | ||
a3ad94ed ILT |
759 | private: |
760 | Stringpool* strtab_; | |
761 | }; | |
762 | ||
c06b7b0b ILT |
763 | // This POD class is used to represent a single reloc in the output |
764 | // file. This could be a private class within Output_data_reloc, but | |
765 | // the templatization is complex enough that I broke it out into a | |
766 | // separate class. The class is templatized on either elfcpp::SHT_REL | |
767 | // or elfcpp::SHT_RELA, and also on whether this is a dynamic | |
768 | // relocation or an ordinary relocation. | |
769 | ||
770 | // A relocation can be against a global symbol, a local symbol, an | |
771 | // output section, or the undefined symbol at index 0. We represent | |
772 | // the latter by using a NULL global symbol. | |
773 | ||
774 | template<int sh_type, bool dynamic, int size, bool big_endian> | |
775 | class Output_reloc; | |
776 | ||
777 | template<bool dynamic, int size, bool big_endian> | |
778 | class Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian> | |
779 | { | |
780 | public: | |
781 | typedef typename elfcpp::Elf_types<size>::Elf_Addr Address; | |
782 | ||
783 | // An uninitialized entry. We need this because we want to put | |
784 | // instances of this class into an STL container. | |
785 | Output_reloc() | |
786 | : local_sym_index_(INVALID_CODE) | |
787 | { } | |
788 | ||
789 | // A reloc against a global symbol. | |
5a6f7e2d | 790 | |
a3ad94ed | 791 | Output_reloc(Symbol* gsym, unsigned int type, Output_data* od, |
e8c846c3 | 792 | Address address, bool is_relative); |
5a6f7e2d ILT |
793 | |
794 | Output_reloc(Symbol* gsym, unsigned int type, Relobj* relobj, | |
e8c846c3 | 795 | unsigned int shndx, Address address, bool is_relative); |
c06b7b0b ILT |
796 | |
797 | // A reloc against a local symbol. | |
5a6f7e2d ILT |
798 | |
799 | Output_reloc(Sized_relobj<size, big_endian>* relobj, | |
7bf1f802 | 800 | unsigned int local_sym_index, unsigned int type, |
e8c846c3 | 801 | Output_data* od, Address address, bool is_relative); |
5a6f7e2d ILT |
802 | |
803 | Output_reloc(Sized_relobj<size, big_endian>* relobj, | |
7bf1f802 | 804 | unsigned int local_sym_index, unsigned int type, |
e8c846c3 | 805 | unsigned int shndx, Address address, bool is_relative); |
c06b7b0b ILT |
806 | |
807 | // A reloc against the STT_SECTION symbol of an output section. | |
5a6f7e2d | 808 | |
a3ad94ed | 809 | Output_reloc(Output_section* os, unsigned int type, Output_data* od, |
7bf1f802 | 810 | Address address); |
5a6f7e2d ILT |
811 | |
812 | Output_reloc(Output_section* os, unsigned int type, Relobj* relobj, | |
7bf1f802 | 813 | unsigned int shndx, Address address); |
c06b7b0b | 814 | |
e8c846c3 ILT |
815 | // Return TRUE if this is a RELATIVE relocation. |
816 | bool | |
817 | is_relative() const | |
818 | { return this->is_relative_; } | |
819 | ||
820 | // Get the value of the symbol referred to by a Rel relocation. | |
821 | ||
822 | Address | |
823 | symbol_value() const; | |
824 | ||
c06b7b0b ILT |
825 | // Write the reloc entry to an output view. |
826 | void | |
827 | write(unsigned char* pov) const; | |
828 | ||
829 | // Write the offset and info fields to Write_rel. | |
830 | template<typename Write_rel> | |
831 | void write_rel(Write_rel*) const; | |
832 | ||
833 | private: | |
834 | // Return the symbol index. We can't do a double template | |
835 | // specialization, so we do a secondary template here. | |
836 | unsigned int | |
837 | get_symbol_index() const; | |
838 | ||
839 | // Codes for local_sym_index_. | |
840 | enum | |
841 | { | |
842 | // Global symbol. | |
843 | GSYM_CODE = -1U, | |
844 | // Output section. | |
845 | SECTION_CODE = -2U, | |
846 | // Invalid uninitialized entry. | |
847 | INVALID_CODE = -3U | |
848 | }; | |
849 | ||
850 | union | |
851 | { | |
852 | // For a local symbol, the object. We will never generate a | |
853 | // relocation against a local symbol in a dynamic object; that | |
854 | // doesn't make sense. And our callers will always be | |
855 | // templatized, so we use Sized_relobj here. | |
5a6f7e2d | 856 | Sized_relobj<size, big_endian>* relobj; |
c06b7b0b ILT |
857 | // For a global symbol, the symbol. If this is NULL, it indicates |
858 | // a relocation against the undefined 0 symbol. | |
859 | Symbol* gsym; | |
860 | // For a relocation against an output section, the output section. | |
861 | Output_section* os; | |
5a6f7e2d ILT |
862 | } u1_; |
863 | union | |
864 | { | |
865 | // If shndx_ is not INVALID CODE, the object which holds the input | |
866 | // section being used to specify the reloc address. | |
867 | Relobj* relobj; | |
868 | // If shndx_ is INVALID_CODE, the output data being used to | |
869 | // specify the reloc address. This may be NULL if the reloc | |
870 | // address is absolute. | |
871 | Output_data* od; | |
872 | } u2_; | |
873 | // The address offset within the input section or the Output_data. | |
874 | Address address_; | |
c06b7b0b ILT |
875 | // For a local symbol, the local symbol index. This is GSYM_CODE |
876 | // for a global symbol, or INVALID_CODE for an uninitialized value. | |
877 | unsigned int local_sym_index_; | |
a3ad94ed | 878 | // The reloc type--a processor specific code. |
e8c846c3 ILT |
879 | unsigned int type_ : 31; |
880 | // True if the relocation is a RELATIVE relocation. | |
881 | bool is_relative_ : 1; | |
5a6f7e2d ILT |
882 | // If the reloc address is an input section in an object, the |
883 | // section index. This is INVALID_CODE if the reloc address is | |
884 | // specified in some other way. | |
885 | unsigned int shndx_; | |
c06b7b0b ILT |
886 | }; |
887 | ||
888 | // The SHT_RELA version of Output_reloc<>. This is just derived from | |
889 | // the SHT_REL version of Output_reloc, but it adds an addend. | |
890 | ||
891 | template<bool dynamic, int size, bool big_endian> | |
892 | class Output_reloc<elfcpp::SHT_RELA, dynamic, size, big_endian> | |
893 | { | |
894 | public: | |
895 | typedef typename elfcpp::Elf_types<size>::Elf_Addr Address; | |
896 | typedef typename elfcpp::Elf_types<size>::Elf_Addr Addend; | |
897 | ||
898 | // An uninitialized entry. | |
899 | Output_reloc() | |
900 | : rel_() | |
901 | { } | |
902 | ||
903 | // A reloc against a global symbol. | |
5a6f7e2d | 904 | |
a3ad94ed | 905 | Output_reloc(Symbol* gsym, unsigned int type, Output_data* od, |
e8c846c3 ILT |
906 | Address address, Addend addend, bool is_relative) |
907 | : rel_(gsym, type, od, address, is_relative), addend_(addend) | |
c06b7b0b ILT |
908 | { } |
909 | ||
5a6f7e2d | 910 | Output_reloc(Symbol* gsym, unsigned int type, Relobj* relobj, |
e8c846c3 ILT |
911 | unsigned int shndx, Address address, Addend addend, |
912 | bool is_relative) | |
913 | : rel_(gsym, type, relobj, shndx, address, is_relative), addend_(addend) | |
5a6f7e2d ILT |
914 | { } |
915 | ||
c06b7b0b | 916 | // A reloc against a local symbol. |
5a6f7e2d ILT |
917 | |
918 | Output_reloc(Sized_relobj<size, big_endian>* relobj, | |
e8c846c3 ILT |
919 | unsigned int local_sym_index, unsigned int type, |
920 | Output_data* od, Address address, | |
921 | Addend addend, bool is_relative) | |
922 | : rel_(relobj, local_sym_index, type, od, address, is_relative), | |
923 | addend_(addend) | |
5a6f7e2d ILT |
924 | { } |
925 | ||
926 | Output_reloc(Sized_relobj<size, big_endian>* relobj, | |
e8c846c3 ILT |
927 | unsigned int local_sym_index, unsigned int type, |
928 | unsigned int shndx, Address address, | |
929 | Addend addend, bool is_relative) | |
930 | : rel_(relobj, local_sym_index, type, shndx, address, is_relative), | |
5a6f7e2d | 931 | addend_(addend) |
c06b7b0b ILT |
932 | { } |
933 | ||
934 | // A reloc against the STT_SECTION symbol of an output section. | |
5a6f7e2d | 935 | |
a3ad94ed ILT |
936 | Output_reloc(Output_section* os, unsigned int type, Output_data* od, |
937 | Address address, Addend addend) | |
938 | : rel_(os, type, od, address), addend_(addend) | |
c06b7b0b ILT |
939 | { } |
940 | ||
5a6f7e2d ILT |
941 | Output_reloc(Output_section* os, unsigned int type, Relobj* relobj, |
942 | unsigned int shndx, Address address, Addend addend) | |
943 | : rel_(os, type, relobj, shndx, address), addend_(addend) | |
944 | { } | |
945 | ||
c06b7b0b ILT |
946 | // Write the reloc entry to an output view. |
947 | void | |
948 | write(unsigned char* pov) const; | |
949 | ||
950 | private: | |
951 | // The basic reloc. | |
952 | Output_reloc<elfcpp::SHT_REL, dynamic, size, big_endian> rel_; | |
953 | // The addend. | |
954 | Addend addend_; | |
955 | }; | |
956 | ||
957 | // Output_data_reloc is used to manage a section containing relocs. | |
958 | // SH_TYPE is either elfcpp::SHT_REL or elfcpp::SHT_RELA. DYNAMIC | |
959 | // indicates whether this is a dynamic relocation or a normal | |
960 | // relocation. Output_data_reloc_base is a base class. | |
961 | // Output_data_reloc is the real class, which we specialize based on | |
962 | // the reloc type. | |
963 | ||
964 | template<int sh_type, bool dynamic, int size, bool big_endian> | |
27bc2bce | 965 | class Output_data_reloc_base : public Output_section_data_build |
c06b7b0b ILT |
966 | { |
967 | public: | |
968 | typedef Output_reloc<sh_type, dynamic, size, big_endian> Output_reloc_type; | |
969 | typedef typename Output_reloc_type::Address Address; | |
970 | static const int reloc_size = | |
971 | Reloc_types<sh_type, size, big_endian>::reloc_size; | |
972 | ||
973 | // Construct the section. | |
974 | Output_data_reloc_base() | |
27bc2bce | 975 | : Output_section_data_build(Output_data::default_alignment_for_size(size)) |
c06b7b0b ILT |
976 | { } |
977 | ||
27bc2bce | 978 | protected: |
c06b7b0b ILT |
979 | // Write out the data. |
980 | void | |
981 | do_write(Output_file*); | |
982 | ||
16649710 ILT |
983 | // Set the entry size and the link. |
984 | void | |
985 | do_adjust_output_section(Output_section *os); | |
986 | ||
c06b7b0b ILT |
987 | // Add a relocation entry. |
988 | void | |
4f4c5f80 | 989 | add(Output_data *od, const Output_reloc_type& reloc) |
c06b7b0b ILT |
990 | { |
991 | this->relocs_.push_back(reloc); | |
27bc2bce | 992 | this->set_current_data_size(this->relocs_.size() * reloc_size); |
4f4c5f80 | 993 | od->add_dynamic_reloc(); |
c06b7b0b ILT |
994 | } |
995 | ||
996 | private: | |
997 | typedef std::vector<Output_reloc_type> Relocs; | |
998 | ||
999 | Relocs relocs_; | |
1000 | }; | |
1001 | ||
1002 | // The class which callers actually create. | |
1003 | ||
1004 | template<int sh_type, bool dynamic, int size, bool big_endian> | |
1005 | class Output_data_reloc; | |
1006 | ||
1007 | // The SHT_REL version of Output_data_reloc. | |
1008 | ||
1009 | template<bool dynamic, int size, bool big_endian> | |
1010 | class Output_data_reloc<elfcpp::SHT_REL, dynamic, size, big_endian> | |
1011 | : public Output_data_reloc_base<elfcpp::SHT_REL, dynamic, size, big_endian> | |
1012 | { | |
1013 | private: | |
1014 | typedef Output_data_reloc_base<elfcpp::SHT_REL, dynamic, size, | |
1015 | big_endian> Base; | |
1016 | ||
1017 | public: | |
1018 | typedef typename Base::Output_reloc_type Output_reloc_type; | |
1019 | typedef typename Output_reloc_type::Address Address; | |
1020 | ||
1021 | Output_data_reloc() | |
1022 | : Output_data_reloc_base<elfcpp::SHT_REL, dynamic, size, big_endian>() | |
1023 | { } | |
1024 | ||
1025 | // Add a reloc against a global symbol. | |
5a6f7e2d | 1026 | |
c06b7b0b | 1027 | void |
a3ad94ed | 1028 | add_global(Symbol* gsym, unsigned int type, Output_data* od, Address address) |
e8c846c3 | 1029 | { this->add(od, Output_reloc_type(gsym, type, od, address, false)); } |
c06b7b0b | 1030 | |
5a6f7e2d | 1031 | void |
4f4c5f80 | 1032 | add_global(Symbol* gsym, unsigned int type, Output_data* od, Relobj* relobj, |
5a6f7e2d | 1033 | unsigned int shndx, Address address) |
e8c846c3 ILT |
1034 | { this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address, |
1035 | false)); } | |
1036 | ||
1037 | // Add a RELATIVE reloc against a global symbol. The final relocation | |
1038 | // will not reference the symbol. | |
1039 | ||
1040 | void | |
1041 | add_global_relative(Symbol* gsym, unsigned int type, Output_data* od, | |
1042 | Address address) | |
1043 | { this->add(od, Output_reloc_type(gsym, type, od, address, true)); } | |
1044 | ||
1045 | void | |
1046 | add_global_relative(Symbol* gsym, unsigned int type, Output_data* od, | |
1047 | Relobj* relobj, unsigned int shndx, Address address) | |
1048 | { this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address, | |
1049 | true)); } | |
5a6f7e2d | 1050 | |
c06b7b0b | 1051 | // Add a reloc against a local symbol. |
5a6f7e2d | 1052 | |
c06b7b0b | 1053 | void |
5a6f7e2d | 1054 | add_local(Sized_relobj<size, big_endian>* relobj, |
a3ad94ed ILT |
1055 | unsigned int local_sym_index, unsigned int type, |
1056 | Output_data* od, Address address) | |
4f4c5f80 | 1057 | { this->add(od, Output_reloc_type(relobj, local_sym_index, type, od, |
e8c846c3 | 1058 | address, false)); } |
5a6f7e2d ILT |
1059 | |
1060 | void | |
1061 | add_local(Sized_relobj<size, big_endian>* relobj, | |
1062 | unsigned int local_sym_index, unsigned int type, | |
4f4c5f80 ILT |
1063 | Output_data* od, unsigned int shndx, Address address) |
1064 | { this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx, | |
e8c846c3 ILT |
1065 | address, false)); } |
1066 | ||
1067 | // Add a RELATIVE reloc against a local symbol. | |
5a6f7e2d | 1068 | |
e8c846c3 ILT |
1069 | void |
1070 | add_local_relative(Sized_relobj<size, big_endian>* relobj, | |
1071 | unsigned int local_sym_index, unsigned int type, | |
1072 | Output_data* od, Address address) | |
1073 | { this->add(od, Output_reloc_type(relobj, local_sym_index, type, od, | |
1074 | address, true)); } | |
1075 | ||
1076 | void | |
1077 | add_local_relative(Sized_relobj<size, big_endian>* relobj, | |
1078 | unsigned int local_sym_index, unsigned int type, | |
1079 | Output_data* od, unsigned int shndx, Address address) | |
1080 | { this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx, | |
1081 | address, true)); } | |
c06b7b0b ILT |
1082 | |
1083 | // A reloc against the STT_SECTION symbol of an output section. | |
4f4c5f80 ILT |
1084 | // OS is the Output_section that the relocation refers to; OD is |
1085 | // the Output_data object being relocated. | |
5a6f7e2d | 1086 | |
c06b7b0b | 1087 | void |
a3ad94ed ILT |
1088 | add_output_section(Output_section* os, unsigned int type, |
1089 | Output_data* od, Address address) | |
4f4c5f80 | 1090 | { this->add(od, Output_reloc_type(os, type, od, address)); } |
5a6f7e2d ILT |
1091 | |
1092 | void | |
4f4c5f80 | 1093 | add_output_section(Output_section* os, unsigned int type, Output_data* od, |
5a6f7e2d | 1094 | Relobj* relobj, unsigned int shndx, Address address) |
4f4c5f80 | 1095 | { this->add(od, Output_reloc_type(os, type, relobj, shndx, address)); } |
c06b7b0b ILT |
1096 | }; |
1097 | ||
1098 | // The SHT_RELA version of Output_data_reloc. | |
1099 | ||
1100 | template<bool dynamic, int size, bool big_endian> | |
1101 | class Output_data_reloc<elfcpp::SHT_RELA, dynamic, size, big_endian> | |
1102 | : public Output_data_reloc_base<elfcpp::SHT_RELA, dynamic, size, big_endian> | |
1103 | { | |
1104 | private: | |
1105 | typedef Output_data_reloc_base<elfcpp::SHT_RELA, dynamic, size, | |
1106 | big_endian> Base; | |
1107 | ||
1108 | public: | |
1109 | typedef typename Base::Output_reloc_type Output_reloc_type; | |
1110 | typedef typename Output_reloc_type::Address Address; | |
1111 | typedef typename Output_reloc_type::Addend Addend; | |
1112 | ||
1113 | Output_data_reloc() | |
1114 | : Output_data_reloc_base<elfcpp::SHT_RELA, dynamic, size, big_endian>() | |
1115 | { } | |
1116 | ||
1117 | // Add a reloc against a global symbol. | |
5a6f7e2d | 1118 | |
c06b7b0b | 1119 | void |
a3ad94ed ILT |
1120 | add_global(Symbol* gsym, unsigned int type, Output_data* od, |
1121 | Address address, Addend addend) | |
e8c846c3 ILT |
1122 | { this->add(od, Output_reloc_type(gsym, type, od, address, addend, |
1123 | false)); } | |
c06b7b0b | 1124 | |
5a6f7e2d | 1125 | void |
4f4c5f80 ILT |
1126 | add_global(Symbol* gsym, unsigned int type, Output_data* od, Relobj* relobj, |
1127 | unsigned int shndx, Address address, | |
1128 | Addend addend) | |
1129 | { this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address, | |
e8c846c3 ILT |
1130 | addend, false)); } |
1131 | ||
1132 | // Add a RELATIVE reloc against a global symbol. The final output | |
1133 | // relocation will not reference the symbol, but we must keep the symbol | |
1134 | // information long enough to set the addend of the relocation correctly | |
1135 | // when it is written. | |
1136 | ||
1137 | void | |
1138 | add_global_relative(Symbol* gsym, unsigned int type, Output_data* od, | |
1139 | Address address, Addend addend) | |
1140 | { this->add(od, Output_reloc_type(gsym, type, od, address, addend, true)); } | |
1141 | ||
1142 | void | |
1143 | add_global_relative(Symbol* gsym, unsigned int type, Output_data* od, | |
1144 | Relobj* relobj, unsigned int shndx, Address address, | |
1145 | Addend addend) | |
1146 | { this->add(od, Output_reloc_type(gsym, type, relobj, shndx, address, | |
1147 | addend, true)); } | |
5a6f7e2d | 1148 | |
c06b7b0b | 1149 | // Add a reloc against a local symbol. |
5a6f7e2d | 1150 | |
c06b7b0b | 1151 | void |
5a6f7e2d | 1152 | add_local(Sized_relobj<size, big_endian>* relobj, |
c06b7b0b | 1153 | unsigned int local_sym_index, unsigned int type, |
a3ad94ed | 1154 | Output_data* od, Address address, Addend addend) |
c06b7b0b | 1155 | { |
4f4c5f80 | 1156 | this->add(od, Output_reloc_type(relobj, local_sym_index, type, od, address, |
e8c846c3 | 1157 | addend, false)); |
5a6f7e2d ILT |
1158 | } |
1159 | ||
1160 | void | |
1161 | add_local(Sized_relobj<size, big_endian>* relobj, | |
1162 | unsigned int local_sym_index, unsigned int type, | |
4f4c5f80 ILT |
1163 | Output_data* od, unsigned int shndx, Address address, |
1164 | Addend addend) | |
5a6f7e2d | 1165 | { |
4f4c5f80 | 1166 | this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx, |
e8c846c3 ILT |
1167 | address, addend, false)); |
1168 | } | |
1169 | ||
1170 | // Add a RELATIVE reloc against a local symbol. | |
1171 | ||
1172 | void | |
1173 | add_local_relative(Sized_relobj<size, big_endian>* relobj, | |
1174 | unsigned int local_sym_index, unsigned int type, | |
1175 | Output_data* od, Address address, Addend addend) | |
1176 | { | |
1177 | this->add(od, Output_reloc_type(relobj, local_sym_index, type, od, address, | |
1178 | addend, true)); | |
1179 | } | |
1180 | ||
1181 | void | |
1182 | add_local_relative(Sized_relobj<size, big_endian>* relobj, | |
1183 | unsigned int local_sym_index, unsigned int type, | |
1184 | Output_data* od, unsigned int shndx, Address address, | |
1185 | Addend addend) | |
1186 | { | |
1187 | this->add(od, Output_reloc_type(relobj, local_sym_index, type, shndx, | |
1188 | address, addend, true)); | |
c06b7b0b ILT |
1189 | } |
1190 | ||
1191 | // A reloc against the STT_SECTION symbol of an output section. | |
5a6f7e2d | 1192 | |
c06b7b0b | 1193 | void |
a3ad94ed ILT |
1194 | add_output_section(Output_section* os, unsigned int type, Output_data* od, |
1195 | Address address, Addend addend) | |
4f4c5f80 | 1196 | { this->add(os, Output_reloc_type(os, type, od, address, addend)); } |
5a6f7e2d ILT |
1197 | |
1198 | void | |
1199 | add_output_section(Output_section* os, unsigned int type, Relobj* relobj, | |
1200 | unsigned int shndx, Address address, Addend addend) | |
4f4c5f80 ILT |
1201 | { this->add(os, Output_reloc_type(os, type, relobj, shndx, address, |
1202 | addend)); } | |
c06b7b0b ILT |
1203 | }; |
1204 | ||
6a74a719 ILT |
1205 | // Output_relocatable_relocs represents a relocation section in a |
1206 | // relocatable link. The actual data is written out in the target | |
1207 | // hook relocate_for_relocatable. This just saves space for it. | |
1208 | ||
1209 | template<int sh_type, int size, bool big_endian> | |
1210 | class Output_relocatable_relocs : public Output_section_data | |
1211 | { | |
1212 | public: | |
1213 | Output_relocatable_relocs(Relocatable_relocs* rr) | |
1214 | : Output_section_data(Output_data::default_alignment_for_size(size)), | |
1215 | rr_(rr) | |
1216 | { } | |
1217 | ||
1218 | void | |
1219 | set_final_data_size(); | |
1220 | ||
1221 | // Write out the data. There is nothing to do here. | |
1222 | void | |
1223 | do_write(Output_file*) | |
1224 | { } | |
1225 | ||
1226 | private: | |
1227 | // The relocs associated with this input section. | |
1228 | Relocatable_relocs* rr_; | |
1229 | }; | |
1230 | ||
1231 | // Handle a GROUP section. | |
1232 | ||
1233 | template<int size, bool big_endian> | |
1234 | class Output_data_group : public Output_section_data | |
1235 | { | |
1236 | public: | |
1237 | Output_data_group(Sized_relobj<size, big_endian>* relobj, | |
1238 | section_size_type entry_count, | |
1239 | const elfcpp::Elf_Word* contents); | |
1240 | ||
1241 | void | |
1242 | do_write(Output_file*); | |
1243 | ||
1244 | private: | |
1245 | // The input object. | |
1246 | Sized_relobj<size, big_endian>* relobj_; | |
1247 | // The group flag word. | |
1248 | elfcpp::Elf_Word flags_; | |
1249 | // The section indexes of the input sections in this group. | |
1250 | std::vector<unsigned int> input_sections_; | |
1251 | }; | |
1252 | ||
dbe717ef ILT |
1253 | // Output_data_got is used to manage a GOT. Each entry in the GOT is |
1254 | // for one symbol--either a global symbol or a local symbol in an | |
ead1e424 | 1255 | // object. The target specific code adds entries to the GOT as |
dbe717ef | 1256 | // needed. |
ead1e424 ILT |
1257 | |
1258 | template<int size, bool big_endian> | |
27bc2bce | 1259 | class Output_data_got : public Output_section_data_build |
ead1e424 ILT |
1260 | { |
1261 | public: | |
1262 | typedef typename elfcpp::Elf_types<size>::Elf_Addr Valtype; | |
7bf1f802 ILT |
1263 | typedef Output_data_reloc<elfcpp::SHT_REL, true, size, big_endian> Rel_dyn; |
1264 | typedef Output_data_reloc<elfcpp::SHT_RELA, true, size, big_endian> Rela_dyn; | |
ead1e424 | 1265 | |
7e1edb90 | 1266 | Output_data_got() |
27bc2bce | 1267 | : Output_section_data_build(Output_data::default_alignment_for_size(size)), |
730cdc88 | 1268 | entries_() |
ead1e424 ILT |
1269 | { } |
1270 | ||
dbe717ef ILT |
1271 | // Add an entry for a global symbol to the GOT. Return true if this |
1272 | // is a new GOT entry, false if the symbol was already in the GOT. | |
1273 | bool | |
1274 | add_global(Symbol* gsym); | |
ead1e424 | 1275 | |
7bf1f802 ILT |
1276 | // Add an entry for a global symbol to the GOT, and add a dynamic |
1277 | // relocation of type R_TYPE for the GOT entry. | |
1278 | void | |
1279 | add_global_with_rel(Symbol* gsym, Rel_dyn* rel_dyn, unsigned int r_type); | |
1280 | ||
1281 | void | |
1282 | add_global_with_rela(Symbol* gsym, Rela_dyn* rela_dyn, unsigned int r_type); | |
1283 | ||
e727fa71 ILT |
1284 | // Add an entry for a local symbol to the GOT. This returns true if |
1285 | // this is a new GOT entry, false if the symbol already has a GOT | |
1286 | // entry. | |
1287 | bool | |
1288 | add_local(Sized_relobj<size, big_endian>* object, unsigned int sym_index); | |
ead1e424 | 1289 | |
7bf1f802 ILT |
1290 | // Add an entry for a global symbol to the GOT, and add a dynamic |
1291 | // relocation of type R_TYPE for the GOT entry. | |
1292 | void | |
1293 | add_local_with_rel(Sized_relobj<size, big_endian>* object, | |
1294 | unsigned int sym_index, Rel_dyn* rel_dyn, | |
1295 | unsigned int r_type); | |
1296 | ||
1297 | void | |
1298 | add_local_with_rela(Sized_relobj<size, big_endian>* object, | |
1299 | unsigned int sym_index, Rela_dyn* rela_dyn, | |
1300 | unsigned int r_type); | |
1301 | ||
07f397ab ILT |
1302 | // Add an entry (or pair of entries) for a global TLS symbol to the GOT. |
1303 | // Return true if this is a new GOT entry, false if the symbol was | |
1304 | // already in the GOT. | |
1305 | bool | |
1306 | add_global_tls(Symbol* gsym, bool need_pair); | |
1307 | ||
7bf1f802 ILT |
1308 | // Add an entry for a global TLS symbol to the GOT, and add a dynamic |
1309 | // relocation of type R_TYPE. | |
1310 | void | |
1311 | add_global_tls_with_rel(Symbol* gsym, Rel_dyn* rel_dyn, | |
1312 | unsigned int r_type); | |
1313 | ||
1314 | void | |
1315 | add_global_tls_with_rela(Symbol* gsym, Rela_dyn* rela_dyn, | |
1316 | unsigned int r_type); | |
1317 | ||
1318 | // Add a pair of entries for a global TLS symbol to the GOT, and add | |
1319 | // dynamic relocations of type MOD_R_TYPE and DTV_R_TYPE, respectively. | |
1320 | void | |
1321 | add_global_tls_with_rel(Symbol* gsym, Rel_dyn* rel_dyn, | |
1322 | unsigned int mod_r_type, | |
1323 | unsigned int dtv_r_type); | |
1324 | ||
1325 | void | |
1326 | add_global_tls_with_rela(Symbol* gsym, Rela_dyn* rela_dyn, | |
1327 | unsigned int mod_r_type, | |
1328 | unsigned int dtv_r_type); | |
1329 | ||
07f397ab ILT |
1330 | // Add an entry (or pair of entries) for a local TLS symbol to the GOT. |
1331 | // This returns true if this is a new GOT entry, false if the symbol | |
1332 | // already has a GOT entry. | |
1333 | bool | |
1334 | add_local_tls(Sized_relobj<size, big_endian>* object, | |
1335 | unsigned int sym_index, bool need_pair); | |
1336 | ||
7bf1f802 ILT |
1337 | // Add an entry (or pair of entries) for a local TLS symbol to the GOT, |
1338 | // and add a dynamic relocation of type R_TYPE for the first GOT entry. | |
1339 | // Because this is a local symbol, the first GOT entry can be relocated | |
1340 | // relative to a section symbol, and the second GOT entry will have an | |
1341 | // dtv-relative value that can be computed at link time. | |
1342 | void | |
1343 | add_local_tls_with_rel(Sized_relobj<size, big_endian>* object, | |
1344 | unsigned int sym_index, unsigned int shndx, | |
1345 | bool need_pair, Rel_dyn* rel_dyn, | |
1346 | unsigned int r_type); | |
1347 | ||
1348 | void | |
1349 | add_local_tls_with_rela(Sized_relobj<size, big_endian>* object, | |
1350 | unsigned int sym_index, unsigned int shndx, | |
1351 | bool need_pair, Rela_dyn* rela_dyn, | |
1352 | unsigned int r_type); | |
1353 | ||
ead1e424 ILT |
1354 | // Add a constant to the GOT. This returns the offset of the new |
1355 | // entry from the start of the GOT. | |
1356 | unsigned int | |
1357 | add_constant(Valtype constant) | |
1358 | { | |
1359 | this->entries_.push_back(Got_entry(constant)); | |
1360 | this->set_got_size(); | |
1361 | return this->last_got_offset(); | |
1362 | } | |
1363 | ||
27bc2bce | 1364 | protected: |
ead1e424 ILT |
1365 | // Write out the GOT table. |
1366 | void | |
1367 | do_write(Output_file*); | |
1368 | ||
1369 | private: | |
1370 | // This POD class holds a single GOT entry. | |
1371 | class Got_entry | |
1372 | { | |
1373 | public: | |
1374 | // Create a zero entry. | |
1375 | Got_entry() | |
1376 | : local_sym_index_(CONSTANT_CODE) | |
1377 | { this->u_.constant = 0; } | |
1378 | ||
1379 | // Create a global symbol entry. | |
a3ad94ed | 1380 | explicit Got_entry(Symbol* gsym) |
ead1e424 ILT |
1381 | : local_sym_index_(GSYM_CODE) |
1382 | { this->u_.gsym = gsym; } | |
1383 | ||
1384 | // Create a local symbol entry. | |
e727fa71 ILT |
1385 | Got_entry(Sized_relobj<size, big_endian>* object, |
1386 | unsigned int local_sym_index) | |
ead1e424 ILT |
1387 | : local_sym_index_(local_sym_index) |
1388 | { | |
a3ad94ed ILT |
1389 | gold_assert(local_sym_index != GSYM_CODE |
1390 | && local_sym_index != CONSTANT_CODE); | |
ead1e424 ILT |
1391 | this->u_.object = object; |
1392 | } | |
1393 | ||
1394 | // Create a constant entry. The constant is a host value--it will | |
1395 | // be swapped, if necessary, when it is written out. | |
a3ad94ed | 1396 | explicit Got_entry(Valtype constant) |
ead1e424 ILT |
1397 | : local_sym_index_(CONSTANT_CODE) |
1398 | { this->u_.constant = constant; } | |
1399 | ||
1400 | // Write the GOT entry to an output view. | |
1401 | void | |
7e1edb90 | 1402 | write(unsigned char* pov) const; |
ead1e424 ILT |
1403 | |
1404 | private: | |
1405 | enum | |
1406 | { | |
1407 | GSYM_CODE = -1U, | |
1408 | CONSTANT_CODE = -2U | |
1409 | }; | |
1410 | ||
1411 | union | |
1412 | { | |
1413 | // For a local symbol, the object. | |
e727fa71 | 1414 | Sized_relobj<size, big_endian>* object; |
ead1e424 ILT |
1415 | // For a global symbol, the symbol. |
1416 | Symbol* gsym; | |
1417 | // For a constant, the constant. | |
1418 | Valtype constant; | |
1419 | } u_; | |
c06b7b0b ILT |
1420 | // For a local symbol, the local symbol index. This is GSYM_CODE |
1421 | // for a global symbol, or CONSTANT_CODE for a constant. | |
ead1e424 ILT |
1422 | unsigned int local_sym_index_; |
1423 | }; | |
1424 | ||
1425 | typedef std::vector<Got_entry> Got_entries; | |
1426 | ||
1427 | // Return the offset into the GOT of GOT entry I. | |
1428 | unsigned int | |
1429 | got_offset(unsigned int i) const | |
1430 | { return i * (size / 8); } | |
1431 | ||
1432 | // Return the offset into the GOT of the last entry added. | |
1433 | unsigned int | |
1434 | last_got_offset() const | |
1435 | { return this->got_offset(this->entries_.size() - 1); } | |
1436 | ||
1437 | // Set the size of the section. | |
1438 | void | |
1439 | set_got_size() | |
27bc2bce | 1440 | { this->set_current_data_size(this->got_offset(this->entries_.size())); } |
ead1e424 ILT |
1441 | |
1442 | // The list of GOT entries. | |
1443 | Got_entries entries_; | |
1444 | }; | |
1445 | ||
a3ad94ed ILT |
1446 | // Output_data_dynamic is used to hold the data in SHT_DYNAMIC |
1447 | // section. | |
1448 | ||
1449 | class Output_data_dynamic : public Output_section_data | |
1450 | { | |
1451 | public: | |
9025d29d | 1452 | Output_data_dynamic(Stringpool* pool) |
730cdc88 | 1453 | : Output_section_data(Output_data::default_alignment()), |
9025d29d | 1454 | entries_(), pool_(pool) |
a3ad94ed ILT |
1455 | { } |
1456 | ||
1457 | // Add a new dynamic entry with a fixed numeric value. | |
1458 | void | |
1459 | add_constant(elfcpp::DT tag, unsigned int val) | |
1460 | { this->add_entry(Dynamic_entry(tag, val)); } | |
1461 | ||
16649710 | 1462 | // Add a new dynamic entry with the address of output data. |
a3ad94ed | 1463 | void |
16649710 ILT |
1464 | add_section_address(elfcpp::DT tag, const Output_data* od) |
1465 | { this->add_entry(Dynamic_entry(tag, od, false)); } | |
a3ad94ed | 1466 | |
16649710 | 1467 | // Add a new dynamic entry with the size of output data. |
a3ad94ed | 1468 | void |
16649710 ILT |
1469 | add_section_size(elfcpp::DT tag, const Output_data* od) |
1470 | { this->add_entry(Dynamic_entry(tag, od, true)); } | |
a3ad94ed ILT |
1471 | |
1472 | // Add a new dynamic entry with the address of a symbol. | |
1473 | void | |
16649710 | 1474 | add_symbol(elfcpp::DT tag, const Symbol* sym) |
a3ad94ed ILT |
1475 | { this->add_entry(Dynamic_entry(tag, sym)); } |
1476 | ||
1477 | // Add a new dynamic entry with a string. | |
1478 | void | |
1479 | add_string(elfcpp::DT tag, const char* str) | |
cfd73a4e | 1480 | { this->add_entry(Dynamic_entry(tag, this->pool_->add(str, true, NULL))); } |
a3ad94ed | 1481 | |
41f542e7 ILT |
1482 | void |
1483 | add_string(elfcpp::DT tag, const std::string& str) | |
1484 | { this->add_string(tag, str.c_str()); } | |
1485 | ||
27bc2bce ILT |
1486 | protected: |
1487 | // Adjust the output section to set the entry size. | |
1488 | void | |
1489 | do_adjust_output_section(Output_section*); | |
1490 | ||
a3ad94ed ILT |
1491 | // Set the final data size. |
1492 | void | |
27bc2bce | 1493 | set_final_data_size(); |
a3ad94ed ILT |
1494 | |
1495 | // Write out the dynamic entries. | |
1496 | void | |
1497 | do_write(Output_file*); | |
1498 | ||
1499 | private: | |
1500 | // This POD class holds a single dynamic entry. | |
1501 | class Dynamic_entry | |
1502 | { | |
1503 | public: | |
1504 | // Create an entry with a fixed numeric value. | |
1505 | Dynamic_entry(elfcpp::DT tag, unsigned int val) | |
1506 | : tag_(tag), classification_(DYNAMIC_NUMBER) | |
1507 | { this->u_.val = val; } | |
1508 | ||
1509 | // Create an entry with the size or address of a section. | |
16649710 | 1510 | Dynamic_entry(elfcpp::DT tag, const Output_data* od, bool section_size) |
a3ad94ed ILT |
1511 | : tag_(tag), |
1512 | classification_(section_size | |
1513 | ? DYNAMIC_SECTION_SIZE | |
1514 | : DYNAMIC_SECTION_ADDRESS) | |
16649710 | 1515 | { this->u_.od = od; } |
a3ad94ed ILT |
1516 | |
1517 | // Create an entry with the address of a symbol. | |
16649710 | 1518 | Dynamic_entry(elfcpp::DT tag, const Symbol* sym) |
a3ad94ed ILT |
1519 | : tag_(tag), classification_(DYNAMIC_SYMBOL) |
1520 | { this->u_.sym = sym; } | |
1521 | ||
1522 | // Create an entry with a string. | |
1523 | Dynamic_entry(elfcpp::DT tag, const char* str) | |
1524 | : tag_(tag), classification_(DYNAMIC_STRING) | |
1525 | { this->u_.str = str; } | |
1526 | ||
1527 | // Write the dynamic entry to an output view. | |
1528 | template<int size, bool big_endian> | |
1529 | void | |
1ddbd1e6 | 1530 | write(unsigned char* pov, const Stringpool* ACCEPT_SIZE_ENDIAN) const; |
a3ad94ed ILT |
1531 | |
1532 | private: | |
1533 | enum Classification | |
1534 | { | |
1535 | // Number. | |
1536 | DYNAMIC_NUMBER, | |
1537 | // Section address. | |
1538 | DYNAMIC_SECTION_ADDRESS, | |
1539 | // Section size. | |
1540 | DYNAMIC_SECTION_SIZE, | |
1541 | // Symbol adress. | |
1542 | DYNAMIC_SYMBOL, | |
1543 | // String. | |
1544 | DYNAMIC_STRING | |
1545 | }; | |
1546 | ||
1547 | union | |
1548 | { | |
1549 | // For DYNAMIC_NUMBER. | |
1550 | unsigned int val; | |
1551 | // For DYNAMIC_SECTION_ADDRESS and DYNAMIC_SECTION_SIZE. | |
16649710 | 1552 | const Output_data* od; |
a3ad94ed | 1553 | // For DYNAMIC_SYMBOL. |
16649710 | 1554 | const Symbol* sym; |
a3ad94ed ILT |
1555 | // For DYNAMIC_STRING. |
1556 | const char* str; | |
1557 | } u_; | |
1558 | // The dynamic tag. | |
1559 | elfcpp::DT tag_; | |
1560 | // The type of entry. | |
1561 | Classification classification_; | |
1562 | }; | |
1563 | ||
1564 | // Add an entry to the list. | |
1565 | void | |
1566 | add_entry(const Dynamic_entry& entry) | |
1567 | { this->entries_.push_back(entry); } | |
1568 | ||
1569 | // Sized version of write function. | |
1570 | template<int size, bool big_endian> | |
1571 | void | |
1572 | sized_write(Output_file* of); | |
1573 | ||
1574 | // The type of the list of entries. | |
1575 | typedef std::vector<Dynamic_entry> Dynamic_entries; | |
1576 | ||
a3ad94ed ILT |
1577 | // The entries. |
1578 | Dynamic_entries entries_; | |
1579 | // The pool used for strings. | |
1580 | Stringpool* pool_; | |
1581 | }; | |
1582 | ||
a2fb1b05 ILT |
1583 | // An output section. We don't expect to have too many output |
1584 | // sections, so we don't bother to do a template on the size. | |
1585 | ||
54dc6425 | 1586 | class Output_section : public Output_data |
a2fb1b05 ILT |
1587 | { |
1588 | public: | |
1589 | // Create an output section, giving the name, type, and flags. | |
96803768 | 1590 | Output_section(const char* name, elfcpp::Elf_Word, elfcpp::Elf_Xword); |
54dc6425 | 1591 | virtual ~Output_section(); |
a2fb1b05 | 1592 | |
ead1e424 | 1593 | // Add a new input section SHNDX, named NAME, with header SHDR, from |
730cdc88 ILT |
1594 | // object OBJECT. RELOC_SHNDX is the index of a relocation section |
1595 | // which applies to this section, or 0 if none, or -1U if more than | |
a445fddf ILT |
1596 | // one. HAVE_SECTIONS_SCRIPT is true if we have a SECTIONS clause |
1597 | // in a linker script; in that case we need to keep track of input | |
1598 | // sections associated with an output section. Return the offset | |
1599 | // within the output section. | |
a2fb1b05 ILT |
1600 | template<int size, bool big_endian> |
1601 | off_t | |
730cdc88 ILT |
1602 | add_input_section(Sized_relobj<size, big_endian>* object, unsigned int shndx, |
1603 | const char *name, | |
1604 | const elfcpp::Shdr<size, big_endian>& shdr, | |
a445fddf | 1605 | unsigned int reloc_shndx, bool have_sections_script); |
a2fb1b05 | 1606 | |
b8e6aad9 | 1607 | // Add generated data POSD to this output section. |
c06b7b0b | 1608 | void |
ead1e424 ILT |
1609 | add_output_section_data(Output_section_data* posd); |
1610 | ||
a2fb1b05 ILT |
1611 | // Return the section name. |
1612 | const char* | |
1613 | name() const | |
1614 | { return this->name_; } | |
1615 | ||
1616 | // Return the section type. | |
1617 | elfcpp::Elf_Word | |
1618 | type() const | |
1619 | { return this->type_; } | |
1620 | ||
1621 | // Return the section flags. | |
1622 | elfcpp::Elf_Xword | |
1623 | flags() const | |
1624 | { return this->flags_; } | |
1625 | ||
a3ad94ed ILT |
1626 | // Return the entsize field. |
1627 | uint64_t | |
1628 | entsize() const | |
1629 | { return this->entsize_; } | |
1630 | ||
61ba1cf9 ILT |
1631 | // Set the entsize field. |
1632 | void | |
16649710 | 1633 | set_entsize(uint64_t v); |
61ba1cf9 | 1634 | |
a445fddf ILT |
1635 | // Set the load address. |
1636 | void | |
1637 | set_load_address(uint64_t load_address) | |
1638 | { | |
1639 | this->load_address_ = load_address; | |
1640 | this->has_load_address_ = true; | |
1641 | } | |
1642 | ||
16649710 ILT |
1643 | // Set the link field to the output section index of a section. |
1644 | void | |
14b31740 | 1645 | set_link_section(const Output_data* od) |
16649710 ILT |
1646 | { |
1647 | gold_assert(this->link_ == 0 | |
1648 | && !this->should_link_to_symtab_ | |
1649 | && !this->should_link_to_dynsym_); | |
1650 | this->link_section_ = od; | |
1651 | } | |
1652 | ||
1653 | // Set the link field to a constant. | |
61ba1cf9 ILT |
1654 | void |
1655 | set_link(unsigned int v) | |
16649710 ILT |
1656 | { |
1657 | gold_assert(this->link_section_ == NULL | |
1658 | && !this->should_link_to_symtab_ | |
1659 | && !this->should_link_to_dynsym_); | |
1660 | this->link_ = v; | |
1661 | } | |
61ba1cf9 | 1662 | |
16649710 ILT |
1663 | // Record that this section should link to the normal symbol table. |
1664 | void | |
1665 | set_should_link_to_symtab() | |
1666 | { | |
1667 | gold_assert(this->link_section_ == NULL | |
1668 | && this->link_ == 0 | |
1669 | && !this->should_link_to_dynsym_); | |
1670 | this->should_link_to_symtab_ = true; | |
1671 | } | |
1672 | ||
1673 | // Record that this section should link to the dynamic symbol table. | |
1674 | void | |
1675 | set_should_link_to_dynsym() | |
1676 | { | |
1677 | gold_assert(this->link_section_ == NULL | |
1678 | && this->link_ == 0 | |
1679 | && !this->should_link_to_symtab_); | |
1680 | this->should_link_to_dynsym_ = true; | |
1681 | } | |
1682 | ||
1683 | // Return the info field. | |
1684 | unsigned int | |
1685 | info() const | |
1686 | { | |
755ab8af ILT |
1687 | gold_assert(this->info_section_ == NULL |
1688 | && this->info_symndx_ == NULL); | |
16649710 ILT |
1689 | return this->info_; |
1690 | } | |
1691 | ||
1692 | // Set the info field to the output section index of a section. | |
1693 | void | |
755ab8af | 1694 | set_info_section(const Output_section* os) |
16649710 | 1695 | { |
755ab8af ILT |
1696 | gold_assert((this->info_section_ == NULL |
1697 | || (this->info_section_ == os | |
1698 | && this->info_uses_section_index_)) | |
1699 | && this->info_symndx_ == NULL | |
1700 | && this->info_ == 0); | |
1701 | this->info_section_ = os; | |
1702 | this->info_uses_section_index_= true; | |
16649710 ILT |
1703 | } |
1704 | ||
6a74a719 ILT |
1705 | // Set the info field to the symbol table index of a symbol. |
1706 | void | |
1707 | set_info_symndx(const Symbol* sym) | |
1708 | { | |
755ab8af ILT |
1709 | gold_assert(this->info_section_ == NULL |
1710 | && (this->info_symndx_ == NULL | |
1711 | || this->info_symndx_ == sym) | |
1712 | && this->info_ == 0); | |
6a74a719 ILT |
1713 | this->info_symndx_ = sym; |
1714 | } | |
1715 | ||
755ab8af ILT |
1716 | // Set the info field to the symbol table index of a section symbol. |
1717 | void | |
1718 | set_info_section_symndx(const Output_section* os) | |
1719 | { | |
1720 | gold_assert((this->info_section_ == NULL | |
1721 | || (this->info_section_ == os | |
1722 | && !this->info_uses_section_index_)) | |
1723 | && this->info_symndx_ == NULL | |
1724 | && this->info_ == 0); | |
1725 | this->info_section_ = os; | |
1726 | this->info_uses_section_index_ = false; | |
1727 | } | |
1728 | ||
16649710 | 1729 | // Set the info field to a constant. |
61ba1cf9 ILT |
1730 | void |
1731 | set_info(unsigned int v) | |
16649710 | 1732 | { |
755ab8af ILT |
1733 | gold_assert(this->info_section_ == NULL |
1734 | && this->info_symndx_ == NULL | |
1735 | && (this->info_ == 0 | |
1736 | || this->info_ == v)); | |
16649710 ILT |
1737 | this->info_ = v; |
1738 | } | |
61ba1cf9 ILT |
1739 | |
1740 | // Set the addralign field. | |
1741 | void | |
1742 | set_addralign(uint64_t v) | |
1743 | { this->addralign_ = v; } | |
1744 | ||
c06b7b0b ILT |
1745 | // Indicate that we need a symtab index. |
1746 | void | |
1747 | set_needs_symtab_index() | |
1748 | { this->needs_symtab_index_ = true; } | |
1749 | ||
1750 | // Return whether we need a symtab index. | |
1751 | bool | |
1752 | needs_symtab_index() const | |
1753 | { return this->needs_symtab_index_; } | |
1754 | ||
1755 | // Get the symtab index. | |
1756 | unsigned int | |
1757 | symtab_index() const | |
1758 | { | |
a3ad94ed | 1759 | gold_assert(this->symtab_index_ != 0); |
c06b7b0b ILT |
1760 | return this->symtab_index_; |
1761 | } | |
1762 | ||
1763 | // Set the symtab index. | |
1764 | void | |
1765 | set_symtab_index(unsigned int index) | |
1766 | { | |
a3ad94ed | 1767 | gold_assert(index != 0); |
c06b7b0b ILT |
1768 | this->symtab_index_ = index; |
1769 | } | |
1770 | ||
1771 | // Indicate that we need a dynsym index. | |
1772 | void | |
1773 | set_needs_dynsym_index() | |
1774 | { this->needs_dynsym_index_ = true; } | |
1775 | ||
1776 | // Return whether we need a dynsym index. | |
1777 | bool | |
1778 | needs_dynsym_index() const | |
1779 | { return this->needs_dynsym_index_; } | |
1780 | ||
1781 | // Get the dynsym index. | |
1782 | unsigned int | |
1783 | dynsym_index() const | |
1784 | { | |
a3ad94ed | 1785 | gold_assert(this->dynsym_index_ != 0); |
c06b7b0b ILT |
1786 | return this->dynsym_index_; |
1787 | } | |
1788 | ||
1789 | // Set the dynsym index. | |
1790 | void | |
1791 | set_dynsym_index(unsigned int index) | |
1792 | { | |
a3ad94ed | 1793 | gold_assert(index != 0); |
c06b7b0b ILT |
1794 | this->dynsym_index_ = index; |
1795 | } | |
1796 | ||
730cdc88 ILT |
1797 | // Return whether this section should be written after all the input |
1798 | // sections are complete. | |
1799 | bool | |
1800 | after_input_sections() const | |
1801 | { return this->after_input_sections_; } | |
1802 | ||
1803 | // Record that this section should be written after all the input | |
1804 | // sections are complete. | |
1805 | void | |
1806 | set_after_input_sections() | |
1807 | { this->after_input_sections_ = true; } | |
1808 | ||
27bc2bce ILT |
1809 | // Return whether this section requires postprocessing after all |
1810 | // relocations have been applied. | |
1811 | bool | |
1812 | requires_postprocessing() const | |
1813 | { return this->requires_postprocessing_; } | |
1814 | ||
96803768 ILT |
1815 | // If a section requires postprocessing, return the buffer to use. |
1816 | unsigned char* | |
1817 | postprocessing_buffer() const | |
1818 | { | |
1819 | gold_assert(this->postprocessing_buffer_ != NULL); | |
1820 | return this->postprocessing_buffer_; | |
1821 | } | |
1822 | ||
1823 | // If a section requires postprocessing, create the buffer to use. | |
27bc2bce | 1824 | void |
96803768 ILT |
1825 | create_postprocessing_buffer(); |
1826 | ||
1827 | // If a section requires postprocessing, this is the size of the | |
1828 | // buffer to which relocations should be applied. | |
1829 | off_t | |
1830 | postprocessing_buffer_size() const | |
1831 | { return this->current_data_size_for_child(); } | |
27bc2bce | 1832 | |
755ab8af ILT |
1833 | // Modify the section name. This is only permitted for an |
1834 | // unallocated section, and only before the size has been finalized. | |
1835 | // Otherwise the name will not get into Layout::namepool_. | |
1836 | void | |
1837 | set_name(const char* newname) | |
1838 | { | |
1839 | gold_assert((this->flags_ & elfcpp::SHF_ALLOC) == 0); | |
1840 | gold_assert(!this->is_data_size_valid()); | |
1841 | this->name_ = newname; | |
1842 | } | |
1843 | ||
730cdc88 ILT |
1844 | // Return whether the offset OFFSET in the input section SHNDX in |
1845 | // object OBJECT is being included in the link. | |
1846 | bool | |
1847 | is_input_address_mapped(const Relobj* object, unsigned int shndx, | |
1848 | off_t offset) const; | |
1849 | ||
1850 | // Return the offset within the output section of OFFSET relative to | |
1851 | // the start of input section SHNDX in object OBJECT. | |
8383303e ILT |
1852 | section_offset_type |
1853 | output_offset(const Relobj* object, unsigned int shndx, | |
1854 | section_offset_type offset) const; | |
730cdc88 | 1855 | |
b8e6aad9 ILT |
1856 | // Return the output virtual address of OFFSET relative to the start |
1857 | // of input section SHNDX in object OBJECT. | |
1858 | uint64_t | |
1859 | output_address(const Relobj* object, unsigned int shndx, | |
1860 | off_t offset) const; | |
1861 | ||
a9a60db6 ILT |
1862 | // Return the output address of the start of the merged section for |
1863 | // input section SHNDX in object OBJECT. This is not necessarily | |
1864 | // the offset corresponding to input offset 0 in the section, since | |
1865 | // the section may be mapped arbitrarily. | |
1866 | uint64_t | |
1867 | starting_output_address(const Relobj* object, unsigned int shndx) const; | |
1868 | ||
a445fddf ILT |
1869 | // Record that this output section was found in the SECTIONS clause |
1870 | // of a linker script. | |
1871 | void | |
1872 | set_found_in_sections_clause() | |
1873 | { this->found_in_sections_clause_ = true; } | |
1874 | ||
1875 | // Return whether this output section was found in the SECTIONS | |
1876 | // clause of a linker script. | |
1877 | bool | |
1878 | found_in_sections_clause() const | |
1879 | { return this->found_in_sections_clause_; } | |
1880 | ||
27bc2bce ILT |
1881 | // Write the section header into *OPHDR. |
1882 | template<int size, bool big_endian> | |
1883 | void | |
1884 | write_header(const Layout*, const Stringpool*, | |
1885 | elfcpp::Shdr_write<size, big_endian>*) const; | |
1886 | ||
a445fddf ILT |
1887 | // The next few calls are for linker script support. |
1888 | ||
1889 | // Store the list of input sections for this Output_section into the | |
1890 | // list passed in. This removes the input sections, leaving only | |
1891 | // any Output_section_data elements. This returns the size of those | |
1892 | // Output_section_data elements. ADDRESS is the address of this | |
1893 | // output section. FILL is the fill value to use, in case there are | |
1894 | // any spaces between the remaining Output_section_data elements. | |
1895 | uint64_t | |
1896 | get_input_sections(uint64_t address, const std::string& fill, | |
1897 | std::list<std::pair<Relobj*, unsigned int > >*); | |
1898 | ||
1899 | // Add an input section from a script. | |
1900 | void | |
1901 | add_input_section_for_script(Relobj* object, unsigned int shndx, | |
1902 | off_t data_size, uint64_t addralign); | |
1903 | ||
1904 | // Set the current size of the output section. | |
1905 | void | |
1906 | set_current_data_size(off_t size) | |
1907 | { this->set_current_data_size_for_child(size); } | |
1908 | ||
1909 | // Get the current size of the output section. | |
1910 | off_t | |
1911 | current_data_size() const | |
1912 | { return this->current_data_size_for_child(); } | |
1913 | ||
1914 | // End of linker script support. | |
1915 | ||
38c5e8b4 ILT |
1916 | // Print merge statistics to stderr. |
1917 | void | |
1918 | print_merge_stats(); | |
1919 | ||
27bc2bce | 1920 | protected: |
77e65537 ILT |
1921 | // Return the output section--i.e., the object itself. |
1922 | Output_section* | |
1923 | do_output_section() | |
1924 | { return this; } | |
1925 | ||
27bc2bce ILT |
1926 | // Return the section index in the output file. |
1927 | unsigned int | |
1928 | do_out_shndx() const | |
1929 | { | |
1930 | gold_assert(this->out_shndx_ != -1U); | |
1931 | return this->out_shndx_; | |
1932 | } | |
1933 | ||
1934 | // Set the output section index. | |
1935 | void | |
1936 | do_set_out_shndx(unsigned int shndx) | |
1937 | { | |
a445fddf | 1938 | gold_assert(this->out_shndx_ == -1U || this->out_shndx_ == shndx); |
27bc2bce ILT |
1939 | this->out_shndx_ = shndx; |
1940 | } | |
1941 | ||
1942 | // Set the final data size of the Output_section. For a typical | |
ead1e424 | 1943 | // Output_section, there is nothing to do, but if there are any |
27bc2bce | 1944 | // Output_section_data objects we need to set their final addresses |
ead1e424 | 1945 | // here. |
96803768 | 1946 | virtual void |
27bc2bce | 1947 | set_final_data_size(); |
ead1e424 | 1948 | |
a445fddf ILT |
1949 | // Reset the address and file offset. |
1950 | void | |
1951 | do_reset_address_and_file_offset(); | |
1952 | ||
54dc6425 | 1953 | // Write the data to the file. For a typical Output_section, this |
ead1e424 ILT |
1954 | // does nothing: the data is written out by calling Object::Relocate |
1955 | // on each input object. But if there are any Output_section_data | |
1956 | // objects we do need to write them out here. | |
96803768 | 1957 | virtual void |
ead1e424 | 1958 | do_write(Output_file*); |
54dc6425 | 1959 | |
75f65a3e ILT |
1960 | // Return the address alignment--function required by parent class. |
1961 | uint64_t | |
1962 | do_addralign() const | |
1963 | { return this->addralign_; } | |
1964 | ||
a445fddf ILT |
1965 | // Return whether there is a load address. |
1966 | bool | |
1967 | do_has_load_address() const | |
1968 | { return this->has_load_address_; } | |
1969 | ||
1970 | // Return the load address. | |
1971 | uint64_t | |
1972 | do_load_address() const | |
1973 | { | |
1974 | gold_assert(this->has_load_address_); | |
1975 | return this->load_address_; | |
1976 | } | |
1977 | ||
75f65a3e ILT |
1978 | // Return whether this is an Output_section. |
1979 | bool | |
1980 | do_is_section() const | |
1981 | { return true; } | |
1982 | ||
54dc6425 ILT |
1983 | // Return whether this is a section of the specified type. |
1984 | bool | |
75f65a3e | 1985 | do_is_section_type(elfcpp::Elf_Word type) const |
54dc6425 ILT |
1986 | { return this->type_ == type; } |
1987 | ||
1988 | // Return whether the specified section flag is set. | |
1989 | bool | |
75f65a3e | 1990 | do_is_section_flag_set(elfcpp::Elf_Xword flag) const |
54dc6425 ILT |
1991 | { return (this->flags_ & flag) != 0; } |
1992 | ||
7bf1f802 ILT |
1993 | // Set the TLS offset. Called only for SHT_TLS sections. |
1994 | void | |
1995 | do_set_tls_offset(uint64_t tls_base); | |
1996 | ||
1997 | // Return the TLS offset, relative to the base of the TLS segment. | |
1998 | // Valid only for SHT_TLS sections. | |
1999 | uint64_t | |
2000 | do_tls_offset() const | |
2001 | { return this->tls_offset_; } | |
2002 | ||
96803768 ILT |
2003 | // This may be implemented by a child class. |
2004 | virtual void | |
2005 | do_finalize_name(Layout*) | |
2006 | { } | |
2007 | ||
2008 | // Record that this section requires postprocessing after all | |
2009 | // relocations have been applied. This is called by a child class. | |
2010 | void | |
2011 | set_requires_postprocessing() | |
2012 | { | |
2013 | this->requires_postprocessing_ = true; | |
2014 | this->after_input_sections_ = true; | |
2015 | } | |
2016 | ||
2017 | // Write all the data of an Output_section into the postprocessing | |
2018 | // buffer. | |
2019 | void | |
2020 | write_to_postprocessing_buffer(); | |
2021 | ||
a2fb1b05 | 2022 | private: |
ead1e424 ILT |
2023 | // In some cases we need to keep a list of the input sections |
2024 | // associated with this output section. We only need the list if we | |
2025 | // might have to change the offsets of the input section within the | |
2026 | // output section after we add the input section. The ordinary | |
2027 | // input sections will be written out when we process the object | |
2028 | // file, and as such we don't need to track them here. We do need | |
2029 | // to track Output_section_data objects here. We store instances of | |
2030 | // this structure in a std::vector, so it must be a POD. There can | |
2031 | // be many instances of this structure, so we use a union to save | |
2032 | // some space. | |
2033 | class Input_section | |
2034 | { | |
2035 | public: | |
2036 | Input_section() | |
b8e6aad9 ILT |
2037 | : shndx_(0), p2align_(0) |
2038 | { | |
2039 | this->u1_.data_size = 0; | |
2040 | this->u2_.object = NULL; | |
2041 | } | |
ead1e424 | 2042 | |
b8e6aad9 | 2043 | // For an ordinary input section. |
f6ce93d6 | 2044 | Input_section(Relobj* object, unsigned int shndx, off_t data_size, |
ead1e424 ILT |
2045 | uint64_t addralign) |
2046 | : shndx_(shndx), | |
b8e6aad9 | 2047 | p2align_(ffsll(static_cast<long long>(addralign))) |
ead1e424 | 2048 | { |
b8e6aad9 ILT |
2049 | gold_assert(shndx != OUTPUT_SECTION_CODE |
2050 | && shndx != MERGE_DATA_SECTION_CODE | |
2051 | && shndx != MERGE_STRING_SECTION_CODE); | |
2052 | this->u1_.data_size = data_size; | |
2053 | this->u2_.object = object; | |
ead1e424 ILT |
2054 | } |
2055 | ||
b8e6aad9 | 2056 | // For a non-merge output section. |
ead1e424 | 2057 | Input_section(Output_section_data* posd) |
b8e6aad9 ILT |
2058 | : shndx_(OUTPUT_SECTION_CODE), |
2059 | p2align_(ffsll(static_cast<long long>(posd->addralign()))) | |
2060 | { | |
2061 | this->u1_.data_size = 0; | |
2062 | this->u2_.posd = posd; | |
2063 | } | |
2064 | ||
2065 | // For a merge section. | |
2066 | Input_section(Output_section_data* posd, bool is_string, uint64_t entsize) | |
2067 | : shndx_(is_string | |
2068 | ? MERGE_STRING_SECTION_CODE | |
2069 | : MERGE_DATA_SECTION_CODE), | |
2070 | p2align_(ffsll(static_cast<long long>(posd->addralign()))) | |
2071 | { | |
2072 | this->u1_.entsize = entsize; | |
2073 | this->u2_.posd = posd; | |
2074 | } | |
ead1e424 ILT |
2075 | |
2076 | // The required alignment. | |
2077 | uint64_t | |
2078 | addralign() const | |
a3ad94ed ILT |
2079 | { |
2080 | return (this->p2align_ == 0 | |
2081 | ? 0 | |
2082 | : static_cast<uint64_t>(1) << (this->p2align_ - 1)); | |
2083 | } | |
ead1e424 ILT |
2084 | |
2085 | // Return the required size. | |
2086 | off_t | |
2087 | data_size() const; | |
2088 | ||
a445fddf ILT |
2089 | // Whether this is an input section. |
2090 | bool | |
2091 | is_input_section() const | |
2092 | { | |
2093 | return (this->shndx_ != OUTPUT_SECTION_CODE | |
2094 | && this->shndx_ != MERGE_DATA_SECTION_CODE | |
2095 | && this->shndx_ != MERGE_STRING_SECTION_CODE); | |
2096 | } | |
2097 | ||
b8e6aad9 ILT |
2098 | // Return whether this is a merge section which matches the |
2099 | // parameters. | |
2100 | bool | |
87f95776 ILT |
2101 | is_merge_section(bool is_string, uint64_t entsize, |
2102 | uint64_t addralign) const | |
b8e6aad9 ILT |
2103 | { |
2104 | return (this->shndx_ == (is_string | |
2105 | ? MERGE_STRING_SECTION_CODE | |
2106 | : MERGE_DATA_SECTION_CODE) | |
87f95776 ILT |
2107 | && this->u1_.entsize == entsize |
2108 | && this->addralign() == addralign); | |
b8e6aad9 ILT |
2109 | } |
2110 | ||
a445fddf ILT |
2111 | // Return the object for an input section. |
2112 | Relobj* | |
2113 | relobj() const | |
2114 | { | |
2115 | gold_assert(this->is_input_section()); | |
2116 | return this->u2_.object; | |
2117 | } | |
2118 | ||
2119 | // Return the input section index for an input section. | |
2120 | unsigned int | |
2121 | shndx() const | |
2122 | { | |
2123 | gold_assert(this->is_input_section()); | |
2124 | return this->shndx_; | |
2125 | } | |
2126 | ||
b8e6aad9 ILT |
2127 | // Set the output section. |
2128 | void | |
2129 | set_output_section(Output_section* os) | |
2130 | { | |
2131 | gold_assert(!this->is_input_section()); | |
2132 | this->u2_.posd->set_output_section(os); | |
2133 | } | |
2134 | ||
ead1e424 | 2135 | // Set the address and file offset. This is called during |
96803768 ILT |
2136 | // Layout::finalize. SECTION_FILE_OFFSET is the file offset of |
2137 | // the enclosing section. | |
ead1e424 | 2138 | void |
96803768 ILT |
2139 | set_address_and_file_offset(uint64_t address, off_t file_offset, |
2140 | off_t section_file_offset); | |
ead1e424 | 2141 | |
a445fddf ILT |
2142 | // Reset the address and file offset. |
2143 | void | |
2144 | reset_address_and_file_offset(); | |
2145 | ||
96803768 ILT |
2146 | // Finalize the data size. |
2147 | void | |
2148 | finalize_data_size(); | |
9a0910c3 | 2149 | |
b8e6aad9 ILT |
2150 | // Add an input section, for SHF_MERGE sections. |
2151 | bool | |
2152 | add_input_section(Relobj* object, unsigned int shndx) | |
2153 | { | |
2154 | gold_assert(this->shndx_ == MERGE_DATA_SECTION_CODE | |
2155 | || this->shndx_ == MERGE_STRING_SECTION_CODE); | |
2156 | return this->u2_.posd->add_input_section(object, shndx); | |
2157 | } | |
2158 | ||
2159 | // Given an input OBJECT, an input section index SHNDX within that | |
2160 | // object, and an OFFSET relative to the start of that input | |
730cdc88 | 2161 | // section, return whether or not the output offset is known. If |
1e983657 ILT |
2162 | // this function returns true, it sets *POUTPUT to the offset in |
2163 | // the output section, relative to the start of the input section | |
2164 | // in the output section. *POUTPUT may be different from OFFSET | |
2165 | // for a merged section. | |
b8e6aad9 | 2166 | bool |
8383303e ILT |
2167 | output_offset(const Relobj* object, unsigned int shndx, |
2168 | section_offset_type offset, | |
2169 | section_offset_type *poutput) const; | |
b8e6aad9 | 2170 | |
a9a60db6 ILT |
2171 | // Return whether this is the merge section for the input section |
2172 | // SHNDX in OBJECT. | |
2173 | bool | |
2174 | is_merge_section_for(const Relobj* object, unsigned int shndx) const; | |
2175 | ||
ead1e424 ILT |
2176 | // Write out the data. This does nothing for an input section. |
2177 | void | |
2178 | write(Output_file*); | |
2179 | ||
96803768 ILT |
2180 | // Write the data to a buffer. This does nothing for an input |
2181 | // section. | |
2182 | void | |
2183 | write_to_buffer(unsigned char*); | |
2184 | ||
38c5e8b4 ILT |
2185 | // Print statistics about merge sections to stderr. |
2186 | void | |
2187 | print_merge_stats(const char* section_name) | |
2188 | { | |
2189 | if (this->shndx_ == MERGE_DATA_SECTION_CODE | |
2190 | || this->shndx_ == MERGE_STRING_SECTION_CODE) | |
2191 | this->u2_.posd->print_merge_stats(section_name); | |
2192 | } | |
2193 | ||
ead1e424 | 2194 | private: |
b8e6aad9 ILT |
2195 | // Code values which appear in shndx_. If the value is not one of |
2196 | // these codes, it is the input section index in the object file. | |
2197 | enum | |
2198 | { | |
2199 | // An Output_section_data. | |
2200 | OUTPUT_SECTION_CODE = -1U, | |
2201 | // An Output_section_data for an SHF_MERGE section with | |
2202 | // SHF_STRINGS not set. | |
2203 | MERGE_DATA_SECTION_CODE = -2U, | |
2204 | // An Output_section_data for an SHF_MERGE section with | |
2205 | // SHF_STRINGS set. | |
2206 | MERGE_STRING_SECTION_CODE = -3U | |
2207 | }; | |
2208 | ||
b8e6aad9 ILT |
2209 | // For an ordinary input section, this is the section index in the |
2210 | // input file. For an Output_section_data, this is | |
2211 | // OUTPUT_SECTION_CODE or MERGE_DATA_SECTION_CODE or | |
2212 | // MERGE_STRING_SECTION_CODE. | |
ead1e424 ILT |
2213 | unsigned int shndx_; |
2214 | // The required alignment, stored as a power of 2. | |
2215 | unsigned int p2align_; | |
ead1e424 ILT |
2216 | union |
2217 | { | |
b8e6aad9 ILT |
2218 | // For an ordinary input section, the section size. |
2219 | off_t data_size; | |
2220 | // For OUTPUT_SECTION_CODE, this is not used. For | |
2221 | // MERGE_DATA_SECTION_CODE or MERGE_STRING_SECTION_CODE, the | |
2222 | // entity size. | |
2223 | uint64_t entsize; | |
2224 | } u1_; | |
2225 | union | |
2226 | { | |
2227 | // For an ordinary input section, the object which holds the | |
ead1e424 | 2228 | // input section. |
f6ce93d6 | 2229 | Relobj* object; |
b8e6aad9 ILT |
2230 | // For OUTPUT_SECTION_CODE or MERGE_DATA_SECTION_CODE or |
2231 | // MERGE_STRING_SECTION_CODE, the data. | |
ead1e424 | 2232 | Output_section_data* posd; |
b8e6aad9 | 2233 | } u2_; |
ead1e424 ILT |
2234 | }; |
2235 | ||
2236 | typedef std::vector<Input_section> Input_section_list; | |
2237 | ||
c51e6221 | 2238 | // Fill data. This is used to fill in data between input sections. |
a445fddf ILT |
2239 | // It is also used for data statements (BYTE, WORD, etc.) in linker |
2240 | // scripts. When we have to keep track of the input sections, we | |
2241 | // can use an Output_data_const, but we don't want to have to keep | |
2242 | // track of input sections just to implement fills. | |
c51e6221 ILT |
2243 | class Fill |
2244 | { | |
2245 | public: | |
2246 | Fill(off_t section_offset, off_t length) | |
a445fddf ILT |
2247 | : section_offset_(section_offset), |
2248 | length_(convert_to_section_size_type(length)) | |
c51e6221 ILT |
2249 | { } |
2250 | ||
2251 | // Return section offset. | |
2252 | off_t | |
2253 | section_offset() const | |
2254 | { return this->section_offset_; } | |
2255 | ||
2256 | // Return fill length. | |
a445fddf | 2257 | section_size_type |
c51e6221 ILT |
2258 | length() const |
2259 | { return this->length_; } | |
2260 | ||
2261 | private: | |
2262 | // The offset within the output section. | |
2263 | off_t section_offset_; | |
2264 | // The length of the space to fill. | |
a445fddf | 2265 | section_size_type length_; |
c51e6221 ILT |
2266 | }; |
2267 | ||
2268 | typedef std::vector<Fill> Fill_list; | |
2269 | ||
b8e6aad9 ILT |
2270 | // Add a new output section by Input_section. |
2271 | void | |
2272 | add_output_section_data(Input_section*); | |
2273 | ||
2274 | // Add an SHF_MERGE input section. Returns true if the section was | |
2275 | // handled. | |
2276 | bool | |
2277 | add_merge_input_section(Relobj* object, unsigned int shndx, uint64_t flags, | |
96803768 | 2278 | uint64_t entsize, uint64_t addralign); |
b8e6aad9 ILT |
2279 | |
2280 | // Add an output SHF_MERGE section POSD to this output section. | |
2281 | // IS_STRING indicates whether it is a SHF_STRINGS section, and | |
2282 | // ENTSIZE is the entity size. This returns the entry added to | |
2283 | // input_sections_. | |
2284 | void | |
2285 | add_output_merge_section(Output_section_data* posd, bool is_string, | |
2286 | uint64_t entsize); | |
2287 | ||
a2fb1b05 ILT |
2288 | // Most of these fields are only valid after layout. |
2289 | ||
2290 | // The name of the section. This will point into a Stringpool. | |
9a0910c3 | 2291 | const char* name_; |
75f65a3e | 2292 | // The section address is in the parent class. |
a2fb1b05 ILT |
2293 | // The section alignment. |
2294 | uint64_t addralign_; | |
2295 | // The section entry size. | |
2296 | uint64_t entsize_; | |
a445fddf ILT |
2297 | // The load address. This is only used when using a linker script |
2298 | // with a SECTIONS clause. The has_load_address_ field indicates | |
2299 | // whether this field is valid. | |
2300 | uint64_t load_address_; | |
75f65a3e | 2301 | // The file offset is in the parent class. |
16649710 | 2302 | // Set the section link field to the index of this section. |
14b31740 | 2303 | const Output_data* link_section_; |
16649710 | 2304 | // If link_section_ is NULL, this is the link field. |
a2fb1b05 | 2305 | unsigned int link_; |
16649710 | 2306 | // Set the section info field to the index of this section. |
755ab8af | 2307 | const Output_section* info_section_; |
6a74a719 ILT |
2308 | // If info_section_ is NULL, set the info field to the symbol table |
2309 | // index of this symbol. | |
2310 | const Symbol* info_symndx_; | |
2311 | // If info_section_ and info_symndx_ are NULL, this is the section | |
2312 | // info field. | |
a2fb1b05 ILT |
2313 | unsigned int info_; |
2314 | // The section type. | |
27bc2bce | 2315 | const elfcpp::Elf_Word type_; |
a2fb1b05 | 2316 | // The section flags. |
a445fddf | 2317 | elfcpp::Elf_Xword flags_; |
61ba1cf9 | 2318 | // The section index. |
ead1e424 | 2319 | unsigned int out_shndx_; |
c06b7b0b ILT |
2320 | // If there is a STT_SECTION for this output section in the normal |
2321 | // symbol table, this is the symbol index. This starts out as zero. | |
2322 | // It is initialized in Layout::finalize() to be the index, or -1U | |
2323 | // if there isn't one. | |
2324 | unsigned int symtab_index_; | |
2325 | // If there is a STT_SECTION for this output section in the dynamic | |
2326 | // symbol table, this is the symbol index. This starts out as zero. | |
2327 | // It is initialized in Layout::finalize() to be the index, or -1U | |
2328 | // if there isn't one. | |
2329 | unsigned int dynsym_index_; | |
ead1e424 ILT |
2330 | // The input sections. This will be empty in cases where we don't |
2331 | // need to keep track of them. | |
2332 | Input_section_list input_sections_; | |
2333 | // The offset of the first entry in input_sections_. | |
2334 | off_t first_input_offset_; | |
c51e6221 ILT |
2335 | // The fill data. This is separate from input_sections_ because we |
2336 | // often will need fill sections without needing to keep track of | |
2337 | // input sections. | |
2338 | Fill_list fills_; | |
96803768 ILT |
2339 | // If the section requires postprocessing, this buffer holds the |
2340 | // section contents during relocation. | |
2341 | unsigned char* postprocessing_buffer_; | |
c06b7b0b ILT |
2342 | // Whether this output section needs a STT_SECTION symbol in the |
2343 | // normal symbol table. This will be true if there is a relocation | |
2344 | // which needs it. | |
2345 | bool needs_symtab_index_ : 1; | |
2346 | // Whether this output section needs a STT_SECTION symbol in the | |
2347 | // dynamic symbol table. This will be true if there is a dynamic | |
2348 | // relocation which needs it. | |
2349 | bool needs_dynsym_index_ : 1; | |
16649710 ILT |
2350 | // Whether the link field of this output section should point to the |
2351 | // normal symbol table. | |
2352 | bool should_link_to_symtab_ : 1; | |
2353 | // Whether the link field of this output section should point to the | |
2354 | // dynamic symbol table. | |
2355 | bool should_link_to_dynsym_ : 1; | |
730cdc88 ILT |
2356 | // Whether this section should be written after all the input |
2357 | // sections are complete. | |
2358 | bool after_input_sections_ : 1; | |
27bc2bce ILT |
2359 | // Whether this section requires post processing after all |
2360 | // relocations have been applied. | |
2361 | bool requires_postprocessing_ : 1; | |
a445fddf ILT |
2362 | // Whether an input section was mapped to this output section |
2363 | // because of a SECTIONS clause in a linker script. | |
2364 | bool found_in_sections_clause_ : 1; | |
2365 | // Whether this section has an explicitly specified load address. | |
2366 | bool has_load_address_ : 1; | |
755ab8af ILT |
2367 | // True if the info_section_ field means the section index of the |
2368 | // section, false if it means the symbol index of the corresponding | |
2369 | // section symbol. | |
2370 | bool info_uses_section_index_ : 1; | |
7bf1f802 ILT |
2371 | // For SHT_TLS sections, the offset of this section relative to the base |
2372 | // of the TLS segment. | |
2373 | uint64_t tls_offset_; | |
a2fb1b05 ILT |
2374 | }; |
2375 | ||
2376 | // An output segment. PT_LOAD segments are built from collections of | |
2377 | // output sections. Other segments typically point within PT_LOAD | |
2378 | // segments, and are built directly as needed. | |
2379 | ||
2380 | class Output_segment | |
2381 | { | |
2382 | public: | |
2383 | // Create an output segment, specifying the type and flags. | |
2384 | Output_segment(elfcpp::Elf_Word, elfcpp::Elf_Word); | |
2385 | ||
2386 | // Return the virtual address. | |
2387 | uint64_t | |
2388 | vaddr() const | |
2389 | { return this->vaddr_; } | |
2390 | ||
2391 | // Return the physical address. | |
2392 | uint64_t | |
2393 | paddr() const | |
2394 | { return this->paddr_; } | |
2395 | ||
2396 | // Return the segment type. | |
2397 | elfcpp::Elf_Word | |
2398 | type() const | |
2399 | { return this->type_; } | |
2400 | ||
2401 | // Return the segment flags. | |
2402 | elfcpp::Elf_Word | |
2403 | flags() const | |
2404 | { return this->flags_; } | |
2405 | ||
92e059d8 ILT |
2406 | // Return the memory size. |
2407 | uint64_t | |
2408 | memsz() const | |
2409 | { return this->memsz_; } | |
2410 | ||
ead1e424 ILT |
2411 | // Return the file size. |
2412 | off_t | |
2413 | filesz() const | |
2414 | { return this->filesz_; } | |
2415 | ||
516cb3d0 ILT |
2416 | // Return the file offset. |
2417 | off_t | |
2418 | offset() const | |
2419 | { return this->offset_; } | |
2420 | ||
75f65a3e ILT |
2421 | // Return the maximum alignment of the Output_data. |
2422 | uint64_t | |
a445fddf | 2423 | maximum_alignment(); |
75f65a3e | 2424 | |
a2fb1b05 ILT |
2425 | // Add an Output_section to this segment. |
2426 | void | |
dbe717ef ILT |
2427 | add_output_section(Output_section* os, elfcpp::Elf_Word seg_flags) |
2428 | { this->add_output_section(os, seg_flags, false); } | |
2429 | ||
2430 | // Add an Output_section to the start of this segment. | |
2431 | void | |
2432 | add_initial_output_section(Output_section* os, elfcpp::Elf_Word seg_flags) | |
2433 | { this->add_output_section(os, seg_flags, true); } | |
75f65a3e ILT |
2434 | |
2435 | // Add an Output_data (which is not an Output_section) to the start | |
2436 | // of this segment. | |
2437 | void | |
2438 | add_initial_output_data(Output_data*); | |
2439 | ||
4f4c5f80 ILT |
2440 | // Return the number of dynamic relocations applied to this segment. |
2441 | unsigned int | |
2442 | dynamic_reloc_count() const; | |
2443 | ||
a445fddf ILT |
2444 | // Return the address of the first section. |
2445 | uint64_t | |
2446 | first_section_load_address() const; | |
2447 | ||
2448 | // Return whether the addresses have been set already. | |
2449 | bool | |
2450 | are_addresses_set() const | |
2451 | { return this->are_addresses_set_; } | |
2452 | ||
2453 | // Set the addresses. | |
2454 | void | |
2455 | set_addresses(uint64_t vaddr, uint64_t paddr) | |
2456 | { | |
2457 | this->vaddr_ = vaddr; | |
2458 | this->paddr_ = paddr; | |
2459 | this->are_addresses_set_ = true; | |
2460 | } | |
2461 | ||
1c4f3631 ILT |
2462 | // Set the segment flags. This is only used if we have a PHDRS |
2463 | // clause which explicitly specifies the flags. | |
2464 | void | |
2465 | set_flags(elfcpp::Elf_Word flags) | |
2466 | { this->flags_ = flags; } | |
2467 | ||
75f65a3e | 2468 | // Set the address of the segment to ADDR and the offset to *POFF |
a445fddf ILT |
2469 | // and set the addresses and offsets of all contained output |
2470 | // sections accordingly. Set the section indexes of all contained | |
2471 | // output sections starting with *PSHNDX. If RESET is true, first | |
2472 | // reset the addresses of the contained sections. Return the | |
2473 | // address of the immediately following segment. Update *POFF and | |
2474 | // *PSHNDX. This should only be called for a PT_LOAD segment. | |
75f65a3e | 2475 | uint64_t |
a445fddf ILT |
2476 | set_section_addresses(bool reset, uint64_t addr, off_t* poff, |
2477 | unsigned int* pshndx); | |
75f65a3e | 2478 | |
0496d5e5 ILT |
2479 | // Set the minimum alignment of this segment. This may be adjusted |
2480 | // upward based on the section alignments. | |
2481 | void | |
a445fddf ILT |
2482 | set_minimum_p_align(uint64_t align) |
2483 | { this->min_p_align_ = align; } | |
0496d5e5 | 2484 | |
75f65a3e ILT |
2485 | // Set the offset of this segment based on the section. This should |
2486 | // only be called for a non-PT_LOAD segment. | |
2487 | void | |
2488 | set_offset(); | |
2489 | ||
7bf1f802 ILT |
2490 | // Set the TLS offsets of the sections contained in the PT_TLS segment. |
2491 | void | |
2492 | set_tls_offsets(); | |
2493 | ||
75f65a3e ILT |
2494 | // Return the number of output sections. |
2495 | unsigned int | |
2496 | output_section_count() const; | |
a2fb1b05 | 2497 | |
1c4f3631 ILT |
2498 | // Return the section attached to the list segment with the lowest |
2499 | // load address. This is used when handling a PHDRS clause in a | |
2500 | // linker script. | |
2501 | Output_section* | |
2502 | section_with_lowest_load_address() const; | |
2503 | ||
61ba1cf9 ILT |
2504 | // Write the segment header into *OPHDR. |
2505 | template<int size, bool big_endian> | |
2506 | void | |
ead1e424 | 2507 | write_header(elfcpp::Phdr_write<size, big_endian>*); |
61ba1cf9 ILT |
2508 | |
2509 | // Write the section headers of associated sections into V. | |
2510 | template<int size, bool big_endian> | |
2511 | unsigned char* | |
16649710 | 2512 | write_section_headers(const Layout*, const Stringpool*, unsigned char* v, |
ead1e424 | 2513 | unsigned int* pshndx ACCEPT_SIZE_ENDIAN) const; |
61ba1cf9 | 2514 | |
a2fb1b05 ILT |
2515 | private: |
2516 | Output_segment(const Output_segment&); | |
2517 | Output_segment& operator=(const Output_segment&); | |
2518 | ||
54dc6425 | 2519 | typedef std::list<Output_data*> Output_data_list; |
a2fb1b05 | 2520 | |
dbe717ef ILT |
2521 | // Add an Output_section to this segment, specifying front or back. |
2522 | void | |
2523 | add_output_section(Output_section*, elfcpp::Elf_Word seg_flags, | |
2524 | bool front); | |
2525 | ||
ead1e424 ILT |
2526 | // Find the maximum alignment in an Output_data_list. |
2527 | static uint64_t | |
a445fddf | 2528 | maximum_alignment_list(const Output_data_list*); |
ead1e424 | 2529 | |
75f65a3e ILT |
2530 | // Set the section addresses in an Output_data_list. |
2531 | uint64_t | |
a445fddf ILT |
2532 | set_section_list_addresses(bool reset, Output_data_list*, uint64_t addr, |
2533 | off_t* poff, unsigned int* pshndx); | |
75f65a3e ILT |
2534 | |
2535 | // Return the number of Output_sections in an Output_data_list. | |
2536 | unsigned int | |
2537 | output_section_count_list(const Output_data_list*) const; | |
2538 | ||
4f4c5f80 ILT |
2539 | // Return the number of dynamic relocs in an Output_data_list. |
2540 | unsigned int | |
2541 | dynamic_reloc_count_list(const Output_data_list*) const; | |
2542 | ||
1c4f3631 ILT |
2543 | // Find the section with the lowest load address in an |
2544 | // Output_data_list. | |
2545 | void | |
2546 | lowest_load_address_in_list(const Output_data_list* pdl, | |
2547 | Output_section** found, | |
2548 | uint64_t* found_lma) const; | |
2549 | ||
61ba1cf9 ILT |
2550 | // Write the section headers in the list into V. |
2551 | template<int size, bool big_endian> | |
2552 | unsigned char* | |
16649710 ILT |
2553 | write_section_headers_list(const Layout*, const Stringpool*, |
2554 | const Output_data_list*, unsigned char* v, | |
ead1e424 | 2555 | unsigned int* pshdx ACCEPT_SIZE_ENDIAN) const; |
61ba1cf9 | 2556 | |
75f65a3e | 2557 | // The list of output data with contents attached to this segment. |
54dc6425 | 2558 | Output_data_list output_data_; |
75f65a3e ILT |
2559 | // The list of output data without contents attached to this segment. |
2560 | Output_data_list output_bss_; | |
a2fb1b05 ILT |
2561 | // The segment virtual address. |
2562 | uint64_t vaddr_; | |
2563 | // The segment physical address. | |
2564 | uint64_t paddr_; | |
2565 | // The size of the segment in memory. | |
2566 | uint64_t memsz_; | |
a445fddf ILT |
2567 | // The maximum section alignment. The is_max_align_known_ field |
2568 | // indicates whether this has been finalized. | |
2569 | uint64_t max_align_; | |
2570 | // The required minimum value for the p_align field. This is used | |
2571 | // for PT_LOAD segments. Note that this does not mean that | |
2572 | // addresses should be aligned to this value; it means the p_paddr | |
2573 | // and p_vaddr fields must be congruent modulo this value. For | |
2574 | // non-PT_LOAD segments, the dynamic linker works more efficiently | |
2575 | // if the p_align field has the more conventional value, although it | |
2576 | // can align as needed. | |
2577 | uint64_t min_p_align_; | |
a2fb1b05 ILT |
2578 | // The offset of the segment data within the file. |
2579 | off_t offset_; | |
2580 | // The size of the segment data in the file. | |
2581 | off_t filesz_; | |
2582 | // The segment type; | |
2583 | elfcpp::Elf_Word type_; | |
2584 | // The segment flags. | |
2585 | elfcpp::Elf_Word flags_; | |
a445fddf ILT |
2586 | // Whether we have finalized max_align_. |
2587 | bool is_max_align_known_ : 1; | |
2588 | // Whether vaddr and paddr were set by a linker script. | |
2589 | bool are_addresses_set_ : 1; | |
a2fb1b05 ILT |
2590 | }; |
2591 | ||
61ba1cf9 | 2592 | // This class represents the output file. |
a2fb1b05 ILT |
2593 | |
2594 | class Output_file | |
2595 | { | |
2596 | public: | |
14144f39 | 2597 | Output_file(const char* name); |
61ba1cf9 | 2598 | |
516cb3d0 ILT |
2599 | // Indicate that this is a temporary file which should not be |
2600 | // output. | |
2601 | void | |
2602 | set_is_temporary() | |
2603 | { this->is_temporary_ = true; } | |
2604 | ||
61ba1cf9 ILT |
2605 | // Open the output file. FILE_SIZE is the final size of the file. |
2606 | void | |
2607 | open(off_t file_size); | |
2608 | ||
27bc2bce ILT |
2609 | // Resize the output file. |
2610 | void | |
2611 | resize(off_t file_size); | |
2612 | ||
c420411f ILT |
2613 | // Close the output file (flushing all buffered data) and make sure |
2614 | // there are no errors. | |
61ba1cf9 ILT |
2615 | void |
2616 | close(); | |
2617 | ||
2618 | // We currently always use mmap which makes the view handling quite | |
2619 | // simple. In the future we may support other approaches. | |
a2fb1b05 ILT |
2620 | |
2621 | // Write data to the output file. | |
2622 | void | |
fe8718a4 | 2623 | write(off_t offset, const void* data, size_t len) |
61ba1cf9 ILT |
2624 | { memcpy(this->base_ + offset, data, len); } |
2625 | ||
2626 | // Get a buffer to use to write to the file, given the offset into | |
2627 | // the file and the size. | |
2628 | unsigned char* | |
fe8718a4 | 2629 | get_output_view(off_t start, size_t size) |
61ba1cf9 | 2630 | { |
8d32f935 ILT |
2631 | gold_assert(start >= 0 |
2632 | && start + static_cast<off_t>(size) <= this->file_size_); | |
61ba1cf9 ILT |
2633 | return this->base_ + start; |
2634 | } | |
2635 | ||
2636 | // VIEW must have been returned by get_output_view. Write the | |
2637 | // buffer to the file, passing in the offset and the size. | |
2638 | void | |
fe8718a4 | 2639 | write_output_view(off_t, size_t, unsigned char*) |
61ba1cf9 ILT |
2640 | { } |
2641 | ||
730cdc88 ILT |
2642 | // Get a read/write buffer. This is used when we want to write part |
2643 | // of the file, read it in, and write it again. | |
2644 | unsigned char* | |
fe8718a4 | 2645 | get_input_output_view(off_t start, size_t size) |
730cdc88 ILT |
2646 | { return this->get_output_view(start, size); } |
2647 | ||
2648 | // Write a read/write buffer back to the file. | |
2649 | void | |
fe8718a4 | 2650 | write_input_output_view(off_t, size_t, unsigned char*) |
730cdc88 ILT |
2651 | { } |
2652 | ||
2653 | // Get a read buffer. This is used when we just want to read part | |
2654 | // of the file back it in. | |
2655 | const unsigned char* | |
fe8718a4 | 2656 | get_input_view(off_t start, size_t size) |
730cdc88 ILT |
2657 | { return this->get_output_view(start, size); } |
2658 | ||
2659 | // Release a read bfufer. | |
2660 | void | |
fe8718a4 | 2661 | free_input_view(off_t, size_t, const unsigned char*) |
730cdc88 ILT |
2662 | { } |
2663 | ||
61ba1cf9 | 2664 | private: |
c420411f | 2665 | // Map the file into memory and return a pointer to the map. |
27bc2bce ILT |
2666 | void |
2667 | map(); | |
2668 | ||
c420411f ILT |
2669 | // Unmap the file from memory (and flush to disk buffers). |
2670 | void | |
2671 | unmap(); | |
2672 | ||
61ba1cf9 ILT |
2673 | // File name. |
2674 | const char* name_; | |
2675 | // File descriptor. | |
2676 | int o_; | |
2677 | // File size. | |
2678 | off_t file_size_; | |
2679 | // Base of file mapped into memory. | |
2680 | unsigned char* base_; | |
c420411f ILT |
2681 | // True iff base_ points to a memory buffer rather than an output file. |
2682 | bool map_is_anonymous_; | |
516cb3d0 ILT |
2683 | // True if this is a temporary file which should not be output. |
2684 | bool is_temporary_; | |
a2fb1b05 ILT |
2685 | }; |
2686 | ||
2687 | } // End namespace gold. | |
2688 | ||
2689 | #endif // !defined(GOLD_OUTPUT_H) |