Another snapshot of the current state of the sources. Gets to the
[binutils-gdb.git] / gold / target.h
1 // target.h -- target support for gold -*- C++ -*-
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
16 #include "symtab.h"
17 #include "elfcpp.h"
18
19 namespace gold
20 {
21
22 class Object;
23
24 // The abstract class for target specific handling.
25
26 class Target
27 {
28 public:
29 virtual ~Target()
30 { }
31
32 // Return the bit size that this target implements. This should
33 // return 32 or 64.
34 int
35 get_size() const
36 { return this->size_; }
37
38 // Return whether this target is big-endian.
39 bool
40 is_big_endian() const
41 { return this->is_big_endian_; }
42
43 // Whether this target has a specific make_symbol function.
44 bool
45 has_make_symbol() const
46 { return this->has_make_symbol_; }
47
48 // Whether this target has a specific resolve function.
49 bool
50 has_resolve() const
51 { return this->has_resolve_; }
52
53 // Resolve a symbol. This is called when we see a symbol with a
54 // target specific binding (STB_LOOS through STB_HIOS or STB_LOPROC
55 // through STB_HIPROC). TO is a pre-existing symbol. SYM is the
56 // new symbol, seen in OBJECT. This returns true on success, false
57 // if the symbol can not be resolved.
58 template<int size, bool big_endian>
59 bool
60 resolve(Sized_symbol<size>* to, const elfcpp::Sym<size, big_endian>& sym,
61 Object* object);
62
63 protected:
64 Target(int size, bool is_big_endian, bool has_make_symbol, bool has_resolve)
65 : size_(size),
66 is_big_endian_(is_big_endian),
67 has_make_symbol_(has_make_symbol),
68 has_resolve_(has_resolve)
69 { }
70
71 private:
72 Target(const Target&);
73 Target& operator=(const Target&);
74
75 // The target size.
76 int size_;
77 // Whether this target is big endian.
78 bool is_big_endian_;
79 // Whether this target has a special make_symbol function.
80 bool has_make_symbol_;
81 // Whether this target has a special resolve function.
82 bool has_resolve_;
83 };
84
85 // The abstract class for a specific size and endianness of target.
86 // Each actual target implementation class should derive from an
87 // instantiation of Sized_target.
88
89 template<int size, bool big_endian>
90 class Sized_target : public Target
91 {
92 public:
93 // Make a new symbol table entry for the target. This should be
94 // overridden by a target which needs additional information in the
95 // symbol table. This will only be called if has_make_symbol()
96 // returns true.
97 virtual Sized_symbol<size>*
98 make_symbol()
99 { abort(); }
100
101 // Resolve a symbol for the target. This should be overridden by a
102 // target which needs to take special action. TO is the
103 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
104 virtual void
105 resolve(Symbol*, const elfcpp::Sym<size, big_endian>&, Object*)
106 { abort(); }
107
108 protected:
109 Sized_target(bool has_make_symbol, bool has_resolve)
110 : Target(size, big_endian, has_make_symbol, has_resolve)
111 { }
112 };
113
114 } // End namespace gold.
115
116 #endif // !defined(GOLD_TARGET_H)