daily update
[deliverable/binutils-gdb.git] / gold / target-select.cc
CommitLineData
14bfc3f5
ILT
1// target-select.cc -- select a target for an object file
2
ebdbb458 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
25#include "elfcpp.h"
26#include "target-select.h"
27
28namespace
29{
30
31// The start of the list of target selectors.
32
33gold::Target_selector* target_selectors;
34
35} // End anonymous namespace.
36
37namespace gold
38{
39
40// Construct a Target_selector, which means adding it to the linked
41// list. This runs at global constructor time, so we want it to be
42// fast.
43
e96caa79
ILT
44Target_selector::Target_selector(int machine, int size, bool is_big_endian,
45 const char* bfd_name)
46 : machine_(machine), size_(size), is_big_endian_(is_big_endian),
47 bfd_name_(bfd_name), instantiated_target_(NULL)
48
14bfc3f5
ILT
49{
50 this->next_ = target_selectors;
51 target_selectors = this;
52}
53
54// Find the target for an ELF file.
55
0daa6f62 56Target*
6340166c 57select_target(int machine, int size, bool is_big_endian, int osabi,
14bfc3f5
ILT
58 int abiversion)
59{
ead1e424 60 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
14bfc3f5
ILT
61 {
62 int pmach = p->machine();
63 if ((pmach == machine || pmach == elfcpp::EM_NONE)
6340166c
ILT
64 && p->get_size() == size
65 && (p->is_big_endian() ? is_big_endian : !is_big_endian))
14bfc3f5
ILT
66 {
67 Target* ret = p->recognize(machine, osabi, abiversion);
68 if (ret != NULL)
69 return ret;
70 }
71 }
72 return NULL;
73}
74
0daa6f62
ILT
75// Find a target using a BFD name. This is used to support the
76// --oformat option.
77
78Target*
79select_target_by_name(const char* name)
80{
81 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
82 {
e96caa79
ILT
83 const char* pname = p->bfd_name();
84 if (pname == NULL || strcmp(pname, name) == 0)
85 {
86 Target* ret = p->recognize_by_name(name);
87 if (ret != NULL)
88 return ret;
89 }
0daa6f62
ILT
90 }
91 return NULL;
92}
93
e96caa79
ILT
94// Push all the supported BFD names onto a vector.
95
96void
97supported_target_names(std::vector<const char*>* names)
98{
99 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
100 p->supported_names(names);
101}
102
14bfc3f5 103} // End namespace gold.
This page took 0.083658 seconds and 4 git commands to generate.