1 //===- 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"
12 #include "LinkerScript.h"
13 #include "Memory.h"
14 #include "Strings.h"
15 #include "SymbolTable.h"
16 #include "SyntheticSections.h"
17 #include "Target.h"
18 #include "lld/Common/Threads.h"
19 #include "llvm/BinaryFormat/Dwarf.h"
20 #include "llvm/Support/Compression.h"
21 #include "llvm/Support/MD5.h"
22 #include "llvm/Support/MathExtras.h"
23 #include "llvm/Support/SHA1.h"
24 
25 using namespace llvm;
26 using namespace llvm::dwarf;
27 using namespace llvm::object;
28 using namespace llvm::support::endian;
29 using namespace llvm::ELF;
30 
31 using namespace lld;
32 using namespace lld::elf;
33 
34 uint8_t Out::First;
35 OutputSection *Out::Opd;
36 uint8_t *Out::OpdBuf;
37 PhdrEntry *Out::TlsPhdr;
38 OutputSection *Out::DebugInfo;
39 OutputSection *Out::ElfHeader;
40 OutputSection *Out::ProgramHeaders;
41 OutputSection *Out::PreinitArray;
42 OutputSection *Out::InitArray;
43 OutputSection *Out::FiniArray;
44 
45 std::vector<OutputSection *> elf::OutputSections;
46 
47 uint32_t OutputSection::getPhdrFlags() const {
48   uint32_t 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     : BaseCommand(OutputSectionKind),
72       SectionBase(Output, Name, Flags, /*Entsize*/ 0, /*Alignment*/ 1, Type,
73                   /*Info*/ 0,
74                   /*Link*/ 0),
75       SectionIndex(INT_MAX) {
76   Live = false;
77 }
78 
79 // We allow sections of types listed below to merged into a
80 // single progbits section. This is typically done by linker
81 // scripts. Merging nobits and progbits will force disk space
82 // to be allocated for nobits sections. Other ones don't require
83 // any special treatment on top of progbits, so there doesn't
84 // seem to be a harm in merging them.
85 static bool canMergeToProgbits(unsigned Type) {
86   return Type == SHT_NOBITS || Type == SHT_PROGBITS || Type == SHT_INIT_ARRAY ||
87          Type == SHT_PREINIT_ARRAY || Type == SHT_FINI_ARRAY ||
88          Type == SHT_NOTE;
89 }
90 
91 void OutputSection::addSection(InputSection *IS) {
92   if (!IS->Live) {
93     reportDiscarded(IS);
94     return;
95   }
96 
97   if (!Live) {
98     // If IS is the first section to be added to this section,
99     // initialize Type by IS->Type.
100     Live = true;
101     Type = IS->Type;
102   } else {
103     // Otherwise, check if new type or flags are compatible with existing ones.
104     if ((Flags & (SHF_ALLOC | SHF_TLS)) != (IS->Flags & (SHF_ALLOC | SHF_TLS)))
105       error("incompatible section flags for " + Name + "\n>>> " + toString(IS) +
106             ": 0x" + utohexstr(IS->Flags) + "\n>>> output section " + Name +
107             ": 0x" + utohexstr(Flags));
108 
109     if (Type != IS->Type) {
110       if (!canMergeToProgbits(Type) || !canMergeToProgbits(IS->Type))
111         error("section type mismatch for " + IS->Name + "\n>>> " +
112               toString(IS) + ": " +
113               getELFSectionTypeName(Config->EMachine, IS->Type) +
114               "\n>>> output section " + Name + ": " +
115               getELFSectionTypeName(Config->EMachine, Type));
116       Type = SHT_PROGBITS;
117     }
118   }
119 
120   IS->Parent = this;
121   Flags |= IS->Flags;
122   Alignment = std::max(Alignment, IS->Alignment);
123 
124   // The actual offsets will be computed by assignAddresses. For now, use
125   // crude approximation so that it is at least easy for other code to know the
126   // section order. It is also used to calculate the output section size early
127   // for compressed debug sections.
128   IS->OutSecOff = alignTo(Size, IS->Alignment);
129   this->Size = IS->OutSecOff + IS->getSize();
130 
131   // If this section contains a table of fixed-size entries, sh_entsize
132   // holds the element size. Consequently, if this contains two or more
133   // input sections, all of them must have the same sh_entsize. However,
134   // you can put different types of input sections into one output
135   // section by using linker scripts. I don't know what to do here.
136   // Probably we sholuld handle that as an error. But for now we just
137   // pick the largest sh_entsize.
138   this->Entsize = std::max(this->Entsize, IS->Entsize);
139 
140   if (!IS->Assigned) {
141     IS->Assigned = true;
142     if (SectionCommands.empty() ||
143         !isa<InputSectionDescription>(SectionCommands.back()))
144       SectionCommands.push_back(make<InputSectionDescription>(""));
145     auto *ISD = cast<InputSectionDescription>(SectionCommands.back());
146     ISD->Sections.push_back(IS);
147   }
148 }
149 
150 static SectionKey createKey(InputSectionBase *IS, StringRef OutsecName) {
151   // When control reaches here, mergeable sections have already been
152   // merged except the -r case. If that's the case, we want to combine
153   // mergeable sections by sh_entsize and sh_flags.
154   if (Config->Relocatable && (IS->Flags & SHF_MERGE)) {
155     uint64_t Flags = IS->Flags & (SHF_MERGE | SHF_STRINGS);
156     uint32_t Alignment = std::max<uint32_t>(IS->Alignment, IS->Entsize);
157     return SectionKey{OutsecName, Flags, Alignment};
158   }
159 
160   //  The ELF spec just says
161   // ----------------------------------------------------------------
162   // In the first phase, input sections that match in name, type and
163   // attribute flags should be concatenated into single sections.
164   // ----------------------------------------------------------------
165   //
166   // However, it is clear that at least some flags have to be ignored for
167   // section merging. At the very least SHF_GROUP and SHF_COMPRESSED have to be
168   // ignored. We should not have two output .text sections just because one was
169   // in a group and another was not for example.
170   //
171   // It also seems that that wording was a late addition and didn't get the
172   // necessary scrutiny.
173   //
174   // Merging sections with different flags is expected by some users. One
175   // reason is that if one file has
176   //
177   // int *const bar __attribute__((section(".foo"))) = (int *)0;
178   //
179   // gcc with -fPIC will produce a read only .foo section. But if another
180   // file has
181   //
182   // int zed;
183   // int *const bar __attribute__((section(".foo"))) = (int *)&zed;
184   //
185   // gcc with -fPIC will produce a read write section.
186   //
187   // Last but not least, when using linker script the merge rules are forced by
188   // the script. Unfortunately, linker scripts are name based. This means that
189   // expressions like *(.foo*) can refer to multiple input sections with
190   // different flags. We cannot put them in different output sections or we
191   // would produce wrong results for
192   //
193   // start = .; *(.foo.*) end = .; *(.bar)
194   //
195   // and a mapping of .foo1 and .bar1 to one section and .foo2 and .bar2 to
196   // another. The problem is that there is no way to layout those output
197   // sections such that the .foo sections are the only thing between the start
198   // and end symbols.
199   //
200   // Given the above issues, we instead merge sections by name and error on
201   // incompatible types and flags.
202   return SectionKey{OutsecName, 0, 0};
203 }
204 
205 OutputSectionFactory::OutputSectionFactory() {}
206 
207 void elf::sortByOrder(MutableArrayRef<InputSection *> In,
208                       std::function<int(InputSectionBase *S)> Order) {
209   typedef std::pair<int, InputSection *> Pair;
210   auto Comp = [](const Pair &A, const Pair &B) { return A.first < B.first; };
211 
212   std::vector<Pair> V;
213   for (InputSection *S : In)
214     V.push_back({Order(S), S});
215   std::stable_sort(V.begin(), V.end(), Comp);
216 
217   for (size_t I = 0; I < V.size(); ++I)
218     In[I] = V[I].second;
219 }
220 
221 void elf::reportDiscarded(InputSectionBase *IS) {
222   if (!Config->PrintGcSections)
223     return;
224   message("removing unused section from '" + IS->Name + "' in file '" +
225           IS->File->getName() + "'");
226 }
227 
228 static OutputSection *createSection(InputSectionBase *IS, StringRef OutsecName) {
229   OutputSection *Sec = Script->createOutputSection(OutsecName, "<internal>");
230   Sec->Type = IS->Type;
231   Sec->Flags = IS->Flags;
232   Sec->addSection(cast<InputSection>(IS));
233   return Sec;
234 }
235 
236 OutputSection *OutputSectionFactory::addInputSec(InputSectionBase *IS,
237                                                  StringRef OutsecName) {
238   if (!IS->Live) {
239     reportDiscarded(IS);
240     return nullptr;
241   }
242 
243   // Sections with SHT_GROUP or SHF_GROUP attributes reach here only when the -r
244   // option is given. A section with SHT_GROUP defines a "section group", and
245   // its members have SHF_GROUP attribute. Usually these flags have already been
246   // stripped by InputFiles.cpp as section groups are processed and uniquified.
247   // However, for the -r option, we want to pass through all section groups
248   // as-is because adding/removing members or merging them with other groups
249   // change their semantics.
250   if (IS->Type == SHT_GROUP || (IS->Flags & SHF_GROUP))
251     return createSection(IS, OutsecName);
252 
253   // Imagine .zed : { *(.foo) *(.bar) } script. Both foo and bar may have
254   // relocation sections .rela.foo and .rela.bar for example. Most tools do
255   // not allow multiple REL[A] sections for output section. Hence we
256   // should combine these relocation sections into single output.
257   // We skip synthetic sections because it can be .rela.dyn/.rela.plt or any
258   // other REL[A] sections created by linker itself.
259   if (!isa<SyntheticSection>(IS) &&
260       (IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
261     auto *Sec = cast<InputSection>(IS);
262     OutputSection *Out = Sec->getRelocatedSection()->getOutputSection();
263 
264     if (Out->RelocationSection) {
265       Out->RelocationSection->addSection(Sec);
266       return nullptr;
267     }
268 
269     Out->RelocationSection = createSection(IS, OutsecName);
270     return Out->RelocationSection;
271   }
272 
273   SectionKey Key = createKey(IS, OutsecName);
274   OutputSection *&Sec = Map[Key];
275   if (Sec) {
276     Sec->addSection(cast<InputSection>(IS));
277     return nullptr;
278   }
279 
280   Sec = createSection(IS, OutsecName);
281   return Sec;
282 }
283 
284 OutputSectionFactory::~OutputSectionFactory() {}
285 
286 SectionKey DenseMapInfo<SectionKey>::getEmptyKey() {
287   return SectionKey{DenseMapInfo<StringRef>::getEmptyKey(), 0, 0};
288 }
289 
290 SectionKey DenseMapInfo<SectionKey>::getTombstoneKey() {
291   return SectionKey{DenseMapInfo<StringRef>::getTombstoneKey(), 0, 0};
292 }
293 
294 unsigned DenseMapInfo<SectionKey>::getHashValue(const SectionKey &Val) {
295   return hash_combine(Val.Name, Val.Flags, Val.Alignment);
296 }
297 
298 bool DenseMapInfo<SectionKey>::isEqual(const SectionKey &LHS,
299                                        const SectionKey &RHS) {
300   return DenseMapInfo<StringRef>::isEqual(LHS.Name, RHS.Name) &&
301          LHS.Flags == RHS.Flags && LHS.Alignment == RHS.Alignment;
302 }
303 
304 uint64_t elf::getHeaderSize() {
305   if (Config->OFormatBinary)
306     return 0;
307   return Out::ElfHeader->Size + Out::ProgramHeaders->Size;
308 }
309 
310 bool OutputSection::classof(const BaseCommand *C) {
311   return C->Kind == OutputSectionKind;
312 }
313 
314 void OutputSection::sort(std::function<int(InputSectionBase *S)> Order) {
315   assert(SectionCommands.size() == 1);
316   sortByOrder(cast<InputSectionDescription>(SectionCommands[0])->Sections,
317               Order);
318 }
319 
320 // Fill [Buf, Buf + Size) with Filler.
321 // This is used for linker script "=fillexp" command.
322 static void fill(uint8_t *Buf, size_t Size, uint32_t Filler) {
323   size_t I = 0;
324   for (; I + 4 < Size; I += 4)
325     memcpy(Buf + I, &Filler, 4);
326   memcpy(Buf + I, &Filler, Size - I);
327 }
328 
329 // Compress section contents if this section contains debug info.
330 template <class ELFT> void OutputSection::maybeCompress() {
331   typedef typename ELFT::Chdr Elf_Chdr;
332 
333   // Compress only DWARF debug sections.
334   if (!Config->CompressDebugSections || (Flags & SHF_ALLOC) ||
335       !Name.startswith(".debug_"))
336     return;
337 
338   // Create a section header.
339   ZDebugHeader.resize(sizeof(Elf_Chdr));
340   auto *Hdr = reinterpret_cast<Elf_Chdr *>(ZDebugHeader.data());
341   Hdr->ch_type = ELFCOMPRESS_ZLIB;
342   Hdr->ch_size = Size;
343   Hdr->ch_addralign = Alignment;
344 
345   // Write section contents to a temporary buffer and compress it.
346   std::vector<uint8_t> Buf(Size);
347   writeTo<ELFT>(Buf.data());
348   if (Error E = zlib::compress(toStringRef(Buf), CompressedData))
349     fatal("compress failed: " + llvm::toString(std::move(E)));
350 
351   // Update section headers.
352   Size = sizeof(Elf_Chdr) + CompressedData.size();
353   Flags |= SHF_COMPRESSED;
354 }
355 
356 static void writeInt(uint8_t *Buf, uint64_t Data, uint64_t Size) {
357   if (Size == 1)
358     *Buf = Data;
359   else if (Size == 2)
360     write16(Buf, Data, Config->Endianness);
361   else if (Size == 4)
362     write32(Buf, Data, Config->Endianness);
363   else if (Size == 8)
364     write64(Buf, Data, Config->Endianness);
365   else
366     llvm_unreachable("unsupported Size argument");
367 }
368 
369 template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) {
370   if (Type == SHT_NOBITS)
371     return;
372 
373   Loc = Buf;
374 
375   // If -compress-debug-section is specified and if this is a debug seciton,
376   // we've already compressed section contents. If that's the case,
377   // just write it down.
378   if (!CompressedData.empty()) {
379     memcpy(Buf, ZDebugHeader.data(), ZDebugHeader.size());
380     memcpy(Buf + ZDebugHeader.size(), CompressedData.data(),
381            CompressedData.size());
382     return;
383   }
384 
385   // Write leading padding.
386   std::vector<InputSection *> Sections;
387   for (BaseCommand *Cmd : SectionCommands)
388     if (auto *ISD = dyn_cast<InputSectionDescription>(Cmd))
389       for (InputSection *IS : ISD->Sections)
390         if (IS->Live)
391           Sections.push_back(IS);
392   uint32_t Filler = getFiller();
393   if (Filler)
394     fill(Buf, Sections.empty() ? Size : Sections[0]->OutSecOff, Filler);
395 
396   parallelForEachN(0, Sections.size(), [&](size_t I) {
397     InputSection *IS = Sections[I];
398     IS->writeTo<ELFT>(Buf);
399 
400     // Fill gaps between sections.
401     if (Filler) {
402       uint8_t *Start = Buf + IS->OutSecOff + IS->getSize();
403       uint8_t *End;
404       if (I + 1 == Sections.size())
405         End = Buf + Size;
406       else
407         End = Buf + Sections[I + 1]->OutSecOff;
408       fill(Start, End - Start, Filler);
409     }
410   });
411 
412   // Linker scripts may have BYTE()-family commands with which you
413   // can write arbitrary bytes to the output. Process them if any.
414   for (BaseCommand *Base : SectionCommands)
415     if (auto *Data = dyn_cast<ByteCommand>(Base))
416       writeInt(Buf + Data->Offset, Data->Expression().getValue(), Data->Size);
417 }
418 
419 static bool compareByFilePosition(InputSection *A, InputSection *B) {
420   // Synthetic doesn't have link order dependecy, stable_sort will keep it last
421   if (A->kind() == InputSectionBase::Synthetic ||
422       B->kind() == InputSectionBase::Synthetic)
423     return false;
424   InputSection *LA = A->getLinkOrderDep();
425   InputSection *LB = B->getLinkOrderDep();
426   OutputSection *AOut = LA->getParent();
427   OutputSection *BOut = LB->getParent();
428   if (AOut != BOut)
429     return AOut->SectionIndex < BOut->SectionIndex;
430   return LA->OutSecOff < LB->OutSecOff;
431 }
432 
433 template <class ELFT>
434 static void finalizeShtGroup(OutputSection *OS,
435                              ArrayRef<InputSection *> Sections) {
436   assert(Config->Relocatable && Sections.size() == 1);
437 
438   // sh_link field for SHT_GROUP sections should contain the section index of
439   // the symbol table.
440   OS->Link = InX::SymTab->getParent()->SectionIndex;
441 
442   // sh_info then contain index of an entry in symbol table section which
443   // provides signature of the section group.
444   ObjFile<ELFT> *Obj = Sections[0]->getFile<ELFT>();
445   ArrayRef<SymbolBody *> Symbols = Obj->getSymbols();
446   OS->Info = InX::SymTab->getSymbolIndex(Symbols[Sections[0]->Info]);
447 }
448 
449 template <class ELFT> void OutputSection::finalize() {
450   // Link order may be distributed across several InputSectionDescriptions
451   // but sort must consider them all at once.
452   std::vector<InputSection **> ScriptSections;
453   std::vector<InputSection *> Sections;
454   for (BaseCommand *Base : SectionCommands) {
455     if (auto *ISD = dyn_cast<InputSectionDescription>(Base)) {
456       for (InputSection *&IS : ISD->Sections) {
457         ScriptSections.push_back(&IS);
458         Sections.push_back(IS);
459       }
460     }
461   }
462 
463   if (Flags & SHF_LINK_ORDER) {
464     std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition);
465     for (int I = 0, N = Sections.size(); I < N; ++I)
466       *ScriptSections[I] = Sections[I];
467 
468     // We must preserve the link order dependency of sections with the
469     // SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We
470     // need to translate the InputSection sh_link to the OutputSection sh_link,
471     // all InputSections in the OutputSection have the same dependency.
472     if (auto *D = Sections.front()->getLinkOrderDep())
473       Link = D->getParent()->SectionIndex;
474   }
475 
476   if (Type == SHT_GROUP) {
477     finalizeShtGroup<ELFT>(this, Sections);
478     return;
479   }
480 
481   if (!Config->CopyRelocs || (Type != SHT_RELA && Type != SHT_REL))
482     return;
483 
484   InputSection *First = Sections[0];
485   if (isa<SyntheticSection>(First))
486     return;
487 
488   Link = InX::SymTab->getParent()->SectionIndex;
489   // sh_info for SHT_REL[A] sections should contain the section header index of
490   // the section to which the relocation applies.
491   InputSectionBase *S = First->getRelocatedSection();
492   Info = S->getOutputSection()->SectionIndex;
493   Flags |= SHF_INFO_LINK;
494 }
495 
496 // Returns true if S matches /Filename.?\.o$/.
497 static bool isCrtBeginEnd(StringRef S, StringRef Filename) {
498   if (!S.endswith(".o"))
499     return false;
500   S = S.drop_back(2);
501   if (S.endswith(Filename))
502     return true;
503   return !S.empty() && S.drop_back().endswith(Filename);
504 }
505 
506 static bool isCrtbegin(StringRef S) { return isCrtBeginEnd(S, "crtbegin"); }
507 static bool isCrtend(StringRef S) { return isCrtBeginEnd(S, "crtend"); }
508 
509 // .ctors and .dtors are sorted by this priority from highest to lowest.
510 //
511 //  1. The section was contained in crtbegin (crtbegin contains
512 //     some sentinel value in its .ctors and .dtors so that the runtime
513 //     can find the beginning of the sections.)
514 //
515 //  2. The section has an optional priority value in the form of ".ctors.N"
516 //     or ".dtors.N" where N is a number. Unlike .{init,fini}_array,
517 //     they are compared as string rather than number.
518 //
519 //  3. The section is just ".ctors" or ".dtors".
520 //
521 //  4. The section was contained in crtend, which contains an end marker.
522 //
523 // In an ideal world, we don't need this function because .init_array and
524 // .ctors are duplicate features (and .init_array is newer.) However, there
525 // are too many real-world use cases of .ctors, so we had no choice to
526 // support that with this rather ad-hoc semantics.
527 static bool compCtors(const InputSection *A, const InputSection *B) {
528   bool BeginA = isCrtbegin(A->File->getName());
529   bool BeginB = isCrtbegin(B->File->getName());
530   if (BeginA != BeginB)
531     return BeginA;
532   bool EndA = isCrtend(A->File->getName());
533   bool EndB = isCrtend(B->File->getName());
534   if (EndA != EndB)
535     return EndB;
536   StringRef X = A->Name;
537   StringRef Y = B->Name;
538   assert(X.startswith(".ctors") || X.startswith(".dtors"));
539   assert(Y.startswith(".ctors") || Y.startswith(".dtors"));
540   X = X.substr(6);
541   Y = Y.substr(6);
542   if (X.empty() && Y.empty())
543     return false;
544   return X < Y;
545 }
546 
547 // Sorts input sections by the special rules for .ctors and .dtors.
548 // Unfortunately, the rules are different from the one for .{init,fini}_array.
549 // Read the comment above.
550 void OutputSection::sortCtorsDtors() {
551   assert(SectionCommands.size() == 1);
552   auto *ISD = cast<InputSectionDescription>(SectionCommands[0]);
553   std::stable_sort(ISD->Sections.begin(), ISD->Sections.end(), compCtors);
554 }
555 
556 // If an input string is in the form of "foo.N" where N is a number,
557 // return N. Otherwise, returns 65536, which is one greater than the
558 // lowest priority.
559 int elf::getPriority(StringRef S) {
560   size_t Pos = S.rfind('.');
561   if (Pos == StringRef::npos)
562     return 65536;
563   int V;
564   if (!to_integer(S.substr(Pos + 1), V, 10))
565     return 65536;
566   return V;
567 }
568 
569 // Sorts input sections by section name suffixes, so that .foo.N comes
570 // before .foo.M if N < M. Used to sort .{init,fini}_array.N sections.
571 // We want to keep the original order if the priorities are the same
572 // because the compiler keeps the original initialization order in a
573 // translation unit and we need to respect that.
574 // For more detail, read the section of the GCC's manual about init_priority.
575 void OutputSection::sortInitFini() {
576   // Sort sections by priority.
577   sort([](InputSectionBase *S) { return getPriority(S->Name); });
578 }
579 
580 uint32_t OutputSection::getFiller() {
581   if (Filler)
582     return *Filler;
583   if (Flags & SHF_EXECINSTR)
584     return Target->TrapInstr;
585   return 0;
586 }
587 
588 template void OutputSection::writeHeaderTo<ELF32LE>(ELF32LE::Shdr *Shdr);
589 template void OutputSection::writeHeaderTo<ELF32BE>(ELF32BE::Shdr *Shdr);
590 template void OutputSection::writeHeaderTo<ELF64LE>(ELF64LE::Shdr *Shdr);
591 template void OutputSection::writeHeaderTo<ELF64BE>(ELF64BE::Shdr *Shdr);
592 
593 template void OutputSection::writeTo<ELF32LE>(uint8_t *Buf);
594 template void OutputSection::writeTo<ELF32BE>(uint8_t *Buf);
595 template void OutputSection::writeTo<ELF64LE>(uint8_t *Buf);
596 template void OutputSection::writeTo<ELF64BE>(uint8_t *Buf);
597 
598 template void OutputSection::maybeCompress<ELF32LE>();
599 template void OutputSection::maybeCompress<ELF32BE>();
600 template void OutputSection::maybeCompress<ELF64LE>();
601 template void OutputSection::maybeCompress<ELF64BE>();
602 
603 template void OutputSection::finalize<ELF32LE>();
604 template void OutputSection::finalize<ELF32BE>();
605 template void OutputSection::finalize<ELF64LE>();
606 template void OutputSection::finalize<ELF64BE>();
607