ld/
[binutils.git] / gold / target.h
blob5230bb2c6019573a5c9e91b220c0a467dff37a2e
1 // target.h -- target support for gold -*- C++ -*-
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.
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.
13 #ifndef GOLD_TARGET_H
14 #define GOLD_TARGET_H
16 #include <cassert>
18 #include "elfcpp.h"
19 #include "symtab.h"
21 namespace gold
24 class Object;
25 template<int size, bool big_endian>
26 class Sized_object;
28 // The abstract class for target specific handling.
30 class Target
32 public:
33 virtual ~Target()
34 { }
36 // Return the bit size that this target implements. This should
37 // return 32 or 64.
38 int
39 get_size() const
40 { return this->pti_->size; }
42 // Return whether this target is big-endian.
43 bool
44 is_big_endian() const
45 { return this->pti_->is_big_endian; }
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; }
52 // Whether this target has a specific make_symbol function.
53 bool
54 has_make_symbol() const
55 { return this->pti_->has_make_symbol; }
57 // Whether this target has a specific resolve function.
58 bool
59 has_resolve() const
60 { return this->pti_->has_resolve; }
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; }
67 // Return the ABI specified page size.
68 uint64_t
69 abi_pagesize() const
70 { return this->pti_->abi_pagesize; }
72 // Return the common page size used on actual systems.
73 uint64_t
74 common_pagesize() const
75 { return this->pti_->common_pagesize; }
77 protected:
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
83 // Address size (32 or 64).
84 int size;
85 // Whether the target is big endian.
86 bool is_big_endian;
87 // The code to store in the e_machine field of the ELF header.
88 elfcpp::EM machine_code;
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;
101 Target(const Target_info* pti)
102 : pti_(pti)
105 private:
106 Target(const Target&);
107 Target& operator=(const Target&);
109 // The target information.
110 const Target_info* pti_;
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.
117 template<int size, bool big_endian>
118 class Sized_target : public Target
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(); }
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(); }
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(); }
159 protected:
160 Sized_target(const Target::Target_info* pti)
161 : Target(pti)
163 assert(pti->size == size);
164 assert(pti->is_big_endian ? big_endian : !big_endian);
168 } // End namespace gold.
170 #endif // !defined(GOLD_TARGET_H)