blob: 9eb222362bbc0e78b78184f6f97c246f69570da2 [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) {
Rafael Espindola87d9f102016-03-11 12:19:0545 switch (Body.kind()) {
46 case SymbolBody::DefinedSyntheticKind: {
Rui Ueyama4f2f50d2016-12-21 08:40:0947 auto &D = cast<DefinedSynthetic>(Body);
Rafael Espindola24e6f362017-02-24 15:07:3048 const OutputSection *Sec = D.Section;
Peter Collingbourne6a422592016-05-03 01:21:0849 if (!Sec)
50 return D.Value;
Rafael Espindolac86b2cd2017-03-08 15:34:0451 if (D.Value == uint64_t(-1))
Rafael Espindola04a2e342016-11-09 01:42:4152 return Sec->Addr + Sec->Size;
53 return Sec->Addr + D.Value;
Rui Ueyamab5a69702016-02-01 21:00:3554 }
Rafael Espindola87d9f102016-03-11 12:19:0555 case SymbolBody::DefinedRegularKind: {
Rui Ueyama80474a22017-02-28 19:29:5556 auto &D = cast<DefinedRegular>(Body);
Rafael Espindolab4c9b812017-02-23 02:28:2857 InputSectionBase *IS = D.Section;
Rui Ueyamab5a69702016-02-01 21:00:3558
Rafael Espindolaccfe3cb2016-04-04 14:04:1659 // According to the ELF spec reference to a local symbol from outside
60 // the group are not allowed. Unfortunately .eh_frame breaks that rule
61 // and must be treated specially. For now we just replace the symbol with
62 // 0.
Rafael Espindola774ea7d2017-02-23 16:49:0763 if (IS == &InputSection::Discarded)
Rafael Espindolaccfe3cb2016-04-04 14:04:1664 return 0;
65
Rui Ueyamab5a69702016-02-01 21:00:3566 // This is an absolute symbol.
Sean Silva902ae3c2016-12-15 00:57:5367 if (!IS)
Rafael Espindolaccfe3cb2016-04-04 14:04:1668 return D.Value;
Rui Ueyamab5a69702016-02-01 21:00:3569
Rafael Espindola9371bab2017-03-08 15:21:3270 uint64_t Offset = D.Value;
Sean Silvaa9ba4502017-02-28 08:32:5671
72 // An object in an SHF_MERGE section might be referenced via a
73 // section symbol (as a hack for reducing the number of local
74 // symbols).
Sean Silvad4e60622017-03-01 04:44:0475 // Depending on the addend, the reference via a section symbol
76 // refers to a different object in the merge section.
77 // Since the objects in the merge section are not necessarily
78 // contiguous in the output, the addend can thus affect the final
79 // VA in a non-linear way.
80 // To make this work, we incorporate the addend into the section
81 // offset (and zero out the addend for later processing) so that
82 // we find the right object in the section.
Rafael Espindolaccfe3cb2016-04-04 14:04:1683 if (D.isSection()) {
Rafael Espindola1f5b70f2016-03-11 14:21:3784 Offset += Addend;
85 Addend = 0;
86 }
Sean Silvaa9ba4502017-02-28 08:32:5687
Rafael Espindola5e434b32017-03-08 16:08:3688 const OutputSection *OutSec = IS->getOutputSection();
Sean Silva6ab39262017-02-28 09:01:5889
90 // In the typical case, this is actually very simple and boils
91 // down to adding together 3 numbers:
92 // 1. The address of the output section.
93 // 2. The offset of the input section within the output section.
94 // 3. The offset within the input section (this addition happens
95 // inside InputSection::getOffset).
96 //
97 // If you understand the data structures involved with this next
98 // line (and how they get built), then you have a pretty good
99 // understanding of the linker.
Rafael Espindolae1294092017-03-08 16:03:41100 uint64_t VA = (OutSec ? OutSec->Addr : 0) + IS->getOffset(Offset);
Sean Silva6ab39262017-02-28 09:01:58101
George Rimar6a3b1542016-10-04 08:52:51102 if (D.isTls() && !Config->Relocatable) {
Rui Ueyama9d1bacb12017-02-27 02:31:26103 if (!Out::TlsPhdr)
Rui Ueyama3fc0f7e2016-11-23 18:07:33104 fatal(toString(D.File) +
George Rimar6a3b1542016-10-04 08:52:51105 " has a STT_TLS symbol but doesn't have a PT_TLS section");
Rui Ueyama9d1bacb12017-02-27 02:31:26106 return VA - Out::TlsPhdr->p_vaddr;
George Rimar6a3b1542016-10-04 08:52:51107 }
Rafael Espindola1f5b70f2016-03-11 14:21:37108 return VA;
Rui Ueyamab5a69702016-02-01 21:00:35109 }
Rui Ueyama07784902016-08-02 01:35:13110 case SymbolBody::DefinedCommonKind:
Rui Ueyamab2a23cf2017-01-24 03:41:20111 if (!Config->DefineCommon)
112 return 0;
Rafael Espindola04a2e342016-11-09 01:42:41113 return In<ELFT>::Common->OutSec->Addr + In<ELFT>::Common->OutSecOff +
Rafael Espindolae7553e42016-08-31 13:28:33114 cast<DefinedCommon>(Body).Offset;
Rui Ueyama007c0022017-03-08 17:24:24115 case SymbolBody::SharedKind: {
116 auto &SS = cast<SharedSymbol>(Body);
117 if (SS.NeedsCopy)
118 return SS.Section->OutSec->Addr + SS.Section->OutSecOff;
119 if (SS.NeedsPltAddr)
Rafael Espindola87d9f102016-03-11 12:19:05120 return Body.getPltVA<ELFT>();
Rui Ueyama924b3612017-02-16 06:12:22121 return 0;
Rui Ueyama007c0022017-03-08 17:24:24122 }
Peter Collingbourne60976ed2016-04-27 00:05:06123 case SymbolBody::UndefinedKind:
Rui Ueyamab5a69702016-02-01 21:00:35124 return 0;
Rui Ueyamaf8baa662016-04-07 19:24:51125 case SymbolBody::LazyArchiveKind:
126 case SymbolBody::LazyObjectKind:
Peter Collingbourne4f952702016-05-01 04:55:03127 assert(Body.symbol()->IsUsedInRegularObj && "lazy symbol reached writer");
Rui Ueyamab5a69702016-02-01 21:00:35128 return 0;
129 }
George Rimar777f9632016-03-12 08:31:34130 llvm_unreachable("invalid symbol kind");
Rui Ueyamab5a69702016-02-01 21:00:35131}
132
Rui Ueyamaa13efc22016-11-29 18:05:04133SymbolBody::SymbolBody(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther,
134 uint8_t Type)
Rui Ueyama007c0022017-03-08 17:24:24135 : SymbolKind(K), NeedsCopy(false), NeedsPltAddr(false), IsLocal(IsLocal),
Peter Smithbaffdb82016-12-08 12:58:55136 IsInGlobalMipsGot(false), Is32BitMipsGot(false), IsInIplt(false),
Rui Ueyama924b3612017-02-16 06:12:22137 IsInIgot(false), Type(Type), StOther(StOther), Name(Name) {}
Rafael Espindolaf4765732016-04-06 13:22:41138
Rui Ueyamac4466602016-03-13 19:48:18139// Returns true if a symbol can be replaced at load-time by a symbol
140// with the same name defined in other ELF executable or DSO.
141bool SymbolBody::isPreemptible() const {
142 if (isLocal())
143 return false;
144
Rafael Espindola66434562016-05-05 19:41:49145 // Shared symbols resolve to the definition in the DSO. The exceptions are
Rui Ueyama007c0022017-03-08 17:24:24146 // symbols with copy relocations (which resolve to .bss) or preempt plt
147 // entries (which resolve to that plt entry).
Rui Ueyamac4466602016-03-13 19:48:18148 if (isShared())
Rui Ueyama007c0022017-03-08 17:24:24149 return !NeedsCopy && !NeedsPltAddr;
Rui Ueyamac4466602016-03-13 19:48:18150
Peter Collingbourne66ac1d62016-04-22 20:21:26151 // That's all that can be preempted in a non-DSO.
Rui Ueyamac4466602016-03-13 19:48:18152 if (!Config->Shared)
153 return false;
Peter Collingbourne66ac1d62016-04-22 20:21:26154
Peter Collingbournedbe41872016-04-24 04:29:59155 // Only symbols that appear in dynsym can be preempted.
Peter Collingbourne4f952702016-05-01 04:55:03156 if (!symbol()->includeInDynsym())
Rui Ueyamac4466602016-03-13 19:48:18157 return false;
Peter Collingbourne66ac1d62016-04-22 20:21:26158
Rafael Espindola580d7a12016-07-07 22:50:54159 // Only default visibility symbols can be preempted.
160 if (symbol()->Visibility != STV_DEFAULT)
161 return false;
162
163 // -Bsymbolic means that definitions are not preempted.
Peter Collingbournedbe41872016-04-24 04:29:59164 if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc()))
165 return !isDefined();
Rafael Espindola580d7a12016-07-07 22:50:54166 return true;
Rui Ueyamac4466602016-03-13 19:48:18167}
168
Rui Ueyamab5a69702016-02-01 21:00:35169template <class ELFT>
Rafael Espindola7386cea2017-02-16 00:12:34170typename ELFT::uint SymbolBody::getVA(int64_t Addend) const {
Rafael Espindola8381c562016-03-17 23:36:19171 typename ELFT::uint OutVA = getSymVA<ELFT>(*this, Addend);
172 return OutVA + Addend;
Rafael Espindola87d9f102016-03-11 12:19:05173}
174
Rui Ueyama9328b2c2016-03-14 23:16:09175template <class ELFT> typename ELFT::uint SymbolBody::getGotVA() const {
Eugene Leviantad4439e2016-11-11 11:33:32176 return In<ELFT>::Got->getVA() + getGotOffset<ELFT>();
Rafael Espindola74031ba2016-04-07 15:20:56177}
178
179template <class ELFT> typename ELFT::uint SymbolBody::getGotOffset() const {
Rui Ueyama803b1202016-07-13 18:55:14180 return GotIndex * Target->GotEntrySize;
Rui Ueyamab5a69702016-02-01 21:00:35181}
182
Rui Ueyama9328b2c2016-03-14 23:16:09183template <class ELFT> typename ELFT::uint SymbolBody::getGotPltVA() const {
Peter Smithbaffdb82016-12-08 12:58:55184 if (this->IsInIgot)
185 return In<ELFT>::IgotPlt->getVA() + getGotPltOffset<ELFT>();
Eugene Leviant41ca3272016-11-10 09:48:29186 return In<ELFT>::GotPlt->getVA() + getGotPltOffset<ELFT>();
Rafael Espindola74031ba2016-04-07 15:20:56187}
188
189template <class ELFT> typename ELFT::uint SymbolBody::getGotPltOffset() const {
Rui Ueyama803b1202016-07-13 18:55:14190 return GotPltIndex * Target->GotPltEntrySize;
Rui Ueyamab5a69702016-02-01 21:00:35191}
192
Rui Ueyama9328b2c2016-03-14 23:16:09193template <class ELFT> typename ELFT::uint SymbolBody::getPltVA() const {
Peter Smithbaffdb82016-12-08 12:58:55194 if (this->IsInIplt)
195 return In<ELFT>::Iplt->getVA() + PltIndex * Target->PltEntrySize;
Eugene Leviantff23d3e2016-11-18 14:35:03196 return In<ELFT>::Plt->getVA() + Target->PltHeaderSize +
Rui Ueyamab5a69702016-02-01 21:00:35197 PltIndex * Target->PltEntrySize;
198}
199
Rui Ueyama9328b2c2016-03-14 23:16:09200template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
Rafael Espindolae7553e42016-08-31 13:28:33201 if (const auto *C = dyn_cast<DefinedCommon>(this))
Rafael Espindolaccfe3cb2016-04-04 14:04:16202 return C->Size;
Rui Ueyama80474a22017-02-28 19:29:55203 if (const auto *DR = dyn_cast<DefinedRegular>(this))
Rafael Espindolaccfe3cb2016-04-04 14:04:16204 return DR->Size;
Rui Ueyama4076fa12017-02-26 23:35:34205 if (const auto *S = dyn_cast<SharedSymbol>(this))
206 return S->getSize<ELFT>();
Rui Ueyama512c61d2016-02-03 00:12:24207 return 0;
208}
209
Rui Ueyama968db482017-02-28 04:02:42210template <class ELFT>
211const OutputSection *SymbolBody::getOutputSection() const {
Rui Ueyama80474a22017-02-28 19:29:55212 if (auto *S = dyn_cast<DefinedRegular>(this)) {
Rui Ueyama968db482017-02-28 04:02:42213 if (S->Section)
Rafael Espindola5e434b32017-03-08 16:08:36214 return S->Section->getOutputSection();
Rui Ueyama968db482017-02-28 04:02:42215 return nullptr;
216 }
217
Rui Ueyama007c0022017-03-08 17:24:24218 if (auto *S = dyn_cast<SharedSymbol>(this)) {
219 if (S->NeedsCopy)
220 return S->Section->OutSec;
Rui Ueyama968db482017-02-28 04:02:42221 return nullptr;
Rui Ueyama007c0022017-03-08 17:24:24222 }
Rui Ueyama968db482017-02-28 04:02:42223
224 if (isa<DefinedCommon>(this)) {
225 if (Config->DefineCommon)
226 return In<ELFT>::Common->OutSec;
227 return nullptr;
228 }
229
230 if (auto *S = dyn_cast<DefinedSynthetic>(this))
231 return S->Section;
232 return nullptr;
233}
234
Rui Ueyama35fa6c52016-11-23 05:48:40235// If a symbol name contains '@', the characters after that is
236// a symbol version name. This function parses that.
237void SymbolBody::parseSymbolVersion() {
238 StringRef S = getName();
239 size_t Pos = S.find('@');
240 if (Pos == 0 || Pos == StringRef::npos)
241 return;
242 StringRef Verstr = S.substr(Pos + 1);
243 if (Verstr.empty())
244 return;
245
246 // Truncate the symbol name so that it doesn't include the version string.
Rui Ueyamaa13efc22016-11-29 18:05:04247 Name = {S.data(), Pos};
Rui Ueyama35fa6c52016-11-23 05:48:40248
Rafael Espindola1d6d1b42017-01-17 16:08:06249 // If this is not in this DSO, it is not a definition.
250 if (!isInCurrentDSO())
Rafael Espindola2756e042017-01-06 22:30:35251 return;
252
Rui Ueyama35fa6c52016-11-23 05:48:40253 // '@@' in a symbol name means the default version.
254 // It is usually the most recent one.
255 bool IsDefault = (Verstr[0] == '@');
256 if (IsDefault)
257 Verstr = Verstr.substr(1);
258
259 for (VersionDefinition &Ver : Config->VersionDefinitions) {
260 if (Ver.Name != Verstr)
261 continue;
262
263 if (IsDefault)
264 symbol()->VersionId = Ver.Id;
265 else
266 symbol()->VersionId = Ver.Id | VERSYM_HIDDEN;
267 return;
268 }
269
270 // It is an error if the specified version is not defined.
Rui Ueyama44da9de2016-12-05 18:40:14271 error(toString(File) + ": symbol " + S + " has undefined version " + Verstr);
Rui Ueyama35fa6c52016-11-23 05:48:40272}
273
Rui Ueyamaa13efc22016-11-29 18:05:04274Defined::Defined(Kind K, StringRefZ Name, bool IsLocal, uint8_t StOther,
275 uint8_t Type)
276 : SymbolBody(K, Name, IsLocal, StOther, Type) {}
Rafael Espindola4d4b06a2015-12-24 00:47:42277
Rui Ueyama80474a22017-02-28 19:29:55278template <class ELFT> bool DefinedRegular::isMipsPIC() const {
Simon Atanasyanf967f092016-09-29 12:58:36279 if (!Section || !isFunc())
280 return false;
281 return (this->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC ||
Rafael Espindolab4c9b812017-02-23 02:28:28282 (Section->getFile<ELFT>()->getObj().getHeader()->e_flags &
283 EF_MIPS_PIC);
Simon Atanasyanf967f092016-09-29 12:58:36284}
285
Peter Smith3a52eb02017-02-01 10:26:03286Undefined::Undefined(StringRefZ Name, bool IsLocal, uint8_t StOther,
287 uint8_t Type, InputFile *File)
Rui Ueyamaa13efc22016-11-29 18:05:04288 : SymbolBody(SymbolBody::UndefinedKind, Name, IsLocal, StOther, Type) {
Rui Ueyama434b5612016-07-17 03:11:46289 this->File = File;
290}
Rafael Espindola5d7593b2015-12-22 23:00:50291
Rui Ueyamaa13efc22016-11-29 18:05:04292DefinedCommon::DefinedCommon(StringRef Name, uint64_t Size, uint64_t Alignment,
Rafael Espindolae7553e42016-08-31 13:28:33293 uint8_t StOther, uint8_t Type, InputFile *File)
Rui Ueyamaa13efc22016-11-29 18:05:04294 : Defined(SymbolBody::DefinedCommonKind, Name, /*IsLocal=*/false, StOther,
295 Type),
Rui Ueyama2a7c1c12016-07-17 17:36:22296 Alignment(Alignment), Size(Size) {
297 this->File = File;
298}
Rafael Espindola11191912015-12-24 16:23:37299
Rui Ueyama4076fa12017-02-26 23:35:34300// If a shared symbol is referred via a copy relocation, its alignment
301// becomes part of the ABI. This function returns a symbol alignment.
302// Because symbols don't have alignment attributes, we need to infer that.
303template <class ELFT> uint64_t SharedSymbol::getAlignment() const {
304 auto *File = cast<SharedFile<ELFT>>(this->File);
305 uint64_t SecAlign = File->getSection(getSym<ELFT>())->sh_addralign;
306 uint64_t SymValue = getSym<ELFT>().st_value;
307 uint64_t SymAlign = uint64_t(1) << countTrailingZeros(SymValue);
308 return std::min(SecAlign, SymAlign);
309}
310
Rui Ueyama55518e72016-10-28 20:57:25311InputFile *Lazy::fetch() {
Rui Ueyamaf8baa662016-04-07 19:24:51312 if (auto *S = dyn_cast<LazyArchive>(this))
Rui Ueyama55518e72016-10-28 20:57:25313 return S->fetch();
314 return cast<LazyObject>(this)->fetch();
Rui Ueyamaf8baa662016-04-07 19:24:51315}
316
Rui Ueyama434b5612016-07-17 03:11:46317LazyArchive::LazyArchive(ArchiveFile &File,
318 const llvm::object::Archive::Symbol S, uint8_t Type)
319 : Lazy(LazyArchiveKind, S.getName(), Type), Sym(S) {
320 this->File = &File;
321}
322
323LazyObject::LazyObject(StringRef Name, LazyObjectFile &File, uint8_t Type)
324 : Lazy(LazyObjectKind, Name, Type) {
325 this->File = &File;
326}
327
Rui Ueyama55518e72016-10-28 20:57:25328InputFile *LazyArchive::fetch() {
Davide Italianobcdd6c62016-10-12 19:35:54329 std::pair<MemoryBufferRef, uint64_t> MBInfo = file()->getMember(&Sym);
Michael J. Spencer1b348a62015-09-04 22:28:10330
331 // getMember returns an empty buffer if the member was already
332 // read from the library.
Davide Italianobcdd6c62016-10-12 19:35:54333 if (MBInfo.first.getBuffer().empty())
Rui Ueyama38dbd3e2016-09-14 00:05:51334 return nullptr;
Rui Ueyama55518e72016-10-28 20:57:25335 return createObjectFile(MBInfo.first, file()->getName(), MBInfo.second);
Michael J. Spencer1b348a62015-09-04 22:28:10336}
337
Rui Ueyama55518e72016-10-28 20:57:25338InputFile *LazyObject::fetch() {
Rui Ueyama434b5612016-07-17 03:11:46339 MemoryBufferRef MBRef = file()->getBuffer();
Rafael Espindola65c65ce2016-06-14 21:56:36340 if (MBRef.getBuffer().empty())
Rui Ueyama38dbd3e2016-09-14 00:05:51341 return nullptr;
Rui Ueyama55518e72016-10-28 20:57:25342 return createObjectFile(MBRef);
Rui Ueyamaf8baa662016-04-07 19:24:51343}
344
Rafael Espindolab7e2ee22017-01-10 17:08:13345uint8_t Symbol::computeBinding() const {
346 if (Config->Relocatable)
347 return Binding;
Peter Collingbournedadcc172016-04-22 18:42:48348 if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
Rafael Espindolab7e2ee22017-01-10 17:08:13349 return STB_LOCAL;
Rafael Espindola41a93a32017-01-16 17:35:23350 const SymbolBody *Body = body();
Rafael Espindola1d6d1b42017-01-17 16:08:06351 if (VersionId == VER_NDX_LOCAL && Body->isInCurrentDSO())
Rafael Espindolab7e2ee22017-01-10 17:08:13352 return STB_LOCAL;
353 if (Config->NoGnuUnique && Binding == STB_GNU_UNIQUE)
354 return STB_GLOBAL;
355 return Binding;
356}
357
358bool Symbol::includeInDynsym() const {
359 if (computeBinding() == STB_LOCAL)
Rafael Espindolaae605c12016-04-21 20:35:25360 return false;
Rafael Espindolab7e2ee22017-01-10 17:08:13361 return ExportDynamic || body()->isShared() ||
Peter Collingbourne4f952702016-05-01 04:55:03362 (body()->isUndefined() && Config->Shared);
Rafael Espindolaae605c12016-04-21 20:35:25363}
Rui Ueyama69c778c2016-07-17 17:50:09364
365// Print out a log message for --trace-symbol.
366void elf::printTraceSymbol(Symbol *Sym) {
367 SymbolBody *B = Sym->body();
Rui Ueyamae6e206d2017-02-21 23:22:56368 std::string S;
Rui Ueyama69c778c2016-07-17 17:50:09369 if (B->isUndefined())
Rui Ueyamae6e206d2017-02-21 23:22:56370 S = ": reference to ";
Rui Ueyama69c778c2016-07-17 17:50:09371 else if (B->isCommon())
Rui Ueyamae6e206d2017-02-21 23:22:56372 S = ": common definition of ";
Rui Ueyama69c778c2016-07-17 17:50:09373 else
Rui Ueyamae6e206d2017-02-21 23:22:56374 S = ": definition of ";
375
376 message(toString(B->File) + S + B->getName());
Rui Ueyama69c778c2016-07-17 17:50:09377}
378
Rui Ueyamaa3ac1732016-11-24 20:24:18379// Returns a symbol for an error message.
Rui Ueyamace039262017-01-06 10:04:08380std::string lld::toString(const SymbolBody &B) {
Rui Ueyamaa3ac1732016-11-24 20:24:18381 if (Config->Demangle)
Rui Ueyama4c5b8ce2016-12-07 23:17:05382 if (Optional<std::string> S = demangle(B.getName()))
383 return *S;
Rui Ueyamaa3ac1732016-11-24 20:24:18384 return B.getName();
385}
386
Rafael Espindola7386cea2017-02-16 00:12:34387template uint32_t SymbolBody::template getVA<ELF32LE>(int64_t) const;
388template uint32_t SymbolBody::template getVA<ELF32BE>(int64_t) const;
389template uint64_t SymbolBody::template getVA<ELF64LE>(int64_t) const;
390template uint64_t SymbolBody::template getVA<ELF64BE>(int64_t) const;
Rui Ueyamab5a69702016-02-01 21:00:35391
392template uint32_t SymbolBody::template getGotVA<ELF32LE>() const;
393template uint32_t SymbolBody::template getGotVA<ELF32BE>() const;
394template uint64_t SymbolBody::template getGotVA<ELF64LE>() const;
395template uint64_t SymbolBody::template getGotVA<ELF64BE>() const;
396
Rafael Espindola74031ba2016-04-07 15:20:56397template uint32_t SymbolBody::template getGotOffset<ELF32LE>() const;
398template uint32_t SymbolBody::template getGotOffset<ELF32BE>() const;
399template uint64_t SymbolBody::template getGotOffset<ELF64LE>() const;
400template uint64_t SymbolBody::template getGotOffset<ELF64BE>() const;
401
Rui Ueyamab5a69702016-02-01 21:00:35402template uint32_t SymbolBody::template getGotPltVA<ELF32LE>() const;
403template uint32_t SymbolBody::template getGotPltVA<ELF32BE>() const;
404template uint64_t SymbolBody::template getGotPltVA<ELF64LE>() const;
405template uint64_t SymbolBody::template getGotPltVA<ELF64BE>() const;
406
Rafael Espindola74031ba2016-04-07 15:20:56407template uint32_t SymbolBody::template getGotPltOffset<ELF32LE>() const;
408template uint32_t SymbolBody::template getGotPltOffset<ELF32BE>() const;
409template uint64_t SymbolBody::template getGotPltOffset<ELF64LE>() const;
410template uint64_t SymbolBody::template getGotPltOffset<ELF64BE>() const;
411
Rui Ueyamab5a69702016-02-01 21:00:35412template uint32_t SymbolBody::template getPltVA<ELF32LE>() const;
413template uint32_t SymbolBody::template getPltVA<ELF32BE>() const;
414template uint64_t SymbolBody::template getPltVA<ELF64LE>() const;
415template uint64_t SymbolBody::template getPltVA<ELF64BE>() const;
416
Rui Ueyama512c61d2016-02-03 00:12:24417template uint32_t SymbolBody::template getSize<ELF32LE>() const;
418template uint32_t SymbolBody::template getSize<ELF32BE>() const;
419template uint64_t SymbolBody::template getSize<ELF64LE>() const;
420template uint64_t SymbolBody::template getSize<ELF64BE>() const;
421
Rui Ueyama968db482017-02-28 04:02:42422template const OutputSection *
423 SymbolBody::template getOutputSection<ELF32LE>() const;
424template const OutputSection *
425 SymbolBody::template getOutputSection<ELF32BE>() const;
426template const OutputSection *
427 SymbolBody::template getOutputSection<ELF64LE>() const;
428template const OutputSection *
429 SymbolBody::template getOutputSection<ELF64BE>() const;
430
Rui Ueyama80474a22017-02-28 19:29:55431template bool DefinedRegular::template isMipsPIC<ELF32LE>() const;
432template bool DefinedRegular::template isMipsPIC<ELF32BE>() const;
433template bool DefinedRegular::template isMipsPIC<ELF64LE>() const;
434template bool DefinedRegular::template isMipsPIC<ELF64BE>() const;
Rui Ueyama4076fa12017-02-26 23:35:34435
436template uint64_t SharedSymbol::template getAlignment<ELF32LE>() const;
437template uint64_t SharedSymbol::template getAlignment<ELF32BE>() const;
438template uint64_t SharedSymbol::template getAlignment<ELF64LE>() const;
439template uint64_t SharedSymbol::template getAlignment<ELF64BE>() const;