Rafael Espindola | beee25e | 2015-08-14 14:12:54 | [diff] [blame] | 1 | //===- DLL.h ----------------------------------------------------*- C++ -*-===// |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 | [diff] [blame] | 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 |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 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 | |
Nico Weber | 7c26641 | 2022-08-08 15:32:26 | [diff] [blame] | 15 | namespace lld::coff { |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 16 | |
| 17 | // Windows-specific. |
Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 | [diff] [blame] | 18 | // IdataContents creates all chunks for the DLL import table. |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 19 | // You are supposed to call add() to add symbols and then |
Martin Storsjo | 5f6d527 | 2018-09-21 22:01:06 | [diff] [blame] | 20 | // call create() to populate the chunk vectors. |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 21 | class IdataContents { |
| 22 | public: |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 23 | void add(DefinedImportData *sym) { imports.push_back(sym); } |
| 24 | bool empty() { return imports.empty(); } |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 25 | |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 26 | void create(COFFLinkerContext &ctx); |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 27 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 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; |
Jacek Caban | 82a3646 | 2024-09-12 20:20:50 | [diff] [blame] | 34 | std::vector<Chunk *> auxIat; |
Jacek Caban | a17a245 | 2024-09-17 12:40:24 | [diff] [blame] | 35 | std::vector<Chunk *> auxIatCopy; |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 36 | }; |
| 37 | |
Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 | [diff] [blame] | 38 | // Windows-specific. |
Rui Ueyama | a77336b | 2015-06-21 22:31:52 | [diff] [blame] | 39 | // DelayLoadContents creates all chunks for the delay-load DLL import table. |
| 40 | class DelayLoadContents { |
| 41 | public: |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 42 | DelayLoadContents(COFFLinkerContext &ctx) : ctx(ctx) {} |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 43 | void add(DefinedImportData *sym) { imports.push_back(sym); } |
| 44 | bool empty() { return imports.empty(); } |
Jacek Caban | 97aa56a | 2025-01-28 11:07:35 | [diff] [blame] | 45 | void create(); |
Rui Ueyama | 382dc96 | 2015-06-26 21:40:15 | [diff] [blame] | 46 | std::vector<Chunk *> getChunks(); |
| 47 | std::vector<Chunk *> getDataChunks(); |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 48 | ArrayRef<Chunk *> getCodeChunks() { return thunks; } |
serge-sans-paille | c512eda | 2023-01-13 13:25:54 | [diff] [blame] | 49 | ArrayRef<Chunk *> getCodePData() { return pdata; } |
| 50 | ArrayRef<Chunk *> getCodeUnwindInfo() { return unwindinfo; } |
Jacek Caban | 18fa9fa | 2024-09-30 18:26:55 | [diff] [blame] | 51 | ArrayRef<Chunk *> getAuxIat() { return auxIat; } |
| 52 | ArrayRef<Chunk *> getAuxIatCopy() { return auxIatCopy; } |
Rui Ueyama | a77336b | 2015-06-21 22:31:52 | [diff] [blame] | 53 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 54 | uint64_t getDirRVA() { return dirs[0]->getRVA(); } |
Rui Ueyama | a77336b | 2015-06-21 22:31:52 | [diff] [blame] | 55 | uint64_t getDirSize(); |
| 56 | |
| 57 | private: |
Martin Storsjo | 6bd26db | 2019-07-11 21:19:11 | [diff] [blame] | 58 | Chunk *newThunkChunk(DefinedImportData *s, Chunk *tailMerge); |
Jacek Caban | 97aa56a | 2025-01-28 11:07:35 | [diff] [blame] | 59 | Chunk *newTailMergeChunk(SymbolTable &symtab, Chunk *dir); |
| 60 | Chunk *newTailMergePDataChunk(SymbolTable &symtab, Chunk *tm); |
Rui Ueyama | 35ccb0f | 2015-07-25 00:20:06 | [diff] [blame] | 61 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 62 | std::vector<DefinedImportData *> imports; |
| 63 | std::vector<Chunk *> dirs; |
| 64 | std::vector<Chunk *> moduleHandles; |
| 65 | std::vector<Chunk *> addresses; |
| 66 | std::vector<Chunk *> names; |
| 67 | std::vector<Chunk *> hintNames; |
| 68 | std::vector<Chunk *> thunks; |
serge-sans-paille | c512eda | 2023-01-13 13:25:54 | [diff] [blame] | 69 | std::vector<Chunk *> pdata; |
| 70 | std::vector<Chunk *> unwindinfo; |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 71 | std::vector<Chunk *> dllNames; |
Jacek Caban | 18fa9fa | 2024-09-30 18:26:55 | [diff] [blame] | 72 | std::vector<Chunk *> auxIat; |
| 73 | std::vector<Chunk *> auxIatCopy; |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 74 | |
| 75 | COFFLinkerContext &ctx; |
Rui Ueyama | a77336b | 2015-06-21 22:31:52 | [diff] [blame] | 76 | }; |
| 77 | |
Jacek Caban | 2cfddda | 2025-01-20 22:02:26 | [diff] [blame] | 78 | // Create all chunks for the DLL export table. |
Jacek Caban | 455b3d6 | 2025-01-21 09:41:15 | [diff] [blame] | 79 | void createEdataChunks(SymbolTable &symtab, std::vector<Chunk *> &chunks); |
Rui Ueyama | 97dff9e | 2015-06-17 00:16:33 | [diff] [blame] | 80 | |
Nico Weber | 7c26641 | 2022-08-08 15:32:26 | [diff] [blame] | 81 | } // namespace lld::coff |
Rui Ueyama | 4b22fa7 | 2015-06-07 01:15:04 | [diff] [blame] | 82 | |
| 83 | #endif |