@@ -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
@@ -2343,7 +2345,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2343
2345
if (!e.extName .empty () && !isDecorated (e.extName ))
2344
2346
e.extName = saver ().save (" _" + e.extName );
2345
2347
}
2346
- config-> exports .push_back (e);
2348
+ mainSymtab. exports .push_back (e);
2347
2349
}
2348
2350
}
2349
2351
@@ -2355,7 +2357,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2355
2357
2356
2358
// Handle generation of import library from a def file.
2357
2359
if (!args.hasArg (OPT_INPUT, OPT_wholearchive_file)) {
2358
- fixupExports ();
2360
+ ctx. forEachSymtab ([](SymbolTable &symtab) { symtab. fixupExports (); } );
2359
2361
if (!config->noimplib )
2360
2362
createImportLibrary (/* asLib=*/ true );
2361
2363
return ;
@@ -2541,16 +2543,16 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2541
2543
// search for its mangled names.
2542
2544
if (symtab.entry )
2543
2545
symtab.mangleMaybe (symtab.entry );
2544
- });
2545
2546
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
+ });
2554
2556
2555
2557
// Add weak aliases. Weak aliases is a mechanism to give remaining
2556
2558
// undefined symbols final chance to be resolved successfully.
@@ -2651,7 +2653,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2651
2653
if (errorCount ())
2652
2654
return ;
2653
2655
2654
- config->hadExplicitExports = !config->exports .empty ();
2656
+ ctx.forEachSymtab ([](SymbolTable &symtab) {
2657
+ symtab.hadExplicitExports = !symtab.exports .empty ();
2658
+ });
2655
2659
if (config->mingw ) {
2656
2660
// In MinGW, all symbols are automatically exported if no symbols
2657
2661
// are chosen to be exported.
@@ -2716,17 +2720,18 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
2716
2720
// Windows specific -- when we are creating a .dll file, we also
2717
2721
// need to create a .lib file. In MinGW mode, we only do that when the
2718
2722
// -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 ) {
2720
2724
llvm::TimeTraceScope timeScope (" Create .lib exports" );
2721
- fixupExports ();
2725
+ ctx. forEachSymtab ([](SymbolTable &symtab) { symtab. fixupExports (); } );
2722
2726
if (!config->noimplib && (!config->mingw || !config->implib .empty ()))
2723
2727
createImportLibrary (/* asLib=*/ false );
2724
- assignExportOrdinals ();
2728
+ ctx.forEachSymtab (
2729
+ [](SymbolTable &symtab) { symtab.assignExportOrdinals (); });
2725
2730
}
2726
2731
2727
2732
// Handle /output-def (MinGW specific).
2728
2733
if (auto *arg = args.getLastArg (OPT_output_def))
2729
- writeDefFile (ctx, arg->getValue (), config-> exports );
2734
+ writeDefFile (ctx, arg->getValue (), ctx. symtab . exports );
2730
2735
2731
2736
// Set extra alignment for .comm symbols
2732
2737
for (auto pair : config->alignComm ) {
0 commit comments