2006-11-29 Paul Brook <paul@codesourcery.com>
[deliverable/binutils-gdb.git] / gold / reloc.h
CommitLineData
61ba1cf9
ILT
1// reloc.h -- relocate input files for gold -*- C++ -*-
2
3#ifndef GOLD_RELOC_H
4#define GOLD_RELOC_H
5
92e059d8
ILT
6#include <byteswap.h>
7
61ba1cf9
ILT
8#include "workqueue.h"
9
10namespace gold
11{
12
f6ce93d6 13class Relobj;
92e059d8
ILT
14class Read_relocs_data;
15class Stringpool;
ead1e424 16class Layout;
92e059d8
ILT
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
22class 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,
f6ce93d6 28 Layout* layout, Relobj* object, Task_token* symtab_lock,
92e059d8 29 Task_token* blocker)
ead1e424 30 : options_(options), symtab_(symtab), layout_(layout), object_(object),
92e059d8
ILT
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_;
ead1e424 48 Layout* layout_;
f6ce93d6 49 Relobj* object_;
92e059d8
ILT
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
57class 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,
f6ce93d6 63 Layout* layout, Relobj* object, Read_relocs_data* rd,
ead1e424
ILT
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)
92e059d8
ILT
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_;
ead1e424 85 Layout* layout_;
f6ce93d6 86 Relobj* object_;
92e059d8
ILT
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
61ba1cf9
ILT
94class Relocate_task : public Task
95{
96 public:
97 Relocate_task(const General_options& options, const Symbol_table* symtab,
f6ce93d6 98 const Layout* layout, Relobj* object, Output_file* of,
61ba1cf9 99 Task_token* final_blocker)
92e059d8 100 : options_(options), symtab_(symtab), layout_(layout), object_(object),
61ba1cf9
ILT
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_;
92e059d8 120 const Layout* layout_;
f6ce93d6 121 Relobj* object_;
61ba1cf9
ILT
122 Output_file* of_;
123 Task_token* final_blocker_;
124};
125
92e059d8
ILT
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
129template<int size, bool big_endian>
130class Relocate_functions
131{
132private:
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
f6ce93d6
ILT
137 rel(unsigned char* view,
138 typename elfcpp::Swap<valsize, big_endian>::Valtype value)
92e059d8 139 {
f6ce93d6 140 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
92e059d8 141 Valtype* wv = reinterpret_cast<Valtype*>(view);
f6ce93d6
ILT
142 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
143 elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value);
92e059d8
ILT
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
f6ce93d6
ILT
150 pcrel(unsigned char* view,
151 typename elfcpp::Swap<valsize, big_endian>::Valtype value,
92e059d8
ILT
152 typename elfcpp::Elf_types<size>::Elf_Addr address)
153 {
f6ce93d6 154 typedef typename elfcpp::Swap<valsize, big_endian>::Valtype Valtype;
92e059d8 155 Valtype* wv = reinterpret_cast<Valtype*>(view);
f6ce93d6
ILT
156 Valtype x = elfcpp::Swap<valsize, big_endian>::readval(wv);
157 elfcpp::Swap<valsize, big_endian>::writeval(wv, x + value - address);
92e059d8
ILT
158 }
159
160 typedef Relocate_functions<size, big_endian> This;
161
162public:
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
f6ce93d6 217 rel64(unsigned char* view, elfcpp::Elf_Xword value)
92e059d8
ILT
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
f6ce93d6 225 pcrel64(unsigned char* view, elfcpp::Elf_Xword value,
92e059d8
ILT
226 typename elfcpp::Elf_types<size>::Elf_Addr address)
227 {
228 This::template pcrel<64>(view, value, address);
229 }
230};
231
61ba1cf9
ILT
232} // End namespace gold.
233
234#endif // !defined(GOLD_RELOC_H)
This page took 0.042519 seconds and 4 git commands to generate.