daily update
[deliverable/binutils-gdb.git] / gold / target.h
CommitLineData
14bfc3f5 1// target.h -- target support for gold -*- C++ -*-
bae7f79e 2
2c54b4f4
ILT
3// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012
4// Free Software Foundation, Inc.
6cb15b7f
ILT
5// Written by Ian Lance Taylor <iant@google.com>.
6
7// This file is part of gold.
8
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; either version 3 of the License, or
12// (at your option) any later version.
13
14// This program is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18
19// You should have received a copy of the GNU General Public License
20// along with this program; if not, write to the Free Software
21// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22// MA 02110-1301, USA.
23
bae7f79e
ILT
24// The abstract class Target is the interface for target specific
25// support. It defines abstract methods which each target must
26// implement. Typically there will be one target per processor, but
27// in some cases it may be necessary to have subclasses.
28
29// For speed and consistency we want to use inline functions to handle
30// relocation processing. So besides implementations of the abstract
31// methods, each target is expected to define a template
32// specialization of the relocation functions.
33
34#ifndef GOLD_TARGET_H
35#define GOLD_TARGET_H
36
14bfc3f5 37#include "elfcpp.h"
8851ecca 38#include "options.h"
cd72c291 39#include "parameters.h"
20e6d0d6 40#include "debug.h"
14bfc3f5 41
bae7f79e
ILT
42namespace gold
43{
44
14bfc3f5 45class Object;
364c7fa5 46class Relobj;
61ba1cf9 47template<int size, bool big_endian>
f6ce93d6 48class Sized_relobj;
6fa2a40b
CC
49template<int size, bool big_endian>
50class Sized_relobj_file;
6a74a719 51class Relocatable_relocs;
92e059d8 52template<int size, bool big_endian>
2c54b4f4 53struct Relocate_info;
364c7fa5 54class Reloc_symbol_changes;
f6ce93d6
ILT
55class Symbol;
56template<int size>
57class Sized_symbol;
58class Symbol_table;
7223e9ca 59class Output_data;
dd74ae06 60class Output_data_got_base;
730cdc88 61class Output_section;
d5b40221 62class Input_objects;
f625ae50 63class Task;
14bfc3f5
ILT
64
65// The abstract class for target specific handling.
66
bae7f79e
ILT
67class Target
68{
69 public:
14bfc3f5
ILT
70 virtual ~Target()
71 { }
72
73 // Return the bit size that this target implements. This should
74 // return 32 or 64.
75 int
76 get_size() const
75f65a3e 77 { return this->pti_->size; }
14bfc3f5
ILT
78
79 // Return whether this target is big-endian.
80 bool
81 is_big_endian() const
75f65a3e 82 { return this->pti_->is_big_endian; }
14bfc3f5 83
61ba1cf9
ILT
84 // Machine code to store in e_machine field of ELF header.
85 elfcpp::EM
86 machine_code() const
87 { return this->pti_->machine_code; }
88
d5b40221
DK
89 // Processor specific flags to store in e_flags field of ELF header.
90 elfcpp::Elf_Word
91 processor_specific_flags() const
92 { return this->processor_specific_flags_; }
93
94 // Whether processor specific flags are set at least once.
95 bool
96 are_processor_specific_flags_set() const
97 { return this->are_processor_specific_flags_set_; }
98
14bfc3f5
ILT
99 // Whether this target has a specific make_symbol function.
100 bool
101 has_make_symbol() const
75f65a3e 102 { return this->pti_->has_make_symbol; }
14bfc3f5
ILT
103
104 // Whether this target has a specific resolve function.
105 bool
106 has_resolve() const
75f65a3e
ILT
107 { return this->pti_->has_resolve; }
108
c51e6221
ILT
109 // Whether this target has a specific code fill function.
110 bool
111 has_code_fill() const
112 { return this->pti_->has_code_fill; }
113
dbe717ef
ILT
114 // Return the default name of the dynamic linker.
115 const char*
116 dynamic_linker() const
117 { return this->pti_->dynamic_linker; }
118
75f65a3e
ILT
119 // Return the default address to use for the text segment.
120 uint64_t
0c5e9c22
ILT
121 default_text_segment_address() const
122 { return this->pti_->default_text_segment_address; }
75f65a3e
ILT
123
124 // Return the ABI specified page size.
125 uint64_t
126 abi_pagesize() const
cd72c291 127 {
8851ecca
ILT
128 if (parameters->options().max_page_size() > 0)
129 return parameters->options().max_page_size();
cd72c291
ILT
130 else
131 return this->pti_->abi_pagesize;
132 }
75f65a3e
ILT
133
134 // Return the common page size used on actual systems.
135 uint64_t
136 common_pagesize() const
cd72c291 137 {
8851ecca
ILT
138 if (parameters->options().common_page_size() > 0)
139 return std::min(parameters->options().common_page_size(),
cd72c291
ILT
140 this->abi_pagesize());
141 else
142 return std::min(this->pti_->common_pagesize,
143 this->abi_pagesize());
144 }
14bfc3f5 145
2e702c99
RM
146 // Return whether PF_X segments must contain nothing but the contents of
147 // SHF_EXECINSTR sections (no non-executable data, no headers).
148 bool
149 isolate_execinstr() const
150 { return this->pti_->isolate_execinstr; }
151
152 uint64_t
153 rosegment_gap() const
154 { return this->pti_->rosegment_gap; }
155
35cdfc9a
ILT
156 // If we see some object files with .note.GNU-stack sections, and
157 // some objects files without them, this returns whether we should
158 // consider the object files without them to imply that the stack
159 // should be executable.
160 bool
161 is_default_stack_executable() const
162 { return this->pti_->is_default_stack_executable; }
163
0864d551
ILT
164 // Return a character which may appear as a prefix for a wrap
165 // symbol. If this character appears, we strip it when checking for
166 // wrapping and add it back when forming the final symbol name.
167 // This should be '\0' if not special prefix is required, which is
168 // the normal case.
169 char
170 wrap_char() const
171 { return this->pti_->wrap_char; }
172
8a5e3e08
ILT
173 // Return the special section index which indicates a small common
174 // symbol. This will return SHN_UNDEF if there are no small common
175 // symbols.
176 elfcpp::Elf_Half
177 small_common_shndx() const
178 { return this->pti_->small_common_shndx; }
179
180 // Return values to add to the section flags for the section holding
181 // small common symbols.
182 elfcpp::Elf_Xword
183 small_common_section_flags() const
184 {
185 gold_assert(this->pti_->small_common_shndx != elfcpp::SHN_UNDEF);
186 return this->pti_->small_common_section_flags;
187 }
188
189 // Return the special section index which indicates a large common
190 // symbol. This will return SHN_UNDEF if there are no large common
191 // symbols.
192 elfcpp::Elf_Half
193 large_common_shndx() const
194 { return this->pti_->large_common_shndx; }
195
196 // Return values to add to the section flags for the section holding
197 // large common symbols.
198 elfcpp::Elf_Xword
199 large_common_section_flags() const
200 {
201 gold_assert(this->pti_->large_common_shndx != elfcpp::SHN_UNDEF);
202 return this->pti_->large_common_section_flags;
203 }
204
205 // This hook is called when an output section is created.
206 void
207 new_output_section(Output_section* os) const
208 { this->do_new_output_section(os); }
209
5a6f7e2d
ILT
210 // This is called to tell the target to complete any sections it is
211 // handling. After this all sections must have their final size.
212 void
f59f41f3
DK
213 finalize_sections(Layout* layout, const Input_objects* input_objects,
214 Symbol_table* symtab)
215 { return this->do_finalize_sections(layout, input_objects, symtab); }
5a6f7e2d 216
ab5c9e90
ILT
217 // Return the value to use for a global symbol which needs a special
218 // value in the dynamic symbol table. This will only be called if
219 // the backend first calls symbol->set_needs_dynsym_value().
220 uint64_t
221 dynsym_value(const Symbol* sym) const
222 { return this->do_dynsym_value(sym); }
223
c51e6221
ILT
224 // Return a string to use to fill out a code section. This is
225 // basically one or more NOPS which must fill out the specified
226 // length in bytes.
227 std::string
8851ecca 228 code_fill(section_size_type length) const
c51e6221
ILT
229 { return this->do_code_fill(length); }
230
9a2d6984
ILT
231 // Return whether SYM is known to be defined by the ABI. This is
232 // used to avoid inappropriate warnings about undefined symbols.
233 bool
9c2d0ef9 234 is_defined_by_abi(const Symbol* sym) const
9a2d6984
ILT
235 { return this->do_is_defined_by_abi(sym); }
236
36959681
ILT
237 // Adjust the output file header before it is written out. VIEW
238 // points to the header in external form. LEN is the length.
239 void
240 adjust_elf_header(unsigned char* view, int len) const
241 { return this->do_adjust_elf_header(view, len); }
242
9d5781f8
AM
243 // Return address and size to plug into eh_frame FDEs associated with a PLT.
244 void
245 plt_fde_location(const Output_data* plt, unsigned char* oview,
246 uint64_t* address, off_t* len) const
247 { return this->do_plt_fde_location(plt, oview, address, len); }
248
bb04269c
DK
249 // Return whether NAME is a local label name. This is used to implement the
250 // --discard-locals options.
251 bool
252 is_local_label_name(const char* name) const
253 { return this->do_is_local_label_name(name); }
254
e291e7b9
ILT
255 // Get the symbol index to use for a target specific reloc.
256 unsigned int
257 reloc_symbol_index(void* arg, unsigned int type) const
258 { return this->do_reloc_symbol_index(arg, type); }
259
260 // Get the addend to use for a target specific reloc.
261 uint64_t
262 reloc_addend(void* arg, unsigned int type, uint64_t addend) const
263 { return this->do_reloc_addend(arg, type, addend); }
264
19fec8c1 265 // Return the PLT address to use for a global symbol.
67181c72
ILT
266 uint64_t
267 plt_address_for_global(const Symbol* sym) const
268 { return this->do_plt_address_for_global(sym); }
269
19fec8c1 270 // Return the PLT address to use for a local symbol.
67181c72
ILT
271 uint64_t
272 plt_address_for_local(const Relobj* object, unsigned int symndx) const
273 { return this->do_plt_address_for_local(object, symndx); }
7223e9ca 274
bd73a62d
AM
275 // Return the offset to use for the GOT_INDX'th got entry which is
276 // for a local tls symbol specified by OBJECT, SYMNDX.
277 int64_t
278 tls_offset_for_local(const Relobj* object,
279 unsigned int symndx,
280 unsigned int got_indx) const
281 { return do_tls_offset_for_local(object, symndx, got_indx); }
282
283 // Return the offset to use for the GOT_INDX'th got entry which is
284 // for global tls symbol GSYM.
285 int64_t
286 tls_offset_for_global(Symbol* gsym, unsigned int got_indx) const
287 { return do_tls_offset_for_global(gsym, got_indx); }
288
b3ce541e
ILT
289 // Return whether this target can use relocation types to determine
290 // if a function's address is taken.
291 bool
292 can_check_for_function_pointers() const
293 { return this->do_can_check_for_function_pointers(); }
294
295 // Return whether a relocation to a merged section can be processed
296 // to retrieve the contents.
297 bool
298 can_icf_inline_merge_sections () const
299 { return this->pti_->can_icf_inline_merge_sections; }
300
301 // Whether a section called SECTION_NAME may have function pointers to
302 // sections not eligible for safe ICF folding.
303 virtual bool
304 section_may_have_icf_unsafe_pointers(const char* section_name) const
305 { return this->do_section_may_have_icf_unsafe_pointers(section_name); }
306
02d7cd44
ILT
307 // Return the base to use for the PC value in an FDE when it is
308 // encoded using DW_EH_PE_datarel. This does not appear to be
309 // documented anywhere, but it is target specific. Any use of
310 // DW_EH_PE_datarel in gcc requires defining a special macro
311 // (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value.
312 uint64_t
313 ehframe_datarel_base() const
314 { return this->do_ehframe_datarel_base(); }
315
b6848d3c
ILT
316 // Return true if a reference to SYM from a reloc of type R_TYPE
317 // means that the current function may call an object compiled
318 // without -fsplit-stack. SYM is known to be defined in an object
319 // compiled without -fsplit-stack.
320 bool
321 is_call_to_non_split(const Symbol* sym, unsigned int r_type) const
322 { return this->do_is_call_to_non_split(sym, r_type); }
323
364c7fa5
ILT
324 // A function starts at OFFSET in section SHNDX in OBJECT. That
325 // function was compiled with -fsplit-stack, but it refers to a
326 // function which was compiled without -fsplit-stack. VIEW is a
327 // modifiable view of the section; VIEW_SIZE is the size of the
328 // view. The target has to adjust the function so that it allocates
329 // enough stack.
330 void
331 calls_non_split(Relobj* object, unsigned int shndx,
332 section_offset_type fnoffset, section_size_type fnsize,
333 unsigned char* view, section_size_type view_size,
334 std::string* from, std::string* to) const
335 {
336 this->do_calls_non_split(object, shndx, fnoffset, fnsize, view, view_size,
337 from, to);
338 }
339
f733487b
DK
340 // Make an ELF object.
341 template<int size, bool big_endian>
342 Object*
343 make_elf_object(const std::string& name, Input_file* input_file,
344 off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
345 { return this->do_make_elf_object(name, input_file, offset, ehdr); }
346
c0a62865
DK
347 // Make an output section.
348 Output_section*
349 make_output_section(const char* name, elfcpp::Elf_Word type,
350 elfcpp::Elf_Xword flags)
351 { return this->do_make_output_section(name, type, flags); }
352
20e6d0d6
DK
353 // Return true if target wants to perform relaxation.
354 bool
355 may_relax() const
356 {
357 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
358 if (is_debugging_enabled(DEBUG_RELAXATION))
359 return true;
360
361 return this->do_may_relax();
362 }
363
364 // Perform a relaxation pass. Return true if layout may be changed.
365 bool
c0a62865 366 relax(int pass, const Input_objects* input_objects, Symbol_table* symtab,
f625ae50 367 Layout* layout, const Task* task)
20e6d0d6
DK
368 {
369 // Run the dummy relaxation pass twice if relaxation debugging is enabled.
370 if (is_debugging_enabled(DEBUG_RELAXATION))
371 return pass < 2;
372
f625ae50 373 return this->do_relax(pass, input_objects, symtab, layout, task);
2e702c99 374 }
20e6d0d6 375
05a352e6
DK
376 // Return the target-specific name of attributes section. This is
377 // NULL if a target does not use attributes section or if it uses
378 // the default section name ".gnu.attributes".
379 const char*
380 attributes_section() const
381 { return this->pti_->attributes_section; }
382
383 // Return the vendor name of vendor attributes.
384 const char*
385 attributes_vendor() const
386 { return this->pti_->attributes_vendor; }
387
388 // Whether a section called NAME is an attribute section.
389 bool
390 is_attributes_section(const char* name) const
391 {
392 return ((this->pti_->attributes_section != NULL
393 && strcmp(name, this->pti_->attributes_section) == 0)
2e702c99 394 || strcmp(name, ".gnu.attributes") == 0);
05a352e6
DK
395 }
396
397 // Return a bit mask of argument types for attribute with TAG.
398 int
399 attribute_arg_type(int tag) const
400 { return this->do_attribute_arg_type(tag); }
401
402 // Return the attribute tag of the position NUM in the list of fixed
403 // attributes. Normally there is no reordering and
404 // attributes_order(NUM) == NUM.
405 int
406 attributes_order(int num) const
407 { return this->do_attributes_order(num); }
408
0d31c79d
DK
409 // When a target is selected as the default target, we call this method,
410 // which may be used for expensive, target-specific initialization.
411 void
412 select_as_default_target()
2e702c99 413 { this->do_select_as_default_target(); }
0d31c79d 414
200b2bb9
ILT
415 // Return the value to store in the EI_OSABI field in the ELF
416 // header.
417 elfcpp::ELFOSABI
418 osabi() const
419 { return this->osabi_; }
420
421 // Set the value to store in the EI_OSABI field in the ELF header.
422 void
423 set_osabi(elfcpp::ELFOSABI osabi)
424 { this->osabi_ = osabi; }
425
647f1574
DK
426 // Define target-specific standard symbols.
427 void
428 define_standard_symbols(Symbol_table* symtab, Layout* layout)
429 { this->do_define_standard_symbols(symtab, layout); }
430
921b5322
AM
431 // Return the output section name to use given an input section
432 // name, or NULL if no target specific name mapping is required.
433 // Set *PLEN to the length of the name if returning non-NULL.
434 const char*
435 output_section_name(const Relobj* relobj,
436 const char* name,
437 size_t* plen) const
438 { return this->do_output_section_name(relobj, name, plen); }
439
e81fea4d
AM
440 // Add any special sections for this symbol to the gc work list.
441 void
442 gc_mark_symbol(Symbol_table* symtab, Symbol* sym) const
443 { this->do_gc_mark_symbol(symtab, sym); }
444
14bfc3f5 445 protected:
75f65a3e
ILT
446 // This struct holds the constant information for a child class. We
447 // use a struct to avoid the overhead of virtual function calls for
448 // simple information.
449 struct Target_info
450 {
451 // Address size (32 or 64).
452 int size;
453 // Whether the target is big endian.
454 bool is_big_endian;
61ba1cf9
ILT
455 // The code to store in the e_machine field of the ELF header.
456 elfcpp::EM machine_code;
75f65a3e
ILT
457 // Whether this target has a specific make_symbol function.
458 bool has_make_symbol;
459 // Whether this target has a specific resolve function.
460 bool has_resolve;
c51e6221
ILT
461 // Whether this target has a specific code fill function.
462 bool has_code_fill;
35cdfc9a
ILT
463 // Whether an object file with no .note.GNU-stack sections implies
464 // that the stack should be executable.
465 bool is_default_stack_executable;
b3ce541e
ILT
466 // Whether a relocation to a merged section can be processed to
467 // retrieve the contents.
468 bool can_icf_inline_merge_sections;
0864d551
ILT
469 // Prefix character to strip when checking for wrapping.
470 char wrap_char;
dbe717ef
ILT
471 // The default dynamic linker name.
472 const char* dynamic_linker;
75f65a3e 473 // The default text segment address.
0c5e9c22 474 uint64_t default_text_segment_address;
75f65a3e
ILT
475 // The ABI specified page size.
476 uint64_t abi_pagesize;
477 // The common page size used by actual implementations.
478 uint64_t common_pagesize;
2e702c99
RM
479 // Whether PF_X segments must contain nothing but the contents of
480 // SHF_EXECINSTR sections (no non-executable data, no headers).
481 bool isolate_execinstr;
482 // If nonzero, distance from the text segment to the read-only segment.
483 uint64_t rosegment_gap;
8a5e3e08
ILT
484 // The special section index for small common symbols; SHN_UNDEF
485 // if none.
486 elfcpp::Elf_Half small_common_shndx;
487 // The special section index for large common symbols; SHN_UNDEF
488 // if none.
489 elfcpp::Elf_Half large_common_shndx;
490 // Section flags for small common section.
491 elfcpp::Elf_Xword small_common_section_flags;
492 // Section flags for large common section.
493 elfcpp::Elf_Xword large_common_section_flags;
05a352e6
DK
494 // Name of attributes section if it is not ".gnu.attributes".
495 const char* attributes_section;
496 // Vendor name of vendor attributes.
497 const char* attributes_vendor;
75f65a3e
ILT
498 };
499
500 Target(const Target_info* pti)
d5b40221 501 : pti_(pti), processor_specific_flags_(0),
200b2bb9 502 are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE)
14bfc3f5
ILT
503 { }
504
8a5e3e08
ILT
505 // Virtual function which may be implemented by the child class.
506 virtual void
507 do_new_output_section(Output_section*) const
508 { }
509
5a6f7e2d
ILT
510 // Virtual function which may be implemented by the child class.
511 virtual void
f59f41f3 512 do_finalize_sections(Layout*, const Input_objects*, Symbol_table*)
5a6f7e2d
ILT
513 { }
514
ab5c9e90
ILT
515 // Virtual function which may be implemented by the child class.
516 virtual uint64_t
517 do_dynsym_value(const Symbol*) const
518 { gold_unreachable(); }
519
c51e6221
ILT
520 // Virtual function which must be implemented by the child class if
521 // needed.
522 virtual std::string
8851ecca 523 do_code_fill(section_size_type) const
c51e6221
ILT
524 { gold_unreachable(); }
525
9a2d6984
ILT
526 // Virtual function which may be implemented by the child class.
527 virtual bool
9c2d0ef9 528 do_is_defined_by_abi(const Symbol*) const
9a2d6984
ILT
529 { return false; }
530
36959681
ILT
531 // Adjust the output file header before it is written out. VIEW
532 // points to the header in external form. LEN is the length, and
533 // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
200b2bb9
ILT
534 // By default, we set the EI_OSABI field if requested (in
535 // Sized_target).
36959681 536 virtual void
200b2bb9 537 do_adjust_elf_header(unsigned char*, int) const = 0;
36959681 538
9d5781f8
AM
539 // Return address and size to plug into eh_frame FDEs associated with a PLT.
540 virtual void
541 do_plt_fde_location(const Output_data* plt, unsigned char* oview,
542 uint64_t* address, off_t* len) const;
543
9b547ce6 544 // Virtual function which may be overridden by the child class.
bb04269c
DK
545 virtual bool
546 do_is_local_label_name(const char*) const;
547
e291e7b9
ILT
548 // Virtual function that must be overridden by a target which uses
549 // target specific relocations.
550 virtual unsigned int
551 do_reloc_symbol_index(void*, unsigned int) const
552 { gold_unreachable(); }
553
9b547ce6 554 // Virtual function that must be overridden by a target which uses
e291e7b9
ILT
555 // target specific relocations.
556 virtual uint64_t
557 do_reloc_addend(void*, unsigned int, uint64_t) const
558 { gold_unreachable(); }
559
7223e9ca
ILT
560 // Virtual functions that must be overridden by a target that uses
561 // STT_GNU_IFUNC symbols.
67181c72
ILT
562 virtual uint64_t
563 do_plt_address_for_global(const Symbol*) const
7223e9ca
ILT
564 { gold_unreachable(); }
565
67181c72
ILT
566 virtual uint64_t
567 do_plt_address_for_local(const Relobj*, unsigned int) const
7223e9ca
ILT
568 { gold_unreachable(); }
569
bd73a62d
AM
570 virtual int64_t
571 do_tls_offset_for_local(const Relobj*, unsigned int, unsigned int) const
572 { gold_unreachable(); }
573
574 virtual int64_t
575 do_tls_offset_for_global(Symbol*, unsigned int) const
576 { gold_unreachable(); }
577
b3ce541e
ILT
578 // Virtual function which may be overriden by the child class.
579 virtual bool
580 do_can_check_for_function_pointers() const
581 { return false; }
582
583 // Virtual function which may be overridden by the child class. We
584 // recognize some default sections for which we don't care whether
585 // they have function pointers.
586 virtual bool
587 do_section_may_have_icf_unsafe_pointers(const char* section_name) const
588 {
589 // We recognize sections for normal vtables, construction vtables and
590 // EH frames.
591 return (!is_prefix_of(".rodata._ZTV", section_name)
592 && !is_prefix_of(".data.rel.ro._ZTV", section_name)
593 && !is_prefix_of(".rodata._ZTC", section_name)
594 && !is_prefix_of(".data.rel.ro._ZTC", section_name)
595 && !is_prefix_of(".eh_frame", section_name));
596 }
597
02d7cd44
ILT
598 virtual uint64_t
599 do_ehframe_datarel_base() const
600 { gold_unreachable(); }
601
b6848d3c
ILT
602 // Virtual function which may be overridden by the child class. The
603 // default implementation is that any function not defined by the
604 // ABI is a call to a non-split function.
605 virtual bool
606 do_is_call_to_non_split(const Symbol* sym, unsigned int) const;
607
364c7fa5
ILT
608 // Virtual function which may be overridden by the child class.
609 virtual void
610 do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
611 section_size_type, unsigned char*, section_size_type,
612 std::string*, std::string*) const;
613
f733487b 614 // make_elf_object hooks. There are four versions of these for
7296d933 615 // different address sizes and endianness.
364c7fa5 616
d5b40221
DK
617 // Set processor specific flags.
618 void
619 set_processor_specific_flags(elfcpp::Elf_Word flags)
620 {
621 this->processor_specific_flags_ = flags;
622 this->are_processor_specific_flags_set_ = true;
623 }
2e702c99 624
f733487b 625#ifdef HAVE_TARGET_32_LITTLE
9b547ce6 626 // Virtual functions which may be overridden by the child class.
f733487b
DK
627 virtual Object*
628 do_make_elf_object(const std::string&, Input_file*, off_t,
629 const elfcpp::Ehdr<32, false>&);
630#endif
631
632#ifdef HAVE_TARGET_32_BIG
9b547ce6 633 // Virtual functions which may be overridden by the child class.
f733487b
DK
634 virtual Object*
635 do_make_elf_object(const std::string&, Input_file*, off_t,
636 const elfcpp::Ehdr<32, true>&);
637#endif
638
639#ifdef HAVE_TARGET_64_LITTLE
9b547ce6 640 // Virtual functions which may be overridden by the child class.
f733487b
DK
641 virtual Object*
642 do_make_elf_object(const std::string&, Input_file*, off_t,
643 const elfcpp::Ehdr<64, false>& ehdr);
644#endif
645
646#ifdef HAVE_TARGET_64_BIG
9b547ce6 647 // Virtual functions which may be overridden by the child class.
f733487b
DK
648 virtual Object*
649 do_make_elf_object(const std::string& name, Input_file* input_file,
650 off_t offset, const elfcpp::Ehdr<64, true>& ehdr);
651#endif
652
9b547ce6 653 // Virtual functions which may be overridden by the child class.
c0a62865
DK
654 virtual Output_section*
655 do_make_output_section(const char* name, elfcpp::Elf_Word type,
656 elfcpp::Elf_Xword flags);
657
9b547ce6 658 // Virtual function which may be overridden by the child class.
20e6d0d6
DK
659 virtual bool
660 do_may_relax() const
661 { return parameters->options().relax(); }
662
9b547ce6 663 // Virtual function which may be overridden by the child class.
20e6d0d6 664 virtual bool
f625ae50 665 do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*)
20e6d0d6
DK
666 { return false; }
667
364c7fa5
ILT
668 // A function for targets to call. Return whether BYTES/LEN matches
669 // VIEW/VIEW_SIZE at OFFSET.
670 bool
671 match_view(const unsigned char* view, section_size_type view_size,
672 section_offset_type offset, const char* bytes, size_t len) const;
673
674 // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
675 // for LEN bytes.
676 void
677 set_view_to_nop(unsigned char* view, section_size_type view_size,
678 section_offset_type offset, size_t len) const;
679
9b547ce6 680 // This must be overridden by the child class if it has target-specific
2e702c99 681 // attributes subsection in the attribute section.
05a352e6
DK
682 virtual int
683 do_attribute_arg_type(int) const
684 { gold_unreachable(); }
685
686 // This may be overridden by the child class.
687 virtual int
688 do_attributes_order(int num) const
689 { return num; }
690
0d31c79d
DK
691 // This may be overridden by the child class.
692 virtual void
693 do_select_as_default_target()
694 { }
695
647f1574
DK
696 // This may be overridden by the child class.
697 virtual void
698 do_define_standard_symbols(Symbol_table*, Layout*)
699 { }
700
921b5322
AM
701 // This may be overridden by the child class.
702 virtual const char*
703 do_output_section_name(const Relobj*, const char*, size_t*) const
704 { return NULL; }
705
e81fea4d
AM
706 // This may be overridden by the child class.
707 virtual void
708 do_gc_mark_symbol(Symbol_table*, Symbol*) const
709 { }
710
14bfc3f5 711 private:
f733487b 712 // The implementations of the four do_make_elf_object virtual functions are
7296d933 713 // almost identical except for their sizes and endianness. We use a template.
f733487b
DK
714 // for their implementations.
715 template<int size, bool big_endian>
716 inline Object*
717 do_make_elf_object_implementation(const std::string&, Input_file*, off_t,
718 const elfcpp::Ehdr<size, big_endian>&);
719
14bfc3f5
ILT
720 Target(const Target&);
721 Target& operator=(const Target&);
722
75f65a3e
ILT
723 // The target information.
724 const Target_info* pti_;
d5b40221
DK
725 // Processor-specific flags.
726 elfcpp::Elf_Word processor_specific_flags_;
727 // Whether the processor-specific flags are set at least once.
728 bool are_processor_specific_flags_set_;
200b2bb9
ILT
729 // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of
730 // the ELF header. This is handled at this level because it is
731 // OS-specific rather than processor-specific.
732 elfcpp::ELFOSABI osabi_;
bae7f79e
ILT
733};
734
14bfc3f5
ILT
735// The abstract class for a specific size and endianness of target.
736// Each actual target implementation class should derive from an
737// instantiation of Sized_target.
738
739template<int size, bool big_endian>
740class Sized_target : public Target
741{
742 public:
743 // Make a new symbol table entry for the target. This should be
744 // overridden by a target which needs additional information in the
745 // symbol table. This will only be called if has_make_symbol()
746 // returns true.
747 virtual Sized_symbol<size>*
14b31740 748 make_symbol() const
a3ad94ed 749 { gold_unreachable(); }
14bfc3f5
ILT
750
751 // Resolve a symbol for the target. This should be overridden by a
752 // target which needs to take special action. TO is the
753 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
14b31740
ILT
754 // VERSION is the version of SYM. This will only be called if
755 // has_resolve() returns true.
14bfc3f5 756 virtual void
14b31740
ILT
757 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*,
758 const char*)
a3ad94ed 759 { gold_unreachable(); }
14bfc3f5 760
6d03d481
ST
761 // Process the relocs for a section, and record information of the
762 // mapping from source to destination sections. This mapping is later
763 // used to determine unreferenced garbage sections. This procedure is
764 // only called during garbage collection.
765 virtual void
ad0f2072
ILT
766 gc_process_relocs(Symbol_table* symtab,
767 Layout* layout,
6fa2a40b 768 Sized_relobj_file<size, big_endian>* object,
ad0f2072
ILT
769 unsigned int data_shndx,
770 unsigned int sh_type,
771 const unsigned char* prelocs,
772 size_t reloc_count,
773 Output_section* output_section,
774 bool needs_special_offset_handling,
775 size_t local_symbol_count,
776 const unsigned char* plocal_symbols) = 0;
6d03d481 777
92e059d8 778 // Scan the relocs for a section, and record any information
ad0f2072
ILT
779 // required for the symbol. SYMTAB is the symbol table. OBJECT is
780 // the object in which the section appears. DATA_SHNDX is the
781 // section index that these relocs apply to. SH_TYPE is the type of
782 // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to
783 // the relocation data. RELOC_COUNT is the number of relocs.
784 // LOCAL_SYMBOL_COUNT is the number of local symbols.
785 // OUTPUT_SECTION is the output section.
730cdc88
ILT
786 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
787 // sections are not mapped as usual. PLOCAL_SYMBOLS points to the
788 // local symbol data from OBJECT. GLOBAL_SYMBOLS is the array of
789 // pointers to the global symbol table from OBJECT.
61ba1cf9 790 virtual void
ad0f2072 791 scan_relocs(Symbol_table* symtab,
ead1e424 792 Layout* layout,
6fa2a40b 793 Sized_relobj_file<size, big_endian>* object,
a3ad94ed 794 unsigned int data_shndx,
92e059d8
ILT
795 unsigned int sh_type,
796 const unsigned char* prelocs,
797 size_t reloc_count,
730cdc88
ILT
798 Output_section* output_section,
799 bool needs_special_offset_handling,
92e059d8 800 size_t local_symbol_count,
730cdc88 801 const unsigned char* plocal_symbols) = 0;
92e059d8
ILT
802
803 // Relocate section data. SH_TYPE is the type of the relocation
804 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
730cdc88
ILT
805 // information. RELOC_COUNT is the number of relocs.
806 // OUTPUT_SECTION is the output section.
807 // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
808 // to correspond to the output section. VIEW is a view into the
809 // output file holding the section contents, VIEW_ADDRESS is the
810 // virtual address of the view, and VIEW_SIZE is the size of the
811 // view. If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
812 // parameters refer to the complete output section data, not just
813 // the input section data.
92e059d8
ILT
814 virtual void
815 relocate_section(const Relocate_info<size, big_endian>*,
816 unsigned int sh_type,
817 const unsigned char* prelocs,
818 size_t reloc_count,
730cdc88
ILT
819 Output_section* output_section,
820 bool needs_special_offset_handling,
92e059d8
ILT
821 unsigned char* view,
822 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
364c7fa5
ILT
823 section_size_type view_size,
824 const Reloc_symbol_changes*) = 0;
61ba1cf9 825
6a74a719
ILT
826 // Scan the relocs during a relocatable link. The parameters are
827 // like scan_relocs, with an additional Relocatable_relocs
828 // parameter, used to record the disposition of the relocs.
829 virtual void
ad0f2072 830 scan_relocatable_relocs(Symbol_table* symtab,
6a74a719 831 Layout* layout,
6fa2a40b 832 Sized_relobj_file<size, big_endian>* object,
6a74a719
ILT
833 unsigned int data_shndx,
834 unsigned int sh_type,
835 const unsigned char* prelocs,
836 size_t reloc_count,
837 Output_section* output_section,
838 bool needs_special_offset_handling,
839 size_t local_symbol_count,
840 const unsigned char* plocal_symbols,
841 Relocatable_relocs*) = 0;
842
7404fe1b
AM
843 // Emit relocations for a section during a relocatable link, and for
844 // --emit-relocs. The parameters are like relocate_section, with
845 // additional parameters for the view of the output reloc section.
6a74a719 846 virtual void
7404fe1b
AM
847 relocate_relocs(const Relocate_info<size, big_endian>*,
848 unsigned int sh_type,
849 const unsigned char* prelocs,
850 size_t reloc_count,
851 Output_section* output_section,
62fe925a
RM
852 typename elfcpp::Elf_types<size>::Elf_Off
853 offset_in_output_section,
7404fe1b
AM
854 const Relocatable_relocs*,
855 unsigned char* view,
856 typename elfcpp::Elf_types<size>::Elf_Addr view_address,
857 section_size_type view_size,
858 unsigned char* reloc_view,
859 section_size_type reloc_view_size) = 0;
2e702c99 860
5c388529
DK
861 // Perform target-specific processing in a relocatable link. This is
862 // only used if we use the relocation strategy RELOC_SPECIAL.
863 // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation
864 // section type. PRELOC_IN points to the original relocation. RELNUM is
865 // the index number of the relocation in the relocation section.
866 // OUTPUT_SECTION is the output section to which the relocation is applied.
867 // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section
868 // within the output section. VIEW points to the output view of the
869 // output section. VIEW_ADDRESS is output address of the view. VIEW_SIZE
870 // is the size of the output view and PRELOC_OUT points to the new
871 // relocation in the output object.
872 //
873 // A target only needs to override this if the generic code in
874 // target-reloc.h cannot handle some relocation types.
6a74a719 875
5c388529
DK
876 virtual void
877 relocate_special_relocatable(const Relocate_info<size, big_endian>*
878 /*relinfo */,
879 unsigned int /* sh_type */,
880 const unsigned char* /* preloc_in */,
881 size_t /* relnum */,
882 Output_section* /* output_section */,
62fe925a
RM
883 typename elfcpp::Elf_types<size>::Elf_Off
884 /* offset_in_output_section */,
5c388529
DK
885 unsigned char* /* view */,
886 typename elfcpp::Elf_types<size>::Elf_Addr
887 /* view_address */,
888 section_size_type /* view_size */,
889 unsigned char* /* preloc_out*/)
890 { gold_unreachable(); }
2e702c99 891
0e70b911
CC
892 // Return the number of entries in the GOT. This is only used for
893 // laying out the incremental link info sections. A target needs
894 // to implement this to support incremental linking.
895
896 virtual unsigned int
897 got_entry_count() const
898 { gold_unreachable(); }
899
900 // Return the number of entries in the PLT. This is only used for
901 // laying out the incremental link info sections. A target needs
902 // to implement this to support incremental linking.
903
904 virtual unsigned int
905 plt_entry_count() const
906 { gold_unreachable(); }
907
908 // Return the offset of the first non-reserved PLT entry. This is
909 // only used for laying out the incremental link info sections.
910 // A target needs to implement this to support incremental linking.
911
912 virtual unsigned int
913 first_plt_entry_offset() const
914 { gold_unreachable(); }
915
916 // Return the size of each PLT entry. This is only used for
917 // laying out the incremental link info sections. A target needs
918 // to implement this to support incremental linking.
919
920 virtual unsigned int
921 plt_entry_size() const
922 { gold_unreachable(); }
923
4829d394
CC
924 // Create the GOT and PLT sections for an incremental update.
925 // A target needs to implement this to support incremental linking.
926
dd74ae06 927 virtual Output_data_got_base*
4829d394
CC
928 init_got_plt_for_update(Symbol_table*,
929 Layout*,
930 unsigned int /* got_count */,
931 unsigned int /* plt_count */)
932 { gold_unreachable(); }
933
6fa2a40b
CC
934 // Reserve a GOT entry for a local symbol, and regenerate any
935 // necessary dynamic relocations.
936 virtual void
937 reserve_local_got_entry(unsigned int /* got_index */,
938 Sized_relobj<size, big_endian>* /* obj */,
939 unsigned int /* r_sym */,
940 unsigned int /* got_type */)
941 { gold_unreachable(); }
942
943 // Reserve a GOT entry for a global symbol, and regenerate any
944 // necessary dynamic relocations.
945 virtual void
946 reserve_global_got_entry(unsigned int /* got_index */, Symbol* /* gsym */,
947 unsigned int /* got_type */)
948 { gold_unreachable(); }
949
4829d394
CC
950 // Register an existing PLT entry for a global symbol.
951 // A target needs to implement this to support incremental linking.
952
953 virtual void
67181c72
ILT
954 register_global_plt_entry(Symbol_table*, Layout*,
955 unsigned int /* plt_index */,
4829d394
CC
956 Symbol*)
957 { gold_unreachable(); }
958
26d3c67d
CC
959 // Force a COPY relocation for a given symbol.
960 // A target needs to implement this to support incremental linking.
961
962 virtual void
963 emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t)
964 { gold_unreachable(); }
965
94a3fc8b
CC
966 // Apply an incremental relocation.
967
968 virtual void
969 apply_relocation(const Relocate_info<size, big_endian>* /* relinfo */,
970 typename elfcpp::Elf_types<size>::Elf_Addr /* r_offset */,
971 unsigned int /* r_type */,
972 typename elfcpp::Elf_types<size>::Elf_Swxword /* r_addend */,
973 const Symbol* /* gsym */,
974 unsigned char* /* view */,
975 typename elfcpp::Elf_types<size>::Elf_Addr /* address */,
976 section_size_type /* view_size */)
977 { gold_unreachable(); }
978
e81fea4d
AM
979 // Handle target specific gc actions when adding a gc reference from
980 // SRC_OBJ, SRC_SHNDX to a location specified by DST_OBJ, DST_SHNDX
981 // and DST_OFF.
982 void
983 gc_add_reference(Symbol_table* symtab,
984 Object* src_obj,
985 unsigned int src_shndx,
986 Object* dst_obj,
987 unsigned int dst_shndx,
988 typename elfcpp::Elf_types<size>::Elf_Addr dst_off) const
989 {
990 this->do_gc_add_reference(symtab, src_obj, src_shndx,
991 dst_obj, dst_shndx, dst_off);
992 }
993
14bfc3f5 994 protected:
75f65a3e
ILT
995 Sized_target(const Target::Target_info* pti)
996 : Target(pti)
997 {
a3ad94ed
ILT
998 gold_assert(pti->size == size);
999 gold_assert(pti->is_big_endian ? big_endian : !big_endian);
75f65a3e 1000 }
200b2bb9
ILT
1001
1002 // Set the EI_OSABI field if requested.
1003 virtual void
1004 do_adjust_elf_header(unsigned char*, int) const;
e81fea4d
AM
1005
1006 // Handle target specific gc actions when adding a gc reference.
1007 virtual void
1008 do_gc_add_reference(Symbol_table*, Object*, unsigned int,
1009 Object*, unsigned int,
1010 typename elfcpp::Elf_types<size>::Elf_Addr) const
1011 { }
14bfc3f5 1012};
bae7f79e
ILT
1013
1014} // End namespace gold.
1015
1016#endif // !defined(GOLD_TARGET_H)
This page took 0.326964 seconds and 4 git commands to generate.