OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [gold/] [target.h] - Blame information for rev 231

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.