Handle R_X86_64_32 like R_X86_64_64 for ILP32.
[binutils.git] / gold / target-select.h
blob4e2ea92268434fef69d65ac760258540cae1639d
1 // target-select.h -- select a target for an object file -*- C++ -*-
3 // Copyright 2006, 2007, 2008, 2009, 2010 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 #ifndef GOLD_TARGET_SELECT_H
24 #define GOLD_TARGET_SELECT_H
26 #include <vector>
28 #include "gold-threads.h"
30 namespace gold
33 class Target;
34 class Target_selector;
36 // Used to set the target only once.
38 class Set_target_once : public Once
40 public:
41 Set_target_once(Target_selector* target_selector)
42 : target_selector_(target_selector)
43 { }
45 protected:
46 void
47 do_run_once(void*);
49 private:
50 Target_selector* target_selector_;
53 // We want to avoid a master list of targets, which implies using a
54 // global constructor. And we also want the program to start up as
55 // quickly as possible, which implies avoiding global constructors.
56 // We compromise on a very simple global constructor. We use a target
57 // selector, which specifies an ELF machine number and a recognition
58 // function. We use global constructors to build a linked list of
59 // target selectors--a simple pointer list, not a std::list.
61 class Target_selector
63 public:
64 // Create a target selector for a specific machine number, size (32
65 // or 64), and endianness. The machine number can be EM_NONE to
66 // test for any machine number. BFD_NAME is the name of the target
67 // used by the GNU linker, for backward compatibility; it may be
68 // NULL.
69 Target_selector(int machine, int size, bool is_big_endian,
70 const char* bfd_name);
72 virtual ~Target_selector()
73 { }
75 // If we can handle this target, return a pointer to a target
76 // structure. The size and endianness are known.
77 Target*
78 recognize(int machine, int osabi, int abiversion)
79 { return this->do_recognize(machine, osabi, abiversion); }
81 // If NAME matches the target, return a pointer to a target
82 // structure.
83 Target*
84 recognize_by_name(const char* name)
85 { return this->do_recognize_by_name(name); }
87 // Push all supported names onto the vector. This is only used for
88 // help output.
89 void
90 supported_names(std::vector<const char*>* names)
91 { this->do_supported_names(names); }
93 // Return the next Target_selector in the linked list.
94 Target_selector*
95 next() const
96 { return this->next_; }
98 // Return the machine number this selector is looking for. This can
99 // be EM_NONE to match any machine number, in which case the
100 // do_recognize hook will be responsible for matching the machine
101 // number.
103 machine() const
104 { return this->machine_; }
106 // Return the size this is looking for (32 or 64).
108 get_size() const
109 { return this->size_; }
111 // Return the endianness this is looking for.
112 bool
113 is_big_endian() const
114 { return this->is_big_endian_; }
116 // Return the BFD name. This may return NULL, in which case the
117 // do_recognize_by_name hook will be responsible for matching the
118 // BFD name.
119 const char*
120 bfd_name() const
121 { return this->bfd_name_; }
123 protected:
124 // Return an instance of the real target. This must be implemented
125 // by the child class.
126 virtual Target*
127 do_instantiate_target() = 0;
129 // Recognize an object file given a machine code, OSABI code, and
130 // ELF version value. When this is called we already know that they
131 // match the machine_, size_, and is_big_endian_ fields. The child
132 // class may implement a different version of this to do additional
133 // checks, or to check for multiple machine codes if the machine_
134 // field is EM_NONE.
135 virtual Target*
136 do_recognize(int, int, int)
137 { return this->instantiate_target(); }
139 // Recognize a target by name. When this is called we already know
140 // that the name matches (or that the bfd_name_ field is NULL). The
141 // child class may implement a different version of this to
142 // recognize more than one name.
143 virtual Target*
144 do_recognize_by_name(const char*)
145 { return this->instantiate_target(); }
147 // Return a list of supported BFD names. The child class may
148 // implement a different version of this to handle more than one
149 // name.
150 virtual void
151 do_supported_names(std::vector<const char*>* names)
153 gold_assert(this->bfd_name_ != NULL);
154 names->push_back(this->bfd_name_);
157 // Instantiate the target and return it.
158 Target*
159 instantiate_target();
161 private:
162 // Set the target.
163 void
164 set_target();
166 friend class Set_target_once;
168 // ELF machine code.
169 const int machine_;
170 // Target size--32 or 64.
171 const int size_;
172 // Whether the target is big endian.
173 const bool is_big_endian_;
174 // BFD name of target, for compatibility.
175 const char* const bfd_name_;
176 // Next entry in list built at global constructor time.
177 Target_selector* next_;
178 // The singleton Target structure--this points to an instance of the
179 // real implementation.
180 Target* instantiated_target_;
181 // Used to set the target only once.
182 Set_target_once set_target_once_;
185 // Select the target for an ELF file.
187 extern Target*
188 select_target(int machine, int size, bool big_endian, int osabi,
189 int abiversion);
191 // Select a target using a BFD name.
193 extern Target*
194 select_target_by_name(const char* name);
196 // Fill in a vector with the list of supported targets. This returns
197 // a list of BFD names.
199 extern void
200 supported_target_names(std::vector<const char*>*);
202 } // End namespace gold.
204 #endif // !defined(GOLD_TARGET_SELECT_H)