PR gold/12525
[platform/upstream/binutils.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 the base to use for the PC value in an FDE when it is
280   // encoded using DW_EH_PE_datarel.  This does not appear to be
281   // documented anywhere, but it is target specific.  Any use of
282   // DW_EH_PE_datarel in gcc requires defining a special macro
283   // (ASM_MAYBE_OUTPUT_ENCODED_ADDR_RTX) to output the value.
284   uint64_t
285   ehframe_datarel_base() const
286   { return this->do_ehframe_datarel_base(); }
287
288   // Return true if a reference to SYM from a reloc of type R_TYPE
289   // means that the current function may call an object compiled
290   // without -fsplit-stack.  SYM is known to be defined in an object
291   // compiled without -fsplit-stack.
292   bool
293   is_call_to_non_split(const Symbol* sym, unsigned int r_type) const
294   { return this->do_is_call_to_non_split(sym, r_type); }
295
296   // A function starts at OFFSET in section SHNDX in OBJECT.  That
297   // function was compiled with -fsplit-stack, but it refers to a
298   // function which was compiled without -fsplit-stack.  VIEW is a
299   // modifiable view of the section; VIEW_SIZE is the size of the
300   // view.  The target has to adjust the function so that it allocates
301   // enough stack.
302   void
303   calls_non_split(Relobj* object, unsigned int shndx,
304                   section_offset_type fnoffset, section_size_type fnsize,
305                   unsigned char* view, section_size_type view_size,
306                   std::string* from, std::string* to) const
307   {
308     this->do_calls_non_split(object, shndx, fnoffset, fnsize, view, view_size,
309                              from, to);
310   }
311
312   // Make an ELF object.
313   template<int size, bool big_endian>
314   Object*
315   make_elf_object(const std::string& name, Input_file* input_file,
316                   off_t offset, const elfcpp::Ehdr<size, big_endian>& ehdr)
317   { return this->do_make_elf_object(name, input_file, offset, ehdr); }
318
319   // Make an output section.
320   Output_section*
321   make_output_section(const char* name, elfcpp::Elf_Word type,
322                       elfcpp::Elf_Xword flags)
323   { return this->do_make_output_section(name, type, flags); }
324
325   // Return true if target wants to perform relaxation.
326   bool
327   may_relax() const
328   {
329     // Run the dummy relaxation pass twice if relaxation debugging is enabled.
330     if (is_debugging_enabled(DEBUG_RELAXATION))
331       return true;
332
333      return this->do_may_relax();
334   }
335
336   // Perform a relaxation pass.  Return true if layout may be changed.
337   bool
338   relax(int pass, const Input_objects* input_objects, Symbol_table* symtab,
339         Layout* layout, const Task* task)
340   {
341     // Run the dummy relaxation pass twice if relaxation debugging is enabled.
342     if (is_debugging_enabled(DEBUG_RELAXATION))
343       return pass < 2;
344
345     return this->do_relax(pass, input_objects, symtab, layout, task);
346   } 
347
348   // Return the target-specific name of attributes section.  This is
349   // NULL if a target does not use attributes section or if it uses
350   // the default section name ".gnu.attributes".
351   const char*
352   attributes_section() const
353   { return this->pti_->attributes_section; }
354
355   // Return the vendor name of vendor attributes.
356   const char*
357   attributes_vendor() const
358   { return this->pti_->attributes_vendor; }
359
360   // Whether a section called NAME is an attribute section.
361   bool
362   is_attributes_section(const char* name) const
363   {
364     return ((this->pti_->attributes_section != NULL
365              && strcmp(name, this->pti_->attributes_section) == 0)
366             || strcmp(name, ".gnu.attributes") == 0); 
367   }
368
369   // Return a bit mask of argument types for attribute with TAG.
370   int
371   attribute_arg_type(int tag) const
372   { return this->do_attribute_arg_type(tag); }
373
374   // Return the attribute tag of the position NUM in the list of fixed
375   // attributes.  Normally there is no reordering and
376   // attributes_order(NUM) == NUM.
377   int
378   attributes_order(int num) const
379   { return this->do_attributes_order(num); }
380
381   // When a target is selected as the default target, we call this method,
382   // which may be used for expensive, target-specific initialization.
383   void
384   select_as_default_target()
385   { this->do_select_as_default_target(); } 
386
387   // Return the value to store in the EI_OSABI field in the ELF
388   // header.
389   elfcpp::ELFOSABI
390   osabi() const
391   { return this->osabi_; }
392
393   // Set the value to store in the EI_OSABI field in the ELF header.
394   void
395   set_osabi(elfcpp::ELFOSABI osabi)
396   { this->osabi_ = osabi; }
397
398  protected:
399   // This struct holds the constant information for a child class.  We
400   // use a struct to avoid the overhead of virtual function calls for
401   // simple information.
402   struct Target_info
403   {
404     // Address size (32 or 64).
405     int size;
406     // Whether the target is big endian.
407     bool is_big_endian;
408     // The code to store in the e_machine field of the ELF header.
409     elfcpp::EM machine_code;
410     // Whether this target has a specific make_symbol function.
411     bool has_make_symbol;
412     // Whether this target has a specific resolve function.
413     bool has_resolve;
414     // Whether this target has a specific code fill function.
415     bool has_code_fill;
416     // Whether an object file with no .note.GNU-stack sections implies
417     // that the stack should be executable.
418     bool is_default_stack_executable;
419     // Whether a relocation to a merged section can be processed to
420     // retrieve the contents.
421     bool can_icf_inline_merge_sections;
422     // Prefix character to strip when checking for wrapping.
423     char wrap_char;
424     // The default dynamic linker name.
425     const char* dynamic_linker;
426     // The default text segment address.
427     uint64_t default_text_segment_address;
428     // The ABI specified page size.
429     uint64_t abi_pagesize;
430     // The common page size used by actual implementations.
431     uint64_t common_pagesize;
432     // The special section index for small common symbols; SHN_UNDEF
433     // if none.
434     elfcpp::Elf_Half small_common_shndx;
435     // The special section index for large common symbols; SHN_UNDEF
436     // if none.
437     elfcpp::Elf_Half large_common_shndx;
438     // Section flags for small common section.
439     elfcpp::Elf_Xword small_common_section_flags;
440     // Section flags for large common section.
441     elfcpp::Elf_Xword large_common_section_flags;
442     // Name of attributes section if it is not ".gnu.attributes".
443     const char* attributes_section;
444     // Vendor name of vendor attributes.
445     const char* attributes_vendor;
446   };
447
448   Target(const Target_info* pti)
449     : pti_(pti), processor_specific_flags_(0),
450       are_processor_specific_flags_set_(false), osabi_(elfcpp::ELFOSABI_NONE)
451   { }
452
453   // Virtual function which may be implemented by the child class.
454   virtual void
455   do_new_output_section(Output_section*) const
456   { }
457
458   // Virtual function which may be implemented by the child class.
459   virtual void
460   do_finalize_sections(Layout*, const Input_objects*, Symbol_table*)
461   { }
462
463   // Virtual function which may be implemented by the child class.
464   virtual uint64_t
465   do_dynsym_value(const Symbol*) const
466   { gold_unreachable(); }
467
468   // Virtual function which must be implemented by the child class if
469   // needed.
470   virtual std::string
471   do_code_fill(section_size_type) const
472   { gold_unreachable(); }
473
474   // Virtual function which may be implemented by the child class.
475   virtual bool
476   do_is_defined_by_abi(const Symbol*) const
477   { return false; }
478
479   // Adjust the output file header before it is written out.  VIEW
480   // points to the header in external form.  LEN is the length, and
481   // will be one of the values of elfcpp::Elf_sizes<size>::ehdr_size.
482   // By default, we set the EI_OSABI field if requested (in
483   // Sized_target).
484   virtual void
485   do_adjust_elf_header(unsigned char*, int) const = 0;
486
487   // Virtual function which may be overridden by the child class.
488   virtual bool
489   do_is_local_label_name(const char*) const;
490
491   // Virtual function that must be overridden by a target which uses
492   // target specific relocations.
493   virtual unsigned int
494   do_reloc_symbol_index(void*, unsigned int) const
495   { gold_unreachable(); }
496
497   // Virtual function that must be overridden by a target which uses
498   // target specific relocations.
499   virtual uint64_t
500   do_reloc_addend(void*, unsigned int, uint64_t) const
501   { gold_unreachable(); }
502
503   // Virtual functions that must be overridden by a target that uses
504   // STT_GNU_IFUNC symbols.
505   virtual Output_data*
506   do_plt_section_for_global(const Symbol*) const
507   { gold_unreachable(); }
508
509   virtual Output_data*
510   do_plt_section_for_local(const Relobj*, unsigned int) const
511   { gold_unreachable(); }
512
513   // Virtual function which may be overriden by the child class.
514   virtual bool
515   do_can_check_for_function_pointers() const
516   { return false; }
517
518   // Virtual function which may be overridden by the child class.  We
519   // recognize some default sections for which we don't care whether
520   // they have function pointers.
521   virtual bool
522   do_section_may_have_icf_unsafe_pointers(const char* section_name) const
523   {
524     // We recognize sections for normal vtables, construction vtables and
525     // EH frames.
526     return (!is_prefix_of(".rodata._ZTV", section_name)
527             && !is_prefix_of(".data.rel.ro._ZTV", section_name)
528             && !is_prefix_of(".rodata._ZTC", section_name)
529             && !is_prefix_of(".data.rel.ro._ZTC", section_name)
530             && !is_prefix_of(".eh_frame", section_name));
531   }
532
533   virtual uint64_t
534   do_ehframe_datarel_base() const
535   { gold_unreachable(); }
536
537   // Virtual function which may be overridden by the child class.  The
538   // default implementation is that any function not defined by the
539   // ABI is a call to a non-split function.
540   virtual bool
541   do_is_call_to_non_split(const Symbol* sym, unsigned int) const;
542
543   // Virtual function which may be overridden by the child class.
544   virtual void
545   do_calls_non_split(Relobj* object, unsigned int, section_offset_type,
546                      section_size_type, unsigned char*, section_size_type,
547                      std::string*, std::string*) const;
548
549   // make_elf_object hooks.  There are four versions of these for
550   // different address sizes and endianness.
551
552   // Set processor specific flags.
553   void
554   set_processor_specific_flags(elfcpp::Elf_Word flags)
555   {
556     this->processor_specific_flags_ = flags;
557     this->are_processor_specific_flags_set_ = true;
558   }
559   
560 #ifdef HAVE_TARGET_32_LITTLE
561   // Virtual functions which may be overridden by the child class.
562   virtual Object*
563   do_make_elf_object(const std::string&, Input_file*, off_t,
564                      const elfcpp::Ehdr<32, false>&);
565 #endif
566
567 #ifdef HAVE_TARGET_32_BIG
568   // Virtual functions which may be overridden by the child class.
569   virtual Object*
570   do_make_elf_object(const std::string&, Input_file*, off_t,
571                      const elfcpp::Ehdr<32, true>&);
572 #endif
573
574 #ifdef HAVE_TARGET_64_LITTLE
575   // Virtual functions which may be overridden by the child class.
576   virtual Object*
577   do_make_elf_object(const std::string&, Input_file*, off_t,
578                      const elfcpp::Ehdr<64, false>& ehdr);
579 #endif
580
581 #ifdef HAVE_TARGET_64_BIG
582   // Virtual functions which may be overridden by the child class.
583   virtual Object*
584   do_make_elf_object(const std::string& name, Input_file* input_file,
585                      off_t offset, const elfcpp::Ehdr<64, true>& ehdr);
586 #endif
587
588   // Virtual functions which may be overridden by the child class.
589   virtual Output_section*
590   do_make_output_section(const char* name, elfcpp::Elf_Word type,
591                          elfcpp::Elf_Xword flags);
592
593   // Virtual function which may be overridden by the child class.
594   virtual bool
595   do_may_relax() const
596   { return parameters->options().relax(); }
597
598   // Virtual function which may be overridden by the child class.
599   virtual bool
600   do_relax(int, const Input_objects*, Symbol_table*, Layout*, const Task*)
601   { return false; }
602
603   // A function for targets to call.  Return whether BYTES/LEN matches
604   // VIEW/VIEW_SIZE at OFFSET.
605   bool
606   match_view(const unsigned char* view, section_size_type view_size,
607              section_offset_type offset, const char* bytes, size_t len) const;
608
609   // Set the contents of a VIEW/VIEW_SIZE to nops starting at OFFSET
610   // for LEN bytes.
611   void
612   set_view_to_nop(unsigned char* view, section_size_type view_size,
613                   section_offset_type offset, size_t len) const;
614
615   // This must be overridden by the child class if it has target-specific
616   // attributes subsection in the attribute section. 
617   virtual int
618   do_attribute_arg_type(int) const
619   { gold_unreachable(); }
620
621   // This may be overridden by the child class.
622   virtual int
623   do_attributes_order(int num) const
624   { return num; }
625
626   // This may be overridden by the child class.
627   virtual void
628   do_select_as_default_target()
629   { }
630
631  private:
632   // The implementations of the four do_make_elf_object virtual functions are
633   // almost identical except for their sizes and endianness.  We use a template.
634   // for their implementations.
635   template<int size, bool big_endian>
636   inline Object*
637   do_make_elf_object_implementation(const std::string&, Input_file*, off_t,
638                                     const elfcpp::Ehdr<size, big_endian>&);
639
640   Target(const Target&);
641   Target& operator=(const Target&);
642
643   // The target information.
644   const Target_info* pti_;
645   // Processor-specific flags.
646   elfcpp::Elf_Word processor_specific_flags_;
647   // Whether the processor-specific flags are set at least once.
648   bool are_processor_specific_flags_set_;
649   // If not ELFOSABI_NONE, the value to put in the EI_OSABI field of
650   // the ELF header.  This is handled at this level because it is
651   // OS-specific rather than processor-specific.
652   elfcpp::ELFOSABI osabi_;
653 };
654
655 // The abstract class for a specific size and endianness of target.
656 // Each actual target implementation class should derive from an
657 // instantiation of Sized_target.
658
659 template<int size, bool big_endian>
660 class Sized_target : public Target
661 {
662  public:
663   // Make a new symbol table entry for the target.  This should be
664   // overridden by a target which needs additional information in the
665   // symbol table.  This will only be called if has_make_symbol()
666   // returns true.
667   virtual Sized_symbol<size>*
668   make_symbol() const
669   { gold_unreachable(); }
670
671   // Resolve a symbol for the target.  This should be overridden by a
672   // target which needs to take special action.  TO is the
673   // pre-existing symbol.  SYM is the new symbol, seen in OBJECT.
674   // VERSION is the version of SYM.  This will only be called if
675   // has_resolve() returns true.
676   virtual void
677   resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*,
678           const char*)
679   { gold_unreachable(); }
680
681   // Process the relocs for a section, and record information of the
682   // mapping from source to destination sections. This mapping is later
683   // used to determine unreferenced garbage sections. This procedure is
684   // only called during garbage collection.
685   virtual void
686   gc_process_relocs(Symbol_table* symtab,
687                     Layout* layout,
688                     Sized_relobj_file<size, big_endian>* object,
689                     unsigned int data_shndx,
690                     unsigned int sh_type,
691                     const unsigned char* prelocs,
692                     size_t reloc_count,
693                     Output_section* output_section,
694                     bool needs_special_offset_handling,
695                     size_t local_symbol_count,
696                     const unsigned char* plocal_symbols) = 0;
697
698   // Scan the relocs for a section, and record any information
699   // required for the symbol.  SYMTAB is the symbol table.  OBJECT is
700   // the object in which the section appears.  DATA_SHNDX is the
701   // section index that these relocs apply to.  SH_TYPE is the type of
702   // the relocation section, SHT_REL or SHT_RELA.  PRELOCS points to
703   // the relocation data.  RELOC_COUNT is the number of relocs.
704   // LOCAL_SYMBOL_COUNT is the number of local symbols.
705   // OUTPUT_SECTION is the output section.
706   // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets to the output
707   // sections are not mapped as usual.  PLOCAL_SYMBOLS points to the
708   // local symbol data from OBJECT.  GLOBAL_SYMBOLS is the array of
709   // pointers to the global symbol table from OBJECT.
710   virtual void
711   scan_relocs(Symbol_table* symtab,
712               Layout* layout,
713               Sized_relobj_file<size, big_endian>* object,
714               unsigned int data_shndx,
715               unsigned int sh_type,
716               const unsigned char* prelocs,
717               size_t reloc_count,
718               Output_section* output_section,
719               bool needs_special_offset_handling,
720               size_t local_symbol_count,
721               const unsigned char* plocal_symbols) = 0;
722
723   // Relocate section data.  SH_TYPE is the type of the relocation
724   // section, SHT_REL or SHT_RELA.  PRELOCS points to the relocation
725   // information.  RELOC_COUNT is the number of relocs.
726   // OUTPUT_SECTION is the output section.
727   // NEEDS_SPECIAL_OFFSET_HANDLING is true if offsets must be mapped
728   // to correspond to the output section.  VIEW is a view into the
729   // output file holding the section contents, VIEW_ADDRESS is the
730   // virtual address of the view, and VIEW_SIZE is the size of the
731   // view.  If NEEDS_SPECIAL_OFFSET_HANDLING is true, the VIEW_xx
732   // parameters refer to the complete output section data, not just
733   // the input section data.
734   virtual void
735   relocate_section(const Relocate_info<size, big_endian>*,
736                    unsigned int sh_type,
737                    const unsigned char* prelocs,
738                    size_t reloc_count,
739                    Output_section* output_section,
740                    bool needs_special_offset_handling,
741                    unsigned char* view,
742                    typename elfcpp::Elf_types<size>::Elf_Addr view_address,
743                    section_size_type view_size,
744                    const Reloc_symbol_changes*) = 0;
745
746   // Scan the relocs during a relocatable link.  The parameters are
747   // like scan_relocs, with an additional Relocatable_relocs
748   // parameter, used to record the disposition of the relocs.
749   virtual void
750   scan_relocatable_relocs(Symbol_table* symtab,
751                           Layout* layout,
752                           Sized_relobj_file<size, big_endian>* object,
753                           unsigned int data_shndx,
754                           unsigned int sh_type,
755                           const unsigned char* prelocs,
756                           size_t reloc_count,
757                           Output_section* output_section,
758                           bool needs_special_offset_handling,
759                           size_t local_symbol_count,
760                           const unsigned char* plocal_symbols,
761                           Relocatable_relocs*) = 0;
762
763   // Relocate a section during a relocatable link.  The parameters are
764   // like relocate_section, with additional parameters for the view of
765   // the output reloc section.
766   virtual void
767   relocate_for_relocatable(const Relocate_info<size, big_endian>*,
768                            unsigned int sh_type,
769                            const unsigned char* prelocs,
770                            size_t reloc_count,
771                            Output_section* output_section,
772                            off_t offset_in_output_section,
773                            const Relocatable_relocs*,
774                            unsigned char* view,
775                            typename elfcpp::Elf_types<size>::Elf_Addr
776                              view_address,
777                            section_size_type view_size,
778                            unsigned char* reloc_view,
779                            section_size_type reloc_view_size) = 0;
780  
781   // Perform target-specific processing in a relocatable link.  This is
782   // only used if we use the relocation strategy RELOC_SPECIAL.
783   // RELINFO points to a Relocation_info structure. SH_TYPE is the relocation
784   // section type. PRELOC_IN points to the original relocation.  RELNUM is
785   // the index number of the relocation in the relocation section.
786   // OUTPUT_SECTION is the output section to which the relocation is applied.
787   // OFFSET_IN_OUTPUT_SECTION is the offset of the relocation input section
788   // within the output section.  VIEW points to the output view of the
789   // output section.  VIEW_ADDRESS is output address of the view.  VIEW_SIZE
790   // is the size of the output view and PRELOC_OUT points to the new
791   // relocation in the output object.
792   //
793   // A target only needs to override this if the generic code in
794   // target-reloc.h cannot handle some relocation types.
795
796   virtual void
797   relocate_special_relocatable(const Relocate_info<size, big_endian>*
798                                 /*relinfo */,
799                                unsigned int /* sh_type */,
800                                const unsigned char* /* preloc_in */,
801                                size_t /* relnum */,
802                                Output_section* /* output_section */,
803                                off_t /* offset_in_output_section */,
804                                unsigned char* /* view */,
805                                typename elfcpp::Elf_types<size>::Elf_Addr
806                                  /* view_address */,
807                                section_size_type /* view_size */,
808                                unsigned char* /* preloc_out*/)
809   { gold_unreachable(); }
810  
811   // Return the number of entries in the GOT.  This is only used for
812   // laying out the incremental link info sections.  A target needs
813   // to implement this to support incremental linking.
814
815   virtual unsigned int
816   got_entry_count() const
817   { gold_unreachable(); }
818
819   // Return the number of entries in the PLT.  This is only used for
820   // laying out the incremental link info sections.  A target needs
821   // to implement this to support incremental linking.
822
823   virtual unsigned int
824   plt_entry_count() const
825   { gold_unreachable(); }
826
827   // Return the offset of the first non-reserved PLT entry.  This is
828   // only used for laying out the incremental link info sections.
829   // A target needs to implement this to support incremental linking.
830
831   virtual unsigned int
832   first_plt_entry_offset() const
833   { gold_unreachable(); }
834
835   // Return the size of each PLT entry.  This is only used for
836   // laying out the incremental link info sections.  A target needs
837   // to implement this to support incremental linking.
838
839   virtual unsigned int
840   plt_entry_size() const
841   { gold_unreachable(); }
842
843   // Create the GOT and PLT sections for an incremental update.
844   // A target needs to implement this to support incremental linking.
845
846   virtual Output_data_got<size, big_endian>*
847   init_got_plt_for_update(Symbol_table*,
848                           Layout*,
849                           unsigned int /* got_count */,
850                           unsigned int /* plt_count */)
851   { gold_unreachable(); }
852
853   // Reserve a GOT entry for a local symbol, and regenerate any
854   // necessary dynamic relocations.
855   virtual void
856   reserve_local_got_entry(unsigned int /* got_index */,
857                           Sized_relobj<size, big_endian>* /* obj */,
858                           unsigned int /* r_sym */,
859                           unsigned int /* got_type */)
860   { gold_unreachable(); }
861
862   // Reserve a GOT entry for a global symbol, and regenerate any
863   // necessary dynamic relocations.
864   virtual void
865   reserve_global_got_entry(unsigned int /* got_index */, Symbol* /* gsym */,
866                            unsigned int /* got_type */)
867   { gold_unreachable(); }
868
869   // Register an existing PLT entry for a global symbol.
870   // A target needs to implement this to support incremental linking.
871
872   virtual void
873   register_global_plt_entry(unsigned int /* plt_index */,
874                             Symbol*)
875   { gold_unreachable(); }
876
877   // Force a COPY relocation for a given symbol.
878   // A target needs to implement this to support incremental linking.
879
880   virtual void
881   emit_copy_reloc(Symbol_table*, Symbol*, Output_section*, off_t)
882   { gold_unreachable(); }
883
884   // Apply an incremental relocation.
885
886   virtual void
887   apply_relocation(const Relocate_info<size, big_endian>* /* relinfo */,
888                    typename elfcpp::Elf_types<size>::Elf_Addr /* r_offset */,
889                    unsigned int /* r_type */,
890                    typename elfcpp::Elf_types<size>::Elf_Swxword /* r_addend */,
891                    const Symbol* /* gsym */,
892                    unsigned char* /* view */,
893                    typename elfcpp::Elf_types<size>::Elf_Addr /* address */,
894                    section_size_type /* view_size */)
895   { gold_unreachable(); }
896
897  protected:
898   Sized_target(const Target::Target_info* pti)
899     : Target(pti)
900   {
901     gold_assert(pti->size == size);
902     gold_assert(pti->is_big_endian ? big_endian : !big_endian);
903   }
904
905   // Set the EI_OSABI field if requested.
906   virtual void
907   do_adjust_elf_header(unsigned char*, int) const;
908 };
909
910 } // End namespace gold.
911
912 #endif // !defined(GOLD_TARGET_H)