1 // output.h -- manage the output file for gold -*- C++ -*-
16 // An abtract class for data which has to go into the output file
17 // which is not associated with any input section.
22 Output_data(off_t size = 0)
29 // Return the size of the data.
32 { return this->size_; }
34 // Write the data to the output file at the specified offset. This
35 // must be implemented by the real class.
37 write(Output_file*, off_t off) = 0;
40 // Set the size of the data.
43 { this->size_ = size; }
46 Output_data(const Output_data&);
47 Output_data& operator=(const Output_data&);
49 // Size of data in file.
53 // A simple cass of Output_data in which we have constant data to
56 class Output_data_const : public Output_data
59 Output_data_const(const std::string& data)
60 : Output_data(data.size()), data_(data)
63 Output_data_const(const char* p, off_t len)
64 : Output_data(len), data_(p, len)
68 write(Output_file* output, off_t off);
74 // An output section. We don't expect to have too many output
75 // sections, so we don't bother to do a template on the size.
80 // Create an output section, giving the name, type, and flags.
81 Output_section(const char* name, elfcpp::Elf_Word, elfcpp::Elf_Xword);
84 // Add a new input section named NAME with header SHDR from object
85 // OBJECT. Return the offset within the output section.
86 template<int size, bool big_endian>
88 add_input_section(Object* object, const char *name,
89 const elfcpp::Shdr<size, big_endian>& shdr);
91 // Return the section name.
94 { return this->name_; }
96 // Return the section type.
99 { return this->type_; }
101 // Return the section flags.
104 { return this->flags_; }
107 // Most of these fields are only valid after layout.
109 // The name of the section. This will point into a Stringpool.
111 // The section address.
113 // The section alignment.
115 // The section entry size.
121 // The section link field.
123 // The section info field.
126 elfcpp::Elf_Word type_;
127 // The section flags.
128 elfcpp::Elf_Xword flags_;
131 // An output segment. PT_LOAD segments are built from collections of
132 // output sections. Other segments typically point within PT_LOAD
133 // segments, and are built directly as needed.
138 // Create an output segment, specifying the type and flags.
139 Output_segment(elfcpp::Elf_Word, elfcpp::Elf_Word);
141 // Return the virtual address.
144 { return this->vaddr_; }
146 // Return the physical address.
149 { return this->paddr_; }
151 // Return the segment type.
154 { return this->type_; }
156 // Return the segment flags.
159 { return this->flags_; }
161 // Add an Output_section to this segment.
163 add_output_section(Output_section*);
165 // Update the segment flags to be compatible with FLAGS.
167 update_flags(elfcpp::Elf_Word flags)
168 { this->flags_ |= flags & (elfcpp::PF_R | elfcpp::PF_W | elfcpp::PF_X); }
171 Output_segment(const Output_segment&);
172 Output_segment& operator=(const Output_segment&);
174 typedef std::list<Output_section*> Section_list;
176 // The list of output sections attached to this segment. This is
177 // cleared after layout.
178 Section_list output_sections_;
179 // The segment virtual address.
181 // The segment physical address.
183 // The size of the segment in memory.
185 // The segment alignment.
187 // The offset of the segment data within the file.
189 // The size of the segment data in the file.
192 elfcpp::Elf_Word type_;
193 // The segment flags.
194 elfcpp::Elf_Word flags_;
197 // This class represents the output file. The output file is a
198 // collection of output segments and a collection of output sections
199 // which are not associated with segments.
207 // Write data to the output file.
209 write(off_t off, const void* data, off_t len);
212 } // End namespace gold.
214 #endif // !defined(GOLD_OUTPUT_H)