2006-09-29 H.J. Lu <hongjiu.lu@intel.com>
[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
ILT
18#include "symtab.h"
19#include "elfcpp.h"
20
bae7f79e
ILT
21namespace gold
22{
23
14bfc3f5
ILT
24class Object;
25
26// The abstract class for target specific handling.
27
bae7f79e
ILT
28class Target
29{
30 public:
14bfc3f5
ILT
31 virtual ~Target()
32 { }
33
34 // Return the bit size that this target implements. This should
35 // return 32 or 64.
36 int
37 get_size() const
75f65a3e 38 { return this->pti_->size; }
14bfc3f5
ILT
39
40 // Return whether this target is big-endian.
41 bool
42 is_big_endian() const
75f65a3e 43 { return this->pti_->is_big_endian; }
14bfc3f5
ILT
44
45 // Whether this target has a specific make_symbol function.
46 bool
47 has_make_symbol() const
75f65a3e 48 { return this->pti_->has_make_symbol; }
14bfc3f5
ILT
49
50 // Whether this target has a specific resolve function.
51 bool
52 has_resolve() const
75f65a3e
ILT
53 { return this->pti_->has_resolve; }
54
55 // Return the default address to use for the text segment.
56 uint64_t
57 text_segment_address() const
58 { return this->pti_->text_segment_address; }
59
60 // Return the ABI specified page size.
61 uint64_t
62 abi_pagesize() const
63 { return this->pti_->abi_pagesize; }
64
65 // Return the common page size used on actual systems.
66 uint64_t
67 common_pagesize() const
68 { return this->pti_->common_pagesize; }
14bfc3f5 69
14bfc3f5 70 protected:
75f65a3e
ILT
71 // This struct holds the constant information for a child class. We
72 // use a struct to avoid the overhead of virtual function calls for
73 // simple information.
74 struct Target_info
75 {
76 // Address size (32 or 64).
77 int size;
78 // Whether the target is big endian.
79 bool is_big_endian;
80 // Whether this target has a specific make_symbol function.
81 bool has_make_symbol;
82 // Whether this target has a specific resolve function.
83 bool has_resolve;
84 // The default text segment address.
85 uint64_t text_segment_address;
86 // The ABI specified page size.
87 uint64_t abi_pagesize;
88 // The common page size used by actual implementations.
89 uint64_t common_pagesize;
90 };
91
92 Target(const Target_info* pti)
93 : pti_(pti)
14bfc3f5
ILT
94 { }
95
96 private:
97 Target(const Target&);
98 Target& operator=(const Target&);
99
75f65a3e
ILT
100 // The target information.
101 const Target_info* pti_;
bae7f79e
ILT
102};
103
14bfc3f5
ILT
104// The abstract class for a specific size and endianness of target.
105// Each actual target implementation class should derive from an
106// instantiation of Sized_target.
107
108template<int size, bool big_endian>
109class Sized_target : public Target
110{
111 public:
112 // Make a new symbol table entry for the target. This should be
113 // overridden by a target which needs additional information in the
114 // symbol table. This will only be called if has_make_symbol()
115 // returns true.
116 virtual Sized_symbol<size>*
117 make_symbol()
118 { abort(); }
119
120 // Resolve a symbol for the target. This should be overridden by a
121 // target which needs to take special action. TO is the
122 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
123 virtual void
124 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*)
125 { abort(); }
126
127 protected:
75f65a3e
ILT
128 Sized_target(const Target::Target_info* pti)
129 : Target(pti)
130 {
131 assert(pti->size == size);
132 assert(pti->is_big_endian ? big_endian : !big_endian);
133 }
14bfc3f5 134};
bae7f79e
ILT
135
136} // End namespace gold.
137
138#endif // !defined(GOLD_TARGET_H)
This page took 0.031821 seconds and 4 git commands to generate.