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