1 //===- OutputSections.cpp -------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "OutputSections.h"
10 #include "Config.h"
11 #include "LinkerScript.h"
12 #include "SymbolTable.h"
13 #include "SyntheticSections.h"
14 #include "Target.h"
15 #include "lld/Common/Memory.h"
16 #include "lld/Common/Strings.h"
17 #include "llvm/BinaryFormat/Dwarf.h"
18 #include "llvm/Support/Compression.h"
19 #include "llvm/Support/MD5.h"
20 #include "llvm/Support/MathExtras.h"
21 #include "llvm/Support/Parallel.h"
22 #include "llvm/Support/SHA1.h"
23 #include "llvm/Support/TimeProfiler.h"
24 #include <regex>
25 #include <unordered_set>
26 
27 using namespace llvm;
28 using namespace llvm::dwarf;
29 using namespace llvm::object;
30 using namespace llvm::support::endian;
31 using namespace llvm::ELF;
32 using namespace lld;
33 using namespace lld::elf;
34 
35 uint8_t *Out::bufferStart;
36 PhdrEntry *Out::tlsPhdr;
37 OutputSection *Out::elfHeader;
38 OutputSection *Out::programHeaders;
39 OutputSection *Out::preinitArray;
40 OutputSection *Out::initArray;
41 OutputSection *Out::finiArray;
42 
43 std::vector<OutputSection *> elf::outputSections;
44 
45 uint32_t OutputSection::getPhdrFlags() const {
46   uint32_t ret = 0;
47   if (config->emachine != EM_ARM || !(flags & SHF_ARM_PURECODE))
48     ret |= PF_R;
49   if (flags & SHF_WRITE)
50     ret |= PF_W;
51   if (flags & SHF_EXECINSTR)
52     ret |= PF_X;
53   return ret;
54 }
55 
56 template <class ELFT>
57 void OutputSection::writeHeaderTo(typename ELFT::Shdr *shdr) {
58   shdr->sh_entsize = entsize;
59   shdr->sh_addralign = alignment;
60   shdr->sh_type = type;
61   shdr->sh_offset = offset;
62   shdr->sh_flags = flags;
63   shdr->sh_info = info;
64   shdr->sh_link = link;
65   shdr->sh_addr = addr;
66   shdr->sh_size = size;
67   shdr->sh_name = shName;
68 }
69 
70 OutputSection::OutputSection(StringRef name, uint32_t type, uint64_t flags)
71     : SectionCommand(OutputSectionKind),
72       SectionBase(Output, name, flags, /*Entsize*/ 0, /*Alignment*/ 1, type,
73                   /*Info*/ 0, /*Link*/ 0) {}
74 
75 // We allow sections of types listed below to merged into a
76 // single progbits section. This is typically done by linker
77 // scripts. Merging nobits and progbits will force disk space
78 // to be allocated for nobits sections. Other ones don't require
79 // any special treatment on top of progbits, so there doesn't
80 // seem to be a harm in merging them.
81 //
82 // NOTE: clang since rL252300 emits SHT_X86_64_UNWIND .eh_frame sections. Allow
83 // them to be merged into SHT_PROGBITS .eh_frame (GNU as .cfi_*).
84 static bool canMergeToProgbits(unsigned type) {
85   return type == SHT_NOBITS || type == SHT_PROGBITS || type == SHT_INIT_ARRAY ||
86          type == SHT_PREINIT_ARRAY || type == SHT_FINI_ARRAY ||
87          type == SHT_NOTE ||
88          (type == SHT_X86_64_UNWIND && config->emachine == EM_X86_64);
89 }
90 
91 // Record that isec will be placed in the OutputSection. isec does not become
92 // permanent until finalizeInputSections() is called. The function should not be
93 // used after finalizeInputSections() is called. If you need to add an
94 // InputSection post finalizeInputSections(), then you must do the following:
95 //
96 // 1. Find or create an InputSectionDescription to hold InputSection.
97 // 2. Add the InputSection to the InputSectionDescription::sections.
98 // 3. Call commitSection(isec).
99 void OutputSection::recordSection(InputSectionBase *isec) {
100   partition = isec->partition;
101   isec->parent = this;
102   if (commands.empty() || !isa<InputSectionDescription>(commands.back()))
103     commands.push_back(make<InputSectionDescription>(""));
104   auto *isd = cast<InputSectionDescription>(commands.back());
105   isd->sectionBases.push_back(isec);
106 }
107 
108 // Update fields (type, flags, alignment, etc) according to the InputSection
109 // isec. Also check whether the InputSection flags and type are consistent with
110 // other InputSections.
111 void OutputSection::commitSection(InputSection *isec) {
112   if (!hasInputSections) {
113     // If IS is the first section to be added to this section,
114     // initialize type, entsize and flags from isec.
115     hasInputSections = true;
116     type = isec->type;
117     entsize = isec->entsize;
118     flags = isec->flags;
119   } else {
120     // Otherwise, check if new type or flags are compatible with existing ones.
121     if ((flags ^ isec->flags) & SHF_TLS)
122       error("incompatible section flags for " + name + "\n>>> " + toString(isec) +
123             ": 0x" + utohexstr(isec->flags) + "\n>>> output section " + name +
124             ": 0x" + utohexstr(flags));
125 
126     if (type != isec->type) {
127       if (!canMergeToProgbits(type) || !canMergeToProgbits(isec->type))
128         error("section type mismatch for " + isec->name + "\n>>> " +
129               toString(isec) + ": " +
130               getELFSectionTypeName(config->emachine, isec->type) +
131               "\n>>> output section " + name + ": " +
132               getELFSectionTypeName(config->emachine, type));
133       type = SHT_PROGBITS;
134     }
135   }
136   if (noload)
137     type = SHT_NOBITS;
138 
139   isec->parent = this;
140   uint64_t andMask =
141       config->emachine == EM_ARM ? (uint64_t)SHF_ARM_PURECODE : 0;
142   uint64_t orMask = ~andMask;
143   uint64_t andFlags = (flags & isec->flags) & andMask;
144   uint64_t orFlags = (flags | isec->flags) & orMask;
145   flags = andFlags | orFlags;
146   if (nonAlloc)
147     flags &= ~(uint64_t)SHF_ALLOC;
148 
149   alignment = std::max(alignment, isec->alignment);
150 
151   // If this section contains a table of fixed-size entries, sh_entsize
152   // holds the element size. If it contains elements of different size we
153   // set sh_entsize to 0.
154   if (entsize != isec->entsize)
155     entsize = 0;
156 }
157 
158 static MergeSyntheticSection *createMergeSynthetic(StringRef name,
159                                                    uint32_t type,
160                                                    uint64_t flags,
161                                                    uint32_t alignment) {
162   if ((flags & SHF_STRINGS) && config->optimize >= 2)
163     return make<MergeTailSection>(name, type, flags, alignment);
164   return make<MergeNoTailSection>(name, type, flags, alignment);
165 }
166 
167 // This function scans over the InputSectionBase list sectionBases to create
168 // InputSectionDescription::sections.
169 //
170 // It removes MergeInputSections from the input section array and adds
171 // new synthetic sections at the location of the first input section
172 // that it replaces. It then finalizes each synthetic section in order
173 // to compute an output offset for each piece of each input section.
174 void OutputSection::finalizeInputSections() {
175   std::vector<MergeSyntheticSection *> mergeSections;
176   for (SectionCommand *cmd : commands) {
177     auto *isd = dyn_cast<InputSectionDescription>(cmd);
178     if (!isd)
179       continue;
180     isd->sections.reserve(isd->sectionBases.size());
181     for (InputSectionBase *s : isd->sectionBases) {
182       MergeInputSection *ms = dyn_cast<MergeInputSection>(s);
183       if (!ms) {
184         isd->sections.push_back(cast<InputSection>(s));
185         continue;
186       }
187 
188       // We do not want to handle sections that are not alive, so just remove
189       // them instead of trying to merge.
190       if (!ms->isLive())
191         continue;
192 
193       auto i = llvm::find_if(mergeSections, [=](MergeSyntheticSection *sec) {
194         // While we could create a single synthetic section for two different
195         // values of Entsize, it is better to take Entsize into consideration.
196         //
197         // With a single synthetic section no two pieces with different Entsize
198         // could be equal, so we may as well have two sections.
199         //
200         // Using Entsize in here also allows us to propagate it to the synthetic
201         // section.
202         //
203         // SHF_STRINGS section with different alignments should not be merged.
204         return sec->flags == ms->flags && sec->entsize == ms->entsize &&
205                (sec->alignment == ms->alignment || !(sec->flags & SHF_STRINGS));
206       });
207       if (i == mergeSections.end()) {
208         MergeSyntheticSection *syn =
209             createMergeSynthetic(name, ms->type, ms->flags, ms->alignment);
210         mergeSections.push_back(syn);
211         i = std::prev(mergeSections.end());
212         syn->entsize = ms->entsize;
213         isd->sections.push_back(syn);
214       }
215       (*i)->addSection(ms);
216     }
217 
218     // sectionBases should not be used from this point onwards. Clear it to
219     // catch misuses.
220     isd->sectionBases.clear();
221 
222     // Some input sections may be removed from the list after ICF.
223     for (InputSection *s : isd->sections)
224       commitSection(s);
225   }
226   for (auto *ms : mergeSections)
227     ms->finalizeContents();
228 }
229 
230 static void sortByOrder(MutableArrayRef<InputSection *> in,
231                         llvm::function_ref<int(InputSectionBase *s)> order) {
232   std::vector<std::pair<int, InputSection *>> v;
233   for (InputSection *s : in)
234     v.push_back({order(s), s});
235   llvm::stable_sort(v, less_first());
236 
237   for (size_t i = 0; i < v.size(); ++i)
238     in[i] = v[i].second;
239 }
240 
241 uint64_t elf::getHeaderSize() {
242   if (config->oFormatBinary)
243     return 0;
244   return Out::elfHeader->size + Out::programHeaders->size;
245 }
246 
247 bool OutputSection::classof(const SectionCommand *c) {
248   return c->kind == OutputSectionKind;
249 }
250 
251 void OutputSection::sort(llvm::function_ref<int(InputSectionBase *s)> order) {
252   assert(isLive());
253   for (SectionCommand *b : commands)
254     if (auto *isd = dyn_cast<InputSectionDescription>(b))
255       sortByOrder(isd->sections, order);
256 }
257 
258 static void nopInstrFill(uint8_t *buf, size_t size) {
259   if (size == 0)
260     return;
261   unsigned i = 0;
262   if (size == 0)
263     return;
264   std::vector<std::vector<uint8_t>> nopFiller = *target->nopInstrs;
265   unsigned num = size / nopFiller.back().size();
266   for (unsigned c = 0; c < num; ++c) {
267     memcpy(buf + i, nopFiller.back().data(), nopFiller.back().size());
268     i += nopFiller.back().size();
269   }
270   unsigned remaining = size - i;
271   if (!remaining)
272     return;
273   assert(nopFiller[remaining - 1].size() == remaining);
274   memcpy(buf + i, nopFiller[remaining - 1].data(), remaining);
275 }
276 
277 // Fill [Buf, Buf + Size) with Filler.
278 // This is used for linker script "=fillexp" command.
279 static void fill(uint8_t *buf, size_t size,
280                  const std::array<uint8_t, 4> &filler) {
281   size_t i = 0;
282   for (; i + 4 < size; i += 4)
283     memcpy(buf + i, filler.data(), 4);
284   memcpy(buf + i, filler.data(), size - i);
285 }
286 
287 // Compress section contents if this section contains debug info.
288 template <class ELFT> void OutputSection::maybeCompress() {
289   using Elf_Chdr = typename ELFT::Chdr;
290 
291   // Compress only DWARF debug sections.
292   if (!config->compressDebugSections || (flags & SHF_ALLOC) ||
293       !name.startswith(".debug_"))
294     return;
295 
296   llvm::TimeTraceScope timeScope("Compress debug sections");
297 
298   // Create a section header.
299   zDebugHeader.resize(sizeof(Elf_Chdr));
300   auto *hdr = reinterpret_cast<Elf_Chdr *>(zDebugHeader.data());
301   hdr->ch_type = ELFCOMPRESS_ZLIB;
302   hdr->ch_size = size;
303   hdr->ch_addralign = alignment;
304 
305   // Write section contents to a temporary buffer and compress it.
306   std::vector<uint8_t> buf(size);
307   writeTo<ELFT>(buf.data());
308   // We chose 1 as the default compression level because it is the fastest. If
309   // -O2 is given, we use level 6 to compress debug info more by ~15%. We found
310   // that level 7 to 9 doesn't make much difference (~1% more compression) while
311   // they take significant amount of time (~2x), so level 6 seems enough.
312   if (Error e = zlib::compress(toStringRef(buf), compressedData,
313                                config->optimize >= 2 ? 6 : 1))
314     fatal("compress failed: " + llvm::toString(std::move(e)));
315 
316   // Update section headers.
317   size = sizeof(Elf_Chdr) + compressedData.size();
318   flags |= SHF_COMPRESSED;
319 }
320 
321 static void writeInt(uint8_t *buf, uint64_t data, uint64_t size) {
322   if (size == 1)
323     *buf = data;
324   else if (size == 2)
325     write16(buf, data);
326   else if (size == 4)
327     write32(buf, data);
328   else if (size == 8)
329     write64(buf, data);
330   else
331     llvm_unreachable("unsupported Size argument");
332 }
333 
334 template <class ELFT> void OutputSection::writeTo(uint8_t *buf) {
335   if (type == SHT_NOBITS)
336     return;
337 
338   // If --compress-debug-section is specified and if this is a debug section,
339   // we've already compressed section contents. If that's the case,
340   // just write it down.
341   if (!compressedData.empty()) {
342     memcpy(buf, zDebugHeader.data(), zDebugHeader.size());
343     memcpy(buf + zDebugHeader.size(), compressedData.data(),
344            compressedData.size());
345     return;
346   }
347 
348   // Write leading padding.
349   std::vector<InputSection *> sections = getInputSections(this);
350   std::array<uint8_t, 4> filler = getFiller();
351   bool nonZeroFiller = read32(filler.data()) != 0;
352   if (nonZeroFiller)
353     fill(buf, sections.empty() ? size : sections[0]->outSecOff, filler);
354 
355   parallelForEachN(0, sections.size(), [&](size_t i) {
356     InputSection *isec = sections[i];
357     isec->writeTo<ELFT>(buf);
358 
359     // Fill gaps between sections.
360     if (nonZeroFiller) {
361       uint8_t *start = buf + isec->outSecOff + isec->getSize();
362       uint8_t *end;
363       if (i + 1 == sections.size())
364         end = buf + size;
365       else
366         end = buf + sections[i + 1]->outSecOff;
367       if (isec->nopFiller) {
368         assert(target->nopInstrs);
369         nopInstrFill(start, end - start);
370       } else
371         fill(start, end - start, filler);
372     }
373   });
374 
375   // Linker scripts may have BYTE()-family commands with which you
376   // can write arbitrary bytes to the output. Process them if any.
377   for (SectionCommand *cmd : commands)
378     if (auto *data = dyn_cast<ByteCommand>(cmd))
379       writeInt(buf + data->offset, data->expression().getValue(), data->size);
380 }
381 
382 static void finalizeShtGroup(OutputSection *os,
383                              InputSection *section) {
384   assert(config->relocatable);
385 
386   // sh_link field for SHT_GROUP sections should contain the section index of
387   // the symbol table.
388   os->link = in.symTab->getParent()->sectionIndex;
389 
390   // sh_info then contain index of an entry in symbol table section which
391   // provides signature of the section group.
392   ArrayRef<Symbol *> symbols = section->file->getSymbols();
393   os->info = in.symTab->getSymbolIndex(symbols[section->info]);
394 
395   // Some group members may be combined or discarded, so we need to compute the
396   // new size. The content will be rewritten in InputSection::copyShtGroup.
397   std::unordered_set<uint32_t> seen;
398   ArrayRef<InputSectionBase *> sections = section->file->getSections();
399   for (const uint32_t &idx : section->getDataAs<uint32_t>().slice(1))
400     if (OutputSection *osec = sections[read32(&idx)]->getOutputSection())
401       seen.insert(osec->sectionIndex);
402   os->size = (1 + seen.size()) * sizeof(uint32_t);
403 }
404 
405 void OutputSection::finalize() {
406   InputSection *first = getFirstInputSection(this);
407 
408   if (flags & SHF_LINK_ORDER) {
409     // We must preserve the link order dependency of sections with the
410     // SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We
411     // need to translate the InputSection sh_link to the OutputSection sh_link,
412     // all InputSections in the OutputSection have the same dependency.
413     if (auto *ex = dyn_cast<ARMExidxSyntheticSection>(first))
414       link = ex->getLinkOrderDep()->getParent()->sectionIndex;
415     else if (first->flags & SHF_LINK_ORDER)
416       if (auto *d = first->getLinkOrderDep())
417         link = d->getParent()->sectionIndex;
418   }
419 
420   if (type == SHT_GROUP) {
421     finalizeShtGroup(this, first);
422     return;
423   }
424 
425   if (!config->copyRelocs || (type != SHT_RELA && type != SHT_REL))
426     return;
427 
428   // Skip if 'first' is synthetic, i.e. not a section created by --emit-relocs.
429   // Normally 'type' was changed by 'first' so 'first' should be non-null.
430   // However, if the output section is .rela.dyn, 'type' can be set by the empty
431   // synthetic .rela.plt and first can be null.
432   if (!first || isa<SyntheticSection>(first))
433     return;
434 
435   link = in.symTab->getParent()->sectionIndex;
436   // sh_info for SHT_REL[A] sections should contain the section header index of
437   // the section to which the relocation applies.
438   InputSectionBase *s = first->getRelocatedSection();
439   info = s->getOutputSection()->sectionIndex;
440   flags |= SHF_INFO_LINK;
441 }
442 
443 // Returns true if S is in one of the many forms the compiler driver may pass
444 // crtbegin files.
445 //
446 // Gcc uses any of crtbegin[<empty>|S|T].o.
447 // Clang uses Gcc's plus clang_rt.crtbegin[<empty>|S|T][-<arch>|<empty>].o.
448 
449 static bool isCrtbegin(StringRef s) {
450   static std::regex re(R"((clang_rt\.)?crtbegin[ST]?(-.*)?\.o)");
451   s = sys::path::filename(s);
452   return std::regex_match(s.begin(), s.end(), re);
453 }
454 
455 static bool isCrtend(StringRef s) {
456   static std::regex re(R"((clang_rt\.)?crtend[ST]?(-.*)?\.o)");
457   s = sys::path::filename(s);
458   return std::regex_match(s.begin(), s.end(), re);
459 }
460 
461 // .ctors and .dtors are sorted by this order:
462 //
463 // 1. .ctors/.dtors in crtbegin (which contains a sentinel value -1).
464 // 2. The section is named ".ctors" or ".dtors" (priority: 65536).
465 // 3. The section has an optional priority value in the form of ".ctors.N" or
466 //    ".dtors.N" where N is a number in the form of %05u (priority: 65535-N).
467 // 4. .ctors/.dtors in crtend (which contains a sentinel value 0).
468 //
469 // For 2 and 3, the sections are sorted by priority from high to low, e.g.
470 // .ctors (65536), .ctors.00100 (65436), .ctors.00200 (65336).  In GNU ld's
471 // internal linker scripts, the sorting is by string comparison which can
472 // achieve the same goal given the optional priority values are of the same
473 // length.
474 //
475 // In an ideal world, we don't need this function because .init_array and
476 // .ctors are duplicate features (and .init_array is newer.) However, there
477 // are too many real-world use cases of .ctors, so we had no choice to
478 // support that with this rather ad-hoc semantics.
479 static bool compCtors(const InputSection *a, const InputSection *b) {
480   bool beginA = isCrtbegin(a->file->getName());
481   bool beginB = isCrtbegin(b->file->getName());
482   if (beginA != beginB)
483     return beginA;
484   bool endA = isCrtend(a->file->getName());
485   bool endB = isCrtend(b->file->getName());
486   if (endA != endB)
487     return endB;
488   return getPriority(a->name) > getPriority(b->name);
489 }
490 
491 // Sorts input sections by the special rules for .ctors and .dtors.
492 // Unfortunately, the rules are different from the one for .{init,fini}_array.
493 // Read the comment above.
494 void OutputSection::sortCtorsDtors() {
495   assert(commands.size() == 1);
496   auto *isd = cast<InputSectionDescription>(commands[0]);
497   llvm::stable_sort(isd->sections, compCtors);
498 }
499 
500 // If an input string is in the form of "foo.N" where N is a number, return N
501 // (65535-N if .ctors.N or .dtors.N). Otherwise, returns 65536, which is one
502 // greater than the lowest priority.
503 int elf::getPriority(StringRef s) {
504   size_t pos = s.rfind('.');
505   if (pos == StringRef::npos)
506     return 65536;
507   int v = 65536;
508   if (to_integer(s.substr(pos + 1), v, 10) &&
509       (pos == 6 && (s.startswith(".ctors") || s.startswith(".dtors"))))
510     v = 65535 - v;
511   return v;
512 }
513 
514 InputSection *elf::getFirstInputSection(const OutputSection *os) {
515   for (SectionCommand *cmd : os->commands)
516     if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
517       if (!isd->sections.empty())
518         return isd->sections[0];
519   return nullptr;
520 }
521 
522 std::vector<InputSection *> elf::getInputSections(const OutputSection *os) {
523   std::vector<InputSection *> ret;
524   for (SectionCommand *cmd : os->commands)
525     if (auto *isd = dyn_cast<InputSectionDescription>(cmd))
526       ret.insert(ret.end(), isd->sections.begin(), isd->sections.end());
527   return ret;
528 }
529 
530 // Sorts input sections by section name suffixes, so that .foo.N comes
531 // before .foo.M if N < M. Used to sort .{init,fini}_array.N sections.
532 // We want to keep the original order if the priorities are the same
533 // because the compiler keeps the original initialization order in a
534 // translation unit and we need to respect that.
535 // For more detail, read the section of the GCC's manual about init_priority.
536 void OutputSection::sortInitFini() {
537   // Sort sections by priority.
538   sort([](InputSectionBase *s) { return getPriority(s->name); });
539 }
540 
541 std::array<uint8_t, 4> OutputSection::getFiller() {
542   if (filler)
543     return *filler;
544   if (flags & SHF_EXECINSTR)
545     return target->trapInstr;
546   return {0, 0, 0, 0};
547 }
548 
549 void OutputSection::checkDynRelAddends(const uint8_t *bufStart) {
550   assert(config->writeAddends && config->checkDynamicRelocs);
551   assert(type == SHT_REL || type == SHT_RELA);
552   std::vector<InputSection *> sections = getInputSections(this);
553   parallelForEachN(0, sections.size(), [&](size_t i) {
554     // When linking with -r or --emit-relocs we might also call this function
555     // for input .rel[a].<sec> sections which we simply pass through to the
556     // output. We skip over those and only look at the synthetic relocation
557     // sections created during linking.
558     const auto *sec = dyn_cast<RelocationBaseSection>(sections[i]);
559     if (!sec)
560       return;
561     for (const DynamicReloc &rel : sec->relocs) {
562       int64_t addend = rel.computeAddend();
563       const OutputSection *relOsec = rel.inputSec->getOutputSection();
564       assert(relOsec != nullptr && "missing output section for relocation");
565       const uint8_t *relocTarget =
566           bufStart + relOsec->offset + rel.inputSec->getOffset(rel.offsetInSec);
567       // For SHT_NOBITS the written addend is always zero.
568       int64_t writtenAddend =
569           relOsec->type == SHT_NOBITS
570               ? 0
571               : target->getImplicitAddend(relocTarget, rel.type);
572       if (addend != writtenAddend)
573         internalLinkerError(
574             getErrorLocation(relocTarget),
575             "wrote incorrect addend value 0x" + utohexstr(writtenAddend) +
576                 " instead of 0x" + utohexstr(addend) +
577                 " for dynamic relocation " + toString(rel.type) +
578                 " at offset 0x" + utohexstr(rel.getOffset()) +
579                 (rel.sym ? " against symbol " + toString(*rel.sym) : ""));
580     }
581   });
582 }
583 
584 template void OutputSection::writeHeaderTo<ELF32LE>(ELF32LE::Shdr *Shdr);
585 template void OutputSection::writeHeaderTo<ELF32BE>(ELF32BE::Shdr *Shdr);
586 template void OutputSection::writeHeaderTo<ELF64LE>(ELF64LE::Shdr *Shdr);
587 template void OutputSection::writeHeaderTo<ELF64BE>(ELF64BE::Shdr *Shdr);
588 
589 template void OutputSection::writeTo<ELF32LE>(uint8_t *Buf);
590 template void OutputSection::writeTo<ELF32BE>(uint8_t *Buf);
591 template void OutputSection::writeTo<ELF64LE>(uint8_t *Buf);
592 template void OutputSection::writeTo<ELF64BE>(uint8_t *Buf);
593 
594 template void OutputSection::maybeCompress<ELF32LE>();
595 template void OutputSection::maybeCompress<ELF32BE>();
596 template void OutputSection::maybeCompress<ELF64LE>();
597 template void OutputSection::maybeCompress<ELF64BE>();
598