Index: lld/COFF/Config.h =================================================================== --- lld/COFF/Config.h +++ lld/COFF/Config.h @@ -10,6 +10,7 @@ #ifndef LLD_COFF_CONFIG_H #define LLD_COFF_CONFIG_H +#include "llvm/ADT/SetVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Object/COFF.h" #include "llvm/Support/CachePruning.h" @@ -103,6 +104,10 @@ // True if we are creating a DLL. bool DLL = false; StringRef Implib; + + // Export in directive sections, parsed later. + llvm::SetVector DirectiveExports; + std::vector Exports; std::set DelayLoads; std::map DLLOrder; Index: lld/COFF/Driver.cpp =================================================================== --- lld/COFF/Driver.cpp +++ lld/COFF/Driver.cpp @@ -245,15 +245,7 @@ Config->Entry = addUndefined(mangle(Arg->getValue())); break; case OPT_export: { - Export E = parseExport(Arg->getValue()); - if (Config->Machine == I386 && Config->MinGW) { - if (!isDecorated(E.Name)) - E.Name = Saver.save("_" + E.Name); - if (!E.ExtName.empty() && !isDecorated(E.ExtName)) - E.ExtName = Saver.save("_" + E.ExtName); - } - E.Directives = true; - Config->Exports.push_back(E); + Config->DirectiveExports.insert(Arg->getValue()); break; } case OPT_failifmismatch: @@ -1054,6 +1046,19 @@ // Read all input files given via the command line. run(); + // Parse deduplicated Exports in directive section. + for (const StringRef & RawE : Config->DirectiveExports) { + Export E = parseExport(RawE); + if (Config->Machine == I386 && Config->MinGW) { + if (!isDecorated(E.Name)) + E.Name = Saver.save("_" + E.Name); + if (!E.ExtName.empty() && !isDecorated(E.ExtName)) + E.ExtName = Saver.save("_" + E.ExtName); + } + E.Directives = true; + Config->Exports.push_back(E); + } + // We should have inferred a machine type by now from the input files, but if // not we assume x64. if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {