2006-09-27 Dave Brolley <brolley@redhat.com>
[deliverable/binutils-gdb.git] / gold / layout.h
CommitLineData
a2fb1b05
ILT
1// layout.h -- lay out output file sections for gold -*- C++ -*-
2
3#ifndef GOLD_LAYOUT_H
4#define GOLD_LAYOUT_H
5
6#include <list>
7#include <string>
8#include <utility>
9#include <vector>
10
11#include "options.h"
12#include "workqueue.h"
13#include "object.h"
14#include "stringpool.h"
15
16namespace gold
17{
18
54dc6425 19class Input_objects;
a2fb1b05 20class Output_section;
54dc6425 21class Output_section_symtab;
a2fb1b05 22class Output_segment;
54dc6425 23class Output_data;
a2fb1b05
ILT
24
25// This Task handles mapping the input sections to output sections and
26// laying them out in memory.
27
28class Layout_task : public Task
29{
30 public:
31 // OPTIONS is the command line options, INPUT_OBJECTS is the list of
32 // input objects, THIS_BLOCKER is a token which blocks this task
33 // from executing until all the input symbols have been read.
54dc6425
ILT
34 Layout_task(const General_options& options,
35 const Input_objects* input_objects,
a2fb1b05
ILT
36 Task_token* this_blocker)
37 : options_(options), input_objects_(input_objects),
38 this_blocker_(this_blocker)
39 { }
40
41 ~Layout_task();
42
43 // The standard Task methods.
44
45 Is_runnable_type
46 is_runnable(Workqueue*);
47
48 Task_locker*
49 locks(Workqueue*);
50
51 void
52 run(Workqueue*);
53
54 private:
55 Layout_task(const Layout_task&);
56 Layout_task& operator=(const Layout_task&);
57
58 const General_options& options_;
54dc6425 59 const Input_objects* input_objects_;
a2fb1b05
ILT
60 Task_token* this_blocker_;
61};
62
63// This class handles the details of laying out input sections.
64
65class Layout
66{
67 public:
54dc6425
ILT
68 Layout(const General_options& options);
69
70 // Initialize the object.
71 void
72 init();
a2fb1b05
ILT
73
74 // Given an input section named NAME with data in SHDR from the
75 // object file OBJECT, return the output section where this input
76 // section should go. Set *OFFSET to the offset within the output
77 // section.
78 template<int size, bool big_endian>
79 Output_section*
80 layout(Object *object, const char* name,
81 const elfcpp::Shdr<size, big_endian>& shdr, off_t* offset);
82
83 // Return whether a section is a .gnu.linkonce section, given the
84 // section name.
85 static inline bool
86 is_linkonce(const char* name)
87 { return strncmp(name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0; }
88
89 // Record the signature of a comdat section, and return whether to
90 // include it in the link. The GROUP parameter is true for a
91 // section group signature, false for a signature derived from a
92 // .gnu.linkonce section.
93 bool
94 add_comdat(const char*, bool group);
95
54dc6425
ILT
96 // Finalize the layout after all the input sections have been added.
97 void
98 finalize(const Input_objects*);
99
100 // The list of segments.
101
102 typedef std::vector<Output_segment*> Segment_list;
103
104 // The list of sections not attached to a segment.
105
106 typedef std::list<Output_section*> Section_list;
107
108 // The list of information to write out which is not attached to
109 // either a section or a segment.
110 typedef std::list<Output_data*> Data_list;
111
a2fb1b05
ILT
112 private:
113 Layout(const Layout&);
114 Layout& operator=(const Layout&);
115
116 // Mapping from .gnu.linkonce section names to output section names.
117 struct Linkonce_mapping
118 {
119 const char* from;
120 int fromlen;
121 const char* to;
122 };
123 static const Linkonce_mapping linkonce_mapping[];
124 static const int linkonce_mapping_count;
125
54dc6425
ILT
126 // Lay out the local symbols from a SHT_SYMTAB section.
127 template<int size, bool big_endian>
128 void
129 add_symtab_locals(Object* object, const elfcpp::Shdr<size, big_endian>&);
130
131 // Create the output sections for the symbol table.
132 void
133 create_symtab_sections();
134
135 // Finalize the symbol table.
136 void
137 finalize_symtab();
138
a2fb1b05
ILT
139 // Return whether to include this section in the link.
140 template<int size, bool big_endian>
141 bool
142 include_section(Object* object, const char* name,
143 const elfcpp::Shdr<size, big_endian>&);
144
145 // Return the output section name to use for a linkonce section
146 // name.
147 static const char*
148 linkonce_output_name(const char* name);
149
150 // Create a new Output_section.
151 Output_section*
152 make_output_section(const char* name, elfcpp::Elf_Word type,
153 elfcpp::Elf_Xword flags);
154
155 // Return whether SEG1 comes before SEG2 in the output file.
156 static bool
b3168e9d 157 segment_precedes(const Output_segment* seg1, const Output_segment* seg2);
a2fb1b05
ILT
158
159 // Map from section flags to segment flags.
160 static elfcpp::Elf_Word
161 section_flags_to_segment(elfcpp::Elf_Xword flags);
162
163 // A mapping used for group signatures.
164 typedef Unordered_map<std::string, bool> Signatures;
165
166 // Mapping from input section name/type/flags to output section. We
167 // use canonicalized strings here.
168
169 typedef std::pair<const char*,
170 std::pair<elfcpp::Elf_Word, elfcpp::Elf_Xword> > Key;
171
172 struct Hash_key
173 {
174 size_t
175 operator()(const Key& k) const;
176 };
177
178 typedef Unordered_map<Key, Output_section*, Hash_key> Section_name_map;
179
180 // A comparison class for segments.
181
182 struct Compare_segments
183 {
184 bool
185 operator()(const Output_segment* seg1, const Output_segment* seg2)
186 { return Layout::segment_precedes(seg1, seg2); }
187 };
188
a2fb1b05
ILT
189 // A reference to the options on the command line.
190 const General_options& options_;
191 // The output section names.
192 Stringpool namepool_;
193 // The list of group sections and linkonce sections which we have seen.
194 Signatures signatures_;
195 // The mapping from input section name/type/flags to output sections.
196 Section_name_map section_name_map_;
197 // The list of output segments.
198 Segment_list segment_list_;
199 // The list of output sections which are not attached to any output
200 // segment.
201 Section_list section_list_;
54dc6425
ILT
202 // The list of output data objects which are not attached to any
203 // output section or output segment.
204 Data_list data_list_;
a2fb1b05
ILT
205};
206
207} // End namespace gold.
208
209#endif // !defined(GOLD_LAYOUT_H)
This page took 0.029892 seconds and 4 git commands to generate.