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