Finished layout code.
[binutils.git] / gold / target.h
blobbba3d5a50fdd7d8134f53d8a03b018c52ef428e6
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 "symtab.h"
19 #include "elfcpp.h"
21 namespace gold
24 class Object;
26 // The abstract class for target specific handling.
28 class Target
30 public:
31 virtual ~Target()
32 { }
34 // Return the bit size that this target implements. This should
35 // return 32 or 64.
36 int
37 get_size() const
38 { return this->pti_->size; }
40 // Return whether this target is big-endian.
41 bool
42 is_big_endian() const
43 { return this->pti_->is_big_endian; }
45 // Whether this target has a specific make_symbol function.
46 bool
47 has_make_symbol() const
48 { return this->pti_->has_make_symbol; }
50 // Whether this target has a specific resolve function.
51 bool
52 has_resolve() const
53 { return this->pti_->has_resolve; }
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; }
60 // Return the ABI specified page size.
61 uint64_t
62 abi_pagesize() const
63 { return this->pti_->abi_pagesize; }
65 // Return the common page size used on actual systems.
66 uint64_t
67 common_pagesize() const
68 { return this->pti_->common_pagesize; }
70 protected:
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
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;
92 Target(const Target_info* pti)
93 : pti_(pti)
94 { }
96 private:
97 Target(const Target&);
98 Target& operator=(const Target&);
100 // The target information.
101 const Target_info* pti_;
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.
108 template<int size, bool big_endian>
109 class Sized_target : public Target
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(); }
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(); }
127 protected:
128 Sized_target(const Target::Target_info* pti)
129 : Target(pti)
131 assert(pti->size == size);
132 assert(pti->is_big_endian ? big_endian : !big_endian);
136 } // End namespace gold.
138 #endif // !defined(GOLD_TARGET_H)