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