* elf32-spu.c (mark_functions_via_relocs): Handle cycles in the
[binutils.git] / gold / script-sections.h
blob390c35089678cb301ae3c08f8ead73b84dc2e512
1 // script-sections.h -- linker script SECTIONS for gold -*- C++ -*-
3 // Copyright 2008, 2009 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
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.
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.
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.
23 // This is for the support of the SECTIONS clause in linker scripts.
25 #ifndef GOLD_SCRIPT_SECTIONS_H
26 #define GOLD_SCRIPT_SECTIONS_H
28 #include <cstdio>
29 #include <list>
30 #include <vector>
32 namespace gold
35 struct Parser_output_section_header;
36 struct Parser_output_section_trailer;
37 struct Input_section_spec;
38 class Expression;
39 class Sections_element;
40 class Phdrs_element;
41 class Output_data;
42 class Output_section_definition;
43 class Output_section;
44 class Output_segment;
45 class Orphan_section_placement;
47 class Script_sections
49 private:
50 // This is a list, not a vector, because we insert orphan sections
51 // in the middle.
52 typedef std::list<Sections_element*> Sections_elements;
54 public:
55 Script_sections();
57 // Start a SECTIONS clause.
58 void
59 start_sections();
61 // Finish a SECTIONS clause.
62 void
63 finish_sections();
65 // Return whether we ever saw a SECTIONS clause. If we did, then
66 // all section layout needs to go through this class.
67 bool
68 saw_sections_clause() const
69 { return this->saw_sections_clause_; }
71 // Return whether we are currently processing a SECTIONS clause.
72 bool
73 in_sections_clause() const
74 { return this->in_sections_clause_; }
76 // Return whether we ever saw a PHDRS clause. We ignore the PHDRS
77 // clause unless we also saw a SECTIONS clause.
78 bool
79 saw_phdrs_clause() const
80 { return this->saw_sections_clause_ && this->phdrs_elements_ != NULL; }
82 // Start processing entries for an output section.
83 void
84 start_output_section(const char* name, size_t namelen,
85 const Parser_output_section_header*);
87 // Finish processing entries for an output section.
88 void
89 finish_output_section(const Parser_output_section_trailer*);
91 // Add a data item to the current output section.
92 void
93 add_data(int size, bool is_signed, Expression* val);
95 // Add a symbol to be defined.
96 void
97 add_symbol_assignment(const char* name, size_t length, Expression* value,
98 bool provide, bool hidden);
100 // Add an assignment to the special dot symbol.
101 void
102 add_dot_assignment(Expression* value);
104 // Add an assertion.
105 void
106 add_assertion(Expression* check, const char* message, size_t messagelen);
108 // Add a setting for the fill value.
109 void
110 add_fill(Expression* val);
112 // Add an input section specification.
113 void
114 add_input_section(const Input_section_spec* spec, bool keep);
116 // Saw DATA_SEGMENT_ALIGN.
117 void
118 data_segment_align();
120 // Saw DATA_SEGMENT_RELRO_END.
121 void
122 data_segment_relro_end();
124 // Create any required sections.
125 void
126 create_sections(Layout*);
128 // Add any symbols we are defining to the symbol table.
129 void
130 add_symbols_to_table(Symbol_table*);
132 // Finalize symbol values and check assertions.
133 void
134 finalize_symbols(Symbol_table* symtab, const Layout* layout);
136 // Find the name of the output section to use for an input file name
137 // and section name. This returns a name, and sets
138 // *OUTPUT_SECTION_SLOT to point to the address where the actual
139 // output section may be stored.
140 // 1) If the input section should be discarded, this returns NULL
141 // and sets *OUTPUT_SECTION_SLOT to NULL.
142 // 2) If the input section is mapped by the SECTIONS clause, this
143 // returns the name to use for the output section (in permanent
144 // storage), and sets *OUTPUT_SECTION_SLOT to point to where the
145 // output section should be stored. **OUTPUT_SECTION_SLOT will be
146 // non-NULL if we have seen this output section already.
147 // 3) If the input section is not mapped by the SECTIONS clause,
148 // this returns SECTION_NAME, and sets *OUTPUT_SECTION_SLOT to
149 // NULL.
150 const char*
151 output_section_name(const char* file_name, const char* section_name,
152 Output_section*** output_section_slot);
154 // Place a marker for an orphan output section into the SECTIONS
155 // clause.
156 void
157 place_orphan(Output_section* os);
159 // Set the addresses of all the output sections. Return the segment
160 // which holds the file header and segment headers, if any.
161 Output_segment*
162 set_section_addresses(Symbol_table*, Layout*);
164 // Add a program header definition.
165 void
166 add_phdr(const char* name, size_t namelen, unsigned int type,
167 bool filehdr, bool phdrs, bool is_flags_valid, unsigned int flags,
168 Expression* load_address);
170 // Return the number of segments we expect to create based on the
171 // SECTIONS clause.
172 size_t
173 expected_segment_count(const Layout*) const;
175 // Add the file header and segment header to non-load segments as
176 // specified by the PHDRS clause.
177 void
178 put_headers_in_phdrs(Output_data* file_header, Output_data* segment_headers);
180 // Look for an output section by name and return the address, the
181 // load address, the alignment, and the size. This is used when an
182 // expression refers to an output section which was not actually
183 // created. This returns true if the section was found, false
184 // otherwise.
185 bool
186 get_output_section_info(const char* name, uint64_t* address,
187 uint64_t* load_address, uint64_t* addralign,
188 uint64_t* size) const;
190 // Print the contents to the FILE. This is for debugging.
191 void
192 print(FILE*) const;
194 // Used for orphan sections.
195 typedef Sections_elements::iterator Elements_iterator;
197 private:
198 typedef std::vector<Phdrs_element*> Phdrs_elements;
200 // Create segments.
201 Output_segment*
202 create_segments(Layout*);
204 // Create PT_NOTE and PT_TLS segments.
205 void
206 create_note_and_tls_segments(Layout*, const std::vector<Output_section*>*);
208 // Return whether the section is a BSS section.
209 static bool
210 is_bss_section(const Output_section*);
212 // Return the total size of the headers.
213 size_t
214 total_header_size(Layout* layout) const;
216 // Return the amount we have to subtract from the LMA to accomodate
217 // headers of the given size.
218 uint64_t
219 header_size_adjustment(uint64_t lma, size_t sizeof_headers) const;
221 // Create the segments from a PHDRS clause.
222 Output_segment*
223 create_segments_from_phdrs_clause(Layout* layout);
225 // Attach sections to segments from a PHDRS clause.
226 void
227 attach_sections_using_phdrs_clause(Layout*);
229 // Set addresses of segments from a PHDRS clause.
230 Output_segment*
231 set_phdrs_clause_addresses(Layout*);
233 // True if we ever saw a SECTIONS clause.
234 bool saw_sections_clause_;
235 // True if we are currently processing a SECTIONS clause.
236 bool in_sections_clause_;
237 // The list of elements in the SECTIONS clause.
238 Sections_elements* sections_elements_;
239 // The current output section, if there is one.
240 Output_section_definition* output_section_;
241 // The list of program headers in the PHDRS clause.
242 Phdrs_elements* phdrs_elements_;
243 // Where to put orphan sections.
244 Orphan_section_placement* orphan_section_placement_;
245 // A pointer to the last Sections_element when we see
246 // DATA_SEGMENT_ALIGN.
247 Sections_elements::iterator data_segment_align_start_;
248 // Whether we have seen DATA_SEGMENT_ALIGN.
249 bool saw_data_segment_align_;
250 // Whether we have seen DATA_SEGMENT_RELRO_END.
251 bool saw_relro_end_;
254 } // End namespace gold.
256 #endif // !defined(GOLD_SCRIPT_SECTIONS_H