blob: 01b59215807832dff374935f63009d6f08b6c859 [file] [log] [blame]
Rafael Espindola5805c4f2015-09-21 21:38:08 +00001//===- OutputSections.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 "OutputSections.h"
11#include "Config.h"
Rafael Espindola5805c4f2015-09-21 21:38:08 +000012#include "SymbolTable.h"
Rafael Espindola01205f72015-09-22 18:19:46 +000013#include "Target.h"
Rafael Espindola5805c4f2015-09-21 21:38:08 +000014
Rafael Espindola5805c4f2015-09-21 21:38:08 +000015using namespace llvm;
16using namespace llvm::object;
17using namespace llvm::ELF;
18
19using namespace lld;
20using namespace lld::elf2;
21
22template <bool Is64Bits>
23OutputSectionBase<Is64Bits>::OutputSectionBase(StringRef Name, uint32_t sh_type,
24 uintX_t sh_flags)
25 : Name(Name) {
26 memset(&Header, 0, sizeof(HeaderT));
27 Header.sh_type = sh_type;
28 Header.sh_flags = sh_flags;
29}
30
Rafael Espindola35c6af32015-09-25 17:19:10 +000031template <class ELFT>
32GotSection<ELFT>::GotSection()
33 : OutputSectionBase<ELFT::Is64Bits>(".got", llvm::ELF::SHT_PROGBITS,
34 llvm::ELF::SHF_ALLOC |
35 llvm::ELF::SHF_WRITE) {
36 this->Header.sh_addralign = this->getAddrSize();
37}
38
Rafael Espindola5805c4f2015-09-21 21:38:08 +000039template <class ELFT> void GotSection<ELFT>::addEntry(SymbolBody *Sym) {
40 Sym->setGotIndex(Entries.size());
41 Entries.push_back(Sym);
42}
43
44template <class ELFT>
45typename GotSection<ELFT>::uintX_t
46GotSection<ELFT>::getEntryAddr(const SymbolBody &B) const {
47 return this->getVA() + B.getGotIndex() * this->getAddrSize();
48}
49
Rafael Espindola35c6af32015-09-25 17:19:10 +000050template <class ELFT>
51PltSection<ELFT>::PltSection(const GotSection<ELFT> &GotSec)
52 : OutputSectionBase<ELFT::Is64Bits>(".plt", llvm::ELF::SHT_PROGBITS,
53 llvm::ELF::SHF_ALLOC |
54 llvm::ELF::SHF_EXECINSTR),
55 GotSec(GotSec) {
56 this->Header.sh_addralign = 16;
57}
58
Rafael Espindola5805c4f2015-09-21 21:38:08 +000059template <class ELFT> void PltSection<ELFT>::writeTo(uint8_t *Buf) {
60 uintptr_t Start = reinterpret_cast<uintptr_t>(Buf);
61 ArrayRef<uint8_t> Jmp = {0xff, 0x25}; // jmpq *val(%rip)
62 for (const SymbolBody *E : Entries) {
Rafael Espindola01205f72015-09-22 18:19:46 +000063 uint64_t GotEntryAddr = GotSec.getEntryAddr(*E);
Rafael Espindola5805c4f2015-09-21 21:38:08 +000064 uintptr_t InstPos = reinterpret_cast<uintptr_t>(Buf);
Rafael Espindola01205f72015-09-22 18:19:46 +000065 uint64_t PltEntryAddr = (InstPos - Start) + this->getVA();
66 Target->writePltEntry(Buf, GotEntryAddr, PltEntryAddr);
67 Buf += 8;
Rafael Espindola5805c4f2015-09-21 21:38:08 +000068 }
69}
70
71template <class ELFT> void PltSection<ELFT>::addEntry(SymbolBody *Sym) {
72 Sym->setPltIndex(Entries.size());
73 Entries.push_back(Sym);
74}
75
76template <class ELFT>
77typename PltSection<ELFT>::uintX_t
78PltSection<ELFT>::getEntryAddr(const SymbolBody &B) const {
79 return this->getVA() + B.getPltIndex() * EntrySize;
80}
81
Rafael Espindola35c6af32015-09-25 17:19:10 +000082template <class ELFT>
83RelocationSection<ELFT>::RelocationSection(SymbolTableSection<ELFT> &DynSymSec,
84 const GotSection<ELFT> &GotSec,
85 bool IsRela)
86 : OutputSectionBase<ELFT::Is64Bits>(IsRela ? ".rela.dyn" : ".rel.dyn",
87 IsRela ? llvm::ELF::SHT_RELA
88 : llvm::ELF::SHT_REL,
89 llvm::ELF::SHF_ALLOC),
90 DynSymSec(DynSymSec), GotSec(GotSec), IsRela(IsRela) {
91 this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
92 this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
93}
94
Rafael Espindola5805c4f2015-09-21 21:38:08 +000095template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
Rafael Espindola50534c22015-09-22 17:49:38 +000096 const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
Rafael Espindolae1901cc2015-09-24 15:11:50 +000097 bool IsMips64EL = Relocs[0].C.getFile()->getObj().isMips64EL();
Rafael Espindola5805c4f2015-09-21 21:38:08 +000098 for (const DynamicReloc<ELFT> &Rel : Relocs) {
Rafael Espindola50534c22015-09-22 17:49:38 +000099 auto *P = reinterpret_cast<Elf_Rel *>(Buf);
100 Buf += EntrySize;
101
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000102 const InputSection<ELFT> &C = Rel.C;
103 const Elf_Rel &RI = Rel.RI;
104 OutputSection<ELFT> *Out = C.getOutputSection();
105 uint32_t SymIndex = RI.getSymbol(IsMips64EL);
106 const SymbolBody *Body = C.getFile()->getSymbolBody(SymIndex);
107 uint32_t Type = RI.getType(IsMips64EL);
Rafael Espindola01205f72015-09-22 18:19:46 +0000108 if (Target->relocNeedsGot(Type)) {
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000109 P->r_offset = GotSec.getEntryAddr(*Body);
Rafael Espindola7f074422015-09-22 21:35:51 +0000110 P->setSymbolAndType(Body->getDynamicSymbolTableIndex(),
111 Target->getGotReloc(), IsMips64EL);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000112 } else {
113 P->r_offset = RI.r_offset + C.getOutputSectionOff() + Out->getVA();
114 P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), Type, IsMips64EL);
115 if (IsRela)
Rafael Espindola50534c22015-09-22 17:49:38 +0000116 static_cast<Elf_Rela *>(P)->r_addend =
117 static_cast<const Elf_Rela &>(RI).r_addend;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000118 }
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000119 }
120}
121
122template <class ELFT> void RelocationSection<ELFT>::finalize() {
123 this->Header.sh_link = DynSymSec.getSectionIndex();
124 this->Header.sh_size = Relocs.size() * this->Header.sh_entsize;
125}
126
127template <bool Is64Bits>
128InterpSection<Is64Bits>::InterpSection()
129 : OutputSectionBase<Is64Bits>(".interp", llvm::ELF::SHT_PROGBITS,
130 llvm::ELF::SHF_ALLOC) {
131 this->Header.sh_size = Config->DynamicLinker.size() + 1;
132 this->Header.sh_addralign = 1;
133}
134
135template <bool Is64Bits>
136template <endianness E>
137void OutputSectionBase<Is64Bits>::writeHeaderTo(
138 typename ELFFile<ELFType<E, Is64Bits>>::Elf_Shdr *SHdr) {
139 SHdr->sh_name = Header.sh_name;
140 SHdr->sh_type = Header.sh_type;
141 SHdr->sh_flags = Header.sh_flags;
142 SHdr->sh_addr = Header.sh_addr;
143 SHdr->sh_offset = Header.sh_offset;
144 SHdr->sh_size = Header.sh_size;
145 SHdr->sh_link = Header.sh_link;
146 SHdr->sh_info = Header.sh_info;
147 SHdr->sh_addralign = Header.sh_addralign;
148 SHdr->sh_entsize = Header.sh_entsize;
149}
150
151template <bool Is64Bits> void InterpSection<Is64Bits>::writeTo(uint8_t *Buf) {
152 memcpy(Buf, Config->DynamicLinker.data(), Config->DynamicLinker.size());
153}
154
Rafael Espindola35c6af32015-09-25 17:19:10 +0000155template <class ELFT>
156HashTableSection<ELFT>::HashTableSection(SymbolTableSection<ELFT> &DynSymSec)
157 : OutputSectionBase<ELFT::Is64Bits>(".hash", llvm::ELF::SHT_HASH,
158 llvm::ELF::SHF_ALLOC),
159 DynSymSec(DynSymSec) {
160 this->Header.sh_entsize = sizeof(Elf_Word);
161 this->Header.sh_addralign = sizeof(Elf_Word);
162}
163
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000164template <class ELFT> void HashTableSection<ELFT>::addSymbol(SymbolBody *S) {
165 StringRef Name = S->getName();
166 DynSymSec.addSymbol(Name);
167 Hashes.push_back(hash(Name));
168 S->setDynamicSymbolTableIndex(Hashes.size());
169}
170
Rafael Espindola35c6af32015-09-25 17:19:10 +0000171template <class ELFT>
172DynamicSection<ELFT>::DynamicSection(SymbolTable &SymTab,
173 HashTableSection<ELFT> &HashSec,
174 RelocationSection<ELFT> &RelaDynSec)
175 : OutputSectionBase<ELFT::Is64Bits>(".dynamic", llvm::ELF::SHT_DYNAMIC,
176 llvm::ELF::SHF_ALLOC |
177 llvm::ELF::SHF_WRITE),
178 HashSec(HashSec), DynSymSec(HashSec.getDynSymSec()),
179 DynStrSec(DynSymSec.getStrTabSec()), RelaDynSec(RelaDynSec),
180 SymTab(SymTab) {
181 typename Base::HeaderT &Header = this->Header;
182 Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
183 Header.sh_entsize = ELFT::Is64Bits ? 16 : 8;
184}
185
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000186template <class ELFT> void DynamicSection<ELFT>::finalize() {
187 typename Base::HeaderT &Header = this->Header;
188 Header.sh_link = DynStrSec.getSectionIndex();
189
190 unsigned NumEntries = 0;
191 if (RelaDynSec.hasRelocs()) {
192 ++NumEntries; // DT_RELA / DT_REL
193 ++NumEntries; // DT_RELASZ / DTRELSZ
194 }
195 ++NumEntries; // DT_SYMTAB
196 ++NumEntries; // DT_STRTAB
197 ++NumEntries; // DT_STRSZ
198 ++NumEntries; // DT_HASH
199
200 StringRef RPath = Config->RPath;
201 if (!RPath.empty()) {
202 ++NumEntries; // DT_RUNPATH
203 DynStrSec.add(RPath);
204 }
205
206 const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =
207 SymTab.getSharedFiles();
208 for (const std::unique_ptr<SharedFileBase> &File : SharedFiles)
209 DynStrSec.add(File->getName());
210 NumEntries += SharedFiles.size();
211
212 ++NumEntries; // DT_NULL
213
214 Header.sh_size = NumEntries * Header.sh_entsize;
215}
216
217template <class ELFT> void DynamicSection<ELFT>::writeTo(uint8_t *Buf) {
218 typedef typename std::conditional<ELFT::Is64Bits, Elf64_Dyn, Elf32_Dyn>::type
219 Elf_Dyn;
220 auto *P = reinterpret_cast<Elf_Dyn *>(Buf);
221
222 if (RelaDynSec.hasRelocs()) {
223 bool IsRela = RelaDynSec.isRela();
224 P->d_tag = IsRela ? DT_RELA : DT_REL;
225 P->d_un.d_ptr = RelaDynSec.getVA();
226 ++P;
227
228 P->d_tag = IsRela ? DT_RELASZ : DT_RELSZ;
229 P->d_un.d_val = RelaDynSec.getSize();
230 ++P;
231 }
232
233 P->d_tag = DT_SYMTAB;
234 P->d_un.d_ptr = DynSymSec.getVA();
235 ++P;
236
237 P->d_tag = DT_STRTAB;
238 P->d_un.d_ptr = DynStrSec.getVA();
239 ++P;
240
241 P->d_tag = DT_STRSZ;
242 P->d_un.d_val = DynStrSec.data().size();
243 ++P;
244
245 P->d_tag = DT_HASH;
246 P->d_un.d_ptr = HashSec.getVA();
247 ++P;
248
249 StringRef RPath = Config->RPath;
250 if (!RPath.empty()) {
251 P->d_tag = DT_RUNPATH;
252 P->d_un.d_val = DynStrSec.getFileOff(RPath);
253 ++P;
254 }
255
256 const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =
257 SymTab.getSharedFiles();
258 for (const std::unique_ptr<SharedFileBase> &File : SharedFiles) {
259 P->d_tag = DT_NEEDED;
260 P->d_un.d_val = DynStrSec.getFileOff(File->getName());
261 ++P;
262 }
263
264 P->d_tag = DT_NULL;
265 P->d_un.d_val = 0;
266 ++P;
267}
268
269template <class ELFT>
Rafael Espindola35c6af32015-09-25 17:19:10 +0000270OutputSection<ELFT>::OutputSection(const PltSection<ELFT> &PltSec,
271 const GotSection<ELFT> &GotSec,
272 const OutputSection<ELFT> &BssSec,
273 StringRef Name, uint32_t sh_type,
274 uintX_t sh_flags)
275 : OutputSectionBase<ELFT::Is64Bits>(Name, sh_type, sh_flags),
276 PltSec(PltSec), GotSec(GotSec), BssSec(BssSec) {}
277
278template <class ELFT>
Rafael Espindola71675852015-09-22 00:16:19 +0000279void OutputSection<ELFT>::addSection(InputSection<ELFT> *C) {
280 Sections.push_back(C);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000281 C->setOutputSection(this);
282 uint32_t Align = C->getAlign();
283 if (Align > this->Header.sh_addralign)
284 this->Header.sh_addralign = Align;
285
286 uintX_t Off = this->Header.sh_size;
287 Off = RoundUpToAlignment(Off, Align);
288 C->setOutputSectionOff(Off);
289 Off += C->getSize();
290 this->Header.sh_size = Off;
291}
292
293template <class ELFT>
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000294typename ELFFile<ELFT>::uintX_t
295lld::elf2::getSymVA(const DefinedRegular<ELFT> *DR) {
296 const InputSection<ELFT> *SC = &DR->Section;
297 OutputSection<ELFT> *OS = SC->getOutputSection();
298 return OS->getVA() + SC->getOutputSectionOff() + DR->Sym.st_value;
299}
300
301template <class ELFT>
302typename ELFFile<ELFT>::uintX_t
303lld::elf2::getLocalSymVA(const typename ELFFile<ELFT>::Elf_Sym *Sym,
304 const ObjectFile<ELFT> &File) {
305 uint32_t SecIndex = Sym->st_shndx;
306
307 if (SecIndex == SHN_XINDEX)
Rafael Espindolae1901cc2015-09-24 15:11:50 +0000308 SecIndex = File.getObj().getExtendedSymbolTableIndex(
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000309 Sym, File.getSymbolTable(), File.getSymbolTableShndx());
Rafael Espindola71675852015-09-22 00:16:19 +0000310 ArrayRef<InputSection<ELFT> *> Sections = File.getSections();
311 InputSection<ELFT> *Section = Sections[SecIndex];
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000312 OutputSection<ELFT> *Out = Section->getOutputSection();
313 return Out->getVA() + Section->getOutputSectionOff() + Sym->st_value;
314}
315
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000316template <class ELFT> void OutputSection<ELFT>::writeTo(uint8_t *Buf) {
Rafael Espindola71675852015-09-22 00:16:19 +0000317 for (InputSection<ELFT> *C : Sections)
Rafael Espindolac2d21192015-09-23 18:25:05 +0000318 C->writeTo(Buf, BssSec, PltSec, GotSec);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000319}
320
321template <bool Is64Bits>
Rafael Espindola35c6af32015-09-25 17:19:10 +0000322StringTableSection<Is64Bits>::StringTableSection(bool Dynamic)
323 : OutputSectionBase<Is64Bits>(Dynamic ? ".dynstr" : ".strtab",
324 llvm::ELF::SHT_STRTAB,
325 Dynamic ? (uintX_t)llvm::ELF::SHF_ALLOC : 0),
326 Dynamic(Dynamic) {
327 this->Header.sh_addralign = 1;
328}
329
330template <bool Is64Bits>
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000331void StringTableSection<Is64Bits>::writeTo(uint8_t *Buf) {
332 StringRef Data = StrTabBuilder.data();
333 memcpy(Buf, Data.data(), Data.size());
334}
335
336bool lld::elf2::includeInSymtab(const SymbolBody &B) {
337 if (B.isLazy())
338 return false;
339 if (!B.isUsedInRegularObj())
340 return false;
341 uint8_t V = B.getMostConstrainingVisibility();
342 if (V != STV_DEFAULT && V != STV_PROTECTED)
343 return false;
344 return true;
345}
346
Rafael Espindola05a3dd22015-09-22 23:38:23 +0000347bool lld::elf2::includeInDynamicSymtab(const SymbolBody &B) {
348 if (Config->ExportDynamic || Config->Shared)
349 return true;
350 return B.isUsedInDynamicReloc();
351}
352
Rafael Espindola35c6af32015-09-25 17:19:10 +0000353template <class ELFT>
354SymbolTableSection<ELFT>::SymbolTableSection(
355 SymbolTable &Table, StringTableSection<ELFT::Is64Bits> &StrTabSec,
356 const OutputSection<ELFT> &BssSec)
357 : OutputSectionBase<ELFT::Is64Bits>(
358 StrTabSec.isDynamic() ? ".dynsym" : ".symtab",
359 StrTabSec.isDynamic() ? llvm::ELF::SHT_DYNSYM : llvm::ELF::SHT_SYMTAB,
360 StrTabSec.isDynamic() ? (uintX_t)llvm::ELF::SHF_ALLOC : 0),
361 Table(Table), StrTabSec(StrTabSec), BssSec(BssSec) {
362 typedef OutputSectionBase<ELFT::Is64Bits> Base;
363 typename Base::HeaderT &Header = this->Header;
364
365 Header.sh_entsize = sizeof(Elf_Sym);
366 Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
367}
368
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000369template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
370 const OutputSection<ELFT> *Out = nullptr;
371 const InputSection<ELFT> *Section = nullptr;
372 Buf += sizeof(Elf_Sym);
373
374 // All symbols with STB_LOCAL binding precede the weak and global symbols.
375 // .dynsym only contains global symbols.
376 if (!Config->DiscardAll && !StrTabSec.isDynamic()) {
377 for (const std::unique_ptr<ObjectFileBase> &FileB :
378 Table.getObjectFiles()) {
379 auto &File = cast<ObjectFile<ELFT>>(*FileB);
380 Elf_Sym_Range Syms = File.getLocalSymbols();
381 for (const Elf_Sym &Sym : Syms) {
382 auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
383 uint32_t SecIndex = Sym.st_shndx;
384 ErrorOr<StringRef> SymName = Sym.getName(File.getStringTable());
Davide Italianod75d3b92015-09-24 15:08:23 +0000385 if (SymName && !shouldKeepInSymtab(*SymName))
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000386 continue;
387 ESym->st_name = (SymName) ? StrTabSec.getFileOff(*SymName) : 0;
388 ESym->st_size = Sym.st_size;
389 ESym->setBindingAndType(Sym.getBinding(), Sym.getType());
390 if (SecIndex == SHN_XINDEX)
Rafael Espindolae1901cc2015-09-24 15:11:50 +0000391 SecIndex = File.getObj().getExtendedSymbolTableIndex(
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000392 &Sym, File.getSymbolTable(), File.getSymbolTableShndx());
Rafael Espindola71675852015-09-22 00:16:19 +0000393 ArrayRef<InputSection<ELFT> *> Sections = File.getSections();
394 Section = Sections[SecIndex];
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000395 assert(Section != nullptr);
396 Out = Section->getOutputSection();
397 assert(Out != nullptr);
398 ESym->st_shndx = Out->getSectionIndex();
399 ESym->st_value =
400 Out->getVA() + Section->getOutputSectionOff() + Sym.st_value;
401 Buf += sizeof(Elf_Sym);
402 }
403 }
404 }
405
406 for (auto &P : Table.getSymbols()) {
407 StringRef Name = P.first;
408 Symbol *Sym = P.second;
409 SymbolBody *Body = Sym->Body;
410 if (!includeInSymtab(*Body))
411 continue;
Rafael Espindola05a3dd22015-09-22 23:38:23 +0000412 if (StrTabSec.isDynamic() && !includeInDynamicSymtab(*Body))
413 continue;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000414
Rafael Espindola05a3dd22015-09-22 23:38:23 +0000415 const Elf_Sym &InputSym = cast<ELFSymbolBody<ELFT>>(Body)->Sym;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000416 auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
417 ESym->st_name = StrTabSec.getFileOff(Name);
418
419 Out = nullptr;
420 Section = nullptr;
421
422 switch (Body->kind()) {
423 case SymbolBody::DefinedRegularKind:
424 Section = &cast<DefinedRegular<ELFT>>(Body)->Section;
425 break;
426 case SymbolBody::DefinedCommonKind:
Rafael Espindolac2d21192015-09-23 18:25:05 +0000427 Out = &BssSec;
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000428 break;
429 case SymbolBody::UndefinedKind:
430 case SymbolBody::DefinedAbsoluteKind:
431 case SymbolBody::SharedKind:
432 break;
433 case SymbolBody::LazyKind:
434 llvm_unreachable("Lazy symbol got to output symbol table!");
435 }
436
437 ESym->setBindingAndType(InputSym.getBinding(), InputSym.getType());
438 ESym->st_size = InputSym.st_size;
439 ESym->setVisibility(Body->getMostConstrainingVisibility());
440 if (InputSym.isAbsolute()) {
441 ESym->st_shndx = SHN_ABS;
442 ESym->st_value = InputSym.st_value;
443 }
444
445 if (Section)
446 Out = Section->getOutputSection();
447
448 if (Out) {
449 ESym->st_shndx = Out->getSectionIndex();
450 uintX_t VA = Out->getVA();
451 if (Section)
452 VA += Section->getOutputSectionOff();
453 if (auto *C = dyn_cast<DefinedCommon<ELFT>>(Body))
454 VA += C->OffsetInBSS;
455 else
456 VA += InputSym.st_value;
457 ESym->st_value = VA;
458 }
459
460 Buf += sizeof(Elf_Sym);
461 }
462}
463
464namespace lld {
465namespace elf2 {
466template class OutputSectionBase<false>;
467template class OutputSectionBase<true>;
468
469template void OutputSectionBase<false>::writeHeaderTo<support::little>(
Rafael Espindolaf68b7072015-09-21 22:21:46 +0000470 ELFFile<ELFType<support::little, false>>::Elf_Shdr *SHdr);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000471template void OutputSectionBase<true>::writeHeaderTo<support::little>(
Rafael Espindolaf68b7072015-09-21 22:21:46 +0000472 ELFFile<ELFType<support::little, true>>::Elf_Shdr *SHdr);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000473template void OutputSectionBase<false>::writeHeaderTo<support::big>(
Rafael Espindolaf68b7072015-09-21 22:21:46 +0000474 ELFFile<ELFType<support::big, false>>::Elf_Shdr *SHdr);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000475template void OutputSectionBase<true>::writeHeaderTo<support::big>(
Rafael Espindolaf68b7072015-09-21 22:21:46 +0000476 ELFFile<ELFType<support::big, true>>::Elf_Shdr *SHdr);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000477
478template class GotSection<ELF32LE>;
479template class GotSection<ELF32BE>;
480template class GotSection<ELF64LE>;
481template class GotSection<ELF64BE>;
482
483template class PltSection<ELF32LE>;
484template class PltSection<ELF32BE>;
485template class PltSection<ELF64LE>;
486template class PltSection<ELF64BE>;
487
488template class RelocationSection<ELF32LE>;
489template class RelocationSection<ELF32BE>;
490template class RelocationSection<ELF64LE>;
491template class RelocationSection<ELF64BE>;
492
493template class InterpSection<false>;
494template class InterpSection<true>;
495
496template class HashTableSection<ELF32LE>;
497template class HashTableSection<ELF32BE>;
498template class HashTableSection<ELF64LE>;
499template class HashTableSection<ELF64BE>;
500
501template class DynamicSection<ELF32LE>;
502template class DynamicSection<ELF32BE>;
503template class DynamicSection<ELF64LE>;
504template class DynamicSection<ELF64BE>;
505
506template class OutputSection<ELF32LE>;
507template class OutputSection<ELF32BE>;
508template class OutputSection<ELF64LE>;
509template class OutputSection<ELF64BE>;
510
511template class StringTableSection<false>;
512template class StringTableSection<true>;
513
514template class SymbolTableSection<ELF32LE>;
515template class SymbolTableSection<ELF32BE>;
516template class SymbolTableSection<ELF64LE>;
517template class SymbolTableSection<ELF64BE>;
518
Rafael Espindola56f965f2015-09-21 22:48:12 +0000519template ELFFile<ELF32LE>::uintX_t getSymVA(const DefinedRegular<ELF32LE> *DR);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000520
Rafael Espindola56f965f2015-09-21 22:48:12 +0000521template ELFFile<ELF32BE>::uintX_t getSymVA(const DefinedRegular<ELF32BE> *DR);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000522
Rafael Espindola56f965f2015-09-21 22:48:12 +0000523template ELFFile<ELF64LE>::uintX_t getSymVA(const DefinedRegular<ELF64LE> *DR);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000524
Rafael Espindola56f965f2015-09-21 22:48:12 +0000525template ELFFile<ELF64BE>::uintX_t getSymVA(const DefinedRegular<ELF64BE> *DR);
Rafael Espindola4ea00212015-09-21 22:01:00 +0000526
Rafael Espindola56f965f2015-09-21 22:48:12 +0000527template ELFFile<ELF32LE>::uintX_t
Denis Protivensky67d01482015-09-22 08:14:46 +0000528getLocalSymVA(const ELFFile<ELF32LE>::Elf_Sym *Sym,
529 const ObjectFile<ELF32LE> &File);
Rafael Espindola4ea00212015-09-21 22:01:00 +0000530
Rafael Espindola56f965f2015-09-21 22:48:12 +0000531template ELFFile<ELF32BE>::uintX_t
Denis Protivensky67d01482015-09-22 08:14:46 +0000532getLocalSymVA(const ELFFile<ELF32BE>::Elf_Sym *Sym,
533 const ObjectFile<ELF32BE> &File);
Rafael Espindola4ea00212015-09-21 22:01:00 +0000534
Rafael Espindola56f965f2015-09-21 22:48:12 +0000535template ELFFile<ELF64LE>::uintX_t
Denis Protivensky67d01482015-09-22 08:14:46 +0000536getLocalSymVA(const ELFFile<ELF64LE>::Elf_Sym *Sym,
537 const ObjectFile<ELF64LE> &File);
Rafael Espindola4ea00212015-09-21 22:01:00 +0000538
Rafael Espindola56f965f2015-09-21 22:48:12 +0000539template ELFFile<ELF64BE>::uintX_t
Denis Protivensky67d01482015-09-22 08:14:46 +0000540getLocalSymVA(const ELFFile<ELF64BE>::Elf_Sym *Sym,
541 const ObjectFile<ELF64BE> &File);
Rafael Espindola5805c4f2015-09-21 21:38:08 +0000542}
543}