1//===- DLL.h ----------------------------------------------------*- C++ -*-===// 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#ifndef LLD_COFF_DLL_H 10#define LLD_COFF_DLL_H 11 12#include "Chunks.h" 13#include "Symbols.h" 14 15namespace lld::coff { 16 17// Windows-specific. 18// IdataContents creates all chunks for the DLL import table. 19// You are supposed to call add() to add symbols and then 20// call create() to populate the chunk vectors. 21class IdataContents { 22public: 23 void add(DefinedImportData *sym) { imports.push_back(sym); } 24 bool empty() { return imports.empty(); } 25 26 void create(COFFLinkerContext &ctx); 27 28 std::vector<DefinedImportData *> imports; 29 std::vector<Chunk *> dirs; 30 std::vector<Chunk *> lookups; 31 std::vector<Chunk *> addresses; 32 std::vector<Chunk *> hints; 33 std::vector<Chunk *> dllNames; 34}; 35 36// Windows-specific. 37// DelayLoadContents creates all chunks for the delay-load DLL import table. 38class DelayLoadContents { 39public: 40 DelayLoadContents(COFFLinkerContext &ctx) : ctx(ctx) {} 41 void add(DefinedImportData *sym) { imports.push_back(sym); } 42 bool empty() { return imports.empty(); } 43 void create(Defined *helper); 44 std::vector<Chunk *> getChunks(); 45 std::vector<Chunk *> getDataChunks(); 46 ArrayRef<Chunk *> getCodeChunks() { return thunks; } 47 ArrayRef<Chunk *> getCodePData() { return pdata; } 48 ArrayRef<Chunk *> getCodeUnwindInfo() { return unwindinfo; } 49 50 uint64_t getDirRVA() { return dirs[0]->getRVA(); } 51 uint64_t getDirSize(); 52 53private: 54 Chunk *newThunkChunk(DefinedImportData *s, Chunk *tailMerge); 55 Chunk *newTailMergeChunk(Chunk *dir); 56 Chunk *newTailMergePDataChunk(Chunk *tm, Chunk *unwind); 57 Chunk *newTailMergeUnwindInfoChunk(); 58 59 Defined *helper; 60 std::vector<DefinedImportData *> imports; 61 std::vector<Chunk *> dirs; 62 std::vector<Chunk *> moduleHandles; 63 std::vector<Chunk *> addresses; 64 std::vector<Chunk *> names; 65 std::vector<Chunk *> hintNames; 66 std::vector<Chunk *> thunks; 67 std::vector<Chunk *> pdata; 68 std::vector<Chunk *> unwindinfo; 69 std::vector<Chunk *> dllNames; 70 71 COFFLinkerContext &ctx; 72}; 73 74// Windows-specific. 75// EdataContents creates all chunks for the DLL export table. 76class EdataContents { 77public: 78 EdataContents(COFFLinkerContext &ctx); 79 std::vector<Chunk *> chunks; 80 81 uint64_t getRVA() { return chunks[0]->getRVA(); } 82 uint64_t getSize() { 83 return chunks.back()->getRVA() + chunks.back()->getSize() - getRVA(); 84 } 85 86 COFFLinkerContext &ctx; 87}; 88 89} // namespace lld::coff 90 91#endif 92