Sync toplevel with GCC, merge.
[binutils.git] / gold / target.cc
blob2dca98a06ec503a7150e0898702e29a7508224e3
1 // target.cc
3 // Copyright 2009 Free Software Foundation, Inc.
4 // Written by Doug Kwan <dougkwan@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 #include "gold.h"
24 #include "target.h"
25 #include "dynobj.h"
27 namespace gold
30 // Return whether NAME is a local label name. This is used to implement the
31 // --discard-locals options and can be overriden by children classes to
32 // implement system-specific behaviour. The logic here is the same as that
33 // in _bfd_elf_is_local_label_name().
35 bool
36 Target::do_is_local_label_name (const char* name) const
38 // Normal local symbols start with ``.L''.
39 if (name[0] == '.' && name[1] == 'L')
40 return true;
42 // At least some SVR4 compilers (e.g., UnixWare 2.1 cc) generate
43 // DWARF debugging symbols starting with ``..''.
44 if (name[0] == '.' && name[1] == '.')
45 return true;
47 // gcc will sometimes generate symbols beginning with ``_.L_'' when
48 // emitting DWARF debugging output. I suspect this is actually a
49 // small bug in gcc (it calls ASM_OUTPUT_LABEL when it should call
50 // ASM_GENERATE_INTERNAL_LABEL, and this causes the leading
51 // underscore to be emitted on some ELF targets). For ease of use,
52 // we treat such symbols as local.
53 if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_')
54 return true;
56 return false;
59 // Implementations of methods Target::do_make_elf_object are almost identical
60 // except for the address sizes and endianities. So we extract this
61 // into a template.
63 template<int size, bool big_endian>
64 inline Object*
65 Target::do_make_elf_object_implementation(
66 const std::string& name,
67 Input_file* input_file,
68 off_t offset,
69 const elfcpp::Ehdr<size, big_endian>& ehdr)
71 int et = ehdr.get_e_type();
72 if (et == elfcpp::ET_REL)
74 Sized_relobj<size, big_endian>* obj =
75 new Sized_relobj<size, big_endian>(name, input_file, offset, ehdr);
76 obj->setup(this);
77 return obj;
79 else if (et == elfcpp::ET_DYN)
81 Sized_dynobj<size, big_endian>* obj =
82 new Sized_dynobj<size, big_endian>(name, input_file, offset, ehdr);
83 obj->setup(this);
84 return obj;
86 else
88 gold_error(_("%s: unsupported ELF file type %d"),
89 name.c_str(), et);
90 return NULL;
94 // Make an ELF object called NAME by reading INPUT_FILE at OFFSET. EHDR
95 // is the ELF header of the object. There are four versions of this
96 // for different address sizes and endianities.
98 #ifdef HAVE_TARGET_32_LITTLE
99 Object*
100 Target::do_make_elf_object(const std::string& name, Input_file* input_file,
101 off_t offset, const elfcpp::Ehdr<32, false>& ehdr)
103 return this->do_make_elf_object_implementation<32, false>(name, input_file,
104 offset, ehdr);
106 #endif
108 #ifdef HAVE_TARGET_32_BIG
109 Object*
110 Target::do_make_elf_object(const std::string& name, Input_file* input_file,
111 off_t offset, const elfcpp::Ehdr<32, true>& ehdr)
113 return this->do_make_elf_object_implementation<32, true>(name, input_file,
114 offset, ehdr);
116 #endif
118 #ifdef HAVE_TARGET_64_LITTLE
119 Object*
120 Target::do_make_elf_object(const std::string& name, Input_file* input_file,
121 off_t offset, const elfcpp::Ehdr<64, false>& ehdr)
123 return this->do_make_elf_object_implementation<64, false>(name, input_file,
124 offset, ehdr);
126 #endif
128 #ifdef HAVE_TARGET_64_BIG
129 Object*
130 Target::do_make_elf_object(const std::string& name, Input_file* input_file,
131 off_t offset, const elfcpp::Ehdr<64, true>& ehdr)
133 return this->do_make_elf_object_implementation<64, true>(name, input_file,
134 offset, ehdr);
136 #endif
138 } // End namespace gold.