@@ -1377,18 +1377,19 @@ void LinkerDriver::pullArm64ECIcallHelper() {
13771377// explicitly specified. The automatic behavior can be disabled using the
13781378// -exclude-all-symbols option, so that lld-link behaves like link.exe rather
13791379// than MinGW in the case that nothing is explicitly exported.
1380- void LinkerDriver::maybeExportMinGWSymbols (const opt::InputArgList &args) {
1380+ void LinkerDriver::maybeExportMinGWSymbols (SymbolTable &symtab,
1381+ const opt::InputArgList &args) {
13811382 if (!args.hasArg (OPT_export_all_symbols)) {
13821383 if (!ctx.config .dll )
13831384 return ;
13841385
1385- if (!ctx. symtab .exports .empty ())
1386+ if (!symtab.exports .empty ())
13861387 return ;
13871388 if (args.hasArg (OPT_exclude_all_symbols))
13881389 return ;
13891390 }
13901391
1391- AutoExporter exporter (ctx , excludedSymbols);
1392+ AutoExporter exporter (symtab , excludedSymbols);
13921393
13931394 for (auto *arg : args.filtered (OPT_wholearchive_file))
13941395 if (std::optional<StringRef> path = findFile (arg->getValue ()))
@@ -1398,10 +1399,10 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
13981399 SmallVector<StringRef, 2 > vec;
13991400 StringRef (arg->getValue ()).split (vec, ' ,' );
14001401 for (StringRef sym : vec)
1401- exporter.addExcludedSymbol (ctx. symtab .mangle (sym));
1402+ exporter.addExcludedSymbol (symtab.mangle (sym));
14021403 }
14031404
1404- ctx. symtab .forEachSymbol ([&](Symbol *s) {
1405+ symtab.forEachSymbol ([&](Symbol *s) {
14051406 auto *def = dyn_cast<Defined>(s);
14061407 if (!exporter.shouldExport (def))
14071408 return ;
@@ -1418,7 +1419,7 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
14181419 if (!(c->getOutputCharacteristics () & IMAGE_SCN_MEM_EXECUTE))
14191420 e.data = true ;
14201421 s->isUsedInRegularObj = true ;
1421- ctx. symtab .exports .push_back (e);
1422+ symtab.exports .push_back (e);
14221423 });
14231424}
14241425
@@ -2613,14 +2614,14 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
26132614 if (errorCount ())
26142615 return ;
26152616
2616- ctx.forEachSymtab ([](SymbolTable &symtab) {
2617+ ctx.forEachSymtab ([& ](SymbolTable &symtab) {
26172618 symtab.hadExplicitExports = !symtab.exports .empty ();
2619+ if (config->mingw ) {
2620+ // In MinGW, all symbols are automatically exported if no symbols
2621+ // are chosen to be exported.
2622+ maybeExportMinGWSymbols (symtab, args);
2623+ }
26182624 });
2619- if (config->mingw ) {
2620- // In MinGW, all symbols are automatically exported if no symbols
2621- // are chosen to be exported.
2622- maybeExportMinGWSymbols (args);
2623- }
26242625
26252626 // Do LTO by compiling bitcode input files to a set of native COFF files then
26262627 // link those files (unless -thinlto-index-only was given, in which case we
0 commit comments