@@ -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
@@ -2343,7 +2345,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
23432345 if (!e.extName .empty () && !isDecorated (e.extName ))
23442346 e.extName = saver ().save (" _" + e.extName );
23452347 }
2346- config-> exports .push_back (e);
2348+ mainSymtab. exports .push_back (e);
23472349 }
23482350 }
23492351
@@ -2355,7 +2357,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
23552357
23562358 // Handle generation of import library from a def file.
23572359 if (!args.hasArg (OPT_INPUT, OPT_wholearchive_file)) {
2358- fixupExports ();
2360+ ctx. forEachSymtab ([](SymbolTable &symtab) { symtab. fixupExports (); } );
23592361 if (!config->noimplib )
23602362 createImportLibrary (/* asLib=*/ true );
23612363 return ;
@@ -2541,16 +2543,16 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
25412543 // search for its mangled names.
25422544 if (symtab.entry )
25432545 symtab.mangleMaybe (symtab.entry );
2544- });
25452546
2546- // Windows specific -- Make sure we resolve all dllexported symbols.
2547- for (Export &e : config->exports ) {
2548- if (!e.forwardTo .empty ())
2549- continue ;
2550- e.sym = ctx.symtab .addGCRoot (e.name , !e.data );
2551- if (e.source != ExportSource::Directives)
2552- e.symbolName = ctx.symtab .mangleMaybe (e.sym );
2553- }
2547+ // Windows specific -- Make sure we resolve all dllexported symbols.
2548+ for (Export &e : symtab.exports ) {
2549+ if (!e.forwardTo .empty ())
2550+ continue ;
2551+ e.sym = symtab.addGCRoot (e.name , !e.data );
2552+ if (e.source != ExportSource::Directives)
2553+ e.symbolName = symtab.mangleMaybe (e.sym );
2554+ }
2555+ });
25542556
25552557 // Add weak aliases. Weak aliases is a mechanism to give remaining
25562558 // undefined symbols final chance to be resolved successfully.
@@ -2651,7 +2653,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
26512653 if (errorCount ())
26522654 return ;
26532655
2654- config->hadExplicitExports = !config->exports .empty ();
2656+ ctx.forEachSymtab ([](SymbolTable &symtab) {
2657+ symtab.hadExplicitExports = !symtab.exports .empty ();
2658+ });
26552659 if (config->mingw ) {
26562660 // In MinGW, all symbols are automatically exported if no symbols
26572661 // are chosen to be exported.
@@ -2716,17 +2720,18 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
27162720 // Windows specific -- when we are creating a .dll file, we also
27172721 // need to create a .lib file. In MinGW mode, we only do that when the
27182722 // -implib option is given explicitly, for compatibility with GNU ld.
2719- if (!config-> exports .empty () || config->dll ) {
2723+ if (!ctx. symtab . exports .empty () || config->dll ) {
27202724 llvm::TimeTraceScope timeScope (" Create .lib exports" );
2721- fixupExports ();
2725+ ctx. forEachSymtab ([](SymbolTable &symtab) { symtab. fixupExports (); } );
27222726 if (!config->noimplib && (!config->mingw || !config->implib .empty ()))
27232727 createImportLibrary (/* asLib=*/ false );
2724- assignExportOrdinals ();
2728+ ctx.forEachSymtab (
2729+ [](SymbolTable &symtab) { symtab.assignExportOrdinals (); });
27252730 }
27262731
27272732 // Handle /output-def (MinGW specific).
27282733 if (auto *arg = args.getLastArg (OPT_output_def))
2729- writeDefFile (ctx, arg->getValue (), config-> exports );
2734+ writeDefFile (ctx, arg->getValue (), ctx. symtab . exports );
27302735
27312736 // Set extra alignment for .comm symbols
27322737 for (auto pair : config->alignComm ) {
0 commit comments