* ld-sh/tlsbin-1.d: Update.
[deliverable/binutils-gdb.git] / gold / target.h
CommitLineData
14bfc3f5 1// target.h -- target support for gold -*- C++ -*-
bae7f79e
ILT
2
3// The abstract class Target is the interface for target specific
4// support. It defines abstract methods which each target must
5// implement. Typically there will be one target per processor, but
6// in some cases it may be necessary to have subclasses.
7
8// For speed and consistency we want to use inline functions to handle
9// relocation processing. So besides implementations of the abstract
10// methods, each target is expected to define a template
11// specialization of the relocation functions.
12
13#ifndef GOLD_TARGET_H
14#define GOLD_TARGET_H
15
75f65a3e
ILT
16#include <cassert>
17
14bfc3f5 18#include "elfcpp.h"
61ba1cf9 19#include "symtab.h"
14bfc3f5 20
bae7f79e
ILT
21namespace gold
22{
23
14bfc3f5 24class Object;
61ba1cf9
ILT
25template<int size, bool big_endian>
26class Sized_object;
14bfc3f5
ILT
27
28// The abstract class for target specific handling.
29
bae7f79e
ILT
30class Target
31{
32 public:
14bfc3f5
ILT
33 virtual ~Target()
34 { }
35
36 // Return the bit size that this target implements. This should
37 // return 32 or 64.
38 int
39 get_size() const
75f65a3e 40 { return this->pti_->size; }
14bfc3f5
ILT
41
42 // Return whether this target is big-endian.
43 bool
44 is_big_endian() const
75f65a3e 45 { return this->pti_->is_big_endian; }
14bfc3f5 46
61ba1cf9
ILT
47 // Machine code to store in e_machine field of ELF header.
48 elfcpp::EM
49 machine_code() const
50 { return this->pti_->machine_code; }
51
14bfc3f5
ILT
52 // Whether this target has a specific make_symbol function.
53 bool
54 has_make_symbol() const
75f65a3e 55 { return this->pti_->has_make_symbol; }
14bfc3f5
ILT
56
57 // Whether this target has a specific resolve function.
58 bool
59 has_resolve() const
75f65a3e
ILT
60 { return this->pti_->has_resolve; }
61
62 // Return the default address to use for the text segment.
63 uint64_t
64 text_segment_address() const
65 { return this->pti_->text_segment_address; }
66
67 // Return the ABI specified page size.
68 uint64_t
69 abi_pagesize() const
70 { return this->pti_->abi_pagesize; }
71
72 // Return the common page size used on actual systems.
73 uint64_t
74 common_pagesize() const
75 { return this->pti_->common_pagesize; }
14bfc3f5 76
14bfc3f5 77 protected:
75f65a3e
ILT
78 // This struct holds the constant information for a child class. We
79 // use a struct to avoid the overhead of virtual function calls for
80 // simple information.
81 struct Target_info
82 {
83 // Address size (32 or 64).
84 int size;
85 // Whether the target is big endian.
86 bool is_big_endian;
61ba1cf9
ILT
87 // The code to store in the e_machine field of the ELF header.
88 elfcpp::EM machine_code;
75f65a3e
ILT
89 // Whether this target has a specific make_symbol function.
90 bool has_make_symbol;
91 // Whether this target has a specific resolve function.
92 bool has_resolve;
93 // The default text segment address.
94 uint64_t text_segment_address;
95 // The ABI specified page size.
96 uint64_t abi_pagesize;
97 // The common page size used by actual implementations.
98 uint64_t common_pagesize;
99 };
100
101 Target(const Target_info* pti)
102 : pti_(pti)
14bfc3f5
ILT
103 { }
104
105 private:
106 Target(const Target&);
107 Target& operator=(const Target&);
108
75f65a3e
ILT
109 // The target information.
110 const Target_info* pti_;
bae7f79e
ILT
111};
112
14bfc3f5
ILT
113// The abstract class for a specific size and endianness of target.
114// Each actual target implementation class should derive from an
115// instantiation of Sized_target.
116
117template<int size, bool big_endian>
118class Sized_target : public Target
119{
120 public:
121 // Make a new symbol table entry for the target. This should be
122 // overridden by a target which needs additional information in the
123 // symbol table. This will only be called if has_make_symbol()
124 // returns true.
125 virtual Sized_symbol<size>*
126 make_symbol()
127 { abort(); }
128
129 // Resolve a symbol for the target. This should be overridden by a
130 // target which needs to take special action. TO is the
131 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
132 virtual void
133 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*)
134 { abort(); }
135
61ba1cf9
ILT
136 // Relocate section data. SYMTAB is the symbol table. OBJECT is
137 // the object in which the section appears. SH_TYPE is the type of
138 // the relocation section, SHT_REL or SHT_RELA. PRELOCS points to
139 // the relocation information. RELOC_COUNT is the number of relocs.
140 // LOCAL_COUNT is the number of local symbols. The VALUES and
141 // GLOBAL_SYMS have symbol table information. VIEW is a view into
142 // the output file holding the section contents, VIEW_ADDRESS is the
143 // virtual address of the view, and VIEW_SIZE is the size of the
144 // view.
145 virtual void
146 relocate_section(const Symbol_table*, // symtab
147 Sized_object<size, big_endian>*, // object
148 unsigned int, // sh_type
149 const unsigned char*, // prelocs
150 size_t, // reloc_count
151 unsigned int, // local_count
152 const typename elfcpp::Elf_types<size>::Elf_Addr*, // values
153 Symbol**, // global_syms
154 unsigned char*, // view
155 typename elfcpp::Elf_types<size>::Elf_Addr, // view_address
156 off_t) // view_size
157 { abort(); }
158
14bfc3f5 159 protected:
75f65a3e
ILT
160 Sized_target(const Target::Target_info* pti)
161 : Target(pti)
162 {
163 assert(pti->size == size);
164 assert(pti->is_big_endian ? big_endian : !big_endian);
165 }
14bfc3f5 166};
bae7f79e
ILT
167
168} // End namespace gold.
169
170#endif // !defined(GOLD_TARGET_H)
This page took 0.034422 seconds and 4 git commands to generate.