1 //===- InputSection.cpp ---------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "InputSection.h"
12 #include "InputFiles.h"
13 #include "LinkerScript.h"
14 #include "OutputSections.h"
15 #include "Relocations.h"
16 #include "SymbolTable.h"
18 #include "SyntheticSections.h"
21 #include "lld/Common/ErrorHandler.h"
22 #include "lld/Common/Memory.h"
23 #include "llvm/Support/Compiler.h"
24 #include "llvm/Support/Compression.h"
25 #include "llvm/Support/Endian.h"
26 #include "llvm/Support/Threading.h"
27 #include "llvm/Support/xxhash.h"
34 using namespace llvm::ELF;
35 using namespace llvm::object;
36 using namespace llvm::support;
37 using namespace llvm::support::endian;
38 using namespace llvm::sys;
41 // Returns a string to construct an error message.
42 std::string toString(const elf::InputSectionBase *sec) {
43 return (toString(sec->file) + ":(" + sec->name + ")").str();
47 std::vector<InputSectionBase *> inputSections;
50 static ArrayRef<uint8_t> getSectionContents(ObjFile<ELFT> &file,
51 const typename ELFT::Shdr &hdr) {
52 if (hdr.sh_type == SHT_NOBITS)
53 return makeArrayRef<uint8_t>(nullptr, hdr.sh_size);
54 return check(file.getObj().getSectionContents(&hdr));
57 InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
58 uint32_t type, uint64_t entsize,
59 uint32_t link, uint32_t info,
60 uint32_t alignment, ArrayRef<uint8_t> data,
61 StringRef name, Kind sectionKind)
62 : SectionBase(sectionKind, name, flags, entsize, alignment, type, info,
64 file(file), rawData(data) {
65 // In order to reduce memory allocation, we assume that mergeable
66 // sections are smaller than 4 GiB, which is not an unreasonable
67 // assumption as of 2017.
68 if (sectionKind == SectionBase::Merge && rawData.size() > UINT32_MAX)
69 error(toString(this) + ": section too large");
72 areRelocsRela = false;
74 // The ELF spec states that a value of 0 means the section has
75 // no alignment constraints.
76 uint32_t v = std::max<uint32_t>(alignment, 1);
77 if (!isPowerOf2_64(v))
78 fatal(toString(this) + ": sh_addralign is not a power of 2");
81 // In ELF, each section can be compressed by zlib, and if compressed,
82 // section name may be mangled by appending "z" (e.g. ".zdebug_info").
83 // If that's the case, demangle section name so that we can handle a
84 // section as if it weren't compressed.
85 if ((flags & SHF_COMPRESSED) || name.startswith(".zdebug")) {
86 if (!zlib::isAvailable())
87 error(toString(file) + ": contains a compressed section, " +
88 "but zlib is not available");
89 parseCompressedHeader();
93 // Drop SHF_GROUP bit unless we are producing a re-linkable object file.
94 // SHF_GROUP is a marker that a section belongs to some comdat group.
95 // That flag doesn't make sense in an executable.
96 static uint64_t getFlags(uint64_t flags) {
97 flags &= ~(uint64_t)SHF_INFO_LINK;
98 if (!config->relocatable)
99 flags &= ~(uint64_t)SHF_GROUP;
103 // GNU assembler 2.24 and LLVM 4.0.0's MC (the newest release as of
104 // March 2017) fail to infer section types for sections starting with
105 // ".init_array." or ".fini_array.". They set SHT_PROGBITS instead of
106 // SHF_INIT_ARRAY. As a result, the following assembler directive
107 // creates ".init_array.100" with SHT_PROGBITS, for example.
109 // .section .init_array.100, "aw"
111 // This function forces SHT_{INIT,FINI}_ARRAY so that we can handle
112 // incorrect inputs as if they were correct from the beginning.
113 static uint64_t getType(uint64_t type, StringRef name) {
114 if (type == SHT_PROGBITS && name.startswith(".init_array."))
115 return SHT_INIT_ARRAY;
116 if (type == SHT_PROGBITS && name.startswith(".fini_array."))
117 return SHT_FINI_ARRAY;
121 template <class ELFT>
122 InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,
123 const typename ELFT::Shdr &hdr,
124 StringRef name, Kind sectionKind)
125 : InputSectionBase(&file, getFlags(hdr.sh_flags),
126 getType(hdr.sh_type, name), hdr.sh_entsize, hdr.sh_link,
127 hdr.sh_info, hdr.sh_addralign,
128 getSectionContents(file, hdr), name, sectionKind) {
129 // We reject object files having insanely large alignments even though
130 // they are allowed by the spec. I think 4GB is a reasonable limitation.
131 // We might want to relax this in the future.
132 if (hdr.sh_addralign > UINT32_MAX)
133 fatal(toString(&file) + ": section sh_addralign is too large");
136 size_t InputSectionBase::getSize() const {
137 if (auto *s = dyn_cast<SyntheticSection>(this))
139 if (uncompressedSize >= 0)
140 return uncompressedSize;
141 return rawData.size();
144 void InputSectionBase::uncompress() const {
145 size_t size = uncompressedSize;
146 char *uncompressedBuf;
148 static std::mutex mu;
149 std::lock_guard<std::mutex> lock(mu);
150 uncompressedBuf = bAlloc.Allocate<char>(size);
153 if (Error e = zlib::uncompress(toStringRef(rawData), uncompressedBuf, size))
154 fatal(toString(this) +
155 ": uncompress failed: " + llvm::toString(std::move(e)));
156 rawData = makeArrayRef((uint8_t *)uncompressedBuf, size);
157 uncompressedSize = -1;
160 uint64_t InputSectionBase::getOffsetInFile() const {
161 const uint8_t *fileStart = (const uint8_t *)file->mb.getBufferStart();
162 const uint8_t *secStart = data().begin();
163 return secStart - fileStart;
166 uint64_t SectionBase::getOffset(uint64_t offset) const {
169 auto *os = cast<OutputSection>(this);
170 // For output sections we treat offset -1 as the end of the section.
171 return offset == uint64_t(-1) ? os->size : offset;
175 return cast<InputSection>(this)->getOffset(offset);
177 // The file crtbeginT.o has relocations pointing to the start of an empty
178 // .eh_frame that is known to be the first in the link. It does that to
179 // identify the start of the output .eh_frame.
182 const MergeInputSection *ms = cast<MergeInputSection>(this);
183 if (InputSection *isec = ms->getParent())
184 return isec->getOffset(ms->getParentOffset(offset));
185 return ms->getParentOffset(offset);
187 llvm_unreachable("invalid section kind");
190 uint64_t SectionBase::getVA(uint64_t offset) const {
191 const OutputSection *out = getOutputSection();
192 return (out ? out->addr : 0) + getOffset(offset);
195 OutputSection *SectionBase::getOutputSection() {
197 if (auto *isec = dyn_cast<InputSection>(this))
199 else if (auto *ms = dyn_cast<MergeInputSection>(this))
200 sec = ms->getParent();
201 else if (auto *eh = dyn_cast<EhInputSection>(this))
202 sec = eh->getParent();
204 return cast<OutputSection>(this);
205 return sec ? sec->getParent() : nullptr;
208 // When a section is compressed, `rawData` consists with a header followed
209 // by zlib-compressed data. This function parses a header to initialize
210 // `uncompressedSize` member and remove the header from `rawData`.
211 void InputSectionBase::parseCompressedHeader() {
212 using Chdr64 = typename ELF64LE::Chdr;
213 using Chdr32 = typename ELF32LE::Chdr;
216 if (name.startswith(".zdebug")) {
217 if (!toStringRef(rawData).startswith("ZLIB")) {
218 error(toString(this) + ": corrupted compressed section header");
221 rawData = rawData.slice(4);
223 if (rawData.size() < 8) {
224 error(toString(this) + ": corrupted compressed section header");
228 uncompressedSize = read64be(rawData.data());
229 rawData = rawData.slice(8);
231 // Restore the original section name.
232 // (e.g. ".zdebug_info" -> ".debug_info")
233 name = saver.save("." + name.substr(2));
237 assert(flags & SHF_COMPRESSED);
238 flags &= ~(uint64_t)SHF_COMPRESSED;
240 // New-style 64-bit header
242 if (rawData.size() < sizeof(Chdr64)) {
243 error(toString(this) + ": corrupted compressed section");
247 auto *hdr = reinterpret_cast<const Chdr64 *>(rawData.data());
248 if (hdr->ch_type != ELFCOMPRESS_ZLIB) {
249 error(toString(this) + ": unsupported compression type");
253 uncompressedSize = hdr->ch_size;
254 alignment = std::max<uint32_t>(hdr->ch_addralign, 1);
255 rawData = rawData.slice(sizeof(*hdr));
259 // New-style 32-bit header
260 if (rawData.size() < sizeof(Chdr32)) {
261 error(toString(this) + ": corrupted compressed section");
265 auto *hdr = reinterpret_cast<const Chdr32 *>(rawData.data());
266 if (hdr->ch_type != ELFCOMPRESS_ZLIB) {
267 error(toString(this) + ": unsupported compression type");
271 uncompressedSize = hdr->ch_size;
272 alignment = std::max<uint32_t>(hdr->ch_addralign, 1);
273 rawData = rawData.slice(sizeof(*hdr));
276 InputSection *InputSectionBase::getLinkOrderDep() const {
278 assert(flags & SHF_LINK_ORDER);
279 return cast<InputSection>(file->getSections()[link]);
282 // Find a function symbol that encloses a given location.
283 template <class ELFT>
284 Defined *InputSectionBase::getEnclosingFunction(uint64_t offset) {
285 for (Symbol *b : file->getSymbols())
286 if (Defined *d = dyn_cast<Defined>(b))
287 if (d->section == this && d->type == STT_FUNC && d->value <= offset &&
288 offset < d->value + d->size)
293 // Returns a source location string. Used to construct an error message.
294 template <class ELFT>
295 std::string InputSectionBase::getLocation(uint64_t offset) {
296 std::string secAndOffset = (name + "+0x" + utohexstr(offset)).str();
298 // We don't have file for synthetic sections.
299 if (getFile<ELFT>() == nullptr)
300 return (config->outputFile + ":(" + secAndOffset + ")")
303 // First check if we can get desired values from debugging information.
304 if (Optional<DILineInfo> info = getFile<ELFT>()->getDILineInfo(this, offset))
305 return info->FileName + ":" + std::to_string(info->Line) + ":(" +
308 // File->sourceFile contains STT_FILE symbol that contains a
309 // source file name. If it's missing, we use an object file name.
310 std::string srcFile = getFile<ELFT>()->sourceFile;
312 srcFile = toString(file);
314 if (Defined *d = getEnclosingFunction<ELFT>(offset))
315 return srcFile + ":(function " + toString(*d) + ": " + secAndOffset + ")";
317 // If there's no symbol, print out the offset in the section.
318 return (srcFile + ":(" + secAndOffset + ")");
321 // This function is intended to be used for constructing an error message.
322 // The returned message looks like this:
324 // foo.c:42 (/home/alice/possibly/very/long/path/foo.c:42)
326 // Returns an empty string if there's no way to get line info.
327 std::string InputSectionBase::getSrcMsg(const Symbol &sym, uint64_t offset) {
328 return file->getSrcMsg(sym, *this, offset);
331 // Returns a filename string along with an optional section name. This
332 // function is intended to be used for constructing an error
333 // message. The returned message looks like this:
335 // path/to/foo.o:(function bar)
339 // path/to/foo.o:(function bar) in archive path/to/bar.a
340 std::string InputSectionBase::getObjMsg(uint64_t off) {
341 std::string filename = file->getName();
344 if (!file->archiveName.empty())
345 archive = " in archive " + file->archiveName;
347 // Find a symbol that encloses a given location.
348 for (Symbol *b : file->getSymbols())
349 if (auto *d = dyn_cast<Defined>(b))
350 if (d->section == this && d->value <= off && off < d->value + d->size)
351 return filename + ":(" + toString(*d) + ")" + archive;
353 // If there's no symbol, print out the offset in the section.
354 return (filename + ":(" + name + "+0x" + utohexstr(off) + ")" + archive)
358 InputSection InputSection::discarded(nullptr, 0, 0, 0, ArrayRef<uint8_t>(), "");
360 InputSection::InputSection(InputFile *f, uint64_t flags, uint32_t type,
361 uint32_t alignment, ArrayRef<uint8_t> data,
362 StringRef name, Kind k)
363 : InputSectionBase(f, flags, type,
364 /*Entsize*/ 0, /*Link*/ 0, /*Info*/ 0, alignment, data,
367 template <class ELFT>
368 InputSection::InputSection(ObjFile<ELFT> &f, const typename ELFT::Shdr &header,
370 : InputSectionBase(f, header, name, InputSectionBase::Regular) {}
372 bool InputSection::classof(const SectionBase *s) {
373 return s->kind() == SectionBase::Regular ||
374 s->kind() == SectionBase::Synthetic;
377 OutputSection *InputSection::getParent() const {
378 return cast_or_null<OutputSection>(parent);
381 // Copy SHT_GROUP section contents. Used only for the -r option.
382 template <class ELFT> void InputSection::copyShtGroup(uint8_t *buf) {
383 // ELFT::Word is the 32-bit integral type in the target endianness.
384 using u32 = typename ELFT::Word;
385 ArrayRef<u32> from = getDataAs<u32>();
386 auto *to = reinterpret_cast<u32 *>(buf);
388 // The first entry is not a section number but a flag.
391 // Adjust section numbers because section numbers in an input object
392 // files are different in the output.
393 ArrayRef<InputSectionBase *> sections = file->getSections();
394 for (uint32_t idx : from.slice(1))
395 *to++ = sections[idx]->getOutputSection()->sectionIndex;
398 InputSectionBase *InputSection::getRelocatedSection() const {
399 if (!file || (type != SHT_RELA && type != SHT_REL))
401 ArrayRef<InputSectionBase *> sections = file->getSections();
402 return sections[info];
405 // This is used for -r and --emit-relocs. We can't use memcpy to copy
406 // relocations because we need to update symbol table offset and section index
407 // for each relocation. So we copy relocations one by one.
408 template <class ELFT, class RelTy>
409 void InputSection::copyRelocations(uint8_t *buf, ArrayRef<RelTy> rels) {
410 InputSectionBase *sec = getRelocatedSection();
412 for (const RelTy &rel : rels) {
413 RelType type = rel.getType(config->isMips64EL);
414 const ObjFile<ELFT> *file = getFile<ELFT>();
415 Symbol &sym = file->getRelocTargetSym(rel);
417 auto *p = reinterpret_cast<typename ELFT::Rela *>(buf);
418 buf += sizeof(RelTy);
421 p->r_addend = getAddend<ELFT>(rel);
423 // Output section VA is zero for -r, so r_offset is an offset within the
424 // section, but for --emit-relocs it is a virtual address.
425 p->r_offset = sec->getVA(rel.r_offset);
426 p->setSymbolAndType(in.symTab->getSymbolIndex(&sym), type,
429 if (sym.type == STT_SECTION) {
430 // We combine multiple section symbols into only one per
431 // section. This means we have to update the addend. That is
432 // trivial for Elf_Rela, but for Elf_Rel we have to write to the
433 // section data. We do that by adding to the Relocation vector.
435 // .eh_frame is horribly special and can reference discarded sections. To
436 // avoid having to parse and recreate .eh_frame, we just replace any
437 // relocation in it pointing to discarded sections with R_*_NONE, which
438 // hopefully creates a frame that is ignored at runtime. Also, don't warn
439 // on .gcc_except_table and debug sections.
441 // See the comment in maybeReportUndefined for PPC32 .got2 and PPC64 .toc
442 auto *d = dyn_cast<Defined>(&sym);
444 if (!sec->name.startswith(".debug") &&
445 !sec->name.startswith(".zdebug") && sec->name != ".eh_frame" &&
446 sec->name != ".gcc_except_table" && sec->name != ".got2" &&
447 sec->name != ".toc") {
448 uint32_t secIdx = cast<Undefined>(sym).discardedSecIdx;
449 Elf_Shdr_Impl<ELFT> sec =
450 CHECK(file->getObj().sections(), file)[secIdx];
451 warn("relocation refers to a discarded section: " +
452 CHECK(file->getObj().getSectionName(&sec), file) +
453 "\n>>> referenced by " + getObjMsg(p->r_offset));
455 p->setSymbolAndType(0, 0, false);
458 SectionBase *section = d->section->repl;
459 if (!section->isLive()) {
460 p->setSymbolAndType(0, 0, false);
464 int64_t addend = getAddend<ELFT>(rel);
465 const uint8_t *bufLoc = sec->data().begin() + rel.r_offset;
467 addend = target->getImplicitAddend(bufLoc, type);
469 if (config->emachine == EM_MIPS && config->relocatable &&
470 target->getRelExpr(type, sym, bufLoc) == R_MIPS_GOTREL) {
471 // Some MIPS relocations depend on "gp" value. By default,
472 // this value has 0x7ff0 offset from a .got section. But
473 // relocatable files produced by a compiler or a linker
474 // might redefine this default value and we must use it
475 // for a calculation of the relocation result. When we
476 // generate EXE or DSO it's trivial. Generating a relocatable
477 // output is more difficult case because the linker does
478 // not calculate relocations in this mode and loses
479 // individual "gp" values used by each input object file.
480 // As a workaround we add the "gp" value to the relocation
481 // addend and save it back to the file.
482 addend += sec->getFile<ELFT>()->mipsGp0;
486 p->r_addend = sym.getVA(addend) - section->getOutputSection()->addr;
487 else if (config->relocatable && type != target->noneRel)
488 sec->relocations.push_back({R_ABS, type, rel.r_offset, addend, &sym});
489 } else if (config->emachine == EM_PPC && type == R_PPC_PLTREL24 &&
490 p->r_addend >= 0x8000) {
491 // Similar to R_MIPS_GPREL{16,32}. If the addend of R_PPC_PLTREL24
492 // indicates that r30 is relative to the input section .got2
493 // (r_addend>=0x8000), after linking, r30 should be relative to the output
494 // section .got2 . To compensate for the shift, adjust r_addend by
495 // ppc32Got2OutSecOff.
496 p->r_addend += sec->file->ppc32Got2OutSecOff;
501 // The ARM and AArch64 ABI handle pc-relative relocations to undefined weak
502 // references specially. The general rule is that the value of the symbol in
503 // this context is the address of the place P. A further special case is that
504 // branch relocations to an undefined weak reference resolve to the next
506 static uint32_t getARMUndefinedRelativeWeakVA(RelType type, uint32_t a,
509 // Unresolved branch relocations to weak references resolve to next
510 // instruction, this will be either 2 or 4 bytes on from P.
511 case R_ARM_THM_JUMP11:
518 case R_ARM_THM_JUMP19:
519 case R_ARM_THM_JUMP24:
522 // We don't want an interworking BLX to ARM
524 // Unresolved non branch pc-relative relocations
525 // R_ARM_TARGET2 which can be resolved relatively is not present as it never
526 // targets a weak-reference.
527 case R_ARM_MOVW_PREL_NC:
528 case R_ARM_MOVT_PREL:
530 case R_ARM_THM_MOVW_PREL_NC:
531 case R_ARM_THM_MOVT_PREL:
534 llvm_unreachable("ARM pc-relative relocation expected\n");
537 // The comment above getARMUndefinedRelativeWeakVA applies to this function.
538 static uint64_t getAArch64UndefinedRelativeWeakVA(uint64_t type, uint64_t a,
541 // Unresolved branch relocations to weak references resolve to next
542 // instruction, this is 4 bytes on from P.
543 case R_AARCH64_CALL26:
544 case R_AARCH64_CONDBR19:
545 case R_AARCH64_JUMP26:
546 case R_AARCH64_TSTBR14:
548 // Unresolved non branch pc-relative relocations
549 case R_AARCH64_PREL16:
550 case R_AARCH64_PREL32:
551 case R_AARCH64_PREL64:
552 case R_AARCH64_ADR_PREL_LO21:
553 case R_AARCH64_LD_PREL_LO19:
556 llvm_unreachable("AArch64 pc-relative relocation expected\n");
559 // ARM SBREL relocations are of the form S + A - B where B is the static base
560 // The ARM ABI defines base to be "addressing origin of the output segment
561 // defining the symbol S". We defined the "addressing origin"/static base to be
562 // the base of the PT_LOAD segment containing the Sym.
563 // The procedure call standard only defines a Read Write Position Independent
564 // RWPI variant so in practice we should expect the static base to be the base
565 // of the RW segment.
566 static uint64_t getARMStaticBase(const Symbol &sym) {
567 OutputSection *os = sym.getOutputSection();
568 if (!os || !os->ptLoad || !os->ptLoad->firstSec)
569 fatal("SBREL relocation to " + sym.getName() + " without static base");
570 return os->ptLoad->firstSec->addr;
573 // For R_RISCV_PC_INDIRECT (R_RISCV_PCREL_LO12_{I,S}), the symbol actually
574 // points the corresponding R_RISCV_PCREL_HI20 relocation, and the target VA
575 // is calculated using PCREL_HI20's symbol.
577 // This function returns the R_RISCV_PCREL_HI20 relocation from
578 // R_RISCV_PCREL_LO12's symbol and addend.
579 static Relocation *getRISCVPCRelHi20(const Symbol *sym, uint64_t addend) {
580 const Defined *d = cast<Defined>(sym);
582 error("R_RISCV_PCREL_LO12 relocation points to an absolute symbol: " +
586 InputSection *isec = cast<InputSection>(d->section);
589 warn("Non-zero addend in R_RISCV_PCREL_LO12 relocation to " +
590 isec->getObjMsg(d->value) + " is ignored");
592 // Relocations are sorted by offset, so we can use std::equal_range to do
597 std::equal_range(isec->relocations.begin(), isec->relocations.end(), r,
598 [](const Relocation &lhs, const Relocation &rhs) {
599 return lhs.offset < rhs.offset;
602 for (auto it = range.first; it != range.second; ++it)
603 if (it->type == R_RISCV_PCREL_HI20 || it->type == R_RISCV_GOT_HI20 ||
604 it->type == R_RISCV_TLS_GD_HI20 || it->type == R_RISCV_TLS_GOT_HI20)
607 error("R_RISCV_PCREL_LO12 relocation points to " + isec->getObjMsg(d->value) +
608 " without an associated R_RISCV_PCREL_HI20 relocation");
612 // A TLS symbol's virtual address is relative to the TLS segment. Add a
613 // target-specific adjustment to produce a thread-pointer-relative offset.
614 static int64_t getTlsTpOffset(const Symbol &s) {
615 // On targets that support TLSDESC, _TLS_MODULE_BASE_@tpoff = 0.
616 if (&s == ElfSym::tlsModuleBase)
619 // There are 2 TLS layouts. Among targets we support, x86 uses TLS Variant 2
620 // while most others use Variant 1. At run time TP will be aligned to p_align.
622 // Variant 1. TP will be followed by an optional gap (which is the size of 2
623 // pointers on ARM/AArch64, 0 on other targets), followed by alignment
624 // padding, then the static TLS blocks. The alignment padding is added so that
625 // (TP + gap + padding) is congruent to p_vaddr modulo p_align.
627 // Variant 2. Static TLS blocks, followed by alignment padding are placed
628 // before TP. The alignment padding is added so that (TP - padding -
629 // p_memsz) is congruent to p_vaddr modulo p_align.
630 PhdrEntry *tls = Out::tlsPhdr;
631 switch (config->emachine) {
635 return s.getVA(0) + config->wordsize * 2 +
636 ((tls->p_vaddr - config->wordsize * 2) & (tls->p_align - 1));
640 // Adjusted Variant 1. TP is placed with a displacement of 0x7000, which is
641 // to allow a signed 16-bit offset to reach 0x1000 of TCB/thread-library
642 // data and 0xf000 of the program's TLS segment.
643 return s.getVA(0) + (tls->p_vaddr & (tls->p_align - 1)) - 0x7000;
645 return s.getVA(0) + (tls->p_vaddr & (tls->p_align - 1));
651 return s.getVA(0) - tls->p_memsz -
652 ((-tls->p_vaddr - tls->p_memsz) & (tls->p_align - 1));
654 llvm_unreachable("unhandled Config->EMachine");
658 static uint64_t getRelocTargetVA(const InputFile *file, RelType type, int64_t a,
659 uint64_t p, const Symbol &sym, RelExpr expr) {
663 case R_RELAX_TLS_LD_TO_LE_ABS:
664 case R_RELAX_GOT_PC_NOPIC:
670 return sym.getVA(a) - getARMStaticBase(sym);
672 case R_RELAX_TLS_GD_TO_IE_ABS:
673 return sym.getGotVA() + a;
675 return in.got->getVA() + a - p;
676 case R_GOTPLTONLY_PC:
677 return in.gotPlt->getVA() + a - p;
679 case R_PPC64_RELAX_TOC:
680 return sym.getVA(a) - in.got->getVA();
682 return sym.getVA(a) - in.gotPlt->getVA();
684 case R_RELAX_TLS_GD_TO_IE_GOTPLT:
685 return sym.getGotVA() + a - in.gotPlt->getVA();
686 case R_TLSLD_GOT_OFF:
688 case R_RELAX_TLS_GD_TO_IE_GOT_OFF:
689 return sym.getGotOffset() + a;
690 case R_AARCH64_GOT_PAGE_PC:
691 case R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC:
692 return getAArch64Page(sym.getGotVA() + a) - getAArch64Page(p);
694 case R_RELAX_TLS_GD_TO_IE:
695 return sym.getGotVA() + a - p;
697 return sym.getVA(a) - in.mipsGot->getGp(file);
699 return in.mipsGot->getGp(file) + a;
700 case R_MIPS_GOT_GP_PC: {
701 // R_MIPS_LO16 expression has R_MIPS_GOT_GP_PC type iif the target
702 // is _gp_disp symbol. In that case we should use the following
703 // formula for calculation "AHL + GP - P + 4". For details see p. 4-19 at
704 // ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
705 // microMIPS variants of these relocations use slightly different
706 // expressions: AHL + GP - P + 3 for %lo() and AHL + GP - P - 1 for %hi()
707 // to correctly handle less-sugnificant bit of the microMIPS symbol.
708 uint64_t v = in.mipsGot->getGp(file) + a - p;
709 if (type == R_MIPS_LO16 || type == R_MICROMIPS_LO16)
711 if (type == R_MICROMIPS_LO16 || type == R_MICROMIPS_HI16)
715 case R_MIPS_GOT_LOCAL_PAGE:
716 // If relocation against MIPS local symbol requires GOT entry, this entry
717 // should be initialized by 'page address'. This address is high 16-bits
718 // of sum the symbol's value and the addend.
719 return in.mipsGot->getVA() + in.mipsGot->getPageEntryOffset(file, sym, a) -
720 in.mipsGot->getGp(file);
722 case R_MIPS_GOT_OFF32:
723 // In case of MIPS if a GOT relocation has non-zero addend this addend
724 // should be applied to the GOT entry content not to the GOT entry offset.
725 // That is why we use separate expression type.
726 return in.mipsGot->getVA() + in.mipsGot->getSymEntryOffset(file, sym, a) -
727 in.mipsGot->getGp(file);
729 return in.mipsGot->getVA() + in.mipsGot->getGlobalDynOffset(file, sym) -
730 in.mipsGot->getGp(file);
732 return in.mipsGot->getVA() + in.mipsGot->getTlsIndexOffset(file) -
733 in.mipsGot->getGp(file);
734 case R_AARCH64_PAGE_PC: {
735 uint64_t val = sym.isUndefWeak() ? p + a : sym.getVA(a);
736 return getAArch64Page(val) - getAArch64Page(p);
738 case R_RISCV_PC_INDIRECT: {
739 if (const Relocation *hiRel = getRISCVPCRelHi20(&sym, a))
740 return getRelocTargetVA(file, hiRel->type, hiRel->addend, sym.getVA(),
741 *hiRel->sym, hiRel->expr);
746 if (sym.isUndefWeak()) {
747 // On ARM and AArch64 a branch to an undefined weak resolves to the
748 // next instruction, otherwise the place.
749 if (config->emachine == EM_ARM)
750 dest = getARMUndefinedRelativeWeakVA(type, a, p);
751 else if (config->emachine == EM_AARCH64)
752 dest = getAArch64UndefinedRelativeWeakVA(type, a, p);
753 else if (config->emachine == EM_PPC)
763 return sym.getPltVA() + a;
765 case R_PPC64_CALL_PLT:
766 return sym.getPltVA() + a - p;
768 // R_PPC_PLTREL24 uses the addend (usually 0 or 0x8000) to indicate r30
769 // stores _GLOBAL_OFFSET_TABLE_ or .got2+0x8000. The addend is ignored for
770 // target VA computation.
771 return sym.getPltVA() - p;
773 uint64_t symVA = sym.getVA(a);
774 // If we have an undefined weak symbol, we might get here with a symbol
775 // address of zero. That could overflow, but the code must be unreachable,
776 // so don't bother doing anything at all.
780 // PPC64 V2 ABI describes two entry points to a function. The global entry
781 // point is used for calls where the caller and callee (may) have different
782 // TOC base pointers and r2 needs to be modified to hold the TOC base for
783 // the callee. For local calls the caller and callee share the same
784 // TOC base and so the TOC pointer initialization code should be skipped by
785 // branching to the local entry point.
786 return symVA - p + getPPC64GlobalEntryToLocalEntryOffset(sym.stOther);
788 case R_PPC64_TOCBASE:
789 return getPPC64TocBase() + a;
791 return sym.getVA(a) - p;
792 case R_RELAX_TLS_GD_TO_LE:
793 case R_RELAX_TLS_IE_TO_LE:
794 case R_RELAX_TLS_LD_TO_LE:
796 // It is not very clear what to return if the symbol is undefined. With
797 // --noinhibit-exec, even a non-weak undefined reference may reach here.
798 // Just return A, which matches R_ABS, and the behavior of some dynamic
800 if (sym.isUndefined())
802 return getTlsTpOffset(sym) + a;
803 case R_RELAX_TLS_GD_TO_LE_NEG:
805 if (sym.isUndefined())
807 return -getTlsTpOffset(sym) + a;
809 return sym.getSize() + a;
811 return in.got->getGlobalDynAddr(sym) + a;
813 return in.got->getGlobalDynAddr(sym) + a - p;
814 case R_AARCH64_TLSDESC_PAGE:
815 return getAArch64Page(in.got->getGlobalDynAddr(sym) + a) -
818 return in.got->getGlobalDynOffset(sym) + a;
820 return in.got->getVA() + in.got->getGlobalDynOffset(sym) + a - in.gotPlt->getVA();
822 return in.got->getGlobalDynAddr(sym) + a - p;
824 return in.got->getVA() + in.got->getTlsIndexOff() + a - in.gotPlt->getVA();
826 return in.got->getTlsIndexOff() + a;
828 return in.got->getTlsIndexVA() + a - p;
830 llvm_unreachable("invalid expression");
834 // This function applies relocations to sections without SHF_ALLOC bit.
835 // Such sections are never mapped to memory at runtime. Debug sections are
836 // an example. Relocations in non-alloc sections are much easier to
837 // handle than in allocated sections because it will never need complex
838 // treatment such as GOT or PLT (because at runtime no one refers them).
839 // So, we handle relocations for non-alloc sections directly in this
840 // function as a performance optimization.
841 template <class ELFT, class RelTy>
842 void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
843 const unsigned bits = sizeof(typename ELFT::uint) * 8;
845 for (const RelTy &rel : rels) {
846 RelType type = rel.getType(config->isMips64EL);
848 // GCC 8.0 or earlier have a bug that they emit R_386_GOTPC relocations
849 // against _GLOBAL_OFFSET_TABLE_ for .debug_info. The bug has been fixed
850 // in 2017 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630), but we
851 // need to keep this bug-compatible code for a while.
852 if (config->emachine == EM_386 && type == R_386_GOTPC)
855 uint64_t offset = getOffset(rel.r_offset);
856 uint8_t *bufLoc = buf + offset;
857 int64_t addend = getAddend<ELFT>(rel);
859 addend += target->getImplicitAddend(bufLoc, type);
861 Symbol &sym = getFile<ELFT>()->getRelocTargetSym(rel);
862 RelExpr expr = target->getRelExpr(type, sym, bufLoc);
866 if (expr != R_ABS && expr != R_DTPREL && expr != R_RISCV_ADD) {
867 std::string msg = getLocation<ELFT>(offset) +
868 ": has non-ABS relocation " + toString(type) +
869 " against symbol '" + toString(sym) + "'";
875 // If the control reaches here, we found a PC-relative relocation in a
876 // non-ALLOC section. Since non-ALLOC section is not loaded into memory
877 // at runtime, the notion of PC-relative doesn't make sense here. So,
878 // this is a usage error. However, GNU linkers historically accept such
879 // relocations without any errors and relocate them as if they were at
880 // address 0. For bug-compatibilty, we accept them with warnings. We
881 // know Steel Bank Common Lisp as of 2018 have this bug.
883 target->relocateOne(bufLoc, type,
884 SignExtend64<bits>(sym.getVA(addend - offset)));
888 if (sym.isTls() && !Out::tlsPhdr)
889 target->relocateOne(bufLoc, type, 0);
891 target->relocateOne(bufLoc, type, SignExtend64<bits>(sym.getVA(addend)));
895 // This is used when '-r' is given.
896 // For REL targets, InputSection::copyRelocations() may store artificial
897 // relocations aimed to update addends. They are handled in relocateAlloc()
898 // for allocatable sections, and this function does the same for
899 // non-allocatable sections, such as sections with debug information.
900 static void relocateNonAllocForRelocatable(InputSection *sec, uint8_t *buf) {
901 const unsigned bits = config->is64 ? 64 : 32;
903 for (const Relocation &rel : sec->relocations) {
904 // InputSection::copyRelocations() adds only R_ABS relocations.
905 assert(rel.expr == R_ABS);
906 uint8_t *bufLoc = buf + rel.offset + sec->outSecOff;
907 uint64_t targetVA = SignExtend64(rel.sym->getVA(rel.addend), bits);
908 target->relocateOne(bufLoc, rel.type, targetVA);
912 template <class ELFT>
913 void InputSectionBase::relocate(uint8_t *buf, uint8_t *bufEnd) {
914 if (flags & SHF_EXECINSTR)
915 adjustSplitStackFunctionPrologues<ELFT>(buf, bufEnd);
917 if (flags & SHF_ALLOC) {
918 relocateAlloc(buf, bufEnd);
922 auto *sec = cast<InputSection>(this);
923 if (config->relocatable)
924 relocateNonAllocForRelocatable(sec, buf);
925 else if (sec->areRelocsRela)
926 sec->relocateNonAlloc<ELFT>(buf, sec->template relas<ELFT>());
928 sec->relocateNonAlloc<ELFT>(buf, sec->template rels<ELFT>());
931 void InputSectionBase::relocateAlloc(uint8_t *buf, uint8_t *bufEnd) {
932 assert(flags & SHF_ALLOC);
933 const unsigned bits = config->wordsize * 8;
935 for (const Relocation &rel : relocations) {
936 uint64_t offset = rel.offset;
937 if (auto *sec = dyn_cast<InputSection>(this))
938 offset += sec->outSecOff;
939 uint8_t *bufLoc = buf + offset;
940 RelType type = rel.type;
942 uint64_t addrLoc = getOutputSection()->addr + offset;
943 RelExpr expr = rel.expr;
944 uint64_t targetVA = SignExtend64(
945 getRelocTargetVA(file, type, rel.addend, addrLoc, *rel.sym, expr),
950 case R_RELAX_GOT_PC_NOPIC:
951 target->relaxGot(bufLoc, type, targetVA);
953 case R_PPC64_RELAX_TOC:
954 if (!tryRelaxPPC64TocIndirection(type, rel, bufLoc))
955 target->relocateOne(bufLoc, type, targetVA);
957 case R_RELAX_TLS_IE_TO_LE:
958 target->relaxTlsIeToLe(bufLoc, type, targetVA);
960 case R_RELAX_TLS_LD_TO_LE:
961 case R_RELAX_TLS_LD_TO_LE_ABS:
962 target->relaxTlsLdToLe(bufLoc, type, targetVA);
964 case R_RELAX_TLS_GD_TO_LE:
965 case R_RELAX_TLS_GD_TO_LE_NEG:
966 target->relaxTlsGdToLe(bufLoc, type, targetVA);
968 case R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC:
969 case R_RELAX_TLS_GD_TO_IE:
970 case R_RELAX_TLS_GD_TO_IE_ABS:
971 case R_RELAX_TLS_GD_TO_IE_GOT_OFF:
972 case R_RELAX_TLS_GD_TO_IE_GOTPLT:
973 target->relaxTlsGdToIe(bufLoc, type, targetVA);
976 // If this is a call to __tls_get_addr, it may be part of a TLS
977 // sequence that has been relaxed and turned into a nop. In this
978 // case, we don't want to handle it as a call.
979 if (read32(bufLoc) == 0x60000000) // nop
982 // Patch a nop (0x60000000) to a ld.
983 if (rel.sym->needsTocRestore) {
984 // gcc/gfortran 5.4, 6.3 and earlier versions do not add nop for
985 // recursive calls even if the function is preemptible. This is not
986 // wrong in the common case where the function is not preempted at
987 // runtime. Just ignore.
988 if ((bufLoc + 8 > bufEnd || read32(bufLoc + 4) != 0x60000000) &&
989 rel.sym->file != file) {
990 // Use substr(6) to remove the "__plt_" prefix.
991 errorOrWarn(getErrorLocation(bufLoc) + "call to " +
992 lld::toString(*rel.sym).substr(6) +
993 " lacks nop, can't restore toc");
996 write32(bufLoc + 4, 0xe8410018); // ld %r2, 24(%r1)
998 target->relocateOne(bufLoc, type, targetVA);
1001 target->relocateOne(bufLoc, type, targetVA);
1007 // For each function-defining prologue, find any calls to __morestack,
1008 // and replace them with calls to __morestack_non_split.
1009 static void switchMorestackCallsToMorestackNonSplit(
1010 DenseSet<Defined *> &prologues, std::vector<Relocation *> &morestackCalls) {
1012 // If the target adjusted a function's prologue, all calls to
1013 // __morestack inside that function should be switched to
1014 // __morestack_non_split.
1015 Symbol *moreStackNonSplit = symtab->find("__morestack_non_split");
1016 if (!moreStackNonSplit) {
1017 error("Mixing split-stack objects requires a definition of "
1018 "__morestack_non_split");
1022 // Sort both collections to compare addresses efficiently.
1023 llvm::sort(morestackCalls, [](const Relocation *l, const Relocation *r) {
1024 return l->offset < r->offset;
1026 std::vector<Defined *> functions(prologues.begin(), prologues.end());
1027 llvm::sort(functions, [](const Defined *l, const Defined *r) {
1028 return l->value < r->value;
1031 auto it = morestackCalls.begin();
1032 for (Defined *f : functions) {
1033 // Find the first call to __morestack within the function.
1034 while (it != morestackCalls.end() && (*it)->offset < f->value)
1036 // Adjust all calls inside the function.
1037 while (it != morestackCalls.end() && (*it)->offset < f->value + f->size) {
1038 (*it)->sym = moreStackNonSplit;
1044 static bool enclosingPrologueAttempted(uint64_t offset,
1045 const DenseSet<Defined *> &prologues) {
1046 for (Defined *f : prologues)
1047 if (f->value <= offset && offset < f->value + f->size)
1052 // If a function compiled for split stack calls a function not
1053 // compiled for split stack, then the caller needs its prologue
1054 // adjusted to ensure that the called function will have enough stack
1055 // available. Find those functions, and adjust their prologues.
1056 template <class ELFT>
1057 void InputSectionBase::adjustSplitStackFunctionPrologues(uint8_t *buf,
1059 if (!getFile<ELFT>()->splitStack)
1061 DenseSet<Defined *> prologues;
1062 std::vector<Relocation *> morestackCalls;
1064 for (Relocation &rel : relocations) {
1065 // Local symbols can't possibly be cross-calls, and should have been
1066 // resolved long before this line.
1067 if (rel.sym->isLocal())
1070 // Ignore calls into the split-stack api.
1071 if (rel.sym->getName().startswith("__morestack")) {
1072 if (rel.sym->getName().equals("__morestack"))
1073 morestackCalls.push_back(&rel);
1077 // A relocation to non-function isn't relevant. Sometimes
1078 // __morestack is not marked as a function, so this check comes
1079 // after the name check.
1080 if (rel.sym->type != STT_FUNC)
1083 // If the callee's-file was compiled with split stack, nothing to do. In
1084 // this context, a "Defined" symbol is one "defined by the binary currently
1085 // being produced". So an "undefined" symbol might be provided by a shared
1086 // library. It is not possible to tell how such symbols were compiled, so be
1088 if (Defined *d = dyn_cast<Defined>(rel.sym))
1089 if (InputSection *isec = cast_or_null<InputSection>(d->section))
1090 if (!isec || !isec->getFile<ELFT>() || isec->getFile<ELFT>()->splitStack)
1093 if (enclosingPrologueAttempted(rel.offset, prologues))
1096 if (Defined *f = getEnclosingFunction<ELFT>(rel.offset)) {
1097 prologues.insert(f);
1098 if (target->adjustPrologueForCrossSplitStack(buf + getOffset(f->value),
1101 if (!getFile<ELFT>()->someNoSplitStack)
1102 error(toString(this) + ": " + f->getName() +
1103 " (with -fsplit-stack) calls " + rel.sym->getName() +
1104 " (without -fsplit-stack), but couldn't adjust its prologue");
1108 if (target->needsMoreStackNonSplit)
1109 switchMorestackCallsToMorestackNonSplit(prologues, morestackCalls);
1112 template <class ELFT> void InputSection::writeTo(uint8_t *buf) {
1113 if (type == SHT_NOBITS)
1116 if (auto *s = dyn_cast<SyntheticSection>(this)) {
1117 s->writeTo(buf + outSecOff);
1121 // If -r or --emit-relocs is given, then an InputSection
1122 // may be a relocation section.
1123 if (type == SHT_RELA) {
1124 copyRelocations<ELFT>(buf + outSecOff, getDataAs<typename ELFT::Rela>());
1127 if (type == SHT_REL) {
1128 copyRelocations<ELFT>(buf + outSecOff, getDataAs<typename ELFT::Rel>());
1132 // If -r is given, we may have a SHT_GROUP section.
1133 if (type == SHT_GROUP) {
1134 copyShtGroup<ELFT>(buf + outSecOff);
1138 // If this is a compressed section, uncompress section contents directly
1140 if (uncompressedSize >= 0) {
1141 size_t size = uncompressedSize;
1142 if (Error e = zlib::uncompress(toStringRef(rawData),
1143 (char *)(buf + outSecOff), size))
1144 fatal(toString(this) +
1145 ": uncompress failed: " + llvm::toString(std::move(e)));
1146 uint8_t *bufEnd = buf + outSecOff + size;
1147 relocate<ELFT>(buf, bufEnd);
1151 // Copy section contents from source object file to output file
1152 // and then apply relocations.
1153 memcpy(buf + outSecOff, data().data(), data().size());
1154 uint8_t *bufEnd = buf + outSecOff + data().size();
1155 relocate<ELFT>(buf, bufEnd);
1158 void InputSection::replace(InputSection *other) {
1159 alignment = std::max(alignment, other->alignment);
1161 // When a section is replaced with another section that was allocated to
1162 // another partition, the replacement section (and its associated sections)
1163 // need to be placed in the main partition so that both partitions will be
1164 // able to access it.
1165 if (partition != other->partition) {
1167 for (InputSection *isec : dependentSections)
1168 isec->partition = 1;
1175 template <class ELFT>
1176 EhInputSection::EhInputSection(ObjFile<ELFT> &f,
1177 const typename ELFT::Shdr &header,
1179 : InputSectionBase(f, header, name, InputSectionBase::EHFrame) {}
1181 SyntheticSection *EhInputSection::getParent() const {
1182 return cast_or_null<SyntheticSection>(parent);
1185 // Returns the index of the first relocation that points to a region between
1186 // Begin and Begin+Size.
1187 template <class IntTy, class RelTy>
1188 static unsigned getReloc(IntTy begin, IntTy size, const ArrayRef<RelTy> &rels,
1190 // Start search from RelocI for fast access. That works because the
1191 // relocations are sorted in .eh_frame.
1192 for (unsigned n = rels.size(); relocI < n; ++relocI) {
1193 const RelTy &rel = rels[relocI];
1194 if (rel.r_offset < begin)
1197 if (rel.r_offset < begin + size)
1204 // .eh_frame is a sequence of CIE or FDE records.
1205 // This function splits an input section into records and returns them.
1206 template <class ELFT> void EhInputSection::split() {
1208 split<ELFT>(relas<ELFT>());
1210 split<ELFT>(rels<ELFT>());
1213 template <class ELFT, class RelTy>
1214 void EhInputSection::split(ArrayRef<RelTy> rels) {
1216 for (size_t off = 0, end = data().size(); off != end;) {
1217 size_t size = readEhRecordSize(this, off);
1218 pieces.emplace_back(off, this, size, getReloc(off, size, rels, relI));
1219 // The empty record is the end marker.
1226 static size_t findNull(StringRef s, size_t entSize) {
1227 // Optimize the common case.
1231 for (unsigned i = 0, n = s.size(); i != n; i += entSize) {
1232 const char *b = s.begin() + i;
1233 if (std::all_of(b, b + entSize, [](char c) { return c == 0; }))
1236 return StringRef::npos;
1239 SyntheticSection *MergeInputSection::getParent() const {
1240 return cast_or_null<SyntheticSection>(parent);
1243 // Split SHF_STRINGS section. Such section is a sequence of
1244 // null-terminated strings.
1245 void MergeInputSection::splitStrings(ArrayRef<uint8_t> data, size_t entSize) {
1247 bool isAlloc = flags & SHF_ALLOC;
1248 StringRef s = toStringRef(data);
1250 while (!s.empty()) {
1251 size_t end = findNull(s, entSize);
1252 if (end == StringRef::npos)
1253 fatal(toString(this) + ": string is not null terminated");
1254 size_t size = end + entSize;
1256 pieces.emplace_back(off, xxHash64(s.substr(0, size)), !isAlloc);
1262 // Split non-SHF_STRINGS section. Such section is a sequence of
1263 // fixed size records.
1264 void MergeInputSection::splitNonStrings(ArrayRef<uint8_t> data,
1266 size_t size = data.size();
1267 assert((size % entSize) == 0);
1268 bool isAlloc = flags & SHF_ALLOC;
1270 for (size_t i = 0; i != size; i += entSize)
1271 pieces.emplace_back(i, xxHash64(data.slice(i, entSize)), !isAlloc);
1274 template <class ELFT>
1275 MergeInputSection::MergeInputSection(ObjFile<ELFT> &f,
1276 const typename ELFT::Shdr &header,
1278 : InputSectionBase(f, header, name, InputSectionBase::Merge) {}
1280 MergeInputSection::MergeInputSection(uint64_t flags, uint32_t type,
1281 uint64_t entsize, ArrayRef<uint8_t> data,
1283 : InputSectionBase(nullptr, flags, type, entsize, /*Link*/ 0, /*Info*/ 0,
1284 /*Alignment*/ entsize, data, name, SectionBase::Merge) {}
1286 // This function is called after we obtain a complete list of input sections
1287 // that need to be linked. This is responsible to split section contents
1288 // into small chunks for further processing.
1290 // Note that this function is called from parallelForEach. This must be
1291 // thread-safe (i.e. no memory allocation from the pools).
1292 void MergeInputSection::splitIntoPieces() {
1293 assert(pieces.empty());
1295 if (flags & SHF_STRINGS)
1296 splitStrings(data(), entsize);
1298 splitNonStrings(data(), entsize);
1301 SectionPiece *MergeInputSection::getSectionPiece(uint64_t offset) {
1302 if (this->data().size() <= offset)
1303 fatal(toString(this) + ": offset is outside the section");
1305 // If Offset is not at beginning of a section piece, it is not in the map.
1306 // In that case we need to do a binary search of the original section piece vector.
1307 auto it = partition_point(
1308 pieces, [=](SectionPiece p) { return p.inputOff <= offset; });
1312 // Returns the offset in an output section for a given input offset.
1313 // Because contents of a mergeable section is not contiguous in output,
1314 // it is not just an addition to a base output offset.
1315 uint64_t MergeInputSection::getParentOffset(uint64_t offset) const {
1316 // If Offset is not at beginning of a section piece, it is not in the map.
1317 // In that case we need to search from the original section piece vector.
1318 const SectionPiece &piece =
1319 *(const_cast<MergeInputSection *>(this)->getSectionPiece (offset));
1320 uint64_t addend = offset - piece.inputOff;
1321 return piece.outputOff + addend;
1324 template InputSection::InputSection(ObjFile<ELF32LE> &, const ELF32LE::Shdr &,
1326 template InputSection::InputSection(ObjFile<ELF32BE> &, const ELF32BE::Shdr &,
1328 template InputSection::InputSection(ObjFile<ELF64LE> &, const ELF64LE::Shdr &,
1330 template InputSection::InputSection(ObjFile<ELF64BE> &, const ELF64BE::Shdr &,
1333 template std::string InputSectionBase::getLocation<ELF32LE>(uint64_t);
1334 template std::string InputSectionBase::getLocation<ELF32BE>(uint64_t);
1335 template std::string InputSectionBase::getLocation<ELF64LE>(uint64_t);
1336 template std::string InputSectionBase::getLocation<ELF64BE>(uint64_t);
1338 template void InputSection::writeTo<ELF32LE>(uint8_t *);
1339 template void InputSection::writeTo<ELF32BE>(uint8_t *);
1340 template void InputSection::writeTo<ELF64LE>(uint8_t *);
1341 template void InputSection::writeTo<ELF64BE>(uint8_t *);
1343 template MergeInputSection::MergeInputSection(ObjFile<ELF32LE> &,
1344 const ELF32LE::Shdr &, StringRef);
1345 template MergeInputSection::MergeInputSection(ObjFile<ELF32BE> &,
1346 const ELF32BE::Shdr &, StringRef);
1347 template MergeInputSection::MergeInputSection(ObjFile<ELF64LE> &,
1348 const ELF64LE::Shdr &, StringRef);
1349 template MergeInputSection::MergeInputSection(ObjFile<ELF64BE> &,
1350 const ELF64BE::Shdr &, StringRef);
1352 template EhInputSection::EhInputSection(ObjFile<ELF32LE> &,
1353 const ELF32LE::Shdr &, StringRef);
1354 template EhInputSection::EhInputSection(ObjFile<ELF32BE> &,
1355 const ELF32BE::Shdr &, StringRef);
1356 template EhInputSection::EhInputSection(ObjFile<ELF64LE> &,
1357 const ELF64LE::Shdr &, StringRef);
1358 template EhInputSection::EhInputSection(ObjFile<ELF64BE> &,
1359 const ELF64BE::Shdr &, StringRef);
1361 template void EhInputSection::split<ELF32LE>();
1362 template void EhInputSection::split<ELF32BE>();
1363 template void EhInputSection::split<ELF64LE>();
1364 template void EhInputSection::split<ELF64BE>();