xref: /freebsd/contrib/llvm-project/lld/COFF/Chunks.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- Chunks.h -------------------------------------------------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #ifndef LLD_COFF_CHUNKS_H
10*0b57cec5SDimitry Andric #define LLD_COFF_CHUNKS_H
11*0b57cec5SDimitry Andric 
12*0b57cec5SDimitry Andric #include "Config.h"
13*0b57cec5SDimitry Andric #include "InputFiles.h"
14*0b57cec5SDimitry Andric #include "lld/Common/LLVM.h"
15*0b57cec5SDimitry Andric #include "llvm/ADT/ArrayRef.h"
16*0b57cec5SDimitry Andric #include "llvm/ADT/PointerIntPair.h"
17*0b57cec5SDimitry Andric #include "llvm/ADT/iterator.h"
18*0b57cec5SDimitry Andric #include "llvm/ADT/iterator_range.h"
19*0b57cec5SDimitry Andric #include "llvm/MC/StringTableBuilder.h"
20*0b57cec5SDimitry Andric #include "llvm/Object/COFF.h"
21*0b57cec5SDimitry Andric #include <utility>
22*0b57cec5SDimitry Andric #include <vector>
23*0b57cec5SDimitry Andric 
24*0b57cec5SDimitry Andric namespace lld {
25*0b57cec5SDimitry Andric namespace coff {
26*0b57cec5SDimitry Andric 
27*0b57cec5SDimitry Andric using llvm::COFF::ImportDirectoryTableEntry;
28*0b57cec5SDimitry Andric using llvm::object::COFFSymbolRef;
29*0b57cec5SDimitry Andric using llvm::object::SectionRef;
30*0b57cec5SDimitry Andric using llvm::object::coff_relocation;
31*0b57cec5SDimitry Andric using llvm::object::coff_section;
32*0b57cec5SDimitry Andric 
33*0b57cec5SDimitry Andric class Baserel;
34*0b57cec5SDimitry Andric class Defined;
35*0b57cec5SDimitry Andric class DefinedImportData;
36*0b57cec5SDimitry Andric class DefinedRegular;
37*0b57cec5SDimitry Andric class ObjFile;
38*0b57cec5SDimitry Andric class OutputSection;
39*0b57cec5SDimitry Andric class RuntimePseudoReloc;
40*0b57cec5SDimitry Andric class Symbol;
41*0b57cec5SDimitry Andric 
42*0b57cec5SDimitry Andric // Mask for permissions (discardable, writable, readable, executable, etc).
43*0b57cec5SDimitry Andric const uint32_t permMask = 0xFE000000;
44*0b57cec5SDimitry Andric 
45*0b57cec5SDimitry Andric // Mask for section types (code, data, bss).
46*0b57cec5SDimitry Andric const uint32_t typeMask = 0x000000E0;
47*0b57cec5SDimitry Andric 
48*0b57cec5SDimitry Andric // The log base 2 of the largest section alignment, which is log2(8192), or 13.
49*0b57cec5SDimitry Andric enum : unsigned { Log2MaxSectionAlignment = 13 };
50*0b57cec5SDimitry Andric 
51*0b57cec5SDimitry Andric // A Chunk represents a chunk of data that will occupy space in the
52*0b57cec5SDimitry Andric // output (if the resolver chose that). It may or may not be backed by
53*0b57cec5SDimitry Andric // a section of an input file. It could be linker-created data, or
54*0b57cec5SDimitry Andric // doesn't even have actual data (if common or bss).
55*0b57cec5SDimitry Andric class Chunk {
56*0b57cec5SDimitry Andric public:
57*0b57cec5SDimitry Andric   enum Kind : uint8_t { SectionKind, OtherKind, ImportThunkKind };
58*0b57cec5SDimitry Andric   Kind kind() const { return chunkKind; }
59*0b57cec5SDimitry Andric 
60*0b57cec5SDimitry Andric   // Returns the size of this chunk (even if this is a common or BSS.)
61*0b57cec5SDimitry Andric   size_t getSize() const;
62*0b57cec5SDimitry Andric 
63*0b57cec5SDimitry Andric   // Returns chunk alignment in power of two form. Value values are powers of
64*0b57cec5SDimitry Andric   // two from 1 to 8192.
65*0b57cec5SDimitry Andric   uint32_t getAlignment() const { return 1U << p2Align; }
66*0b57cec5SDimitry Andric 
67*0b57cec5SDimitry Andric   // Update the chunk section alignment measured in bytes. Internally alignment
68*0b57cec5SDimitry Andric   // is stored in log2.
69*0b57cec5SDimitry Andric   void setAlignment(uint32_t align) {
70*0b57cec5SDimitry Andric     // Treat zero byte alignment as 1 byte alignment.
71*0b57cec5SDimitry Andric     align = align ? align : 1;
72*0b57cec5SDimitry Andric     assert(llvm::isPowerOf2_32(align) && "alignment is not a power of 2");
73*0b57cec5SDimitry Andric     p2Align = llvm::Log2_32(align);
74*0b57cec5SDimitry Andric     assert(p2Align <= Log2MaxSectionAlignment &&
75*0b57cec5SDimitry Andric            "impossible requested alignment");
76*0b57cec5SDimitry Andric   }
77*0b57cec5SDimitry Andric 
78*0b57cec5SDimitry Andric   // Write this chunk to a mmap'ed file, assuming Buf is pointing to
79*0b57cec5SDimitry Andric   // beginning of the file. Because this function may use RVA values
80*0b57cec5SDimitry Andric   // of other chunks for relocations, you need to set them properly
81*0b57cec5SDimitry Andric   // before calling this function.
82*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const;
83*0b57cec5SDimitry Andric 
84*0b57cec5SDimitry Andric   // The writer sets and uses the addresses. In practice, PE images cannot be
85*0b57cec5SDimitry Andric   // larger than 2GB. Chunks are always laid as part of the image, so Chunk RVAs
86*0b57cec5SDimitry Andric   // can be stored with 32 bits.
87*0b57cec5SDimitry Andric   uint32_t getRVA() const { return rva; }
88*0b57cec5SDimitry Andric   void setRVA(uint64_t v) {
89*0b57cec5SDimitry Andric     rva = (uint32_t)v;
90*0b57cec5SDimitry Andric     assert(rva == v && "RVA truncated");
91*0b57cec5SDimitry Andric   }
92*0b57cec5SDimitry Andric 
93*0b57cec5SDimitry Andric   // Returns readable/writable/executable bits.
94*0b57cec5SDimitry Andric   uint32_t getOutputCharacteristics() const;
95*0b57cec5SDimitry Andric 
96*0b57cec5SDimitry Andric   // Returns the section name if this is a section chunk.
97*0b57cec5SDimitry Andric   // It is illegal to call this function on non-section chunks.
98*0b57cec5SDimitry Andric   StringRef getSectionName() const;
99*0b57cec5SDimitry Andric 
100*0b57cec5SDimitry Andric   // An output section has pointers to chunks in the section, and each
101*0b57cec5SDimitry Andric   // chunk has a back pointer to an output section.
102*0b57cec5SDimitry Andric   void setOutputSectionIdx(uint16_t o) { osidx = o; }
103*0b57cec5SDimitry Andric   uint16_t getOutputSectionIdx() const { return osidx; }
104*0b57cec5SDimitry Andric   OutputSection *getOutputSection() const;
105*0b57cec5SDimitry Andric 
106*0b57cec5SDimitry Andric   // Windows-specific.
107*0b57cec5SDimitry Andric   // Collect all locations that contain absolute addresses for base relocations.
108*0b57cec5SDimitry Andric   void getBaserels(std::vector<Baserel> *res);
109*0b57cec5SDimitry Andric 
110*0b57cec5SDimitry Andric   // Returns a human-readable name of this chunk. Chunks are unnamed chunks of
111*0b57cec5SDimitry Andric   // bytes, so this is used only for logging or debugging.
112*0b57cec5SDimitry Andric   StringRef getDebugName() const;
113*0b57cec5SDimitry Andric 
114*0b57cec5SDimitry Andric   // Return true if this file has the hotpatch flag set to true in the
115*0b57cec5SDimitry Andric   // S_COMPILE3 record in codeview debug info. Also returns true for some thunks
116*0b57cec5SDimitry Andric   // synthesized by the linker.
117*0b57cec5SDimitry Andric   bool isHotPatchable() const;
118*0b57cec5SDimitry Andric 
119*0b57cec5SDimitry Andric protected:
120*0b57cec5SDimitry Andric   Chunk(Kind k = OtherKind) : chunkKind(k), hasData(true), p2Align(0) {}
121*0b57cec5SDimitry Andric 
122*0b57cec5SDimitry Andric   const Kind chunkKind;
123*0b57cec5SDimitry Andric 
124*0b57cec5SDimitry Andric public:
125*0b57cec5SDimitry Andric   // Returns true if this has non-zero data. BSS chunks return
126*0b57cec5SDimitry Andric   // false. If false is returned, the space occupied by this chunk
127*0b57cec5SDimitry Andric   // will be filled with zeros. Corresponds to the
128*0b57cec5SDimitry Andric   // IMAGE_SCN_CNT_UNINITIALIZED_DATA section characteristic bit.
129*0b57cec5SDimitry Andric   uint8_t hasData : 1;
130*0b57cec5SDimitry Andric 
131*0b57cec5SDimitry Andric public:
132*0b57cec5SDimitry Andric   // The alignment of this chunk, stored in log2 form. The writer uses the
133*0b57cec5SDimitry Andric   // value.
134*0b57cec5SDimitry Andric   uint8_t p2Align : 7;
135*0b57cec5SDimitry Andric 
136*0b57cec5SDimitry Andric   // The output section index for this chunk. The first valid section number is
137*0b57cec5SDimitry Andric   // one.
138*0b57cec5SDimitry Andric   uint16_t osidx = 0;
139*0b57cec5SDimitry Andric 
140*0b57cec5SDimitry Andric   // The RVA of this chunk in the output. The writer sets a value.
141*0b57cec5SDimitry Andric   uint32_t rva = 0;
142*0b57cec5SDimitry Andric };
143*0b57cec5SDimitry Andric 
144*0b57cec5SDimitry Andric class NonSectionChunk : public Chunk {
145*0b57cec5SDimitry Andric public:
146*0b57cec5SDimitry Andric   virtual ~NonSectionChunk() = default;
147*0b57cec5SDimitry Andric 
148*0b57cec5SDimitry Andric   // Returns the size of this chunk (even if this is a common or BSS.)
149*0b57cec5SDimitry Andric   virtual size_t getSize() const = 0;
150*0b57cec5SDimitry Andric 
151*0b57cec5SDimitry Andric   virtual uint32_t getOutputCharacteristics() const { return 0; }
152*0b57cec5SDimitry Andric 
153*0b57cec5SDimitry Andric   // Write this chunk to a mmap'ed file, assuming Buf is pointing to
154*0b57cec5SDimitry Andric   // beginning of the file. Because this function may use RVA values
155*0b57cec5SDimitry Andric   // of other chunks for relocations, you need to set them properly
156*0b57cec5SDimitry Andric   // before calling this function.
157*0b57cec5SDimitry Andric   virtual void writeTo(uint8_t *buf) const {}
158*0b57cec5SDimitry Andric 
159*0b57cec5SDimitry Andric   // Returns the section name if this is a section chunk.
160*0b57cec5SDimitry Andric   // It is illegal to call this function on non-section chunks.
161*0b57cec5SDimitry Andric   virtual StringRef getSectionName() const {
162*0b57cec5SDimitry Andric     llvm_unreachable("unimplemented getSectionName");
163*0b57cec5SDimitry Andric   }
164*0b57cec5SDimitry Andric 
165*0b57cec5SDimitry Andric   // Windows-specific.
166*0b57cec5SDimitry Andric   // Collect all locations that contain absolute addresses for base relocations.
167*0b57cec5SDimitry Andric   virtual void getBaserels(std::vector<Baserel> *res) {}
168*0b57cec5SDimitry Andric 
169*0b57cec5SDimitry Andric   // Returns a human-readable name of this chunk. Chunks are unnamed chunks of
170*0b57cec5SDimitry Andric   // bytes, so this is used only for logging or debugging.
171*0b57cec5SDimitry Andric   virtual StringRef getDebugName() const { return ""; }
172*0b57cec5SDimitry Andric 
173*0b57cec5SDimitry Andric   static bool classof(const Chunk *c) { return c->kind() != SectionKind; }
174*0b57cec5SDimitry Andric 
175*0b57cec5SDimitry Andric protected:
176*0b57cec5SDimitry Andric   NonSectionChunk(Kind k = OtherKind) : Chunk(k) {}
177*0b57cec5SDimitry Andric };
178*0b57cec5SDimitry Andric 
179*0b57cec5SDimitry Andric // A chunk corresponding a section of an input file.
180*0b57cec5SDimitry Andric class SectionChunk final : public Chunk {
181*0b57cec5SDimitry Andric   // Identical COMDAT Folding feature accesses section internal data.
182*0b57cec5SDimitry Andric   friend class ICF;
183*0b57cec5SDimitry Andric 
184*0b57cec5SDimitry Andric public:
185*0b57cec5SDimitry Andric   class symbol_iterator : public llvm::iterator_adaptor_base<
186*0b57cec5SDimitry Andric                               symbol_iterator, const coff_relocation *,
187*0b57cec5SDimitry Andric                               std::random_access_iterator_tag, Symbol *> {
188*0b57cec5SDimitry Andric     friend SectionChunk;
189*0b57cec5SDimitry Andric 
190*0b57cec5SDimitry Andric     ObjFile *file;
191*0b57cec5SDimitry Andric 
192*0b57cec5SDimitry Andric     symbol_iterator(ObjFile *file, const coff_relocation *i)
193*0b57cec5SDimitry Andric         : symbol_iterator::iterator_adaptor_base(i), file(file) {}
194*0b57cec5SDimitry Andric 
195*0b57cec5SDimitry Andric   public:
196*0b57cec5SDimitry Andric     symbol_iterator() = default;
197*0b57cec5SDimitry Andric 
198*0b57cec5SDimitry Andric     Symbol *operator*() const { return file->getSymbol(I->SymbolTableIndex); }
199*0b57cec5SDimitry Andric   };
200*0b57cec5SDimitry Andric 
201*0b57cec5SDimitry Andric   SectionChunk(ObjFile *file, const coff_section *header);
202*0b57cec5SDimitry Andric   static bool classof(const Chunk *c) { return c->kind() == SectionKind; }
203*0b57cec5SDimitry Andric   size_t getSize() const { return header->SizeOfRawData; }
204*0b57cec5SDimitry Andric   ArrayRef<uint8_t> getContents() const;
205*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const;
206*0b57cec5SDimitry Andric 
207*0b57cec5SDimitry Andric   uint32_t getOutputCharacteristics() const {
208*0b57cec5SDimitry Andric     return header->Characteristics & (permMask | typeMask);
209*0b57cec5SDimitry Andric   }
210*0b57cec5SDimitry Andric   StringRef getSectionName() const {
211*0b57cec5SDimitry Andric     return StringRef(sectionNameData, sectionNameSize);
212*0b57cec5SDimitry Andric   }
213*0b57cec5SDimitry Andric   void getBaserels(std::vector<Baserel> *res);
214*0b57cec5SDimitry Andric   bool isCOMDAT() const;
215*0b57cec5SDimitry Andric   void applyRelX64(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
216*0b57cec5SDimitry Andric                    uint64_t p) const;
217*0b57cec5SDimitry Andric   void applyRelX86(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
218*0b57cec5SDimitry Andric                    uint64_t p) const;
219*0b57cec5SDimitry Andric   void applyRelARM(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
220*0b57cec5SDimitry Andric                    uint64_t p) const;
221*0b57cec5SDimitry Andric   void applyRelARM64(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
222*0b57cec5SDimitry Andric                      uint64_t p) const;
223*0b57cec5SDimitry Andric 
224*0b57cec5SDimitry Andric   void getRuntimePseudoRelocs(std::vector<RuntimePseudoReloc> &res);
225*0b57cec5SDimitry Andric 
226*0b57cec5SDimitry Andric   // Called if the garbage collector decides to not include this chunk
227*0b57cec5SDimitry Andric   // in a final output. It's supposed to print out a log message to stdout.
228*0b57cec5SDimitry Andric   void printDiscardedMessage() const;
229*0b57cec5SDimitry Andric 
230*0b57cec5SDimitry Andric   // Adds COMDAT associative sections to this COMDAT section. A chunk
231*0b57cec5SDimitry Andric   // and its children are treated as a group by the garbage collector.
232*0b57cec5SDimitry Andric   void addAssociative(SectionChunk *child);
233*0b57cec5SDimitry Andric 
234*0b57cec5SDimitry Andric   StringRef getDebugName() const;
235*0b57cec5SDimitry Andric 
236*0b57cec5SDimitry Andric   // True if this is a codeview debug info chunk. These will not be laid out in
237*0b57cec5SDimitry Andric   // the image. Instead they will end up in the PDB, if one is requested.
238*0b57cec5SDimitry Andric   bool isCodeView() const {
239*0b57cec5SDimitry Andric     return getSectionName() == ".debug" || getSectionName().startswith(".debug$");
240*0b57cec5SDimitry Andric   }
241*0b57cec5SDimitry Andric 
242*0b57cec5SDimitry Andric   // True if this is a DWARF debug info or exception handling chunk.
243*0b57cec5SDimitry Andric   bool isDWARF() const {
244*0b57cec5SDimitry Andric     return getSectionName().startswith(".debug_") || getSectionName() == ".eh_frame";
245*0b57cec5SDimitry Andric   }
246*0b57cec5SDimitry Andric 
247*0b57cec5SDimitry Andric   // Allow iteration over the bodies of this chunk's relocated symbols.
248*0b57cec5SDimitry Andric   llvm::iterator_range<symbol_iterator> symbols() const {
249*0b57cec5SDimitry Andric     return llvm::make_range(symbol_iterator(file, relocsData),
250*0b57cec5SDimitry Andric                             symbol_iterator(file, relocsData + relocsSize));
251*0b57cec5SDimitry Andric   }
252*0b57cec5SDimitry Andric 
253*0b57cec5SDimitry Andric   ArrayRef<coff_relocation> getRelocs() const {
254*0b57cec5SDimitry Andric     return llvm::makeArrayRef(relocsData, relocsSize);
255*0b57cec5SDimitry Andric   }
256*0b57cec5SDimitry Andric 
257*0b57cec5SDimitry Andric   // Reloc setter used by ARM range extension thunk insertion.
258*0b57cec5SDimitry Andric   void setRelocs(ArrayRef<coff_relocation> newRelocs) {
259*0b57cec5SDimitry Andric     relocsData = newRelocs.data();
260*0b57cec5SDimitry Andric     relocsSize = newRelocs.size();
261*0b57cec5SDimitry Andric     assert(relocsSize == newRelocs.size() && "reloc size truncation");
262*0b57cec5SDimitry Andric   }
263*0b57cec5SDimitry Andric 
264*0b57cec5SDimitry Andric   // Single linked list iterator for associated comdat children.
265*0b57cec5SDimitry Andric   class AssociatedIterator
266*0b57cec5SDimitry Andric       : public llvm::iterator_facade_base<
267*0b57cec5SDimitry Andric             AssociatedIterator, std::forward_iterator_tag, SectionChunk> {
268*0b57cec5SDimitry Andric   public:
269*0b57cec5SDimitry Andric     AssociatedIterator() = default;
270*0b57cec5SDimitry Andric     AssociatedIterator(SectionChunk *head) : cur(head) {}
271*0b57cec5SDimitry Andric     AssociatedIterator &operator=(const AssociatedIterator &r) {
272*0b57cec5SDimitry Andric       cur = r.cur;
273*0b57cec5SDimitry Andric       return *this;
274*0b57cec5SDimitry Andric     }
275*0b57cec5SDimitry Andric     bool operator==(const AssociatedIterator &r) const { return cur == r.cur; }
276*0b57cec5SDimitry Andric     const SectionChunk &operator*() const { return *cur; }
277*0b57cec5SDimitry Andric     SectionChunk &operator*() { return *cur; }
278*0b57cec5SDimitry Andric     AssociatedIterator &operator++() {
279*0b57cec5SDimitry Andric       cur = cur->assocChildren;
280*0b57cec5SDimitry Andric       return *this;
281*0b57cec5SDimitry Andric     }
282*0b57cec5SDimitry Andric 
283*0b57cec5SDimitry Andric   private:
284*0b57cec5SDimitry Andric     SectionChunk *cur = nullptr;
285*0b57cec5SDimitry Andric   };
286*0b57cec5SDimitry Andric 
287*0b57cec5SDimitry Andric   // Allow iteration over the associated child chunks for this section.
288*0b57cec5SDimitry Andric   llvm::iterator_range<AssociatedIterator> children() const {
289*0b57cec5SDimitry Andric     return llvm::make_range(AssociatedIterator(assocChildren),
290*0b57cec5SDimitry Andric                             AssociatedIterator(nullptr));
291*0b57cec5SDimitry Andric   }
292*0b57cec5SDimitry Andric 
293*0b57cec5SDimitry Andric   // The section ID this chunk belongs to in its Obj.
294*0b57cec5SDimitry Andric   uint32_t getSectionNumber() const;
295*0b57cec5SDimitry Andric 
296*0b57cec5SDimitry Andric   ArrayRef<uint8_t> consumeDebugMagic();
297*0b57cec5SDimitry Andric 
298*0b57cec5SDimitry Andric   static ArrayRef<uint8_t> consumeDebugMagic(ArrayRef<uint8_t> data,
299*0b57cec5SDimitry Andric                                              StringRef sectionName);
300*0b57cec5SDimitry Andric 
301*0b57cec5SDimitry Andric   static SectionChunk *findByName(ArrayRef<SectionChunk *> sections,
302*0b57cec5SDimitry Andric                                   StringRef name);
303*0b57cec5SDimitry Andric 
304*0b57cec5SDimitry Andric   // The file that this chunk was created from.
305*0b57cec5SDimitry Andric   ObjFile *file;
306*0b57cec5SDimitry Andric 
307*0b57cec5SDimitry Andric   // Pointer to the COFF section header in the input file.
308*0b57cec5SDimitry Andric   const coff_section *header;
309*0b57cec5SDimitry Andric 
310*0b57cec5SDimitry Andric   // The COMDAT leader symbol if this is a COMDAT chunk.
311*0b57cec5SDimitry Andric   DefinedRegular *sym = nullptr;
312*0b57cec5SDimitry Andric 
313*0b57cec5SDimitry Andric   // The CRC of the contents as described in the COFF spec 4.5.5.
314*0b57cec5SDimitry Andric   // Auxiliary Format 5: Section Definitions. Used for ICF.
315*0b57cec5SDimitry Andric   uint32_t checksum = 0;
316*0b57cec5SDimitry Andric 
317*0b57cec5SDimitry Andric   // Used by the garbage collector.
318*0b57cec5SDimitry Andric   bool live;
319*0b57cec5SDimitry Andric 
320*0b57cec5SDimitry Andric   // Whether this section needs to be kept distinct from other sections during
321*0b57cec5SDimitry Andric   // ICF. This is set by the driver using address-significance tables.
322*0b57cec5SDimitry Andric   bool keepUnique = false;
323*0b57cec5SDimitry Andric 
324*0b57cec5SDimitry Andric   // The COMDAT selection if this is a COMDAT chunk.
325*0b57cec5SDimitry Andric   llvm::COFF::COMDATType selection = (llvm::COFF::COMDATType)0;
326*0b57cec5SDimitry Andric 
327*0b57cec5SDimitry Andric   // A pointer pointing to a replacement for this chunk.
328*0b57cec5SDimitry Andric   // Initially it points to "this" object. If this chunk is merged
329*0b57cec5SDimitry Andric   // with other chunk by ICF, it points to another chunk,
330*0b57cec5SDimitry Andric   // and this chunk is considered as dead.
331*0b57cec5SDimitry Andric   SectionChunk *repl;
332*0b57cec5SDimitry Andric 
333*0b57cec5SDimitry Andric private:
334*0b57cec5SDimitry Andric   SectionChunk *assocChildren = nullptr;
335*0b57cec5SDimitry Andric 
336*0b57cec5SDimitry Andric   // Used for ICF (Identical COMDAT Folding)
337*0b57cec5SDimitry Andric   void replace(SectionChunk *other);
338*0b57cec5SDimitry Andric   uint32_t eqClass[2] = {0, 0};
339*0b57cec5SDimitry Andric 
340*0b57cec5SDimitry Andric   // Relocations for this section. Size is stored below.
341*0b57cec5SDimitry Andric   const coff_relocation *relocsData;
342*0b57cec5SDimitry Andric 
343*0b57cec5SDimitry Andric   // Section name string. Size is stored below.
344*0b57cec5SDimitry Andric   const char *sectionNameData;
345*0b57cec5SDimitry Andric 
346*0b57cec5SDimitry Andric   uint32_t relocsSize = 0;
347*0b57cec5SDimitry Andric   uint32_t sectionNameSize = 0;
348*0b57cec5SDimitry Andric };
349*0b57cec5SDimitry Andric 
350*0b57cec5SDimitry Andric // Inline methods to implement faux-virtual dispatch for SectionChunk.
351*0b57cec5SDimitry Andric 
352*0b57cec5SDimitry Andric inline size_t Chunk::getSize() const {
353*0b57cec5SDimitry Andric   if (isa<SectionChunk>(this))
354*0b57cec5SDimitry Andric     return static_cast<const SectionChunk *>(this)->getSize();
355*0b57cec5SDimitry Andric   else
356*0b57cec5SDimitry Andric     return static_cast<const NonSectionChunk *>(this)->getSize();
357*0b57cec5SDimitry Andric }
358*0b57cec5SDimitry Andric 
359*0b57cec5SDimitry Andric inline uint32_t Chunk::getOutputCharacteristics() const {
360*0b57cec5SDimitry Andric   if (isa<SectionChunk>(this))
361*0b57cec5SDimitry Andric     return static_cast<const SectionChunk *>(this)->getOutputCharacteristics();
362*0b57cec5SDimitry Andric   else
363*0b57cec5SDimitry Andric     return static_cast<const NonSectionChunk *>(this)
364*0b57cec5SDimitry Andric         ->getOutputCharacteristics();
365*0b57cec5SDimitry Andric }
366*0b57cec5SDimitry Andric 
367*0b57cec5SDimitry Andric inline void Chunk::writeTo(uint8_t *buf) const {
368*0b57cec5SDimitry Andric   if (isa<SectionChunk>(this))
369*0b57cec5SDimitry Andric     static_cast<const SectionChunk *>(this)->writeTo(buf);
370*0b57cec5SDimitry Andric   else
371*0b57cec5SDimitry Andric     static_cast<const NonSectionChunk *>(this)->writeTo(buf);
372*0b57cec5SDimitry Andric }
373*0b57cec5SDimitry Andric 
374*0b57cec5SDimitry Andric inline StringRef Chunk::getSectionName() const {
375*0b57cec5SDimitry Andric   if (isa<SectionChunk>(this))
376*0b57cec5SDimitry Andric     return static_cast<const SectionChunk *>(this)->getSectionName();
377*0b57cec5SDimitry Andric   else
378*0b57cec5SDimitry Andric     return static_cast<const NonSectionChunk *>(this)->getSectionName();
379*0b57cec5SDimitry Andric }
380*0b57cec5SDimitry Andric 
381*0b57cec5SDimitry Andric inline void Chunk::getBaserels(std::vector<Baserel> *res) {
382*0b57cec5SDimitry Andric   if (isa<SectionChunk>(this))
383*0b57cec5SDimitry Andric     static_cast<SectionChunk *>(this)->getBaserels(res);
384*0b57cec5SDimitry Andric   else
385*0b57cec5SDimitry Andric     static_cast<NonSectionChunk *>(this)->getBaserels(res);
386*0b57cec5SDimitry Andric }
387*0b57cec5SDimitry Andric 
388*0b57cec5SDimitry Andric inline StringRef Chunk::getDebugName() const {
389*0b57cec5SDimitry Andric   if (isa<SectionChunk>(this))
390*0b57cec5SDimitry Andric     return static_cast<const SectionChunk *>(this)->getDebugName();
391*0b57cec5SDimitry Andric   else
392*0b57cec5SDimitry Andric     return static_cast<const NonSectionChunk *>(this)->getDebugName();
393*0b57cec5SDimitry Andric }
394*0b57cec5SDimitry Andric 
395*0b57cec5SDimitry Andric // This class is used to implement an lld-specific feature (not implemented in
396*0b57cec5SDimitry Andric // MSVC) that minimizes the output size by finding string literals sharing tail
397*0b57cec5SDimitry Andric // parts and merging them.
398*0b57cec5SDimitry Andric //
399*0b57cec5SDimitry Andric // If string tail merging is enabled and a section is identified as containing a
400*0b57cec5SDimitry Andric // string literal, it is added to a MergeChunk with an appropriate alignment.
401*0b57cec5SDimitry Andric // The MergeChunk then tail merges the strings using the StringTableBuilder
402*0b57cec5SDimitry Andric // class and assigns RVAs and section offsets to each of the member chunks based
403*0b57cec5SDimitry Andric // on the offsets assigned by the StringTableBuilder.
404*0b57cec5SDimitry Andric class MergeChunk : public NonSectionChunk {
405*0b57cec5SDimitry Andric public:
406*0b57cec5SDimitry Andric   MergeChunk(uint32_t alignment);
407*0b57cec5SDimitry Andric   static void addSection(SectionChunk *c);
408*0b57cec5SDimitry Andric   void finalizeContents();
409*0b57cec5SDimitry Andric   void assignSubsectionRVAs();
410*0b57cec5SDimitry Andric 
411*0b57cec5SDimitry Andric   uint32_t getOutputCharacteristics() const override;
412*0b57cec5SDimitry Andric   StringRef getSectionName() const override { return ".rdata"; }
413*0b57cec5SDimitry Andric   size_t getSize() const override;
414*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
415*0b57cec5SDimitry Andric 
416*0b57cec5SDimitry Andric   static MergeChunk *instances[Log2MaxSectionAlignment + 1];
417*0b57cec5SDimitry Andric   std::vector<SectionChunk *> sections;
418*0b57cec5SDimitry Andric 
419*0b57cec5SDimitry Andric private:
420*0b57cec5SDimitry Andric   llvm::StringTableBuilder builder;
421*0b57cec5SDimitry Andric   bool finalized = false;
422*0b57cec5SDimitry Andric };
423*0b57cec5SDimitry Andric 
424*0b57cec5SDimitry Andric // A chunk for common symbols. Common chunks don't have actual data.
425*0b57cec5SDimitry Andric class CommonChunk : public NonSectionChunk {
426*0b57cec5SDimitry Andric public:
427*0b57cec5SDimitry Andric   CommonChunk(const COFFSymbolRef sym);
428*0b57cec5SDimitry Andric   size_t getSize() const override { return sym.getValue(); }
429*0b57cec5SDimitry Andric   uint32_t getOutputCharacteristics() const override;
430*0b57cec5SDimitry Andric   StringRef getSectionName() const override { return ".bss"; }
431*0b57cec5SDimitry Andric 
432*0b57cec5SDimitry Andric private:
433*0b57cec5SDimitry Andric   const COFFSymbolRef sym;
434*0b57cec5SDimitry Andric };
435*0b57cec5SDimitry Andric 
436*0b57cec5SDimitry Andric // A chunk for linker-created strings.
437*0b57cec5SDimitry Andric class StringChunk : public NonSectionChunk {
438*0b57cec5SDimitry Andric public:
439*0b57cec5SDimitry Andric   explicit StringChunk(StringRef s) : str(s) {}
440*0b57cec5SDimitry Andric   size_t getSize() const override { return str.size() + 1; }
441*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
442*0b57cec5SDimitry Andric 
443*0b57cec5SDimitry Andric private:
444*0b57cec5SDimitry Andric   StringRef str;
445*0b57cec5SDimitry Andric };
446*0b57cec5SDimitry Andric 
447*0b57cec5SDimitry Andric static const uint8_t importThunkX86[] = {
448*0b57cec5SDimitry Andric     0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // JMP *0x0
449*0b57cec5SDimitry Andric };
450*0b57cec5SDimitry Andric 
451*0b57cec5SDimitry Andric static const uint8_t importThunkARM[] = {
452*0b57cec5SDimitry Andric     0x40, 0xf2, 0x00, 0x0c, // mov.w ip, #0
453*0b57cec5SDimitry Andric     0xc0, 0xf2, 0x00, 0x0c, // mov.t ip, #0
454*0b57cec5SDimitry Andric     0xdc, 0xf8, 0x00, 0xf0, // ldr.w pc, [ip]
455*0b57cec5SDimitry Andric };
456*0b57cec5SDimitry Andric 
457*0b57cec5SDimitry Andric static const uint8_t importThunkARM64[] = {
458*0b57cec5SDimitry Andric     0x10, 0x00, 0x00, 0x90, // adrp x16, #0
459*0b57cec5SDimitry Andric     0x10, 0x02, 0x40, 0xf9, // ldr  x16, [x16]
460*0b57cec5SDimitry Andric     0x00, 0x02, 0x1f, 0xd6, // br   x16
461*0b57cec5SDimitry Andric };
462*0b57cec5SDimitry Andric 
463*0b57cec5SDimitry Andric // Windows-specific.
464*0b57cec5SDimitry Andric // A chunk for DLL import jump table entry. In a final output, its
465*0b57cec5SDimitry Andric // contents will be a JMP instruction to some __imp_ symbol.
466*0b57cec5SDimitry Andric class ImportThunkChunk : public NonSectionChunk {
467*0b57cec5SDimitry Andric public:
468*0b57cec5SDimitry Andric   ImportThunkChunk(Defined *s)
469*0b57cec5SDimitry Andric       : NonSectionChunk(ImportThunkKind), impSymbol(s) {}
470*0b57cec5SDimitry Andric   static bool classof(const Chunk *c) { return c->kind() == ImportThunkKind; }
471*0b57cec5SDimitry Andric 
472*0b57cec5SDimitry Andric protected:
473*0b57cec5SDimitry Andric   Defined *impSymbol;
474*0b57cec5SDimitry Andric };
475*0b57cec5SDimitry Andric 
476*0b57cec5SDimitry Andric class ImportThunkChunkX64 : public ImportThunkChunk {
477*0b57cec5SDimitry Andric public:
478*0b57cec5SDimitry Andric   explicit ImportThunkChunkX64(Defined *s);
479*0b57cec5SDimitry Andric   size_t getSize() const override { return sizeof(importThunkX86); }
480*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
481*0b57cec5SDimitry Andric };
482*0b57cec5SDimitry Andric 
483*0b57cec5SDimitry Andric class ImportThunkChunkX86 : public ImportThunkChunk {
484*0b57cec5SDimitry Andric public:
485*0b57cec5SDimitry Andric   explicit ImportThunkChunkX86(Defined *s) : ImportThunkChunk(s) {}
486*0b57cec5SDimitry Andric   size_t getSize() const override { return sizeof(importThunkX86); }
487*0b57cec5SDimitry Andric   void getBaserels(std::vector<Baserel> *res) override;
488*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
489*0b57cec5SDimitry Andric };
490*0b57cec5SDimitry Andric 
491*0b57cec5SDimitry Andric class ImportThunkChunkARM : public ImportThunkChunk {
492*0b57cec5SDimitry Andric public:
493*0b57cec5SDimitry Andric   explicit ImportThunkChunkARM(Defined *s) : ImportThunkChunk(s) {}
494*0b57cec5SDimitry Andric   size_t getSize() const override { return sizeof(importThunkARM); }
495*0b57cec5SDimitry Andric   void getBaserels(std::vector<Baserel> *res) override;
496*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
497*0b57cec5SDimitry Andric };
498*0b57cec5SDimitry Andric 
499*0b57cec5SDimitry Andric class ImportThunkChunkARM64 : public ImportThunkChunk {
500*0b57cec5SDimitry Andric public:
501*0b57cec5SDimitry Andric   explicit ImportThunkChunkARM64(Defined *s) : ImportThunkChunk(s) {}
502*0b57cec5SDimitry Andric   size_t getSize() const override { return sizeof(importThunkARM64); }
503*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
504*0b57cec5SDimitry Andric };
505*0b57cec5SDimitry Andric 
506*0b57cec5SDimitry Andric class RangeExtensionThunkARM : public NonSectionChunk {
507*0b57cec5SDimitry Andric public:
508*0b57cec5SDimitry Andric   explicit RangeExtensionThunkARM(Defined *t) : target(t) {}
509*0b57cec5SDimitry Andric   size_t getSize() const override;
510*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
511*0b57cec5SDimitry Andric 
512*0b57cec5SDimitry Andric   Defined *target;
513*0b57cec5SDimitry Andric };
514*0b57cec5SDimitry Andric 
515*0b57cec5SDimitry Andric class RangeExtensionThunkARM64 : public NonSectionChunk {
516*0b57cec5SDimitry Andric public:
517*0b57cec5SDimitry Andric   explicit RangeExtensionThunkARM64(Defined *t) : target(t) {}
518*0b57cec5SDimitry Andric   size_t getSize() const override;
519*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
520*0b57cec5SDimitry Andric 
521*0b57cec5SDimitry Andric   Defined *target;
522*0b57cec5SDimitry Andric };
523*0b57cec5SDimitry Andric 
524*0b57cec5SDimitry Andric // Windows-specific.
525*0b57cec5SDimitry Andric // See comments for DefinedLocalImport class.
526*0b57cec5SDimitry Andric class LocalImportChunk : public NonSectionChunk {
527*0b57cec5SDimitry Andric public:
528*0b57cec5SDimitry Andric   explicit LocalImportChunk(Defined *s) : sym(s) {
529*0b57cec5SDimitry Andric     setAlignment(config->wordsize);
530*0b57cec5SDimitry Andric   }
531*0b57cec5SDimitry Andric   size_t getSize() const override;
532*0b57cec5SDimitry Andric   void getBaserels(std::vector<Baserel> *res) override;
533*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
534*0b57cec5SDimitry Andric 
535*0b57cec5SDimitry Andric private:
536*0b57cec5SDimitry Andric   Defined *sym;
537*0b57cec5SDimitry Andric };
538*0b57cec5SDimitry Andric 
539*0b57cec5SDimitry Andric // Duplicate RVAs are not allowed in RVA tables, so unique symbols by chunk and
540*0b57cec5SDimitry Andric // offset into the chunk. Order does not matter as the RVA table will be sorted
541*0b57cec5SDimitry Andric // later.
542*0b57cec5SDimitry Andric struct ChunkAndOffset {
543*0b57cec5SDimitry Andric   Chunk *inputChunk;
544*0b57cec5SDimitry Andric   uint32_t offset;
545*0b57cec5SDimitry Andric 
546*0b57cec5SDimitry Andric   struct DenseMapInfo {
547*0b57cec5SDimitry Andric     static ChunkAndOffset getEmptyKey() {
548*0b57cec5SDimitry Andric       return {llvm::DenseMapInfo<Chunk *>::getEmptyKey(), 0};
549*0b57cec5SDimitry Andric     }
550*0b57cec5SDimitry Andric     static ChunkAndOffset getTombstoneKey() {
551*0b57cec5SDimitry Andric       return {llvm::DenseMapInfo<Chunk *>::getTombstoneKey(), 0};
552*0b57cec5SDimitry Andric     }
553*0b57cec5SDimitry Andric     static unsigned getHashValue(const ChunkAndOffset &co) {
554*0b57cec5SDimitry Andric       return llvm::DenseMapInfo<std::pair<Chunk *, uint32_t>>::getHashValue(
555*0b57cec5SDimitry Andric           {co.inputChunk, co.offset});
556*0b57cec5SDimitry Andric     }
557*0b57cec5SDimitry Andric     static bool isEqual(const ChunkAndOffset &lhs, const ChunkAndOffset &rhs) {
558*0b57cec5SDimitry Andric       return lhs.inputChunk == rhs.inputChunk && lhs.offset == rhs.offset;
559*0b57cec5SDimitry Andric     }
560*0b57cec5SDimitry Andric   };
561*0b57cec5SDimitry Andric };
562*0b57cec5SDimitry Andric 
563*0b57cec5SDimitry Andric using SymbolRVASet = llvm::DenseSet<ChunkAndOffset>;
564*0b57cec5SDimitry Andric 
565*0b57cec5SDimitry Andric // Table which contains symbol RVAs. Used for /safeseh and /guard:cf.
566*0b57cec5SDimitry Andric class RVATableChunk : public NonSectionChunk {
567*0b57cec5SDimitry Andric public:
568*0b57cec5SDimitry Andric   explicit RVATableChunk(SymbolRVASet s) : syms(std::move(s)) {}
569*0b57cec5SDimitry Andric   size_t getSize() const override { return syms.size() * 4; }
570*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
571*0b57cec5SDimitry Andric 
572*0b57cec5SDimitry Andric private:
573*0b57cec5SDimitry Andric   SymbolRVASet syms;
574*0b57cec5SDimitry Andric };
575*0b57cec5SDimitry Andric 
576*0b57cec5SDimitry Andric // Windows-specific.
577*0b57cec5SDimitry Andric // This class represents a block in .reloc section.
578*0b57cec5SDimitry Andric // See the PE/COFF spec 5.6 for details.
579*0b57cec5SDimitry Andric class BaserelChunk : public NonSectionChunk {
580*0b57cec5SDimitry Andric public:
581*0b57cec5SDimitry Andric   BaserelChunk(uint32_t page, Baserel *begin, Baserel *end);
582*0b57cec5SDimitry Andric   size_t getSize() const override { return data.size(); }
583*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
584*0b57cec5SDimitry Andric 
585*0b57cec5SDimitry Andric private:
586*0b57cec5SDimitry Andric   std::vector<uint8_t> data;
587*0b57cec5SDimitry Andric };
588*0b57cec5SDimitry Andric 
589*0b57cec5SDimitry Andric class Baserel {
590*0b57cec5SDimitry Andric public:
591*0b57cec5SDimitry Andric   Baserel(uint32_t v, uint8_t ty) : rva(v), type(ty) {}
592*0b57cec5SDimitry Andric   explicit Baserel(uint32_t v) : Baserel(v, getDefaultType()) {}
593*0b57cec5SDimitry Andric   uint8_t getDefaultType();
594*0b57cec5SDimitry Andric 
595*0b57cec5SDimitry Andric   uint32_t rva;
596*0b57cec5SDimitry Andric   uint8_t type;
597*0b57cec5SDimitry Andric };
598*0b57cec5SDimitry Andric 
599*0b57cec5SDimitry Andric // This is a placeholder Chunk, to allow attaching a DefinedSynthetic to a
600*0b57cec5SDimitry Andric // specific place in a section, without any data. This is used for the MinGW
601*0b57cec5SDimitry Andric // specific symbol __RUNTIME_PSEUDO_RELOC_LIST_END__, even though the concept
602*0b57cec5SDimitry Andric // of an empty chunk isn't MinGW specific.
603*0b57cec5SDimitry Andric class EmptyChunk : public NonSectionChunk {
604*0b57cec5SDimitry Andric public:
605*0b57cec5SDimitry Andric   EmptyChunk() {}
606*0b57cec5SDimitry Andric   size_t getSize() const override { return 0; }
607*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override {}
608*0b57cec5SDimitry Andric };
609*0b57cec5SDimitry Andric 
610*0b57cec5SDimitry Andric // MinGW specific, for the "automatic import of variables from DLLs" feature.
611*0b57cec5SDimitry Andric // This provides the table of runtime pseudo relocations, for variable
612*0b57cec5SDimitry Andric // references that turned out to need to be imported from a DLL even though
613*0b57cec5SDimitry Andric // the reference didn't use the dllimport attribute. The MinGW runtime will
614*0b57cec5SDimitry Andric // process this table after loading, before handling control over to user
615*0b57cec5SDimitry Andric // code.
616*0b57cec5SDimitry Andric class PseudoRelocTableChunk : public NonSectionChunk {
617*0b57cec5SDimitry Andric public:
618*0b57cec5SDimitry Andric   PseudoRelocTableChunk(std::vector<RuntimePseudoReloc> &relocs)
619*0b57cec5SDimitry Andric       : relocs(std::move(relocs)) {
620*0b57cec5SDimitry Andric     setAlignment(4);
621*0b57cec5SDimitry Andric   }
622*0b57cec5SDimitry Andric   size_t getSize() const override;
623*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
624*0b57cec5SDimitry Andric 
625*0b57cec5SDimitry Andric private:
626*0b57cec5SDimitry Andric   std::vector<RuntimePseudoReloc> relocs;
627*0b57cec5SDimitry Andric };
628*0b57cec5SDimitry Andric 
629*0b57cec5SDimitry Andric // MinGW specific; information about one individual location in the image
630*0b57cec5SDimitry Andric // that needs to be fixed up at runtime after loading. This represents
631*0b57cec5SDimitry Andric // one individual element in the PseudoRelocTableChunk table.
632*0b57cec5SDimitry Andric class RuntimePseudoReloc {
633*0b57cec5SDimitry Andric public:
634*0b57cec5SDimitry Andric   RuntimePseudoReloc(Defined *sym, SectionChunk *target, uint32_t targetOffset,
635*0b57cec5SDimitry Andric                      int flags)
636*0b57cec5SDimitry Andric       : sym(sym), target(target), targetOffset(targetOffset), flags(flags) {}
637*0b57cec5SDimitry Andric 
638*0b57cec5SDimitry Andric   Defined *sym;
639*0b57cec5SDimitry Andric   SectionChunk *target;
640*0b57cec5SDimitry Andric   uint32_t targetOffset;
641*0b57cec5SDimitry Andric   // The Flags field contains the size of the relocation, in bits. No other
642*0b57cec5SDimitry Andric   // flags are currently defined.
643*0b57cec5SDimitry Andric   int flags;
644*0b57cec5SDimitry Andric };
645*0b57cec5SDimitry Andric 
646*0b57cec5SDimitry Andric // MinGW specific. A Chunk that contains one pointer-sized absolute value.
647*0b57cec5SDimitry Andric class AbsolutePointerChunk : public NonSectionChunk {
648*0b57cec5SDimitry Andric public:
649*0b57cec5SDimitry Andric   AbsolutePointerChunk(uint64_t value) : value(value) {
650*0b57cec5SDimitry Andric     setAlignment(getSize());
651*0b57cec5SDimitry Andric   }
652*0b57cec5SDimitry Andric   size_t getSize() const override;
653*0b57cec5SDimitry Andric   void writeTo(uint8_t *buf) const override;
654*0b57cec5SDimitry Andric 
655*0b57cec5SDimitry Andric private:
656*0b57cec5SDimitry Andric   uint64_t value;
657*0b57cec5SDimitry Andric };
658*0b57cec5SDimitry Andric 
659*0b57cec5SDimitry Andric // Return true if this file has the hotpatch flag set to true in the S_COMPILE3
660*0b57cec5SDimitry Andric // record in codeview debug info. Also returns true for some thunks synthesized
661*0b57cec5SDimitry Andric // by the linker.
662*0b57cec5SDimitry Andric inline bool Chunk::isHotPatchable() const {
663*0b57cec5SDimitry Andric   if (auto *sc = dyn_cast<SectionChunk>(this))
664*0b57cec5SDimitry Andric     return sc->file->hotPatchable;
665*0b57cec5SDimitry Andric   else if (isa<ImportThunkChunk>(this))
666*0b57cec5SDimitry Andric     return true;
667*0b57cec5SDimitry Andric   return false;
668*0b57cec5SDimitry Andric }
669*0b57cec5SDimitry Andric 
670*0b57cec5SDimitry Andric void applyMOV32T(uint8_t *off, uint32_t v);
671*0b57cec5SDimitry Andric void applyBranch24T(uint8_t *off, int32_t v);
672*0b57cec5SDimitry Andric 
673*0b57cec5SDimitry Andric void applyArm64Addr(uint8_t *off, uint64_t s, uint64_t p, int shift);
674*0b57cec5SDimitry Andric void applyArm64Imm(uint8_t *off, uint64_t imm, uint32_t rangeLimit);
675*0b57cec5SDimitry Andric void applyArm64Branch26(uint8_t *off, int64_t v);
676*0b57cec5SDimitry Andric 
677*0b57cec5SDimitry Andric } // namespace coff
678*0b57cec5SDimitry Andric } // namespace lld
679*0b57cec5SDimitry Andric 
680*0b57cec5SDimitry Andric namespace llvm {
681*0b57cec5SDimitry Andric template <>
682*0b57cec5SDimitry Andric struct DenseMapInfo<lld::coff::ChunkAndOffset>
683*0b57cec5SDimitry Andric     : lld::coff::ChunkAndOffset::DenseMapInfo {};
684*0b57cec5SDimitry Andric }
685*0b57cec5SDimitry Andric 
686*0b57cec5SDimitry Andric #endif
687