1 // reloc.h -- relocate input files for gold -*- C++ -*-
14 class Read_relocs_data
;
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
22 class Read_relocs
: public Task
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
,
30 : options_(options
), symtab_(symtab
), layout_(layout
), object_(object
),
31 symtab_lock_(symtab_lock
), blocker_(blocker
)
34 // The standard Task methods.
37 is_runnable(Workqueue
*);
46 const General_options
& options_
;
47 Symbol_table
* symtab_
;
50 Task_token
* symtab_lock_
;
54 // Scan the relocations for an object to see if they require any
55 // GOT/PLT/COPY relocations.
57 class Scan_relocs
: public Task
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
)
69 // The standard Task methods.
72 is_runnable(Workqueue
*);
81 class Scan_relocs_locker
;
83 const General_options
& options_
;
84 Symbol_table
* symtab_
;
87 Read_relocs_data
* rd_
;
88 Task_token
* symtab_lock_
;
92 // A class to perform all the relocations for an object file.
94 class Relocate_task
: public Task
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
)
104 // The standard Task methods.
107 is_runnable(Workqueue
*);
116 class Relocate_locker
;
118 const General_options
& options_
;
119 const Symbol_table
* symtab_
;
120 const Layout
* layout_
;
123 Task_token
* final_blocker_
;
126 // Standard relocation routines which are used on many targets. Here
127 // SIZE and BIG_ENDIAN refer to the target, not the relocation type.
129 template<int size
, bool big_endian
>
130 class Relocate_functions
133 // Do a simple relocation with the addend in the section contents.
134 // VALSIZE is the size of the value.
135 template<int valsize
>
137 rel(unsigned char* view
,
138 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype value
)
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
);
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
>
150 pcrel(unsigned char* view
,
151 typename
elfcpp::Swap
<valsize
, big_endian
>::Valtype value
,
152 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
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
);
160 typedef Relocate_functions
<size
, big_endian
> This
;
163 // Do a simple 8-bit REL relocation with the addend in the object
166 rel8(unsigned char* view
, unsigned char value
)
168 This::template rel
<8>(view
, value
);
171 // Do a simple 8-bit PC relative relocation with the addend in the
174 pcrel8(unsigned char* view
, unsigned char value
,
175 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
177 This::template pcrel
<8>(view
, value
, address
);
180 // Do a simple 16-bit REL relocation with the addend in the object
183 rel16(unsigned char* view
, elfcpp::Elf_Half value
)
185 This::template rel
<16>(view
, value
);
188 // Do a simple 32-bit PC relative REL relocation with the addend in
189 // the object file data.
191 pcrel16(unsigned char* view
, elfcpp::Elf_Word value
,
192 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
194 This::template pcrel
<16>(view
, value
, address
);
197 // Do a simple 32-bit REL relocation with the addend in the section
200 rel32(unsigned char* view
, elfcpp::Elf_Word value
)
202 This::template rel
<32>(view
, value
);
205 // Do a simple 32-bit PC relative REL relocation with the addend in
206 // the section contents.
208 pcrel32(unsigned char* view
, elfcpp::Elf_Word value
,
209 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
211 This::template pcrel
<32>(view
, value
, address
);
214 // Do a simple 64-bit REL relocation with the addend in the section
217 rel64(unsigned char* view
, elfcpp::Elf_Xword value
)
219 This::template rel
<64>(view
, value
);
222 // Do a simple 64-bit PC relative REL relocation with the addend in
223 // the section contents.
225 pcrel64(unsigned char* view
, elfcpp::Elf_Xword value
,
226 typename
elfcpp::Elf_types
<size
>::Elf_Addr address
)
228 This::template pcrel
<64>(view
, value
, address
);
232 } // End namespace gold.
234 #endif // !defined(GOLD_RELOC_H)