Add licensing text to every source file.
[deliverable/binutils-gdb.git] / gold / target-select.cc
1 // target-select.cc -- select a target for an object file
2
3 // Copyright 2006, 2007 Free Software Foundation, Inc.
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
23 #include "gold.h"
24
25 #include "elfcpp.h"
26 #include "target-select.h"
27
28 namespace
29 {
30
31 // The start of the list of target selectors.
32
33 gold::Target_selector* target_selectors;
34
35 } // End anonymous namespace.
36
37 namespace 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
44 Target_selector::Target_selector(int machine, int size, bool big_endian)
45 : machine_(machine), size_(size), big_endian_(big_endian)
46 {
47 this->next_ = target_selectors;
48 target_selectors = this;
49 }
50
51 // Find the target for an ELF file.
52
53 extern Target*
54 select_target(int machine, int size, bool big_endian, int osabi,
55 int abiversion)
56 {
57 for (Target_selector* p = target_selectors; p != NULL; p = p->next())
58 {
59 int pmach = p->machine();
60 if ((pmach == machine || pmach == elfcpp::EM_NONE)
61 && p->size() == size
62 && p->big_endian() ? big_endian : !big_endian)
63 {
64 Target* ret = p->recognize(machine, osabi, abiversion);
65 if (ret != NULL)
66 return ret;
67 }
68 }
69 return NULL;
70 }
71
72 } // End namespace gold.
This page took 0.030459 seconds and 5 git commands to generate.