1 // output.h -- manage the output file for gold -*- C++ -*-
17 template<int size
, bool big_endian
>
20 // An abtract class for data which has to go into the output file.
25 Output_data(off_t size
= 0)
32 // Return the size of the data. This can't be called "size" since
33 // that interferes with the widely used template parameter name.
36 { return this->size_
; }
38 // Write the data to the output file at the specified offset. This
39 // must be implemented by the real class.
41 write(Output_file
*, off_t off
) = 0;
43 // Return whether this is an Output_section of the specified type.
45 is_section_type(elfcpp::Elf_Word
)
48 // Return whether this is an Output_section with the specified flag
51 is_section_flag_set(elfcpp::Elf_Xword
)
55 // Set the size of the data.
58 { this->size_
= size
; }
61 Output_data(const Output_data
&);
62 Output_data
& operator=(const Output_data
&);
64 // Size of data in file.
68 // A simple case of Output_data in which we have constant data to
71 class Output_data_const
: public Output_data
74 Output_data_const(const std::string
& data
)
75 : Output_data(data
.size()), data_(data
)
78 Output_data_const(const char* p
, off_t len
)
79 : Output_data(len
), data_(p
, len
)
82 // Write the data to the file.
84 write(Output_file
* output
, off_t off
);
90 // Output the section headers.
92 class Output_section_headers
: public Output_data
95 Output_section_headers(const Layout::Segment_list
&,
96 const Layout::Section_list
&);
98 // Write the data to the file.
100 write(Output_file
*, off_t
);
103 const Layout::Segment_list
& segment_list_
;
104 const Layout::Section_list
& section_list_
;
107 // Output the segment headers.
109 class Output_segment_headers
: public Output_data
112 Output_segment_headers(const Layout::Segment_list
& segment_list
)
113 : segment_list_(segment_list
)
116 // Write the data to the file.
118 write(Output_file
*, off_t
);
121 const Layout::Segment_list
& segment_list_
;
124 // Output the ELF file header.
126 class Output_file_header
: public Output_data
129 Output_file_header(const General_options
&,
132 const Output_segment_headers
*,
133 const Output_section_headers
*,
134 const Output_section
* shstrtab
);
136 // Write the data to the file.
138 write(Output_file
*, off_t
);
141 const General_options
& options_
;
142 const Target
* target_
;
143 const Symbol_table
* symtab_
;
144 const Output_segment_headers
* program_header_
;
145 const Output_section_headers
* section_header_
;
146 const Output_section
* shstrtab_
;
149 // An output section. We don't expect to have too many output
150 // sections, so we don't bother to do a template on the size.
152 class Output_section
: public Output_data
155 // Create an output section, giving the name, type, and flags.
156 Output_section(const char* name
, elfcpp::Elf_Word
, elfcpp::Elf_Xword
);
157 virtual ~Output_section();
159 // Add a new input section named NAME with header SHDR from object
160 // OBJECT. Return the offset within the output section.
161 template<int size
, bool big_endian
>
163 add_input_section(Object
* object
, const char *name
,
164 const elfcpp::Shdr
<size
, big_endian
>& shdr
);
166 // Return the section name.
169 { return this->name_
; }
171 // Return the section type.
174 { return this->type_
; }
176 // Return the section flags.
179 { return this->flags_
; }
181 // Write the data to the file. For a typical Output_section, this
182 // does nothing. We write out the data by looping over all the
185 write(Output_file
*, off_t
)
188 // Return whether this is a section of the specified type.
190 is_section_type(elfcpp::Elf_Word type
)
191 { return this->type_
== type
; }
193 // Return whether the specified section flag is set.
195 is_section_flag_set(elfcpp::Elf_Xword flag
)
196 { return (this->flags_
& flag
) != 0; }
199 // Most of these fields are only valid after layout.
201 // The name of the section. This will point into a Stringpool.
203 // The section address.
205 // The section alignment.
207 // The section entry size.
211 // The section link field.
213 // The section info field.
216 elfcpp::Elf_Word type_
;
217 // The section flags.
218 elfcpp::Elf_Xword flags_
;
221 // A special Output_section which represents the symbol table
224 class Output_section_symtab
: public Output_section
227 Output_section_symtab();
228 ~Output_section_symtab();
231 // An output segment. PT_LOAD segments are built from collections of
232 // output sections. Other segments typically point within PT_LOAD
233 // segments, and are built directly as needed.
238 // Create an output segment, specifying the type and flags.
239 Output_segment(elfcpp::Elf_Word
, elfcpp::Elf_Word
);
241 // Return the virtual address.
244 { return this->vaddr_
; }
246 // Return the physical address.
249 { return this->paddr_
; }
251 // Return the segment type.
254 { return this->type_
; }
256 // Return the segment flags.
259 { return this->flags_
; }
261 // Add an Output_section to this segment.
263 add_output_section(Output_section
*);
266 Output_segment(const Output_segment
&);
267 Output_segment
& operator=(const Output_segment
&);
269 typedef std::list
<Output_data
*> Output_data_list
;
271 // The list of output sections attached to this segment. This is
272 // cleared after layout.
273 Output_data_list output_data_
;
274 // The segment virtual address.
276 // The segment physical address.
278 // The size of the segment in memory.
280 // The segment alignment.
282 // The offset of the segment data within the file.
284 // The size of the segment data in the file.
287 elfcpp::Elf_Word type_
;
288 // The segment flags.
289 elfcpp::Elf_Word flags_
;
292 // This class represents the output file. The output file is a
293 // collection of output segments and a collection of output sections
294 // which are not associated with segments.
302 // Write data to the output file.
304 write(off_t off
, const void* data
, off_t len
);
307 } // End namespace gold.
309 #endif // !defined(GOLD_OUTPUT_H)