@@ -458,7 +458,7 @@ void LinkerDriver::parseDirectives(InputFile *file) {
458458 // declarations, many object files may end up with having the
459459 // same /EXPORT options. In order to save cost of parsing them,
460460 // we dedup them first.
461- if (!directivesExports.insert (e).second )
461+ if (!file-> symtab . directivesExports .insert (e).second )
462462 continue ;
463463
464464 Export exp = parseExport (e);
@@ -469,7 +469,7 @@ void LinkerDriver::parseDirectives(InputFile *file) {
469469 exp.extName = saver ().save (" _" + exp.extName );
470470 }
471471 exp.source = ExportSource::Directives;
472- ctx. config .exports .push_back (exp);
472+ file-> symtab .exports .push_back (exp);
473473 }
474474
475475 // Handle /include: in bulk.
@@ -956,7 +956,7 @@ std::string LinkerDriver::getImportName(bool asLib) {
956956void LinkerDriver::createImportLibrary (bool asLib) {
957957 llvm::TimeTraceScope timeScope (" Create import library" );
958958 std::vector<COFFShortExport> exports;
959- for (Export &e1 : ctx.config .exports ) {
959+ for (Export &e1 : ctx.symtab .exports ) {
960960 COFFShortExport e2 ;
961961 e2 .Name = std::string (e1 .name );
962962 e2 .SymbolName = std::string (e1 .symbolName );
@@ -1069,7 +1069,7 @@ void LinkerDriver::parseModuleDefs(StringRef path) {
10691069 e2 .isPrivate = e1 .Private ;
10701070 e2 .constant = e1 .Constant ;
10711071 e2 .source = ExportSource::ModuleDefinition;
1072- ctx.config .exports .push_back (e2 );
1072+ ctx.symtab .exports .push_back (e2 );
10731073 }
10741074}
10751075
@@ -1222,8 +1222,10 @@ static void findKeepUniqueSections(COFFLinkerContext &ctx) {
12221222
12231223 // Exported symbols could be address-significant in other executables or DSOs,
12241224 // so we conservatively mark them as address-significant.
1225- for (Export &r : ctx.config .exports )
1226- markAddrsig (r.sym );
1225+ ctx.forEachSymtab ([](SymbolTable &symtab) {
1226+ for (Export &r : symtab.exports )
1227+ markAddrsig (r.sym );
1228+ });
12271229
12281230 // Visit the address-significance table in each object file and mark each
12291231 // referenced symbol as address-significant.
@@ -1376,13 +1378,13 @@ void LinkerDriver::maybeCreateECExportThunk(StringRef name, Symbol *&sym) {
13761378void LinkerDriver::createECExportThunks () {
13771379 // Check if EXP+ symbols have corresponding $hp_target symbols and use them
13781380 // to create export thunks when available.
1379- for (Symbol *s : ctx.symtab . expSymbols ) {
1381+ for (Symbol *s : ctx.symtabEC -> expSymbols ) {
13801382 if (!s->isUsedInRegularObj )
13811383 continue ;
13821384 assert (s->getName ().starts_with (" EXP+" ));
13831385 std::string targetName =
13841386 (s->getName ().substr (strlen (" EXP+" )) + " $hp_target" ).str ();
1385- Symbol *sym = ctx.symtab . find (targetName);
1387+ Symbol *sym = ctx.symtabEC -> find (targetName);
13861388 if (!sym)
13871389 continue ;
13881390 Defined *targetSym;
@@ -1407,7 +1409,7 @@ void LinkerDriver::createECExportThunks() {
14071409 if (ctx.symtabEC ->entry )
14081410 maybeCreateECExportThunk (ctx.symtabEC ->entry ->getName (),
14091411 ctx.symtabEC ->entry );
1410- for (Export &e : ctx.config . exports ) {
1412+ for (Export &e : ctx.symtabEC -> exports ) {
14111413 if (!e.data )
14121414 maybeCreateECExportThunk (e.extName .empty () ? e.name : e.extName , e.sym );
14131415 }
@@ -1430,7 +1432,7 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
14301432 if (!ctx.config .dll )
14311433 return ;
14321434
1433- if (!ctx.config .exports .empty ())
1435+ if (!ctx.symtab .exports .empty ())
14341436 return ;
14351437 if (args.hasArg (OPT_exclude_all_symbols))
14361438 return ;
@@ -1466,7 +1468,7 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
14661468 if (!(c->getOutputCharacteristics () & IMAGE_SCN_MEM_EXECUTE))
14671469 e.data = true ;
14681470 s->isUsedInRegularObj = true ;
1469- ctx.config .exports .push_back (e);
1471+ ctx.symtab .exports .push_back (e);
14701472 });
14711473}
14721474
@@ -2339,7 +2341,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
23392341 if (!e.extName .empty () && !isDecorated (e.extName ))
23402342 e.extName = saver ().save (" _" + e.extName );
23412343 }
2342- config-> exports .push_back (e);
2344+ mainSymtab. exports .push_back (e);
23432345 }
23442346 }
23452347
@@ -2351,7 +2353,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
23512353
23522354 // Handle generation of import library from a def file.
23532355 if (!args.hasArg (OPT_INPUT, OPT_wholearchive_file)) {
2354- fixupExports ();
2356+ ctx. forEachSymtab ([](SymbolTable &symtab) { symtab. fixupExports (); } );
23552357 if (!config->noimplib )
23562358 createImportLibrary (/* asLib=*/ true );
23572359 return ;
@@ -2537,16 +2539,16 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
25372539 // search for its mangled names.
25382540 if (symtab.entry )
25392541 symtab.mangleMaybe (symtab.entry );
2540- });
25412542
2542- // Windows specific -- Make sure we resolve all dllexported symbols.
2543- for (Export &e : config->exports ) {
2544- if (!e.forwardTo .empty ())
2545- continue ;
2546- e.sym = ctx.symtab .addGCRoot (e.name , !e.data );
2547- if (e.source != ExportSource::Directives)
2548- e.symbolName = ctx.symtab .mangleMaybe (e.sym );
2549- }
2543+ // Windows specific -- Make sure we resolve all dllexported symbols.
2544+ for (Export &e : symtab.exports ) {
2545+ if (!e.forwardTo .empty ())
2546+ continue ;
2547+ e.sym = symtab.addGCRoot (e.name , !e.data );
2548+ if (e.source != ExportSource::Directives)
2549+ e.symbolName = symtab.mangleMaybe (e.sym );
2550+ }
2551+ });
25502552
25512553 // Add weak aliases. Weak aliases is a mechanism to give remaining
25522554 // undefined symbols final chance to be resolved successfully.
@@ -2647,7 +2649,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
26472649 if (errorCount ())
26482650 return ;
26492651
2650- config->hadExplicitExports = !config->exports .empty ();
2652+ ctx.forEachSymtab ([](SymbolTable &symtab) {
2653+ symtab.hadExplicitExports = !symtab.exports .empty ();
2654+ });
26512655 if (config->mingw ) {
26522656 // In MinGW, all symbols are automatically exported if no symbols
26532657 // are chosen to be exported.
@@ -2712,17 +2716,18 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
27122716 // Windows specific -- when we are creating a .dll file, we also
27132717 // need to create a .lib file. In MinGW mode, we only do that when the
27142718 // -implib option is given explicitly, for compatibility with GNU ld.
2715- if (!config-> exports .empty () || config->dll ) {
2719+ if (!ctx. symtab . exports .empty () || config->dll ) {
27162720 llvm::TimeTraceScope timeScope (" Create .lib exports" );
2717- fixupExports ();
2721+ ctx. forEachSymtab ([](SymbolTable &symtab) { symtab. fixupExports (); } );
27182722 if (!config->noimplib && (!config->mingw || !config->implib .empty ()))
27192723 createImportLibrary (/* asLib=*/ false );
2720- assignExportOrdinals ();
2724+ ctx.forEachSymtab (
2725+ [](SymbolTable &symtab) { symtab.assignExportOrdinals (); });
27212726 }
27222727
27232728 // Handle /output-def (MinGW specific).
27242729 if (auto *arg = args.getLastArg (OPT_output_def))
2725- writeDefFile (ctx, arg->getValue (), config-> exports );
2730+ writeDefFile (ctx, arg->getValue (), ctx. symtab . exports );
27262731
27272732 // Set extra alignment for .comm symbols
27282733 for (auto pair : config->alignComm ) {
0 commit comments