Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 1 | //===- MinGW.cpp ----------------------------------------------------------===// |
| 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 |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "MinGW.h" |
Amy Huang | 6f7483b | 2021-09-16 23:48:26 | [diff] [blame] | 10 | #include "COFFLinkerContext.h" |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 11 | #include "Driver.h" |
| 12 | #include "InputFiles.h" |
Martin Storsjo | 0010707 | 2017-11-29 05:50:49 | [diff] [blame] | 13 | #include "SymbolTable.h" |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 14 | #include "llvm/ADT/DenseMap.h" |
| 15 | #include "llvm/ADT/DenseSet.h" |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 16 | #include "llvm/Object/COFF.h" |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 17 | #include "llvm/Support/Parallel.h" |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 18 | #include "llvm/Support/Path.h" |
Alexandre Ganea | 356139b | 2023-10-06 02:33:58 | [diff] [blame] | 19 | #include "llvm/Support/TimeProfiler.h" |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 20 | #include "llvm/Support/raw_ostream.h" |
| 21 | |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | using namespace llvm::COFF; |
Reid Kleckner | 8a310f4 | 2020-02-20 01:05:42 | [diff] [blame] | 24 | using namespace lld; |
| 25 | using namespace lld::coff; |
Fangrui Song | d79c3be | 2019-10-10 11:27:58 | [diff] [blame] | 26 | |
Martin Storsjö | 5d513ef | 2022-07-17 21:11:37 | [diff] [blame] | 27 | AutoExporter::AutoExporter( |
Jacek Caban | f729477 | 2025-02-06 21:25:53 | [diff] [blame] | 28 | SymbolTable &symtab, const llvm::DenseSet<StringRef> &manualExcludeSymbols) |
| 29 | : manualExcludeSymbols(manualExcludeSymbols), symtab(symtab) { |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 30 | excludeLibs = { |
Rui Ueyama | 659f275 | 2019-02-19 22:06:44 | [diff] [blame] | 31 | "libgcc", |
| 32 | "libgcc_s", |
| 33 | "libstdc++", |
| 34 | "libmingw32", |
| 35 | "libmingwex", |
| 36 | "libg2c", |
| 37 | "libsupc++", |
| 38 | "libobjc", |
| 39 | "libgcj", |
| 40 | "libclang_rt.builtins", |
| 41 | "libclang_rt.builtins-aarch64", |
| 42 | "libclang_rt.builtins-arm", |
| 43 | "libclang_rt.builtins-i386", |
| 44 | "libclang_rt.builtins-x86_64", |
Peiyuan Song | da324f9 | 2020-07-30 20:32:37 | [diff] [blame] | 45 | "libclang_rt.profile", |
| 46 | "libclang_rt.profile-aarch64", |
| 47 | "libclang_rt.profile-arm", |
| 48 | "libclang_rt.profile-i386", |
| 49 | "libclang_rt.profile-x86_64", |
Rui Ueyama | 659f275 | 2019-02-19 22:06:44 | [diff] [blame] | 50 | "libc++", |
| 51 | "libc++abi", |
Michael Kruse | 5c8c2b3 | 2025-02-08 17:02:54 | [diff] [blame] | 52 | "libflang_rt.runtime", |
Rui Ueyama | 659f275 | 2019-02-19 22:06:44 | [diff] [blame] | 53 | "libunwind", |
| 54 | "libmsvcrt", |
Martin Storsjö | af93db9 | 2025-03-21 13:33:25 | [diff] [blame] | 55 | "libmsvcrt-os", |
Rui Ueyama | 659f275 | 2019-02-19 22:06:44 | [diff] [blame] | 56 | "libucrtbase", |
Martin Storsjö | af93db9 | 2025-03-21 13:33:25 | [diff] [blame] | 57 | "libucrt", |
| 58 | "libucrtapp", |
| 59 | "libpthread", |
| 60 | "libwinpthread", |
Rui Ueyama | 659f275 | 2019-02-19 22:06:44 | [diff] [blame] | 61 | }; |
| 62 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 63 | excludeObjects = { |
Rui Ueyama | 659f275 | 2019-02-19 22:06:44 | [diff] [blame] | 64 | "crt0.o", "crt1.o", "crt1u.o", "crt2.o", "crt2u.o", "dllcrt1.o", |
| 65 | "dllcrt2.o", "gcrt0.o", "gcrt1.o", "gcrt2.o", "crtbegin.o", "crtend.o", |
| 66 | }; |
| 67 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 68 | excludeSymbolPrefixes = { |
Martin Storsjo | 32e651e | 2018-09-26 06:13:47 | [diff] [blame] | 69 | // Import symbols |
| 70 | "__imp_", |
| 71 | "__IMPORT_DESCRIPTOR_", |
| 72 | // Extra import symbols from GNU import libraries |
| 73 | "__nm_", |
| 74 | // C++ symbols |
| 75 | "__rtti_", |
| 76 | "__builtin_", |
Nico Weber | 79a8476 | 2019-10-10 02:04:56 | [diff] [blame] | 77 | // Artificial symbols such as .refptr |
Martin Storsjo | 32e651e | 2018-09-26 06:13:47 | [diff] [blame] | 78 | ".", |
Peiyuan Song | da324f9 | 2020-07-30 20:32:37 | [diff] [blame] | 79 | // profile generate symbols |
| 80 | "__profc_", |
| 81 | "__profd_", |
| 82 | "__profvp_", |
Martin Storsjo | 32e651e | 2018-09-26 06:13:47 | [diff] [blame] | 83 | }; |
Rui Ueyama | 659f275 | 2019-02-19 22:06:44 | [diff] [blame] | 84 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 85 | excludeSymbolSuffixes = { |
Martin Storsjo | 32e651e | 2018-09-26 06:13:47 | [diff] [blame] | 86 | "_iname", |
| 87 | "_NULL_THUNK_DATA", |
| 88 | }; |
Rui Ueyama | 659f275 | 2019-02-19 22:06:44 | [diff] [blame] | 89 | |
Jacek Caban | f729477 | 2025-02-06 21:25:53 | [diff] [blame] | 90 | if (symtab.machine == I386) { |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 91 | excludeSymbols = { |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 92 | "__NULL_IMPORT_DESCRIPTOR", |
| 93 | "__pei386_runtime_relocator", |
| 94 | "_do_pseudo_reloc", |
| 95 | "_impure_ptr", |
| 96 | "__impure_ptr", |
| 97 | "__fmode", |
| 98 | "_environ", |
| 99 | "___dso_handle", |
Jacek Caban | abd31b4 | 2025-02-07 14:52:39 | [diff] [blame] | 100 | "__load_config_used", |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 101 | // These are the MinGW names that differ from the standard |
| 102 | // ones (lacking an extra underscore). |
| 103 | "_DllMain@12", |
| 104 | "_DllEntryPoint@12", |
| 105 | "_DllMainCRTStartup@12", |
| 106 | }; |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 107 | excludeSymbolPrefixes.insert("__head_"); |
Rui Ueyama | c121401 | 2017-11-22 09:06:27 | [diff] [blame] | 108 | } else { |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 109 | excludeSymbols = { |
Martin Storsjo | 5fefad7 | 2018-09-18 07:22:05 | [diff] [blame] | 110 | "__NULL_IMPORT_DESCRIPTOR", |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 111 | "_pei386_runtime_relocator", |
| 112 | "do_pseudo_reloc", |
| 113 | "impure_ptr", |
| 114 | "_impure_ptr", |
| 115 | "_fmode", |
| 116 | "environ", |
| 117 | "__dso_handle", |
Jacek Caban | abd31b4 | 2025-02-07 14:52:39 | [diff] [blame] | 118 | "_load_config_used", |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 119 | // These are the MinGW names that differ from the standard |
| 120 | // ones (lacking an extra underscore). |
| 121 | "DllMain", |
| 122 | "DllEntryPoint", |
| 123 | "DllMainCRTStartup", |
| 124 | }; |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 125 | excludeSymbolPrefixes.insert("_head_"); |
Rui Ueyama | c121401 | 2017-11-22 09:06:27 | [diff] [blame] | 126 | } |
Jacek Caban | abd31b4 | 2025-02-07 14:52:39 | [diff] [blame] | 127 | if (symtab.isEC()) { |
| 128 | excludeSymbols.insert("__chpe_metadata"); |
| 129 | excludeSymbolPrefixes.insert("__os_arm64x_"); |
| 130 | } |
Martin Storsjo | a47957a | 2018-09-04 20:56:56 | [diff] [blame] | 131 | } |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 132 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 133 | void AutoExporter::addWholeArchive(StringRef path) { |
| 134 | StringRef libName = sys::path::filename(path); |
Martin Storsjo | a47957a | 2018-09-04 20:56:56 | [diff] [blame] | 135 | // Drop the file extension, to match the processing below. |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 136 | libName = libName.substr(0, libName.rfind('.')); |
| 137 | excludeLibs.erase(libName); |
Martin Storsjo | a47957a | 2018-09-04 20:56:56 | [diff] [blame] | 138 | } |
| 139 | |
Martin Storsjö | d1da646 | 2022-07-18 20:43:02 | [diff] [blame] | 140 | void AutoExporter::addExcludedSymbol(StringRef symbol) { |
| 141 | excludeSymbols.insert(symbol); |
| 142 | } |
| 143 | |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 144 | bool AutoExporter::shouldExport(Defined *sym) const { |
Martin Storsjö | 2b01a41 | 2021-04-29 08:57:33 | [diff] [blame] | 145 | if (!sym || !sym->getChunk()) |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 146 | return false; |
Rui Ueyama | c121401 | 2017-11-22 09:06:27 | [diff] [blame] | 147 | |
Martin Storsjo | fe3eda9 | 2017-11-16 07:22:44 | [diff] [blame] | 148 | // Only allow the symbol kinds that make sense to export; in particular, |
| 149 | // disallow import symbols. |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 150 | if (!isa<DefinedRegular>(sym) && !isa<DefinedCommon>(sym)) |
Martin Storsjo | fe3eda9 | 2017-11-16 07:22:44 | [diff] [blame] | 151 | return false; |
Martin Storsjö | 5d513ef | 2022-07-17 21:11:37 | [diff] [blame] | 152 | if (excludeSymbols.count(sym->getName()) || manualExcludeSymbols.count(sym->getName())) |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 153 | return false; |
Rui Ueyama | c121401 | 2017-11-22 09:06:27 | [diff] [blame] | 154 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 155 | for (StringRef prefix : excludeSymbolPrefixes.keys()) |
Fangrui Song | 8d85c96 | 2023-06-05 21:36:19 | [diff] [blame] | 156 | if (sym->getName().starts_with(prefix)) |
Martin Storsjo | 32e651e | 2018-09-26 06:13:47 | [diff] [blame] | 157 | return false; |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 158 | for (StringRef suffix : excludeSymbolSuffixes.keys()) |
Fangrui Song | 8d85c96 | 2023-06-05 21:36:19 | [diff] [blame] | 159 | if (sym->getName().ends_with(suffix)) |
Martin Storsjo | 32e651e | 2018-09-26 06:13:47 | [diff] [blame] | 160 | return false; |
Martin Storsjo | 0010707 | 2017-11-29 05:50:49 | [diff] [blame] | 161 | |
| 162 | // If a corresponding __imp_ symbol exists and is defined, don't export it. |
Jacek Caban | f729477 | 2025-02-06 21:25:53 | [diff] [blame] | 163 | if (symtab.find(("__imp_" + sym->getName()).str())) |
Martin Storsjo | 0010707 | 2017-11-29 05:50:49 | [diff] [blame] | 164 | return false; |
| 165 | |
Martin Storsjo | fe3eda9 | 2017-11-16 07:22:44 | [diff] [blame] | 166 | // Check that file is non-null before dereferencing it, symbols not |
| 167 | // originating in regular object files probably shouldn't be exported. |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 168 | if (!sym->getFile()) |
Martin Storsjo | fe3eda9 | 2017-11-16 07:22:44 | [diff] [blame] | 169 | return false; |
Rui Ueyama | c121401 | 2017-11-22 09:06:27 | [diff] [blame] | 170 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 171 | StringRef libName = sys::path::filename(sym->getFile()->parentName); |
Rui Ueyama | c121401 | 2017-11-22 09:06:27 | [diff] [blame] | 172 | |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 173 | // Drop the file extension. |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 174 | libName = libName.substr(0, libName.rfind('.')); |
| 175 | if (!libName.empty()) |
| 176 | return !excludeLibs.count(libName); |
Rui Ueyama | c121401 | 2017-11-22 09:06:27 | [diff] [blame] | 177 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 178 | StringRef fileName = sys::path::filename(sym->getFile()->getName()); |
| 179 | return !excludeObjects.count(fileName); |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 180 | } |
| 181 | |
Fangrui Song | 983f88c1 | 2024-12-06 04:41:36 | [diff] [blame] | 182 | void lld::coff::writeDefFile(COFFLinkerContext &ctx, StringRef name, |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 183 | const std::vector<Export> &exports) { |
Alexandre Ganea | 356139b | 2023-10-06 02:33:58 | [diff] [blame] | 184 | llvm::TimeTraceScope timeScope("Write .def file"); |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 185 | std::error_code ec; |
Fangrui Song | d9b948b | 2019-08-05 05:43:48 | [diff] [blame] | 186 | raw_fd_ostream os(name, ec, sys::fs::OF_None); |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 187 | if (ec) |
Fangrui Song | 983f88c1 | 2024-12-06 04:41:36 | [diff] [blame] | 188 | Fatal(ctx) << "cannot open " << name << ": " << ec.message(); |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 189 | |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 190 | os << "EXPORTS\n"; |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 191 | for (const Export &e : exports) { |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 192 | os << " " << e.exportName << " " |
| 193 | << "@" << e.ordinal; |
| 194 | if (auto *def = dyn_cast_or_null<Defined>(e.sym)) { |
| 195 | if (def && def->getChunk() && |
| 196 | !(def->getChunk()->getOutputCharacteristics() & IMAGE_SCN_MEM_EXECUTE)) |
| 197 | os << " DATA"; |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 198 | } |
Rui Ueyama | 136d27a | 2019-07-11 05:40:30 | [diff] [blame] | 199 | os << "\n"; |
Martin Storsjo | e1f894d | 2017-10-19 19:49:38 | [diff] [blame] | 200 | } |
| 201 | } |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 202 | |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 203 | static StringRef mangle(Twine sym, MachineTypes machine) { |
| 204 | assert(machine != IMAGE_FILE_MACHINE_UNKNOWN); |
| 205 | if (machine == I386) |
Alexandre Ganea | 83d59e0 | 2022-01-20 19:53:18 | [diff] [blame] | 206 | return saver().save("_" + sym); |
| 207 | return saver().save(sym); |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | // Handles -wrap option. |
| 211 | // |
| 212 | // This function instantiates wrapper symbols. At this point, they seem |
| 213 | // like they are not being used at all, so we explicitly set some flags so |
| 214 | // that LTO won't eliminate them. |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 215 | void lld::coff::addWrappedSymbols(SymbolTable &symtab, |
| 216 | opt::InputArgList &args) { |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 217 | std::vector<WrappedSymbol> v; |
| 218 | DenseSet<StringRef> seen; |
| 219 | |
| 220 | for (auto *arg : args.filtered(OPT_wrap)) { |
| 221 | StringRef name = arg->getValue(); |
| 222 | if (!seen.insert(name).second) |
| 223 | continue; |
| 224 | |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 225 | Symbol *sym = symtab.findUnderscore(name); |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 226 | if (!sym) |
| 227 | continue; |
| 228 | |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 229 | Symbol *real = |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 230 | symtab.addUndefined(mangle("__real_" + name, symtab.machine)); |
Amy Huang | 5a58b19 | 2023-01-10 04:37:28 | [diff] [blame] | 231 | Symbol *wrap = |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 232 | symtab.addUndefined(mangle("__wrap_" + name, symtab.machine)); |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 233 | v.push_back({sym, real, wrap}); |
| 234 | |
| 235 | // These symbols may seem undefined initially, but don't bail out |
Amy Huang | 6f7483b | 2021-09-16 23:48:26 | [diff] [blame] | 236 | // at symtab.reportUnresolvable() due to them, but let wrapSymbols |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 237 | // below sort things out before checking finally with |
Amy Huang | 6f7483b | 2021-09-16 23:48:26 | [diff] [blame] | 238 | // symtab.resolveRemainingUndefines(). |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 239 | sym->deferUndefined = true; |
| 240 | real->deferUndefined = true; |
| 241 | // We want to tell LTO not to inline symbols to be overwritten |
| 242 | // because LTO doesn't know the final symbol contents after renaming. |
| 243 | real->canInline = false; |
| 244 | sym->canInline = false; |
| 245 | |
| 246 | // Tell LTO not to eliminate these symbols. |
| 247 | sym->isUsedInRegularObj = true; |
| 248 | if (!isa<Undefined>(wrap)) |
| 249 | wrap->isUsedInRegularObj = true; |
| 250 | } |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 251 | symtab.wrapped = std::move(v); |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | // Do renaming for -wrap by updating pointers to symbols. |
| 255 | // |
| 256 | // When this function is executed, only InputFiles and symbol table |
| 257 | // contain pointers to symbol objects. We visit them to replace pointers, |
| 258 | // so that wrapped symbols are swapped as instructed by the command line. |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 259 | void lld::coff::wrapSymbols(SymbolTable &symtab) { |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 260 | DenseMap<Symbol *, Symbol *> map; |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 261 | for (const WrappedSymbol &w : symtab.wrapped) { |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 262 | map[w.sym] = w.wrap; |
| 263 | map[w.real] = w.sym; |
Martin Storsjö | 0b2d84f | 2020-11-17 14:05:29 | [diff] [blame] | 264 | if (Defined *d = dyn_cast<Defined>(w.wrap)) { |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 265 | Symbol *imp = symtab.find(("__imp_" + w.sym->getName()).str()); |
Martin Storsjö | 0b2d84f | 2020-11-17 14:05:29 | [diff] [blame] | 266 | // Create a new defined local import for the wrap symbol. If |
| 267 | // no imp prefixed symbol existed, there's no need for it. |
| 268 | // (We can't easily distinguish whether any object file actually |
| 269 | // referenced it or not, though.) |
| 270 | if (imp) { |
| 271 | DefinedLocalImport *wrapimp = make<DefinedLocalImport>( |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 272 | symtab.ctx, saver().save("__imp_" + w.wrap->getName()), d); |
| 273 | symtab.localImportChunks.push_back(wrapimp->getChunk()); |
Martin Storsjö | 0b2d84f | 2020-11-17 14:05:29 | [diff] [blame] | 274 | map[imp] = wrapimp; |
| 275 | } |
| 276 | } |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | // Update pointers in input files. |
Jacek Caban | 94d9563 | 2025-02-10 21:52:11 | [diff] [blame] | 280 | parallelForEach(symtab.ctx.objFileInstances, [&](ObjFile *file) { |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 281 | MutableArrayRef<Symbol *> syms = file->getMutableSymbols(); |
Jez Ng | 3df4c5a | 2023-01-27 01:28:58 | [diff] [blame] | 282 | for (auto &sym : syms) |
| 283 | if (Symbol *s = map.lookup(sym)) |
| 284 | sym = s; |
Martin Storsjö | 3785a41 | 2020-10-06 10:54:49 | [diff] [blame] | 285 | }); |
| 286 | } |