1 // target.h -- target support for gold -*- C++ -*-
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
4 // Written by Ian Lance Taylor <iant@google.com>.
6 // This file is part of gold.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
23 // The abstract class Target is the interface for target specific
24 // support. It defines abstract methods which each target must
25 // implement. Typically there will be one target per processor, but
26 // in some cases it may be necessary to have subclasses.
28 // For speed and consistency we want to use inline functions to handle
29 // relocation processing. So besides implementations of the abstract
30 // methods, each target is expected to define a template
31 // specialization of the relocation functions.
41 class General_options
;
43 template<int size
, bool big_endian
>
45 template<int size
, bool big_endian
>
52 // The abstract class for target specific handling.
60 // Return the bit size that this target implements. This should
64 { return this->pti_
->size
; }
66 // Return whether this target is big-endian.
69 { return this->pti_
->is_big_endian
; }
71 // Machine code to store in e_machine field of ELF header.
74 { return this->pti_
->machine_code
; }
76 // Whether this target has a specific make_symbol function.
78 has_make_symbol() const
79 { return this->pti_
->has_make_symbol
; }
81 // Whether this target has a specific resolve function.
84 { return this->pti_
->has_resolve
; }
86 // Whether this target has a specific code fill function.
89 { return this->pti_
->has_code_fill
; }
91 // Return the default name of the dynamic linker.
93 dynamic_linker() const
94 { return this->pti_
->dynamic_linker
; }
96 // Return the default address to use for the text segment.
98 text_segment_address() const
99 { return this->pti_
->text_segment_address
; }
101 // Return the ABI specified page size.
104 { return this->pti_
->abi_pagesize
; }
106 // Return the common page size used on actual systems.
108 common_pagesize() const
109 { return this->pti_
->common_pagesize
; }
111 // This is called to tell the target to complete any sections it is
112 // handling. After this all sections must have their final size.
114 finalize_sections(Layout
* layout
)
115 { return this->do_finalize_sections(layout
); }
117 // Return the value to use for a global symbol which needs a special
118 // value in the dynamic symbol table. This will only be called if
119 // the backend first calls symbol->set_needs_dynsym_value().
121 dynsym_value(const Symbol
* sym
) const
122 { return this->do_dynsym_value(sym
); }
124 // Return a string to use to fill out a code section. This is
125 // basically one or more NOPS which must fill out the specified
128 code_fill(off_t length
)
129 { return this->do_code_fill(length
); }
132 // This struct holds the constant information for a child class. We
133 // use a struct to avoid the overhead of virtual function calls for
134 // simple information.
137 // Address size (32 or 64).
139 // Whether the target is big endian.
141 // The code to store in the e_machine field of the ELF header.
142 elfcpp::EM machine_code
;
143 // Whether this target has a specific make_symbol function.
144 bool has_make_symbol
;
145 // Whether this target has a specific resolve function.
147 // Whether this target has a specific code fill function.
149 // The default dynamic linker name.
150 const char* dynamic_linker
;
151 // The default text segment address.
152 uint64_t text_segment_address
;
153 // The ABI specified page size.
154 uint64_t abi_pagesize
;
155 // The common page size used by actual implementations.
156 uint64_t common_pagesize
;
159 Target(const Target_info
* pti
)
163 // Virtual function which may be implemented by the child class.
165 do_finalize_sections(Layout
*)
168 // Virtual function which may be implemented by the child class.
170 do_dynsym_value(const Symbol
*) const
171 { gold_unreachable(); }
173 // Virtual function which must be implemented by the child class if
177 { gold_unreachable(); }
180 Target(const Target
&);
181 Target
& operator=(const Target
&);
183 // The target information.
184 const Target_info
* pti_
;
187 // The abstract class for a specific size and endianness of target.
188 // Each actual target implementation class should derive from an
189 // instantiation of Sized_target.
191 template<int size
, bool big_endian
>
192 class Sized_target
: public Target
195 // Make a new symbol table entry for the target. This should be
196 // overridden by a target which needs additional information in the
197 // symbol table. This will only be called if has_make_symbol()
199 virtual Sized_symbol
<size
>*
201 { gold_unreachable(); }
203 // Resolve a symbol for the target. This should be overridden by a
204 // target which needs to take special action. TO is the
205 // pre-existing symbol. SYM is the new symbol, seen in OBJECT.
206 // VERSION is the version of SYM. This will only be called if
207 // has_resolve() returns true.
209 resolve(Symbol
*, const elfcpp::Sym
<size
, big_endian
>&, Object
*,
211 { gold_unreachable(); }
213 // Scan the relocs for a section, and record any information
214 // required for the symbol. OPTIONS is the command line options.
215 // SYMTAB is the symbol table. OBJECT is the object in which the
216 // section appears. DATA_SHNDX is the section index that these
217 // relocs apply to. SH_TYPE is the type of the relocation section,
218 // SHT_REL or SHT_RELA. PRELOCS points to the relocation data.
219 // RELOC_COUNT is the number of relocs. LOCAL_SYMBOL_COUNT is the
220 // number of local symbols. PLOCAL_SYMBOLS points to the local
221 // symbol data from OBJECT. GLOBAL_SYMBOLS is the array of pointers
222 // to the global symbol table from OBJECT.
224 scan_relocs(const General_options
& options
,
225 Symbol_table
* symtab
,
227 Sized_relobj
<size
, big_endian
>* object
,
228 unsigned int data_shndx
,
229 unsigned int sh_type
,
230 const unsigned char* prelocs
,
232 size_t local_symbol_count
,
233 const unsigned char* plocal_symbols
,
234 Symbol
** global_symbols
) = 0;
236 // Relocate section data. SH_TYPE is the type of the relocation
237 // section, SHT_REL or SHT_RELA. PRELOCS points to the relocation
238 // information. RELOC_COUNT is the number of relocs. VIEW is a
239 // view into the output file holding the section contents,
240 // VIEW_ADDRESS is the virtual address of the view, and VIEW_SIZE is
241 // the size of the view.
243 relocate_section(const Relocate_info
<size
, big_endian
>*,
244 unsigned int sh_type
,
245 const unsigned char* prelocs
,
248 typename
elfcpp::Elf_types
<size
>::Elf_Addr view_address
,
249 off_t view_size
) = 0;
252 Sized_target(const Target::Target_info
* pti
)
255 gold_assert(pti
->size
== size
);
256 gold_assert(pti
->is_big_endian
? big_endian
: !big_endian
);
260 } // End namespace gold.
262 #endif // !defined(GOLD_TARGET_H)