Regenerate cgen-derived files.
[deliverable/binutils-gdb.git] / gold / target-select.cc
CommitLineData
14bfc3f5
ILT
1// target-select.cc -- select a target for an object file
2
2ea97941 3// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
6cb15b7f
ILT
4// Written by Ian Lance Taylor <iant@google.com>.
5
6// This file is part of gold.
7
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.
12
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.
17
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.
22
14bfc3f5
ILT
23#include "gold.h"
24
04bf7072
ILT
25#include <cstring>
26
14bfc3f5
ILT
27#include "elfcpp.h"
28#include "target-select.h"
29
30namespace
31{
32
33// The start of the list of target selectors.
34
35gold::Target_selector* target_selectors;
36
37} // End anonymous namespace.
38
39namespace gold
40{
41
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
44// fast.
45
2ea97941
ILT
46Target_selector::Target_selector(int machine, int size, bool is_big_endian,
47 const char* bfd_name)
48 : machine_(machine), size_(size), is_big_endian_(is_big_endian),
49 bfd_name_(bfd_name), instantiated_target_(NULL), lock_(NULL),
7f055c20 50 initialize_lock_(&this->lock_)
e96caa79 51
14bfc3f5
ILT
52{
53 this->next_ = target_selectors;
54 target_selectors = this;
55}
56
7f055c20
ILT
57// Instantiate the target and return it. Use a lock to avoid
58// instantiating two instances of the same target.
59
60Target*
61Target_selector::instantiate_target()
62{
22fd9730
ILT
63 // We assume that the pointer will either be written entirely or not
64 // at all.
7f055c20 65 if (this->instantiated_target_ == NULL)
22fd9730
ILT
66 {
67 this->initialize_lock_.initialize();
68 Hold_optional_lock hl(this->lock_);
69 if (this->instantiated_target_ == NULL)
70 this->instantiated_target_ = this->do_instantiate_target();
71 }
7f055c20
ILT
72 return this->instantiated_target_;
73}
74
14bfc3f5
ILT
75// Find the target for an ELF file.
76
0daa6f62 77Target*
6340166c 78select_target(int machine, int size, bool is_big_endian, int osabi,
14bfc3f5
ILT
79 int abiversion)
80{
ead1e424 81 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
14bfc3f5
ILT
82 {
83 int pmach = p->machine();
84 if ((pmach == machine || pmach == elfcpp::EM_NONE)
6340166c
ILT
85 && p->get_size() == size
86 && (p->is_big_endian() ? is_big_endian : !is_big_endian))
14bfc3f5
ILT
87 {
88 Target* ret = p->recognize(machine, osabi, abiversion);
89 if (ret != NULL)
90 return ret;
91 }
92 }
93 return NULL;
94}
95
0daa6f62
ILT
96// Find a target using a BFD name. This is used to support the
97// --oformat option.
98
99Target*
100select_target_by_name(const char* name)
101{
102 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
103 {
e96caa79
ILT
104 const char* pname = p->bfd_name();
105 if (pname == NULL || strcmp(pname, name) == 0)
106 {
107 Target* ret = p->recognize_by_name(name);
108 if (ret != NULL)
109 return ret;
110 }
0daa6f62
ILT
111 }
112 return NULL;
113}
114
e96caa79
ILT
115// Push all the supported BFD names onto a vector.
116
117void
118supported_target_names(std::vector<const char*>* names)
119{
120 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
121 p->supported_names(names);
122}
123
14bfc3f5 124} // End namespace gold.
This page took 0.191374 seconds and 4 git commands to generate.