Split Object into Dynobj and Relobj, incorporate elfcpp swapping changes.
[deliverable/binutils-gdb.git] / gold / reloc.h
1 // reloc.h -- relocate input files for gold -*- C++ -*-
2
3 #ifndef GOLD_RELOC_H
4 #define GOLD_RELOC_H
5
6 #include <byteswap.h>
7
8 #include "workqueue.h"
9
10 namespace gold
11 {
12
13 class Relobj;
14 class Read_relocs_data;
15 class Stringpool;
16 class Layout;
17
18 // A class to read the relocations for an object file, and then queue
19 // up a task to see if they require any GOT/PLT/COPY relocations in
20 // the symbol table.
21
22 class Read_relocs : public Task
23 {
24 public:
25 // SYMTAB_LOCK is used to lock the symbol table. BLOCKER should be
26 // unblocked when the Scan_relocs task completes.
27 Read_relocs(const General_options& options, Symbol_table* symtab,
28 Layout* layout, Relobj* object, Task_token* symtab_lock,
29 Task_token* blocker)
30 : options_(options), symtab_(symtab), layout_(layout), object_(object),
31 symtab_lock_(symtab_lock), blocker_(blocker)
32 { }
33
34 // The standard Task methods.
35
36 Is_runnable_type
37 is_runnable(Workqueue*);
38
39 Task_locker*
40 locks(Workqueue*);
41
42 void
43 run(Workqueue*);
44
45 private:
46 const General_options& options_;
47 Symbol_table* symtab_;
48 Layout* layout_;
49 Relobj* object_;
50 Task_token* symtab_lock_;
51 Task_token* blocker_;
52 };
53
54 // Scan the relocations for an object to see if they require any
55 // GOT/PLT/COPY relocations.
56
57 class Scan_relocs : public Task
58 {
59 public:
60 // SYMTAB_LOCK is used to lock the symbol table. BLOCKER should be
61 // unblocked when the task completes.
62 Scan_relocs(const General_options& options, Symbol_table* symtab,
63 Layout* layout, Relobj* object, Read_relocs_data* rd,
64 Task_token* symtab_lock, Task_token* blocker)
65 : options_(options), symtab_(symtab), layout_(layout), object_(object),
66 rd_(rd), symtab_lock_(symtab_lock), blocker_(blocker)
67 { }
68
69 // The standard Task methods.
70
71 Is_runnable_type
72 is_runnable(Workqueue*);
73
74 Task_locker*
75 locks(Workqueue*);
76
77 void
78 run(Workqueue*);
79
80 private:
81 class Scan_relocs_locker;
82
83 const General_options& options_;
84 Symbol_table* symtab_;
85 Layout* layout_;
86 Relobj* object_;
87 Read_relocs_data* rd_;
88 Task_token* symtab_lock_;
89 Task_token* blocker_;
90 };
91
92 // A class to perform all the relocations for an object file.
93
94 class Relocate_task : public Task
95 {
96 public:
97 Relocate_task(const General_options& options, const Symbol_table* symtab,
98 const Layout* layout, Relobj* object, Output_file* of,
99 Task_token* final_blocker)
100 : options_(options), symtab_(symtab), layout_(layout), object_(object),
101 of_(of), final_blocker_(final_blocker)
102 { }
103
104 // The standard Task methods.
105
106 Is_runnable_type
107 is_runnable(Workqueue*);
108
109 Task_locker*
110 locks(Workqueue*);
111
112 void
113 run(Workqueue*);
114
115 private:
116 class Relocate_locker;
117
118 const General_options& options_;
119 const Symbol_table* symtab_;
120 const Layout* layout_;
121 Relobj* object_;
122 Output_file* of_;
123 Task_token* final_blocker_;
124 };
125
126 // Standard relocation routines which are used on many targets. Here
127 // SIZE and BIG_ENDIAN refer to the target, not the relocation type.
128
129 template<int size, bool big_endian>
130 class Relocate_functions
131 {
132 private:
133 // Do a simple relocation with the addend in the section contents.
134 // VALSIZE is the size of the value.
135 template<int valsize>
136 static inline void
137 rel(unsigned char* view,
138 typename elfcpp::Swap<valsize, big_endian>::Valtype value)
139 {
140 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
141 Valtype* wv = reinterpret_cast<Valtype*>(view);
142 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
143 elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value);
144 }
145
146 // Do a simple PC relative relocation with the addend in the section
147 // contents. VALSIZE is the size of the value.
148 template<int valsize>
149 static inline void
150 pcrel(unsigned char* view,
151 typename elfcpp::Swap<valsize, big_endian>::Valtype value,
152 typename elfcpp::Elf_types<size>::Elf_Addr address)
153 {
154 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
155 Valtype* wv = reinterpret_cast<Valtype*>(view);
156 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
157 elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value - address);
158 }
159
160 typedef Relocate_functions<size, big_endian> This;
161
162 public:
163 // Do a simple 8-bit REL relocation with the addend in the object
164 // file data.
165 static inline void
166 rel8(unsigned char* view, unsigned char value)
167 {
168 This::template rel<8>(view, value);
169 }
170
171 // Do a simple 8-bit PC relative relocation with the addend in the
172 // object file data.
173 static inline void
174 pcrel8(unsigned char* view, unsigned char value,
175 typename elfcpp::Elf_types<size>::Elf_Addr address)
176 {
177 This::template pcrel<8>(view, value, address);
178 }
179
180 // Do a simple 16-bit REL relocation with the addend in the object
181 // file data.
182 static inline void
183 rel16(unsigned char* view, elfcpp::Elf_Half value)
184 {
185 This::template rel<16>(view, value);
186 }
187
188 // Do a simple 32-bit PC relative REL relocation with the addend in
189 // the object file data.
190 static inline void
191 pcrel16(unsigned char* view, elfcpp::Elf_Word value,
192 typename elfcpp::Elf_types<size>::Elf_Addr address)
193 {
194 This::template pcrel<16>(view, value, address);
195 }
196
197 // Do a simple 32-bit REL relocation with the addend in the section
198 // contents.
199 static inline void
200 rel32(unsigned char* view, elfcpp::Elf_Word value)
201 {
202 This::template rel<32>(view, value);
203 }
204
205 // Do a simple 32-bit PC relative REL relocation with the addend in
206 // the section contents.
207 static inline void
208 pcrel32(unsigned char* view, elfcpp::Elf_Word value,
209 typename elfcpp::Elf_types<size>::Elf_Addr address)
210 {
211 This::template pcrel<32>(view, value, address);
212 }
213
214 // Do a simple 64-bit REL relocation with the addend in the section
215 // contents.
216 static inline void
217 rel64(unsigned char* view, elfcpp::Elf_Xword value)
218 {
219 This::template rel<64>(view, value);
220 }
221
222 // Do a simple 64-bit PC relative REL relocation with the addend in
223 // the section contents.
224 static inline void
225 pcrel64(unsigned char* view, elfcpp::Elf_Xword value,
226 typename elfcpp::Elf_types<size>::Elf_Addr address)
227 {
228 This::template pcrel<64>(view, value, address);
229 }
230 };
231
232 } // End namespace gold.
233
234 #endif // !defined(GOLD_RELOC_H)
This page took 0.03626 seconds and 5 git commands to generate.