1 // target-select.h -- select a target for an object file -*- C++ -*-
3 // Copyright 2006, 2007, 2008 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
33 // We want to avoid a master list of targets, which implies using a
34 // global constructor. And we also want the program to start up as
35 // quickly as possible, which implies avoiding global constructors.
36 // We compromise on a very simple global constructor. We use a target
37 // selector, which specifies an ELF machine number and a recognition
38 // function. We use global constructors to build a linked list of
39 // target selectors--a simple pointer list, not a std::list.
44 // Create a target selector for a specific machine number, size (32
45 // or 64), and endianness. The machine number can be EM_NONE to
46 // test for any machine number. BFD_NAME is the name of the target
47 // used by the GNU linker, for backward compatibility; it may be
49 Target_selector(int machine
, int size
, bool is_big_endian
,
50 const char* bfd_name
);
52 virtual ~Target_selector()
55 // If we can handle this target, return a pointer to a target
56 // structure. The size and endianness are known.
58 recognize(int machine
, int osabi
, int abiversion
)
59 { return this->do_recognize(machine
, osabi
, abiversion
); }
61 // If NAME matches the target, return a pointer to a target
64 recognize_by_name(const char* name
)
65 { return this->do_recognize_by_name(name
); }
67 // Push all supported names onto the vector. This is only used for
70 supported_names(std::vector
<const char*>* names
)
71 { this->do_supported_names(names
); }
73 // Return the next Target_selector in the linked list.
76 { return this->next_
; }
78 // Return the machine number this selector is looking for. This can
79 // be EM_NONE to match any machine number, in which case the
80 // do_recognize hook will be responsible for matching the machine
84 { return this->machine_
; }
86 // Return the size this is looking for (32 or 64).
89 { return this->size_
; }
91 // Return the endianness this is looking for.
94 { return this->is_big_endian_
; }
96 // Return the BFD name. This may return NULL, in which case the
97 // do_recognize_by_name hook will be responsible for matching the
101 { return this->bfd_name_
; }
104 // Return an instance of the real target. This must be implemented
105 // by the child class.
107 do_instantiate_target() = 0;
109 // Recognize an object file given a machine code, size, and
110 // endianness. When this is called we already know that they match
111 // the machine_, size_, and is_big_endian_ fields. The child class
112 // may implement a different version of this to do additional
113 // checks, or to check for multiple machine codes if the machine_
116 do_recognize(int, int, int)
117 { return this->instantiate_target(); }
119 // Recognize a target by name. When this is called we already know
120 // that the name matches (or that the bfd_name_ field is NULL). The
121 // child class may implement a different version of this to
122 // recognize more than one name.
124 do_recognize_by_name(const char*)
125 { return this->instantiate_target(); }
127 // Return a list of supported BFD names. The child class may
128 // implement a different version of this to handle more than one
131 do_supported_names(std::vector
<const char*>* names
)
133 gold_assert(this->bfd_name_
!= NULL
);
134 names
->push_back(this->bfd_name_
);
138 // Instantiate the target and return it.
142 if (this->instantiated_target_
== NULL
)
143 this->instantiated_target_
= this->do_instantiate_target();
144 return this->instantiated_target_
;
149 // Target size--32 or 64.
151 // Whether the target is big endian.
152 const bool is_big_endian_
;
153 // BFD name of target, for compatibility.
154 const char* const bfd_name_
;
155 // Next entry in list built at global constructor time.
156 Target_selector
* next_
;
157 // The singleton Target structure--this points to an instance of the
158 // real implementation.
159 Target
* instantiated_target_
;
162 // Select the target for an ELF file.
165 select_target(int machine
, int size
, bool big_endian
, int osabi
,
168 // Select a target using a BFD name.
171 select_target_by_name(const char* name
);
173 // Fill in a vector with the list of supported targets. This returns
174 // a list of BFD names.
177 supported_target_names(std::vector
<const char*>*);
179 } // End namespace gold.
181 #endif // !defined(GOLD_TARGET_SELECT_H)