@@ -458,7 +458,7 @@ void LinkerDriver::parseDirectives(InputFile *file) {
458
458
// declarations, many object files may end up with having the
459
459
// same /EXPORT options. In order to save cost of parsing them,
460
460
// we dedup them first.
461
- if (!directivesExports.insert (e).second )
461
+ if (!file-> symtab . directivesExports .insert (e).second )
462
462
continue ;
463
463
464
464
Export exp = parseExport (e);
@@ -469,7 +469,7 @@ void LinkerDriver::parseDirectives(InputFile *file) {
469
469
exp .extName = saver ().save (" _" + exp .extName );
470
470
}
471
471
exp .source = ExportSource::Directives;
472
- ctx. config .exports .push_back (exp );
472
+ file-> symtab .exports .push_back (exp );
473
473
}
474
474
475
475
// Handle /include: in bulk.
@@ -956,7 +956,7 @@ std::string LinkerDriver::getImportName(bool asLib) {
956
956
void LinkerDriver::createImportLibrary (bool asLib) {
957
957
llvm::TimeTraceScope timeScope (" Create import library" );
958
958
std::vector<COFFShortExport> exports;
959
- for (Export &e1 : ctx.config .exports ) {
959
+ for (Export &e1 : ctx.symtab .exports ) {
960
960
COFFShortExport e2 ;
961
961
e2 .Name = std::string (e1 .name );
962
962
e2 .SymbolName = std::string (e1 .symbolName );
@@ -1069,7 +1069,7 @@ void LinkerDriver::parseModuleDefs(StringRef path) {
1069
1069
e2 .isPrivate = e1 .Private ;
1070
1070
e2 .constant = e1 .Constant ;
1071
1071
e2 .source = ExportSource::ModuleDefinition;
1072
- ctx.config .exports .push_back (e2 );
1072
+ ctx.symtab .exports .push_back (e2 );
1073
1073
}
1074
1074
}
1075
1075
@@ -1222,8 +1222,10 @@ static void findKeepUniqueSections(COFFLinkerContext &ctx) {
1222
1222
1223
1223
// Exported symbols could be address-significant in other executables or DSOs,
1224
1224
// 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
+ });
1227
1229
1228
1230
// Visit the address-significance table in each object file and mark each
1229
1231
// referenced symbol as address-significant.
@@ -1376,13 +1378,13 @@ void LinkerDriver::maybeCreateECExportThunk(StringRef name, Symbol *&sym) {
1376
1378
void LinkerDriver::createECExportThunks () {
1377
1379
// Check if EXP+ symbols have corresponding $hp_target symbols and use them
1378
1380
// to create export thunks when available.
1379
- for (Symbol *s : ctx.symtab . expSymbols ) {
1381
+ for (Symbol *s : ctx.symtabEC -> expSymbols ) {
1380
1382
if (!s->isUsedInRegularObj )
1381
1383
continue ;
1382
1384
assert (s->getName ().starts_with (" EXP+" ));
1383
1385
std::string targetName =
1384
1386
(s->getName ().substr (strlen (" EXP+" )) + " $hp_target" ).str ();
1385
- Symbol *sym = ctx.symtab . find (targetName);
1387
+ Symbol *sym = ctx.symtabEC -> find (targetName);
1386
1388
if (!sym)
1387
1389
continue ;
1388
1390
Defined *targetSym;
@@ -1407,7 +1409,7 @@ void LinkerDriver::createECExportThunks() {
1407
1409
if (ctx.symtabEC ->entry )
1408
1410
maybeCreateECExportThunk (ctx.symtabEC ->entry ->getName (),
1409
1411
ctx.symtabEC ->entry );
1410
- for (Export &e : ctx.config . exports ) {
1412
+ for (Export &e : ctx.symtabEC -> exports ) {
1411
1413
if (!e.data )
1412
1414
maybeCreateECExportThunk (e.extName .empty () ? e.name : e.extName , e.sym );
1413
1415
}
@@ -1430,7 +1432,7 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
1430
1432
if (!ctx.config .dll )
1431
1433
return ;
1432
1434
1433
- if (!ctx.config .exports .empty ())
1435
+ if (!ctx.symtab .exports .empty ())
1434
1436
return ;
1435
1437
if (args.hasArg (OPT_exclude_all_symbols))
1436
1438
return ;
@@ -1466,7 +1468,7 @@ void LinkerDriver::maybeExportMinGWSymbols(const opt::InputArgList &args) {
1466
1468
if (!(c->getOutputCharacteristics () & IMAGE_SCN_MEM_EXECUTE))
1467
1469
e.data = true ;
1468
1470
s->isUsedInRegularObj = true ;
1469
- ctx.config .exports .push_back (e);
1471
+ ctx.symtab .exports .push_back (e);
1470
1472
});
1471
1473
}
1472
1474
@@ -2339,7 +2341,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2339
2341
if (!e.extName .empty () && !isDecorated (e.extName ))
2340
2342
e.extName = saver ().save (" _" + e.extName );
2341
2343
}
2342
- config-> exports .push_back (e);
2344
+ mainSymtab. exports .push_back (e);
2343
2345
}
2344
2346
}
2345
2347
@@ -2351,7 +2353,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2351
2353
2352
2354
// Handle generation of import library from a def file.
2353
2355
if (!args.hasArg (OPT_INPUT, OPT_wholearchive_file)) {
2354
- fixupExports ();
2356
+ ctx. forEachSymtab ([](SymbolTable &symtab) { symtab. fixupExports (); } );
2355
2357
if (!config->noimplib )
2356
2358
createImportLibrary (/* asLib=*/ true );
2357
2359
return ;
@@ -2537,16 +2539,16 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2537
2539
// search for its mangled names.
2538
2540
if (symtab.entry )
2539
2541
symtab.mangleMaybe (symtab.entry );
2540
- });
2541
2542
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
+ });
2550
2552
2551
2553
// Add weak aliases. Weak aliases is a mechanism to give remaining
2552
2554
// undefined symbols final chance to be resolved successfully.
@@ -2647,7 +2649,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2647
2649
if (errorCount ())
2648
2650
return ;
2649
2651
2650
- config->hadExplicitExports = !config->exports .empty ();
2652
+ ctx.forEachSymtab ([](SymbolTable &symtab) {
2653
+ symtab.hadExplicitExports = !symtab.exports .empty ();
2654
+ });
2651
2655
if (config->mingw ) {
2652
2656
// In MinGW, all symbols are automatically exported if no symbols
2653
2657
// are chosen to be exported.
@@ -2712,17 +2716,18 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2712
2716
// Windows specific -- when we are creating a .dll file, we also
2713
2717
// need to create a .lib file. In MinGW mode, we only do that when the
2714
2718
// -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 ) {
2716
2720
llvm::TimeTraceScope timeScope (" Create .lib exports" );
2717
- fixupExports ();
2721
+ ctx. forEachSymtab ([](SymbolTable &symtab) { symtab. fixupExports (); } );
2718
2722
if (!config->noimplib && (!config->mingw || !config->implib .empty ()))
2719
2723
createImportLibrary (/* asLib=*/ false );
2720
- assignExportOrdinals ();
2724
+ ctx.forEachSymtab (
2725
+ [](SymbolTable &symtab) { symtab.assignExportOrdinals (); });
2721
2726
}
2722
2727
2723
2728
// Handle /output-def (MinGW specific).
2724
2729
if (auto *arg = args.getLastArg (OPT_output_def))
2725
- writeDefFile (ctx, arg->getValue (), config-> exports );
2730
+ writeDefFile (ctx, arg->getValue (), ctx. symtab . exports );
2726
2731
2727
2732
// Set extra alignment for .comm symbols
2728
2733
for (auto pair : config->alignComm ) {
0 commit comments