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