blob: 37435841c3bd4c672b3704a352e76ccafd48ca3b [file] [log] [blame]
Michael J. Spencer84487f12015-07-24 21:03:071//===- Symbols.cpp --------------------------------------------------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "Symbols.h"
Rafael Espindola49a2ca62015-08-06 15:33:1911#include "Error.h"
Michael J. Spencercdae0a42015-07-28 22:58:2512#include "InputFiles.h"
Rui Ueyamab5a69702016-02-01 21:00:3513#include "InputSection.h"
14#include "OutputSections.h"
Rui Ueyamaa3ac1732016-11-24 20:24:1815#include "Strings.h"
Rui Ueyamae8a61022016-11-05 23:05:4716#include "SyntheticSections.h"
Rui Ueyamab5a69702016-02-01 21:00:3517#include "Target.h"
Rafael Espindola17cb7c02016-12-19 17:01:0118#include "Writer.h"
Michael J. Spencer84487f12015-07-24 21:03:0719
Michael J. Spencer1b348a62015-09-04 22:28:1020#include "llvm/ADT/STLExtras.h"
Eugene Leviantc958d8d2016-10-12 08:19:3021#include "llvm/Support/Path.h"
Rui Ueyamac72ba3a2016-11-23 04:57:2522#include <cstring>
Michael J. Spencer1b348a62015-09-04 22:28:1023
24using namespace llvm;
Michael J. Spencer84487f12015-07-24 21:03:0725using namespace llvm::object;
Rafael Espindola78471f02015-09-01 23:12:5226using namespace llvm::ELF;
Michael J. Spencer84487f12015-07-24 21:03:0727
28using namespace lld;
Rafael Espindolae0df00b2016-02-28 00:25:5429using namespace lld::elf;
Michael J. Spencer84487f12015-07-24 21:03:0730
Rui Ueyama80474a22017-02-28 19:29:5531InputSectionBase *DefinedRegular::NullInputSection;
32
33DefinedSynthetic *ElfSym::Etext;
34DefinedSynthetic *ElfSym::Etext2;
35DefinedSynthetic *ElfSym::Edata;
36DefinedSynthetic *ElfSym::Edata2;
37DefinedSynthetic *ElfSym::End;
38DefinedSynthetic *ElfSym::End2;
39DefinedRegular *ElfSym::MipsGpDisp;
40DefinedRegular *ElfSym::MipsLocalGp;
41DefinedRegular *ElfSym::MipsGp;
42
Rui Ueyamab5a69702016-02-01 21:00:3543template <class ELFT>
Rafael Espindola7386cea2017-02-16 00:12:3444static typename ELFT::uint getSymVA(const SymbolBody &Body, int64_t &Addend) {
Rui Ueyama9328b2c2016-03-14 23:16:0945 typedef typename ELFT::uint uintX_t;
Rafael Espindola87d9f102016-03-11 12:19:0546
47 switch (Body.kind()) {
48 case SymbolBody::DefinedSyntheticKind: {
Rui Ueyama4f2f50d2016-12-21 08:40:0949 auto &D = cast<DefinedSynthetic>(Body);
Rafael Espindola24e6f362017-02-24 15:07:3050 const OutputSection *Sec = D.Section;
Peter Collingbourne6a422592016-05-03 01:21:0851 if (!Sec)
52 return D.Value;
Rui Ueyama4f2f50d2016-12-21 08:40:0953 if (D.Value == uintX_t(-1))
Rafael Espindola04a2e342016-11-09 01:42:4154 return Sec->Addr + Sec->Size;
55 return Sec->Addr + D.Value;
Rui Ueyamab5a69702016-02-01 21:00:3556 }
Rafael Espindola87d9f102016-03-11 12:19:0557 case SymbolBody::DefinedRegularKind: {
Rui Ueyama80474a22017-02-28 19:29:5558 auto &D = cast<DefinedRegular>(Body);
Rafael Espindolab4c9b812017-02-23 02:28:2859 InputSectionBase *IS = D.Section;
Rui Ueyamab5a69702016-02-01 21:00:3560
Rafael Espindolaccfe3cb2016-04-04 14:04:1661 // According to the ELF spec reference to a local symbol from outside
62 // the group are not allowed. Unfortunately .eh_frame breaks that rule
63 // and must be treated specially. For now we just replace the symbol with
64 // 0.
Rafael Espindola774ea7d2017-02-23 16:49:0765 if (IS == &InputSection::Discarded)
Rafael Espindolaccfe3cb2016-04-04 14:04:1666 return 0;
67
Rui Ueyamab5a69702016-02-01 21:00:3568 // This is an absolute symbol.
Sean Silva902ae3c2016-12-15 00:57:5369 if (!IS)
Rafael Espindolaccfe3cb2016-04-04 14:04:1670 return D.Value;
Rui Ueyamab5a69702016-02-01 21:00:3571
Rafael Espindolaccfe3cb2016-04-04 14:04:1672 uintX_t Offset = D.Value;
Sean Silvaa9ba4502017-02-28 08:32:5673
74 // An object in an SHF_MERGE section might be referenced via a
75 // section symbol (as a hack for reducing the number of local
76 // symbols).
Sean Silvad4e60622017-03-01 04:44:0477 // Depending on the addend, the reference via a section symbol
78 // refers to a different object in the merge section.
79 // Since the objects in the merge section are not necessarily
80 // contiguous in the output, the addend can thus affect the final
81 // VA in a non-linear way.
82 // To make this work, we incorporate the addend into the section
83 // offset (and zero out the addend for later processing) so that
84 // we find the right object in the section.
Rafael Espindolaccfe3cb2016-04-04 14:04:1685 if (D.isSection()) {
Rafael Espindola1f5b70f2016-03-11 14:21:3786 Offset += Addend;
87 Addend = 0;
88 }
Sean Silvaa9ba4502017-02-28 08:32:5689
Rafael Espindola24e6f362017-02-24 15:07:3090 const OutputSection *OutSec = IS->getOutputSection<ELFT>();
Sean Silva6ab39262017-02-28 09:01:5891
92 // In the typical case, this is actually very simple and boils
93 // down to adding together 3 numbers:
94 // 1. The address of the output section.
95 // 2. The offset of the input section within the output section.
96 // 3. The offset within the input section (this addition happens
97 // inside InputSection::getOffset).
98 //
99 // If you understand the data structures involved with this next
100 // line (and how they get built), then you have a pretty good
101 // understanding of the linker.
Rafael Espindolab4c9b812017-02-23 02:28:28102 uintX_t VA = (OutSec ? OutSec->Addr : 0) + IS->getOffset<ELFT>(Offset);
Sean Silva6ab39262017-02-28 09:01:58103
George Rimar6a3b1542016-10-04 08:52:51104 if (D.isTls() && !Config->Relocatable) {
Rui Ueyama9d1bacb12017-02-27 02:31:26105 if (!Out::TlsPhdr)
Rui Ueyama3fc0f7e2016-11-23 18:07:33106 fatal(toString(D.File) +
George Rimar6a3b1542016-10-04 08:52:51107 " has a STT_TLS symbol but doesn't have a PT_TLS section");
Rui Ueyama9d1bacb12017-02-27 02:31:26108 return VA - Out::TlsPhdr->p_vaddr;
George Rimar6a3b1542016-10-04 08:52:51109 }
Rafael Espindola1f5b70f2016-03-11 14:21:37110 return VA;
Rui Ueyamab5a69702016-02-01 21:00:35111 }
Rui Ueyama07784902016-08-02 01:35:13112 case SymbolBody::DefinedCommonKind:
Rui Ueyamab2a23cf2017-01-24 03:41:20113 if (!Config->DefineCommon)
114 return 0;
Rafael Espindola04a2e342016-11-09 01:42:41115 return In<ELFT>::Common->OutSec->Addr + In<ELFT>::Common->OutSecOff +
Rafael Espindolae7553e42016-08-31 13:28:33116 cast<DefinedCommon>(Body).Offset;
Rafael Espindola87d9f102016-03-11 12:19:05117 case SymbolBody::SharedKind: {
Rui Ueyama4076fa12017-02-26 23:35:34118 auto &SS = cast<SharedSymbol>(Body);
Rui Ueyamaf829e8c2017-02-16 06:12:41119 if (SS.NeedsCopy)
120 return SS.Section->OutSec->Addr + SS.Section->OutSecOff;
Rui Ueyama924b3612017-02-16 06:12:22121 if (SS.NeedsPltAddr)
Rafael Espindola87d9f102016-03-11 12:19:05122 return Body.getPltVA<ELFT>();
Rui Ueyama924b3612017-02-16 06:12:22123 return 0;
Rui Ueyamab5a69702016-02-01 21:00:35124 }
Peter Collingbourne60976ed2016-04-27 00:05:06125 case SymbolBody::UndefinedKind:
Rui Ueyamab5a69702016-02-01 21:00:35126 return 0;
Rui Ueyamaf8baa662016-04-07 19:24:51127 case SymbolBody::LazyArchiveKind:
128 case SymbolBody::LazyObjectKind:
Peter Collingbourne4f952702016-05-01 04:55:03129 assert(Body.symbol()->IsUsedInRegularObj && "lazy symbol reached writer");
Rui Ueyamab5a69702016-02-01 21:00:35130 return 0;
131 }
George Rimar777f9632016-03-12 08:31:34132 llvm_unreachable("invalid symbol kind");
Rui Ueyamab5a69702016-02-01 21:00:35133}
134
Rui Ueyamaa13efc22016-11-29 18:05:04135SymbolBody::SymbolBody(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther,
136 uint8_t Type)
Rui Ueyama924b3612017-02-16 06:12:22137 : SymbolKind(K), NeedsCopy(false), NeedsPltAddr(false), IsLocal(IsLocal),
Peter Smithbaffdb82016-12-08 12:58:55138 IsInGlobalMipsGot(false), Is32BitMipsGot(false), IsInIplt(false),
Rui Ueyama924b3612017-02-16 06:12:22139 IsInIgot(false), Type(Type), StOther(StOther), Name(Name) {}
Rafael Espindolaf4765732016-04-06 13:22:41140
Rui Ueyamac4466602016-03-13 19:48:18141// Returns true if a symbol can be replaced at load-time by a symbol
142// with the same name defined in other ELF executable or DSO.
143bool SymbolBody::isPreemptible() const {
144 if (isLocal())
145 return false;
146
Rafael Espindola66434562016-05-05 19:41:49147 // Shared symbols resolve to the definition in the DSO. The exceptions are
148 // symbols with copy relocations (which resolve to .bss) or preempt plt
149 // entries (which resolve to that plt entry).
Rui Ueyamac4466602016-03-13 19:48:18150 if (isShared())
Rui Ueyama924b3612017-02-16 06:12:22151 return !NeedsCopy && !NeedsPltAddr;
Rui Ueyamac4466602016-03-13 19:48:18152
Peter Collingbourne66ac1d62016-04-22 20:21:26153 // That's all that can be preempted in a non-DSO.
Rui Ueyamac4466602016-03-13 19:48:18154 if (!Config->Shared)
155 return false;
Peter Collingbourne66ac1d62016-04-22 20:21:26156
Peter Collingbournedbe41872016-04-24 04:29:59157 // Only symbols that appear in dynsym can be preempted.
Peter Collingbourne4f952702016-05-01 04:55:03158 if (!symbol()->includeInDynsym())
Rui Ueyamac4466602016-03-13 19:48:18159 return false;
Peter Collingbourne66ac1d62016-04-22 20:21:26160
Rafael Espindola580d7a12016-07-07 22:50:54161 // Only default visibility symbols can be preempted.
162 if (symbol()->Visibility != STV_DEFAULT)
163 return false;
164
165 // -Bsymbolic means that definitions are not preempted.
Peter Collingbournedbe41872016-04-24 04:29:59166 if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc()))
167 return !isDefined();
Rafael Espindola580d7a12016-07-07 22:50:54168 return true;
Rui Ueyamac4466602016-03-13 19:48:18169}
170
Rui Ueyamab5a69702016-02-01 21:00:35171template <class ELFT>
Rafael Espindola7386cea2017-02-16 00:12:34172typename ELFT::uint SymbolBody::getVA(int64_t Addend) const {
Rafael Espindola8381c562016-03-17 23:36:19173 typename ELFT::uint OutVA = getSymVA<ELFT>(*this, Addend);
174 return OutVA + Addend;
Rafael Espindola87d9f102016-03-11 12:19:05175}
176
Rui Ueyama9328b2c2016-03-14 23:16:09177template <class ELFT> typename ELFT::uint SymbolBody::getGotVA() const {
Eugene Leviantad4439e2016-11-11 11:33:32178 return In<ELFT>::Got->getVA() + getGotOffset<ELFT>();
Rafael Espindola74031ba2016-04-07 15:20:56179}
180
181template <class ELFT> typename ELFT::uint SymbolBody::getGotOffset() const {
Rui Ueyama803b1202016-07-13 18:55:14182 return GotIndex * Target->GotEntrySize;
Rui Ueyamab5a69702016-02-01 21:00:35183}
184
Rui Ueyama9328b2c2016-03-14 23:16:09185template <class ELFT> typename ELFT::uint SymbolBody::getGotPltVA() const {
Peter Smithbaffdb82016-12-08 12:58:55186 if (this->IsInIgot)
187 return In<ELFT>::IgotPlt->getVA() + getGotPltOffset<ELFT>();
Eugene Leviant41ca3272016-11-10 09:48:29188 return In<ELFT>::GotPlt->getVA() + getGotPltOffset<ELFT>();
Rafael Espindola74031ba2016-04-07 15:20:56189}
190
191template <class ELFT> typename ELFT::uint SymbolBody::getGotPltOffset() const {
Rui Ueyama803b1202016-07-13 18:55:14192 return GotPltIndex * Target->GotPltEntrySize;
Rui Ueyamab5a69702016-02-01 21:00:35193}
194
Rui Ueyama9328b2c2016-03-14 23:16:09195template <class ELFT> typename ELFT::uint SymbolBody::getPltVA() const {
Peter Smithbaffdb82016-12-08 12:58:55196 if (this->IsInIplt)
197 return In<ELFT>::Iplt->getVA() + PltIndex * Target->PltEntrySize;
Eugene Leviantff23d3e2016-11-18 14:35:03198 return In<ELFT>::Plt->getVA() + Target->PltHeaderSize +
Rui Ueyamab5a69702016-02-01 21:00:35199 PltIndex * Target->PltEntrySize;
200}
201
Rui Ueyama9328b2c2016-03-14 23:16:09202template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
Rafael Espindolae7553e42016-08-31 13:28:33203 if (const auto *C = dyn_cast<DefinedCommon>(this))
Rafael Espindolaccfe3cb2016-04-04 14:04:16204 return C->Size;
Rui Ueyama80474a22017-02-28 19:29:55205 if (const auto *DR = dyn_cast<DefinedRegular>(this))
Rafael Espindolaccfe3cb2016-04-04 14:04:16206 return DR->Size;
Rui Ueyama4076fa12017-02-26 23:35:34207 if (const auto *S = dyn_cast<SharedSymbol>(this))
208 return S->getSize<ELFT>();
Rui Ueyama512c61d2016-02-03 00:12:24209 return 0;
210}
211
Rui Ueyama968db482017-02-28 04:02:42212template <class ELFT>
213const OutputSection *SymbolBody::getOutputSection() const {
Rui Ueyama80474a22017-02-28 19:29:55214 if (auto *S = dyn_cast<DefinedRegular>(this)) {
Rui Ueyama968db482017-02-28 04:02:42215 if (S->Section)
216 return S->Section->template getOutputSection<ELFT>();
217 return nullptr;
218 }
219
220 if (auto *S = dyn_cast<SharedSymbol>(this)) {
221 if (S->NeedsCopy)
222 return S->Section->OutSec;
223 return nullptr;
224 }
225
226 if (isa<DefinedCommon>(this)) {
227 if (Config->DefineCommon)
228 return In<ELFT>::Common->OutSec;
229 return nullptr;
230 }
231
232 if (auto *S = dyn_cast<DefinedSynthetic>(this))
233 return S->Section;
234 return nullptr;
235}
236
Rui Ueyama35fa6c52016-11-23 05:48:40237// If a symbol name contains '@', the characters after that is
238// a symbol version name. This function parses that.
239void SymbolBody::parseSymbolVersion() {
240 StringRef S = getName();
241 size_t Pos = S.find('@');
242 if (Pos == 0 || Pos == StringRef::npos)
243 return;
244 StringRef Verstr = S.substr(Pos + 1);
245 if (Verstr.empty())
246 return;
247
248 // Truncate the symbol name so that it doesn't include the version string.
Rui Ueyamaa13efc22016-11-29 18:05:04249 Name = {S.data(), Pos};
Rui Ueyama35fa6c52016-11-23 05:48:40250
Rafael Espindola1d6d1b42017-01-17 16:08:06251 // If this is not in this DSO, it is not a definition.
252 if (!isInCurrentDSO())
Rafael Espindola2756e042017-01-06 22:30:35253 return;
254
Rui Ueyama35fa6c52016-11-23 05:48:40255 // '@@' in a symbol name means the default version.
256 // It is usually the most recent one.
257 bool IsDefault = (Verstr[0] == '@');
258 if (IsDefault)
259 Verstr = Verstr.substr(1);
260
261 for (VersionDefinition &Ver : Config->VersionDefinitions) {
262 if (Ver.Name != Verstr)
263 continue;
264
265 if (IsDefault)
266 symbol()->VersionId = Ver.Id;
267 else
268 symbol()->VersionId = Ver.Id | VERSYM_HIDDEN;
269 return;
270 }
271
272 // It is an error if the specified version is not defined.
Rui Ueyama44da9de2016-12-05 18:40:14273 error(toString(File) + ": symbol " + S + " has undefined version " + Verstr);
Rui Ueyama35fa6c52016-11-23 05:48:40274}
275
Rui Ueyamaa13efc22016-11-29 18:05:04276Defined::Defined(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther,
277 uint8_t Type)
278 : SymbolBody(K, Name, IsLocal, StOther, Type) {}
Rafael Espindola4d4b06a2015-12-24 00:47:42279
Rui Ueyama80474a22017-02-28 19:29:55280template <class ELFT> bool DefinedRegular::isMipsPIC() const {
Simon Atanasyanf967f092016-09-29 12:58:36281 if (!Section || !isFunc())
282 return false;
283 return (this->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC ||
Rafael Espindolab4c9b812017-02-23 02:28:28284 (Section->getFile<ELFT>()->getObj().getHeader()->e_flags &
285 EF_MIPS_PIC);
Simon Atanasyanf967f092016-09-29 12:58:36286}
287
Peter Smith3a52eb02017-02-01 10:26:03288Undefined::Undefined(StringRefZ Name, bool IsLocal, uint8_t StOther,
289 uint8_t Type, InputFile *File)
Rui Ueyamaa13efc22016-11-29 18:05:04290 : SymbolBody(SymbolBody::UndefinedKind, Name, IsLocal, StOther, Type) {
Rui Ueyama434b5612016-07-17 03:11:46291 this->File = File;
292}
Rafael Espindola5d7593b2015-12-22 23:00:50293
Rui Ueyamaa13efc22016-11-29 18:05:04294DefinedCommon::DefinedCommon(StringRef Name, uint64_t Size, uint64_t Alignment,
Rafael Espindolae7553e42016-08-31 13:28:33295 uint8_t StOther, uint8_t Type, InputFile *File)
Rui Ueyamaa13efc22016-11-29 18:05:04296 : Defined(SymbolBody::DefinedCommonKind, Name, /*IsLocal=*/false, StOther,
297 Type),
Rui Ueyama2a7c1c12016-07-17 17:36:22298 Alignment(Alignment), Size(Size) {
299 this->File = File;
300}
Rafael Espindola11191912015-12-24 16:23:37301
Rui Ueyama4076fa12017-02-26 23:35:34302// If a shared symbol is referred via a copy relocation, its alignment
303// becomes part of the ABI. This function returns a symbol alignment.
304// Because symbols don't have alignment attributes, we need to infer that.
305template <class ELFT> uint64_t SharedSymbol::getAlignment() const {
306 auto *File = cast<SharedFile<ELFT>>(this->File);
307 uint64_t SecAlign = File->getSection(getSym<ELFT>())->sh_addralign;
308 uint64_t SymValue = getSym<ELFT>().st_value;
309 uint64_t SymAlign = uint64_t(1) << countTrailingZeros(SymValue);
310 return std::min(SecAlign, SymAlign);
311}
312
Rui Ueyama55518e72016-10-28 20:57:25313InputFile *Lazy::fetch() {
Rui Ueyamaf8baa662016-04-07 19:24:51314 if (auto *S = dyn_cast<LazyArchive>(this))
Rui Ueyama55518e72016-10-28 20:57:25315 return S->fetch();
316 return cast<LazyObject>(this)->fetch();
Rui Ueyamaf8baa662016-04-07 19:24:51317}
318
Rui Ueyama434b5612016-07-17 03:11:46319LazyArchive::LazyArchive(ArchiveFile &File,
320 const llvm::object::Archive::Symbol S, uint8_t Type)
321 : Lazy(LazyArchiveKind, S.getName(), Type), Sym(S) {
322 this->File = &File;
323}
324
325LazyObject::LazyObject(StringRef Name, LazyObjectFile &File, uint8_t Type)
326 : Lazy(LazyObjectKind, Name, Type) {
327 this->File = &File;
328}
329
Rui Ueyama55518e72016-10-28 20:57:25330InputFile *LazyArchive::fetch() {
Davide Italianobcdd6c62016-10-12 19:35:54331 std::pair<MemoryBufferRef, uint64_t> MBInfo = file()->getMember(&Sym);
Michael J. Spencer1b348a62015-09-04 22:28:10332
333 // getMember returns an empty buffer if the member was already
334 // read from the library.
Davide Italianobcdd6c62016-10-12 19:35:54335 if (MBInfo.first.getBuffer().empty())
Rui Ueyama38dbd3e2016-09-14 00:05:51336 return nullptr;
Rui Ueyama55518e72016-10-28 20:57:25337 return createObjectFile(MBInfo.first, file()->getName(), MBInfo.second);
Michael J. Spencer1b348a62015-09-04 22:28:10338}
339
Rui Ueyama55518e72016-10-28 20:57:25340InputFile *LazyObject::fetch() {
Rui Ueyama434b5612016-07-17 03:11:46341 MemoryBufferRef MBRef = file()->getBuffer();
Rafael Espindola65c65ce2016-06-14 21:56:36342 if (MBRef.getBuffer().empty())
Rui Ueyama38dbd3e2016-09-14 00:05:51343 return nullptr;
Rui Ueyama55518e72016-10-28 20:57:25344 return createObjectFile(MBRef);
Rui Ueyamaf8baa662016-04-07 19:24:51345}
346
Rafael Espindolab7e2ee22017-01-10 17:08:13347uint8_t Symbol::computeBinding() const {
348 if (Config->Relocatable)
349 return Binding;
Peter Collingbournedadcc172016-04-22 18:42:48350 if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
Rafael Espindolab7e2ee22017-01-10 17:08:13351 return STB_LOCAL;
Rafael Espindola41a93a32017-01-16 17:35:23352 const SymbolBody *Body = body();
Rafael Espindola1d6d1b42017-01-17 16:08:06353 if (VersionId == VER_NDX_LOCAL && Body->isInCurrentDSO())
Rafael Espindolab7e2ee22017-01-10 17:08:13354 return STB_LOCAL;
355 if (Config->NoGnuUnique && Binding == STB_GNU_UNIQUE)
356 return STB_GLOBAL;
357 return Binding;
358}
359
360bool Symbol::includeInDynsym() const {
361 if (computeBinding() == STB_LOCAL)
Rafael Espindolaae605c12016-04-21 20:35:25362 return false;
Rafael Espindolab7e2ee22017-01-10 17:08:13363 return ExportDynamic || body()->isShared() ||
Peter Collingbourne4f952702016-05-01 04:55:03364 (body()->isUndefined() && Config->Shared);
Rafael Espindolaae605c12016-04-21 20:35:25365}
Rui Ueyama69c778c2016-07-17 17:50:09366
367// Print out a log message for --trace-symbol.
368void elf::printTraceSymbol(Symbol *Sym) {
369 SymbolBody *B = Sym->body();
Rui Ueyamae6e206d2017-02-21 23:22:56370 std::string S;
Rui Ueyama69c778c2016-07-17 17:50:09371 if (B->isUndefined())
Rui Ueyamae6e206d2017-02-21 23:22:56372 S = ": reference to ";
Rui Ueyama69c778c2016-07-17 17:50:09373 else if (B->isCommon())
Rui Ueyamae6e206d2017-02-21 23:22:56374 S = ": common definition of ";
Rui Ueyama69c778c2016-07-17 17:50:09375 else
Rui Ueyamae6e206d2017-02-21 23:22:56376 S = ": definition of ";
377
378 message(toString(B->File) + S + B->getName());
Rui Ueyama69c778c2016-07-17 17:50:09379}
380
Rui Ueyamaa3ac1732016-11-24 20:24:18381// Returns a symbol for an error message.
Rui Ueyamace039262017-01-06 10:04:08382std::string lld::toString(const SymbolBody &B) {
Rui Ueyamaa3ac1732016-11-24 20:24:18383 if (Config->Demangle)
Rui Ueyama4c5b8ce2016-12-07 23:17:05384 if (Optional<std::string> S = demangle(B.getName()))
385 return *S;
Rui Ueyamaa3ac1732016-11-24 20:24:18386 return B.getName();
387}
388
Rafael Espindola7386cea2017-02-16 00:12:34389template uint32_t SymbolBody::template getVA<ELF32LE>(int64_t) const;
390template uint32_t SymbolBody::template getVA<ELF32BE>(int64_t) const;
391template uint64_t SymbolBody::template getVA<ELF64LE>(int64_t) const;
392template uint64_t SymbolBody::template getVA<ELF64BE>(int64_t) const;
Rui Ueyamab5a69702016-02-01 21:00:35393
394template uint32_t SymbolBody::template getGotVA<ELF32LE>() const;
395template uint32_t SymbolBody::template getGotVA<ELF32BE>() const;
396template uint64_t SymbolBody::template getGotVA<ELF64LE>() const;
397template uint64_t SymbolBody::template getGotVA<ELF64BE>() const;
398
Rafael Espindola74031ba2016-04-07 15:20:56399template uint32_t SymbolBody::template getGotOffset<ELF32LE>() const;
400template uint32_t SymbolBody::template getGotOffset<ELF32BE>() const;
401template uint64_t SymbolBody::template getGotOffset<ELF64LE>() const;
402template uint64_t SymbolBody::template getGotOffset<ELF64BE>() const;
403
Rui Ueyamab5a69702016-02-01 21:00:35404template uint32_t SymbolBody::template getGotPltVA<ELF32LE>() const;
405template uint32_t SymbolBody::template getGotPltVA<ELF32BE>() const;
406template uint64_t SymbolBody::template getGotPltVA<ELF64LE>() const;
407template uint64_t SymbolBody::template getGotPltVA<ELF64BE>() const;
408
Rafael Espindola74031ba2016-04-07 15:20:56409template uint32_t SymbolBody::template getGotPltOffset<ELF32LE>() const;
410template uint32_t SymbolBody::template getGotPltOffset<ELF32BE>() const;
411template uint64_t SymbolBody::template getGotPltOffset<ELF64LE>() const;
412template uint64_t SymbolBody::template getGotPltOffset<ELF64BE>() const;
413
Rui Ueyamab5a69702016-02-01 21:00:35414template uint32_t SymbolBody::template getPltVA<ELF32LE>() const;
415template uint32_t SymbolBody::template getPltVA<ELF32BE>() const;
416template uint64_t SymbolBody::template getPltVA<ELF64LE>() const;
417template uint64_t SymbolBody::template getPltVA<ELF64BE>() const;
418
Rui Ueyama512c61d2016-02-03 00:12:24419template uint32_t SymbolBody::template getSize<ELF32LE>() const;
420template uint32_t SymbolBody::template getSize<ELF32BE>() const;
421template uint64_t SymbolBody::template getSize<ELF64LE>() const;
422template uint64_t SymbolBody::template getSize<ELF64BE>() const;
423
Rui Ueyama968db482017-02-28 04:02:42424template const OutputSection *
425 SymbolBody::template getOutputSection<ELF32LE>() const;
426template const OutputSection *
427 SymbolBody::template getOutputSection<ELF32BE>() const;
428template const OutputSection *
429 SymbolBody::template getOutputSection<ELF64LE>() const;
430template const OutputSection *
431 SymbolBody::template getOutputSection<ELF64BE>() const;
432
Rui Ueyama80474a22017-02-28 19:29:55433template bool DefinedRegular::template isMipsPIC<ELF32LE>() const;
434template bool DefinedRegular::template isMipsPIC<ELF32BE>() const;
435template bool DefinedRegular::template isMipsPIC<ELF64LE>() const;
436template bool DefinedRegular::template isMipsPIC<ELF64BE>() const;
Rui Ueyama4076fa12017-02-26 23:35:34437
438template uint64_t SharedSymbol::template getAlignment<ELF32LE>() const;
439template uint64_t SharedSymbol::template getAlignment<ELF32BE>() const;
440template uint64_t SharedSymbol::template getAlignment<ELF64LE>() const;
441template uint64_t SharedSymbol::template getAlignment<ELF64BE>() const;