1 // object.h -- support for an object file for linking in gold -*- C++ -*-
20 // Data to pass from read_symbols() to add_symbols().
22 struct Read_symbols_data
26 // Size of symbol data in bytes.
28 // Index of first global symbol.
29 unsigned int first_global
;
31 File_view
* symbol_names
;
32 // Size of symbol name data in bytes.
33 off_t symbol_names_size
;
36 // Object is an interface which represents either a 32-bit or a 64-bit
37 // input object. This can be a regular object file (ET_REL) or a
38 // shared object (ET_DYN). The actual instantiations are
39 // Sized_object<32> and Sized_object<64>
44 // NAME is the name of the object as we would report it to the user
45 // (e.g., libfoo.a(bar.o) if this is in an archive. INPUT_FILE is
46 // used to read the file. OFFSET is the offset within the input
47 // file--0 for a .o or .so file, something else for a .a file.
48 Object(const std::string
& name
, Input_file
* input_file
, bool is_dynamic
,
50 : name_(name
), input_file_(input_file
), offset_(offset
),
51 shnum_(0), is_dynamic_(is_dynamic
), target_(NULL
),
58 // Return the name of the object as we would report it to the tuser.
61 { return this->name_
; }
63 // Return whether this is a dynamic object.
66 { return this->is_dynamic_
; }
68 // Return the target structure associated with this object.
71 { return this->target_
; }
73 // Lock the underlying file.
76 { this->input_file_
->file().lock(); }
78 // Unlock the underlying file.
81 { this->input_file_
->file().unlock(); }
83 // Return whether the underlying file is locked.
86 { return this->input_file_
->file().is_locked(); }
88 // Return the sized target structure associated with this object.
89 // This is like the target method but it returns a pointer of
90 // appropriate checked type.
91 template<int size
, bool big_endian
>
92 Sized_target
<size
, big_endian
>*
95 // Read the symbol and relocation information.
98 { return this->do_read_symbols(); }
100 // Add symbol information to the global symbol table.
102 add_symbols(Symbol_table
* symtab
, Read_symbols_data rd
)
103 { this->do_add_symbols(symtab
, rd
); }
105 // Pass sections which should be included in the link to the Layout
106 // object, and record where the sections go in the output file.
109 { this->do_layout(lay
); }
112 // What we need to know to map an input section to an output
113 // section. We keep an array of these, one for each input section,
114 // indexed by the input section number.
117 // The output section. This is NULL if the input section is to be
119 Output_section
* output_section
;
120 // The offset within the output section.
124 // Read the symbols--implemented by child class.
125 virtual Read_symbols_data
126 do_read_symbols() = 0;
128 // Add symbol information to the global symbol table--implemented by
131 do_add_symbols(Symbol_table
*, Read_symbols_data
) = 0;
133 // Lay out sections--implemented by child class.
135 do_layout(Layout
*) = 0;
140 { return this->input_file_
; }
142 // Get the offset into the file.
145 { return this->offset_
; }
147 // Get a view into the underlying file.
149 get_view(off_t start
, off_t size
);
151 // Get the number of sections.
154 { return this->shnum_
; }
156 // Set the number of sections.
159 { this->shnum_
= shnum
; }
163 set_target(Target
* target
)
164 { this->target_
= target
; }
166 // Read data from the underlying file.
168 read(off_t start
, off_t size
, void* p
);
170 // Get a lasting view into the underlying file.
172 get_lasting_view(off_t start
, off_t size
);
174 // Return the vector mapping input sections to output sections.
175 std::vector
<Map_to_output
>&
177 { return this->map_to_output_
; }
180 // This class may not be copied.
181 Object(const Object
&);
182 Object
& operator=(const Object
&);
184 // Name of object as printed to use.
186 // For reading the file.
187 Input_file
* input_file_
;
188 // Offset within the file--0 for an object file, non-0 for an
191 // Number of input sections.
193 // Whether this is a dynamic object.
195 // Target functions--may be NULL if the target is not known.
197 // Mapping from input sections to output section.
198 std::vector
<Map_to_output
> map_to_output_
;
201 // Implement sized_target inline for efficiency. This approach breaks
202 // static type checking, but is made safe using asserts.
204 template<int size
, bool big_endian
>
205 inline Sized_target
<size
, big_endian
>*
206 Object::sized_target()
208 assert(this->target_
->get_size() == size
);
209 assert(this->target_
->is_big_endian() ? big_endian
: !big_endian
);
210 return static_cast<Sized_target
<size
, big_endian
>*>(this->target_
);
213 // A regular object file. This is size and endian specific.
215 template<int size
, bool big_endian
>
216 class Sized_object
: public Object
219 Sized_object(const std::string
& name
, Input_file
* input_file
, off_t offset
,
220 const typename
elfcpp::Ehdr
<size
, big_endian
>&);
224 // Set up the object file based on the ELF header.
226 setup(const typename
elfcpp::Ehdr
<size
, big_endian
>&);
232 // Add the symbols to the symbol table.
234 do_add_symbols(Symbol_table
*, Read_symbols_data
);
236 // Lay out the input sections.
240 // Return the appropriate Sized_target structure.
241 Sized_target
<size
, big_endian
>*
243 { return this->Object::sized_target
<size
, big_endian
>(); }
246 // This object may not be copied.
247 Sized_object(const Sized_object
&);
248 Sized_object
& operator=(const Sized_object
&);
251 typedef Sized_object
<size
, big_endian
> This
;
252 static const int ehdr_size
= elfcpp::Elf_sizes
<size
>::ehdr_size
;
253 static const int shdr_size
= elfcpp::Elf_sizes
<size
>::shdr_size
;
254 static const int sym_size
= elfcpp::Elf_sizes
<size
>::sym_size
;
256 // Whether to include a section group in the link.
258 include_section_group(Layout
*, unsigned int,
259 const elfcpp::Shdr
<size
, big_endian
>&,
262 // Whether to include a linkonce section in the link.
264 include_linkonce_section(Layout
*, const char*,
265 const elfcpp::Shdr
<size
, big_endian
>&);
267 // ELF file header e_flags field.
269 // File offset of section header table.
271 // Offset of SHT_STRTAB section holding section names.
272 unsigned int shstrndx_
;
273 // Index of SHT_SYMTAB section.
274 unsigned int symtab_shnum_
;
275 // The entries in the symbol table for the external symbols.
279 // A class to manage the list of all objects.
288 // The type of the list of input objects.
289 typedef std::list
<Object
*> Object_list
;
291 // Add an object to the list.
295 // Iterate over all objects.
296 Object_list::const_iterator
298 { return this->object_list_
.begin(); }
300 Object_list::const_iterator
302 { return this->object_list_
.end(); }
304 // Return whether we have seen any dynamic objects.
307 { return this->any_dynamic_
; }
310 Input_objects(const Input_objects
&);
311 Input_objects
& operator=(const Input_objects
&);
313 Object_list object_list_
;
317 // Return an Object appropriate for the input file. P is BYTES long,
318 // and holds the ELF header.
320 extern Object
* make_elf_object(const std::string
& name
, Input_file
*,
321 off_t offset
, const unsigned char* p
,
324 } // end namespace gold
326 #endif // !defined(GOLD_OBJECT_H)
This page took 0.040596 seconds and 5 git commands to generate.