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