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