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