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.
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().
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')
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] == '.')
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] == '_')
59 // Implementations of methods Target::do_make_elf_object are almost identical
60 // except for the address sizes and endianities. So we extract this
63 template<int size
, bool big_endian
>
65 Target::do_make_elf_object_implementation(
66 const std::string
& name
,
67 Input_file
* input_file
,
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
);
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
);
88 gold_error(_("%s: unsupported ELF file type %d"),
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
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
,
108 #ifdef HAVE_TARGET_32_BIG
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
,
118 #ifdef HAVE_TARGET_64_LITTLE
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
,
128 #ifdef HAVE_TARGET_64_BIG
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
,
138 } // End namespace gold.