Rename "process" to "lwp" throughout.
[deliverable/binutils-gdb.git] / gold / layout.h
CommitLineData
a2fb1b05
ILT
1// layout.h -- lay out output file sections for gold -*- C++ -*-
2
8a4c0b0d 3// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
6cb15b7f
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
8// This program is free software; you can redistribute it and/or modify
9// it under the terms of the GNU General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or
11// (at your option) any later version.
12
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21// MA 02110-1301, USA.
22
a2fb1b05
ILT
23#ifndef GOLD_LAYOUT_H
24#define GOLD_LAYOUT_H
25
e94cf127 26#include <cstring>
a2fb1b05
ILT
27#include <list>
28#include <string>
29#include <utility>
30#include <vector>
31
e5756efb 32#include "script.h"
a2fb1b05
ILT
33#include "workqueue.h"
34#include "object.h"
14b31740 35#include "dynobj.h"
a2fb1b05
ILT
36#include "stringpool.h"
37
38namespace gold
39{
40
ead1e424 41class General_options;
54dc6425 42class Input_objects;
7d9e3d98 43class Mapfile;
75f65a3e 44class Symbol_table;
ead1e424 45class Output_section_data;
a2fb1b05 46class Output_section;
75f65a3e 47class Output_section_headers;
a2fb1b05 48class Output_segment;
54dc6425 49class Output_data;
a3ad94ed 50class Output_data_dynamic;
d491d34e 51class Output_symtab_xindex;
62b01cb5
ILT
52class Output_reduced_debug_abbrev_section;
53class Output_reduced_debug_info_section;
730cdc88 54class Eh_frame;
61ba1cf9 55class Target;
a2fb1b05 56
92e059d8
ILT
57// This task function handles mapping the input sections to output
58// sections and laying them out in memory.
a2fb1b05 59
92e059d8 60class Layout_task_runner : public Task_function_runner
a2fb1b05
ILT
61{
62 public:
63 // OPTIONS is the command line options, INPUT_OBJECTS is the list of
92e059d8
ILT
64 // input objects, SYMTAB is the symbol table, LAYOUT is the layout
65 // object.
66 Layout_task_runner(const General_options& options,
67 const Input_objects* input_objects,
68 Symbol_table* symtab,
8851ecca 69 Target* target,
7d9e3d98
ILT
70 Layout* layout,
71 Mapfile* mapfile)
75f65a3e 72 : options_(options), input_objects_(input_objects), symtab_(symtab),
7d9e3d98 73 target_(target), layout_(layout), mapfile_(mapfile)
a2fb1b05
ILT
74 { }
75
92e059d8 76 // Run the operation.
a2fb1b05 77 void
17a1d0a9 78 run(Workqueue*, const Task*);
a2fb1b05
ILT
79
80 private:
92e059d8
ILT
81 Layout_task_runner(const Layout_task_runner&);
82 Layout_task_runner& operator=(const Layout_task_runner&);
a2fb1b05
ILT
83
84 const General_options& options_;
54dc6425 85 const Input_objects* input_objects_;
75f65a3e 86 Symbol_table* symtab_;
8851ecca 87 Target* target_;
12e14209 88 Layout* layout_;
7d9e3d98 89 Mapfile* mapfile_;
a2fb1b05
ILT
90};
91
8a4c0b0d
ILT
92// This struct holds information about the comdat or .gnu.linkonce
93// that will be kept.
94
95struct Kept_section
96{
97 Kept_section()
98 : object(NULL), shndx(0), is_group(false), group_sections(NULL)
99 { }
100 Kept_section(Relobj* a_object, unsigned int a_shndx, bool a_is_group)
101 : object(a_object), shndx(a_shndx), is_group(a_is_group),
102 group_sections(NULL)
103 { }
104
105 typedef Unordered_map<std::string, unsigned int> Comdat_group;
106
107 // The object containing the comdat or .gnu.linkonce.
108 Relobj* object;
109 // Index to the group section for comdats and the section itself for
110 // .gnu.linkonce.
111 unsigned int shndx;
112 // The Kept_sections are values of a mapping, that maps names to
113 // them. This field is true if this struct is associated with the
114 // name of a comdat or .gnu.linkonce, false if it is associated with
115 // the name of a symbol obtained from the .gnu.linkonce.* name
116 // through some heuristics.
117 bool is_group;
118 // For comdats, a map from names of the sections in the group to
119 // indexes in OBJECT_. NULL for .gnu.linkonce.
120 Comdat_group* group_sections;
121};
122
a2fb1b05
ILT
123// This class handles the details of laying out input sections.
124
125class Layout
126{
127 public:
e5756efb 128 Layout(const General_options& options, Script_options*);
54dc6425 129
ead1e424
ILT
130 // Given an input section SHNDX, named NAME, with data in SHDR, from
131 // the object file OBJECT, return the output section where this
730cdc88
ILT
132 // input section should go. RELOC_SHNDX is the index of a
133 // relocation section which applies to this section, or 0 if none,
134 // or -1U if more than one. RELOC_TYPE is the type of the
135 // relocation section if there is one. Set *OFFSET to the offset
136 // within the output section.
a2fb1b05
ILT
137 template<int size, bool big_endian>
138 Output_section*
730cdc88
ILT
139 layout(Sized_relobj<size, big_endian> *object, unsigned int shndx,
140 const char* name, const elfcpp::Shdr<size, big_endian>& shdr,
141 unsigned int reloc_shndx, unsigned int reloc_type, off_t* offset);
142
6a74a719
ILT
143 // Layout an input reloc section when doing a relocatable link. The
144 // section is RELOC_SHNDX in OBJECT, with data in SHDR.
145 // DATA_SECTION is the reloc section to which it refers. RR is the
146 // relocatable information.
147 template<int size, bool big_endian>
148 Output_section*
149 layout_reloc(Sized_relobj<size, big_endian>* object,
150 unsigned int reloc_shndx,
151 const elfcpp::Shdr<size, big_endian>& shdr,
152 Output_section* data_section,
153 Relocatable_relocs* rr);
154
155 // Layout a group section when doing a relocatable link.
156 template<int size, bool big_endian>
157 void
158 layout_group(Symbol_table* symtab,
159 Sized_relobj<size, big_endian>* object,
160 unsigned int group_shndx,
161 const char* group_section_name,
162 const char* signature,
163 const elfcpp::Shdr<size, big_endian>& shdr,
8825ac63
ILT
164 elfcpp::Elf_Word flags,
165 std::vector<unsigned int>* shndxes);
6a74a719 166
730cdc88
ILT
167 // Like layout, only for exception frame sections. OBJECT is an
168 // object file. SYMBOLS is the contents of the symbol table
169 // section, with size SYMBOLS_SIZE. SYMBOL_NAMES is the contents of
170 // the symbol name section, with size SYMBOL_NAMES_SIZE. SHNDX is a
171 // .eh_frame section in OBJECT. SHDR is the section header.
172 // RELOC_SHNDX is the index of a relocation section which applies to
173 // this section, or 0 if none, or -1U if more than one. RELOC_TYPE
174 // is the type of the relocation section if there is one. This
175 // returns the output section, and sets *OFFSET to the offset.
176 template<int size, bool big_endian>
177 Output_section*
178 layout_eh_frame(Sized_relobj<size, big_endian>* object,
179 const unsigned char* symbols,
180 off_t symbols_size,
181 const unsigned char* symbol_names,
182 off_t symbol_names_size,
183 unsigned int shndx,
184 const elfcpp::Shdr<size, big_endian>& shdr,
185 unsigned int reloc_shndx, unsigned int reloc_type,
186 off_t* offset);
a2fb1b05 187
35cdfc9a
ILT
188 // Handle a GNU stack note. This is called once per input object
189 // file. SEEN_GNU_STACK is true if the object file has a
190 // .note.GNU-stack section. GNU_STACK_FLAGS is the section flags
191 // from that section if there was one.
192 void
193 layout_gnu_stack(bool seen_gnu_stack, uint64_t gnu_stack_flags);
194
ead1e424
ILT
195 // Add an Output_section_data to the layout. This is used for
196 // special sections like the GOT section.
9f1d377b 197 Output_section*
ead1e424
ILT
198 add_output_section_data(const char* name, elfcpp::Elf_Word type,
199 elfcpp::Elf_Xword flags,
200 Output_section_data*);
201
a3ad94ed
ILT
202 // Create dynamic sections if necessary.
203 void
9b07f471 204 create_initial_dynamic_sections(Symbol_table*);
a3ad94ed 205
bfd58944
ILT
206 // Define __start and __stop symbols for output sections.
207 void
9b07f471 208 define_section_symbols(Symbol_table*);
bfd58944 209
919ed24c
ILT
210 // Create sections for linker scripts.
211 void
212 create_script_sections()
213 { this->script_options_->create_script_sections(this); }
214
e5756efb
ILT
215 // Define symbols from any linker script.
216 void
9b07f471
ILT
217 define_script_symbols(Symbol_table* symtab)
218 { this->script_options_->add_symbols_to_table(symtab); }
e5756efb 219
755ab8af
ILT
220 // Define symbols for group signatures.
221 void
222 define_group_signatures(Symbol_table*);
223
61ba1cf9
ILT
224 // Return the Stringpool used for symbol names.
225 const Stringpool*
226 sympool() const
227 { return &this->sympool_; }
228
16649710
ILT
229 // Return the Stringpool used for dynamic symbol names and dynamic
230 // tags.
231 const Stringpool*
232 dynpool() const
233 { return &this->dynpool_; }
234
d491d34e
ILT
235 // Return the symtab_xindex section used to hold large section
236 // indexes for the normal symbol table.
237 Output_symtab_xindex*
238 symtab_xindex() const
239 { return this->symtab_xindex_; }
240
241 // Return the dynsym_xindex section used to hold large section
242 // indexes for the dynamic symbol table.
243 Output_symtab_xindex*
244 dynsym_xindex() const
245 { return this->dynsym_xindex_; }
246
a2fb1b05
ILT
247 // Return whether a section is a .gnu.linkonce section, given the
248 // section name.
249 static inline bool
250 is_linkonce(const char* name)
251 { return strncmp(name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0; }
252
e94cf127
CC
253 // Return true if a section is a debugging section.
254 static inline bool
255 is_debug_info_section(const char* name)
256 {
257 // Debugging sections can only be recognized by name.
258 return (strncmp(name, ".debug", sizeof(".debug") - 1) == 0
8a4c0b0d 259 || strncmp(name, ".gnu.linkonce.wi.",
e94cf127
CC
260 sizeof(".gnu.linkonce.wi.") - 1) == 0
261 || strncmp(name, ".line", sizeof(".line") - 1) == 0
262 || strncmp(name, ".stab", sizeof(".stab") - 1) == 0);
263 }
264
8a4c0b0d
ILT
265 // Check if a comdat group or .gnu.linkonce section with the given
266 // NAME is selected for the link. If there is already a section,
267 // *KEPT_SECTION is set to point to the signature and the function
268 // returns false. Otherwise, the CANDIDATE signature is recorded
269 // for this NAME in the layout object, *KEPT_SECTION is set to the
270 // internal copy and the function return false. In some cases, with
271 // CANDIDATE->GROUP_ being false, KEPT_SECTION can point back to
272 // CANDIDATE.
a2fb1b05 273 bool
8a4c0b0d
ILT
274 find_or_add_kept_section(const std::string name,
275 Kept_section* candidate,
276 Kept_section** kept_section);
e94cf127
CC
277
278 // Find the given comdat signature, and return the object and section
279 // index of the kept group.
280 Relobj*
281 find_kept_object(const std::string&, unsigned int*) const;
a2fb1b05 282
54dc6425 283 // Finalize the layout after all the input sections have been added.
75f65a3e 284 off_t
8851ecca 285 finalize(const Input_objects*, Symbol_table*, Target*, const Task*);
17a1d0a9
ILT
286
287 // Return whether any sections require postprocessing.
288 bool
289 any_postprocessing_sections() const
290 { return this->any_postprocessing_sections_; }
54dc6425 291
e44fcf3b
ILT
292 // Return the size of the output file.
293 off_t
294 output_file_size() const
295 { return this->output_file_size_; }
296
16649710
ILT
297 // Return the TLS segment. This will return NULL if there isn't
298 // one.
92e059d8
ILT
299 Output_segment*
300 tls_segment() const
301 { return this->tls_segment_; }
302
16649710
ILT
303 // Return the normal symbol table.
304 Output_section*
305 symtab_section() const
306 {
307 gold_assert(this->symtab_section_ != NULL);
308 return this->symtab_section_;
309 }
310
311 // Return the dynamic symbol table.
312 Output_section*
313 dynsym_section() const
314 {
315 gold_assert(this->dynsym_section_ != NULL);
316 return this->dynsym_section_;
317 }
318
319 // Return the dynamic tags.
320 Output_data_dynamic*
321 dynamic_data() const
322 { return this->dynamic_data_; }
323
730cdc88
ILT
324 // Write out the output sections.
325 void
326 write_output_sections(Output_file* of) const;
327
61ba1cf9
ILT
328 // Write out data not associated with an input file or the symbol
329 // table.
330 void
9025d29d 331 write_data(const Symbol_table*, Output_file*) const;
61ba1cf9 332
730cdc88
ILT
333 // Write out output sections which can not be written until all the
334 // input sections are complete.
335 void
27bc2bce 336 write_sections_after_input_sections(Output_file* of);
730cdc88 337
ead1e424
ILT
338 // Return an output section named NAME, or NULL if there is none.
339 Output_section*
340 find_output_section(const char* name) const;
341
342 // Return an output segment of type TYPE, with segment flags SET set
343 // and segment flags CLEAR clear. Return NULL if there is none.
344 Output_segment*
345 find_output_segment(elfcpp::PT type, elfcpp::Elf_Word set,
346 elfcpp::Elf_Word clear) const;
347
3802b2dd
ILT
348 // Return the number of segments we expect to produce.
349 size_t
350 expected_segment_count() const;
351
535890bb
ILT
352 // Set a flag to indicate that an object file uses the static TLS model.
353 void
354 set_has_static_tls()
355 { this->has_static_tls_ = true; }
356
357 // Return true if any object file uses the static TLS model.
358 bool
359 has_static_tls() const
360 { return this->has_static_tls_; }
361
e5756efb
ILT
362 // Return the options which may be set by a linker script.
363 Script_options*
364 script_options()
365 { return this->script_options_; }
366
367 const Script_options*
368 script_options() const
369 { return this->script_options_; }
d391083d 370
8ed814a9
ILT
371 // Compute and write out the build ID if needed.
372 void
373 write_build_id(Output_file*) const;
374
516cb3d0
ILT
375 // Rewrite output file in binary format.
376 void
377 write_binary(Output_file* in) const;
378
7d9e3d98
ILT
379 // Print output sections to the map file.
380 void
381 print_to_mapfile(Mapfile*) const;
382
ad8f37d1
ILT
383 // Dump statistical information to stderr.
384 void
385 print_stats() const;
386
a445fddf 387 // A list of segments.
54dc6425
ILT
388
389 typedef std::vector<Output_segment*> Segment_list;
390
a445fddf 391 // A list of sections.
54dc6425 392
a3ad94ed 393 typedef std::vector<Output_section*> Section_list;
54dc6425
ILT
394
395 // The list of information to write out which is not attached to
396 // either a section or a segment.
a3ad94ed 397 typedef std::vector<Output_data*> Data_list;
54dc6425 398
a445fddf
ILT
399 // Store the allocated sections into the section list. This is used
400 // by the linker script code.
401 void
402 get_allocated_sections(Section_list*) const;
403
919ed24c
ILT
404 // Make a section for a linker script to hold data.
405 Output_section*
406 make_output_section_for_script(const char* name);
407
a445fddf
ILT
408 // Make a segment. This is used by the linker script code.
409 Output_segment*
410 make_output_segment(elfcpp::Elf_Word type, elfcpp::Elf_Word flags);
411
412 // Return the number of segments.
413 size_t
414 segment_count() const
415 { return this->segment_list_.size(); }
416
417 // Map from section flags to segment flags.
418 static elfcpp::Elf_Word
419 section_flags_to_segment(elfcpp::Elf_Xword flags);
420
154e0e9a
ILT
421 // Attach sections to segments.
422 void
423 attach_sections_to_segments();
424
a2fb1b05
ILT
425 private:
426 Layout(const Layout&);
427 Layout& operator=(const Layout&);
428
429 // Mapping from .gnu.linkonce section names to output section names.
430 struct Linkonce_mapping
431 {
432 const char* from;
433 int fromlen;
434 const char* to;
ead1e424 435 int tolen;
a2fb1b05
ILT
436 };
437 static const Linkonce_mapping linkonce_mapping[];
438 static const int linkonce_mapping_count;
439
755ab8af
ILT
440 // During a relocatable link, a list of group sections and
441 // signatures.
442 struct Group_signature
443 {
444 // The group section.
445 Output_section* section;
446 // The signature.
447 const char* signature;
448
449 Group_signature()
450 : section(NULL), signature(NULL)
451 { }
452
453 Group_signature(Output_section* sectiona, const char* signaturea)
454 : section(sectiona), signature(signaturea)
455 { }
456 };
457 typedef std::vector<Group_signature> Group_signatures;
458
8ed814a9
ILT
459 // Create a .note section, filling in the header.
460 Output_section*
461 create_note(const char* name, int note_type, size_t descsz,
462 bool allocate, size_t* trailing_padding);
463
4f211c8b
ILT
464 // Create a .note section for gold.
465 void
35cdfc9a
ILT
466 create_gold_note();
467
468 // Record whether the stack must be executable.
469 void
470 create_executable_stack_info(const Target*);
4f211c8b 471
8ed814a9
ILT
472 // Create a build ID note if needed.
473 void
474 create_build_id();
475
75f65a3e
ILT
476 // Find the first read-only PT_LOAD segment, creating one if
477 // necessary.
478 Output_segment*
479 find_first_load_seg();
480
7bf1f802
ILT
481 // Count the local symbols in the regular symbol table and the dynamic
482 // symbol table, and build the respective string pools.
483 void
17a1d0a9 484 count_local_symbols(const Task*, const Input_objects*);
7bf1f802 485
54dc6425
ILT
486 // Create the output sections for the symbol table.
487 void
d491d34e
ILT
488 create_symtab_sections(const Input_objects*, Symbol_table*,
489 unsigned int, off_t*);
54dc6425 490
75f65a3e
ILT
491 // Create the .shstrtab section.
492 Output_section*
493 create_shstrtab();
494
495 // Create the section header table.
27bc2bce 496 void
d491d34e 497 create_shdrs(const Output_section* shstrtab_section, off_t*);
54dc6425 498
dbe717ef
ILT
499 // Create the dynamic symbol table.
500 void
9b07f471
ILT
501 create_dynamic_symtab(const Input_objects*, Symbol_table*,
502 Output_section** pdynstr,
14b31740
ILT
503 unsigned int* plocal_dynamic_count,
504 std::vector<Symbol*>* pdynamic_symbols,
505 Versions* versions);
dbe717ef 506
7bf1f802
ILT
507 // Assign offsets to each local portion of the dynamic symbol table.
508 void
509 assign_local_dynsym_offsets(const Input_objects*);
510
a3ad94ed 511 // Finish the .dynamic section and PT_DYNAMIC segment.
dbe717ef 512 void
16649710 513 finish_dynamic_section(const Input_objects*, const Symbol_table*);
dbe717ef
ILT
514
515 // Create the .interp section and PT_INTERP segment.
516 void
517 create_interp(const Target* target);
518
14b31740
ILT
519 // Create the version sections.
520 void
9025d29d 521 create_version_sections(const Versions*,
46fe1623 522 const Symbol_table*,
14b31740
ILT
523 unsigned int local_symcount,
524 const std::vector<Symbol*>& dynamic_symbols,
525 const Output_section* dynstr);
526
527 template<int size, bool big_endian>
528 void
529 sized_create_version_sections(const Versions* versions,
46fe1623 530 const Symbol_table*,
14b31740
ILT
531 unsigned int local_symcount,
532 const std::vector<Symbol*>& dynamic_symbols,
7d1a9ebb 533 const Output_section* dynstr);
14b31740 534
a2fb1b05
ILT
535 // Return whether to include this section in the link.
536 template<int size, bool big_endian>
537 bool
730cdc88 538 include_section(Sized_relobj<size, big_endian>* object, const char* name,
a2fb1b05
ILT
539 const elfcpp::Shdr<size, big_endian>&);
540
ead1e424
ILT
541 // Return the output section name to use given an input section
542 // name. Set *PLEN to the length of the name. *PLEN must be
543 // initialized to the length of NAME.
544 static const char*
545 output_section_name(const char* name, size_t* plen);
546
a2fb1b05 547 // Return the output section name to use for a linkonce section
ead1e424 548 // name. PLEN is as for output_section_name.
a2fb1b05 549 static const char*
ead1e424
ILT
550 linkonce_output_name(const char* name, size_t* plen);
551
d491d34e
ILT
552 // Return the number of allocated output sections.
553 size_t
554 allocated_output_section_count() const;
555
ead1e424
ILT
556 // Return the output section for NAME, TYPE and FLAGS.
557 Output_section*
f0641a0b
ILT
558 get_output_section(const char* name, Stringpool::Key name_key,
559 elfcpp::Elf_Word type, elfcpp::Elf_Xword flags);
a2fb1b05 560
a445fddf
ILT
561 // Choose the output section for NAME in RELOBJ.
562 Output_section*
563 choose_output_section(const Relobj* relobj, const char* name,
564 elfcpp::Elf_Word type, elfcpp::Elf_Xword flags,
154e0e9a 565 bool is_input_section);
a445fddf 566
a2fb1b05
ILT
567 // Create a new Output_section.
568 Output_section*
569 make_output_section(const char* name, elfcpp::Elf_Word type,
570 elfcpp::Elf_Xword flags);
571
4e2b1697
ILT
572 // Attach a section to a segment.
573 void
154e0e9a 574 attach_section_to_segment(Output_section*);
4e2b1697 575
154e0e9a 576 // Attach an allocated section to a segment.
1650c4ff 577 void
154e0e9a 578 attach_allocated_section_to_segment(Output_section*);
1650c4ff 579
dbe717ef
ILT
580 // Set the final file offsets of all the segments.
581 off_t
582 set_segment_offsets(const Target*, Output_segment*, unsigned int* pshndx);
583
6a74a719
ILT
584 // Set the file offsets of the sections when doing a relocatable
585 // link.
586 off_t
587 set_relocatable_section_offsets(Output_data*, unsigned int* pshndx);
588
86887060 589 // Set the final file offsets of all the sections not associated
9a0910c3
ILT
590 // with a segment. We set section offsets in three passes: the
591 // first handles all allocated sections, the second sections that
17a1d0a9
ILT
592 // require postprocessing, and the last the late-bound STRTAB
593 // sections (probably only shstrtab, which is the one we care about
594 // because it holds section names).
9a0910c3
ILT
595 enum Section_offset_pass
596 {
597 BEFORE_INPUT_SECTIONS_PASS,
17a1d0a9
ILT
598 POSTPROCESSING_SECTIONS_PASS,
599 STRTAB_AFTER_POSTPROCESSING_SECTIONS_PASS
9a0910c3 600 };
dbe717ef 601 off_t
9a0910c3
ILT
602 set_section_offsets(off_t, Section_offset_pass pass);
603
86887060
ILT
604 // Set the final section indexes of all the sections not associated
605 // with a segment. Returns the next unused index.
606 unsigned int
607 set_section_indexes(unsigned int pshndx);
dbe717ef 608
a445fddf
ILT
609 // Set the section addresses when using a script.
610 Output_segment*
611 set_section_addresses_from_script(Symbol_table*);
612
a2fb1b05
ILT
613 // Return whether SEG1 comes before SEG2 in the output file.
614 static bool
b3168e9d 615 segment_precedes(const Output_segment* seg1, const Output_segment* seg2);
a2fb1b05 616
8a4c0b0d 617 // A mapping used for kept comdats/.gnu.linkonce group signatures.
e94cf127 618 typedef Unordered_map<std::string, Kept_section> Signatures;
a2fb1b05
ILT
619
620 // Mapping from input section name/type/flags to output section. We
621 // use canonicalized strings here.
622
f0641a0b 623 typedef std::pair<Stringpool::Key,
a2fb1b05
ILT
624 std::pair<elfcpp::Elf_Word, elfcpp::Elf_Xword> > Key;
625
626 struct Hash_key
627 {
628 size_t
629 operator()(const Key& k) const;
630 };
631
632 typedef Unordered_map<Key, Output_section*, Hash_key> Section_name_map;
633
634 // A comparison class for segments.
635
636 struct Compare_segments
637 {
638 bool
639 operator()(const Output_segment* seg1, const Output_segment* seg2)
640 { return Layout::segment_precedes(seg1, seg2); }
641 };
642
a2fb1b05
ILT
643 // A reference to the options on the command line.
644 const General_options& options_;
e5756efb
ILT
645 // Information set by scripts or by command line options.
646 Script_options* script_options_;
a2fb1b05
ILT
647 // The output section names.
648 Stringpool namepool_;
75f65a3e
ILT
649 // The output symbol names.
650 Stringpool sympool_;
a3ad94ed
ILT
651 // The dynamic strings, if needed.
652 Stringpool dynpool_;
a2fb1b05
ILT
653 // The list of group sections and linkonce sections which we have seen.
654 Signatures signatures_;
655 // The mapping from input section name/type/flags to output sections.
656 Section_name_map section_name_map_;
657 // The list of output segments.
658 Segment_list segment_list_;
a3ad94ed
ILT
659 // The list of output sections.
660 Section_list section_list_;
a2fb1b05
ILT
661 // The list of output sections which are not attached to any output
662 // segment.
a3ad94ed 663 Section_list unattached_section_list_;
154e0e9a
ILT
664 // Whether we have attached the sections to the segments.
665 bool sections_are_attached_;
a3ad94ed
ILT
666 // The list of unattached Output_data objects which require special
667 // handling because they are not Output_sections.
61ba1cf9 668 Data_list special_output_list_;
27bc2bce
ILT
669 // The section headers.
670 Output_section_headers* section_headers_;
92e059d8
ILT
671 // A pointer to the PT_TLS segment if there is one.
672 Output_segment* tls_segment_;
9f1d377b
ILT
673 // A pointer to the PT_GNU_RELRO segment if there is one.
674 Output_segment* relro_segment_;
a3ad94ed
ILT
675 // The SHT_SYMTAB output section.
676 Output_section* symtab_section_;
d491d34e
ILT
677 // The SHT_SYMTAB_SHNDX for the regular symbol table if there is one.
678 Output_symtab_xindex* symtab_xindex_;
a3ad94ed
ILT
679 // The SHT_DYNSYM output section if there is one.
680 Output_section* dynsym_section_;
d491d34e
ILT
681 // The SHT_SYMTAB_SHNDX for the dynamic symbol table if there is one.
682 Output_symtab_xindex* dynsym_xindex_;
a3ad94ed
ILT
683 // The SHT_DYNAMIC output section if there is one.
684 Output_section* dynamic_section_;
16649710
ILT
685 // The dynamic data which goes into dynamic_section_.
686 Output_data_dynamic* dynamic_data_;
730cdc88 687 // The exception frame output section if there is one.
3151305a 688 Output_section* eh_frame_section_;
730cdc88
ILT
689 // The exception frame data for eh_frame_section_.
690 Eh_frame* eh_frame_data_;
2c38906f
ILT
691 // Whether we have added eh_frame_data_ to the .eh_frame section.
692 bool added_eh_frame_data_;
730cdc88
ILT
693 // The exception frame header output section if there is one.
694 Output_section* eh_frame_hdr_section_;
8ed814a9
ILT
695 // The space for the build ID checksum if there is one.
696 Output_section_data* build_id_note_;
62b01cb5
ILT
697 // The output section containing dwarf abbreviations
698 Output_reduced_debug_abbrev_section* debug_abbrev_;
699 // The output section containing the dwarf debug info tree
700 Output_reduced_debug_info_section* debug_info_;
755ab8af
ILT
701 // A list of group sections and their signatures.
702 Group_signatures group_signatures_;
e44fcf3b
ILT
703 // The size of the output file.
704 off_t output_file_size_;
35cdfc9a
ILT
705 // Whether we have seen an object file marked to require an
706 // executable stack.
707 bool input_requires_executable_stack_;
708 // Whether we have seen at least one object file with an executable
709 // stack marker.
710 bool input_with_gnu_stack_note_;
711 // Whether we have seen at least one object file without an
712 // executable stack marker.
713 bool input_without_gnu_stack_note_;
535890bb
ILT
714 // Whether we have seen an object file that uses the static TLS model.
715 bool has_static_tls_;
17a1d0a9
ILT
716 // Whether any sections require postprocessing.
717 bool any_postprocessing_sections_;
61ba1cf9
ILT
718};
719
730cdc88
ILT
720// This task handles writing out data in output sections which is not
721// part of an input section, or which requires special handling. When
722// this is done, it unblocks both output_sections_blocker and
723// final_blocker.
724
725class Write_sections_task : public Task
726{
727 public:
728 Write_sections_task(const Layout* layout, Output_file* of,
729 Task_token* output_sections_blocker,
730 Task_token* final_blocker)
731 : layout_(layout), of_(of),
732 output_sections_blocker_(output_sections_blocker),
733 final_blocker_(final_blocker)
734 { }
735
736 // The standard Task methods.
737
17a1d0a9
ILT
738 Task_token*
739 is_runnable();
730cdc88 740
17a1d0a9
ILT
741 void
742 locks(Task_locker*);
730cdc88
ILT
743
744 void
745 run(Workqueue*);
746
c7912668
ILT
747 std::string
748 get_name() const
749 { return "Write_sections_task"; }
750
730cdc88
ILT
751 private:
752 class Write_sections_locker;
753
754 const Layout* layout_;
755 Output_file* of_;
756 Task_token* output_sections_blocker_;
757 Task_token* final_blocker_;
758};
759
61ba1cf9
ILT
760// This task handles writing out data which is not part of a section
761// or segment.
762
763class Write_data_task : public Task
764{
765 public:
a3ad94ed 766 Write_data_task(const Layout* layout, const Symbol_table* symtab,
9025d29d
ILT
767 Output_file* of, Task_token* final_blocker)
768 : layout_(layout), symtab_(symtab), of_(of), final_blocker_(final_blocker)
61ba1cf9
ILT
769 { }
770
771 // The standard Task methods.
772
17a1d0a9
ILT
773 Task_token*
774 is_runnable();
61ba1cf9 775
17a1d0a9
ILT
776 void
777 locks(Task_locker*);
61ba1cf9
ILT
778
779 void
780 run(Workqueue*);
781
c7912668
ILT
782 std::string
783 get_name() const
784 { return "Write_data_task"; }
785
61ba1cf9
ILT
786 private:
787 const Layout* layout_;
a3ad94ed 788 const Symbol_table* symtab_;
61ba1cf9
ILT
789 Output_file* of_;
790 Task_token* final_blocker_;
791};
792
793// This task handles writing out the global symbols.
794
795class Write_symbols_task : public Task
796{
797 public:
d491d34e 798 Write_symbols_task(const Layout* layout, const Symbol_table* symtab,
9a2d6984 799 const Input_objects* input_objects,
16649710
ILT
800 const Stringpool* sympool, const Stringpool* dynpool,
801 Output_file* of, Task_token* final_blocker)
d491d34e
ILT
802 : layout_(layout), symtab_(symtab), input_objects_(input_objects),
803 sympool_(sympool), dynpool_(dynpool), of_(of),
804 final_blocker_(final_blocker)
61ba1cf9
ILT
805 { }
806
807 // The standard Task methods.
808
17a1d0a9
ILT
809 Task_token*
810 is_runnable();
61ba1cf9 811
17a1d0a9
ILT
812 void
813 locks(Task_locker*);
61ba1cf9
ILT
814
815 void
816 run(Workqueue*);
817
c7912668
ILT
818 std::string
819 get_name() const
820 { return "Write_symbols_task"; }
821
61ba1cf9 822 private:
d491d34e 823 const Layout* layout_;
61ba1cf9 824 const Symbol_table* symtab_;
9a2d6984 825 const Input_objects* input_objects_;
61ba1cf9 826 const Stringpool* sympool_;
16649710 827 const Stringpool* dynpool_;
61ba1cf9
ILT
828 Output_file* of_;
829 Task_token* final_blocker_;
830};
831
730cdc88
ILT
832// This task handles writing out data in output sections which can't
833// be written out until all the input sections have been handled.
834// This is for sections whose contents is based on the contents of
835// other output sections.
836
837class Write_after_input_sections_task : public Task
838{
839 public:
27bc2bce 840 Write_after_input_sections_task(Layout* layout, Output_file* of,
730cdc88
ILT
841 Task_token* input_sections_blocker,
842 Task_token* final_blocker)
843 : layout_(layout), of_(of),
844 input_sections_blocker_(input_sections_blocker),
845 final_blocker_(final_blocker)
846 { }
847
848 // The standard Task methods.
849
17a1d0a9
ILT
850 Task_token*
851 is_runnable();
730cdc88 852
17a1d0a9
ILT
853 void
854 locks(Task_locker*);
730cdc88
ILT
855
856 void
857 run(Workqueue*);
858
c7912668
ILT
859 std::string
860 get_name() const
861 { return "Write_after_input_sections_task"; }
862
730cdc88 863 private:
27bc2bce 864 Layout* layout_;
730cdc88
ILT
865 Output_file* of_;
866 Task_token* input_sections_blocker_;
867 Task_token* final_blocker_;
868};
869
92e059d8 870// This task function handles closing the file.
61ba1cf9 871
92e059d8 872class Close_task_runner : public Task_function_runner
61ba1cf9
ILT
873{
874 public:
516cb3d0
ILT
875 Close_task_runner(const General_options* options, const Layout* layout,
876 Output_file* of)
877 : options_(options), layout_(layout), of_(of)
61ba1cf9
ILT
878 { }
879
92e059d8 880 // Run the operation.
61ba1cf9 881 void
17a1d0a9 882 run(Workqueue*, const Task*);
61ba1cf9
ILT
883
884 private:
516cb3d0
ILT
885 const General_options* options_;
886 const Layout* layout_;
61ba1cf9 887 Output_file* of_;
a2fb1b05
ILT
888};
889
ead1e424
ILT
890// A small helper function to align an address.
891
892inline uint64_t
893align_address(uint64_t address, uint64_t addralign)
894{
895 if (addralign != 0)
896 address = (address + addralign - 1) &~ (addralign - 1);
897 return address;
898}
899
a2fb1b05
ILT
900} // End namespace gold.
901
902#endif // !defined(GOLD_LAYOUT_H)
This page took 0.162931 seconds and 4 git commands to generate.