1 // target-select.cc -- select a target for an object file
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.
28 #include "target-select.h"
33 // The start of the list of target selectors.
35 gold::Target_selector* target_selectors;
37 } // End anonymous namespace.
42 // Construct a Target_selector, which means adding it to the linked
43 // list. This runs at global constructor time, so we want it to be
46 Target_selector::Target_selector(int machine, int size, bool is_big_endian,
48 : machine_(machine), size_(size), is_big_endian_(is_big_endian),
49 bfd_name_(bfd_name), instantiated_target_(NULL), lock_(NULL),
50 initialize_lock_(&this->lock_)
53 this->next_ = target_selectors;
54 target_selectors = this;
57 // Instantiate the target and return it. Use a lock to avoid
58 // instantiating two instances of the same target.
61 Target_selector::instantiate_target()
63 this->initialize_lock_.initialize();
64 Hold_optional_lock hl(this->lock_);
65 if (this->instantiated_target_ == NULL)
66 this->instantiated_target_ = this->do_instantiate_target();
67 return this->instantiated_target_;
70 // Find the target for an ELF file.
73 select_target(int machine, int size, bool is_big_endian, int osabi,
76 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
78 int pmach = p->machine();
79 if ((pmach == machine || pmach == elfcpp::EM_NONE)
80 && p->get_size() == size
81 && (p->is_big_endian() ? is_big_endian : !is_big_endian))
83 Target* ret = p->recognize(machine, osabi, abiversion);
91 // Find a target using a BFD name. This is used to support the
95 select_target_by_name(const char* name)
97 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
99 const char* pname = p->bfd_name();
100 if (pname == NULL || strcmp(pname, name) == 0)
102 Target* ret = p->recognize_by_name(name);
110 // Push all the supported BFD names onto a vector.
113 supported_target_names(std::vector<const char*>* names)
115 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
116 p->supported_names(names);
119 } // End namespace gold.