Skip to content

Commit a549289

Browse files
committed
[LLD][COFF] Add support for MinGW auto-export on ARM64X
Export all symbols from both EC and native symbol tables. If an explicit export is present in only one symbol table, auto-export for the other symbol table remains unaffected.
1 parent e596387 commit a549289

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

lld/COFF/Driver.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lld/COFF/Driver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ class LinkerDriver {
161161
// trees into one resource tree.
162162
void convertResources();
163163

164-
void maybeExportMinGWSymbols(const llvm::opt::InputArgList &args);
164+
void maybeExportMinGWSymbols(SymbolTable &symtab,
165+
const llvm::opt::InputArgList &args);
165166

166167
// We don't want to add the same file more than once.
167168
// Files are uniquified by their filesystem and file number.

lld/COFF/MinGW.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ using namespace lld;
2525
using namespace lld::coff;
2626

2727
AutoExporter::AutoExporter(
28-
COFFLinkerContext &ctx,
29-
const llvm::DenseSet<StringRef> &manualExcludeSymbols)
30-
: manualExcludeSymbols(manualExcludeSymbols), ctx(ctx) {
28+
SymbolTable &symtab, const llvm::DenseSet<StringRef> &manualExcludeSymbols)
29+
: manualExcludeSymbols(manualExcludeSymbols), symtab(symtab) {
3130
excludeLibs = {
3231
"libgcc",
3332
"libgcc_s",
@@ -84,7 +83,7 @@ AutoExporter::AutoExporter(
8483
"_NULL_THUNK_DATA",
8584
};
8685

87-
if (ctx.config.machine == I386) {
86+
if (symtab.machine == I386) {
8887
excludeSymbols = {
8988
"__NULL_IMPORT_DESCRIPTOR",
9089
"__pei386_runtime_relocator",
@@ -151,7 +150,7 @@ bool AutoExporter::shouldExport(Defined *sym) const {
151150
return false;
152151

153152
// If a corresponding __imp_ symbol exists and is defined, don't export it.
154-
if (ctx.symtab.find(("__imp_" + sym->getName()).str()))
153+
if (symtab.find(("__imp_" + sym->getName()).str()))
155154
return false;
156155

157156
// Check that file is non-null before dereferencing it, symbols not

lld/COFF/MinGW.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class COFFLinkerContext;
2525
// symbols for MinGW.
2626
class AutoExporter {
2727
public:
28-
AutoExporter(COFFLinkerContext &ctx,
28+
AutoExporter(SymbolTable &symtab,
2929
const llvm::DenseSet<StringRef> &manualExcludeSymbols);
3030

3131
void addWholeArchive(StringRef path);
@@ -42,7 +42,7 @@ class AutoExporter {
4242
bool shouldExport(Defined *sym) const;
4343

4444
private:
45-
COFFLinkerContext &ctx;
45+
SymbolTable &symtab;
4646
};
4747

4848
void writeDefFile(COFFLinkerContext &, StringRef name,

0 commit comments

Comments
 (0)