summaryrefslogtreecommitdiffstats
path: root/lld/lib/Driver/WinLinkDriver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/lib/Driver/WinLinkDriver.cpp')
-rw-r--r--lld/lib/Driver/WinLinkDriver.cpp65
1 files changed, 29 insertions, 36 deletions
diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp
index 7aa9a0f7e3e..8f05821495e 100644
--- a/lld/lib/Driver/WinLinkDriver.cpp
+++ b/lld/lib/Driver/WinLinkDriver.cpp
@@ -14,8 +14,8 @@
//===----------------------------------------------------------------------===//
#include "lld/Driver/Driver.h"
+#include "lld/Driver/WinLinkInputGraph.h"
#include "lld/Driver/WinLinkModuleDef.h"
-#include "lld/Driver/WrapperInputGraph.h"
#include "lld/ReaderWriter/PECOFFLinkingContext.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
@@ -800,11 +800,13 @@ parseArgs(int argc, const char **argv, PECOFFLinkingContext &ctx,
// Returns true if the given file node has already been added to the input
// graph.
-static bool hasLibrary(const PECOFFLinkingContext &ctx, File *file) {
- StringRef path = file->path();
+static bool hasLibrary(const PECOFFLinkingContext &ctx, FileNode *fileNode) {
+ ErrorOr<StringRef> path = fileNode->getPath(ctx);
+ if (!path)
+ return false;
for (std::unique_ptr<InputElement> &p : ctx.getInputGraph().inputElements())
if (auto *f = dyn_cast<FileNode>(p.get()))
- if (*f->getPath(ctx) == path)
+ if (*path == *f->getPath(ctx))
return true;
return false;
}
@@ -836,17 +838,6 @@ static bool maybeRunLibCommand(int argc, const char **argv, raw_ostream &diag) {
return true;
}
-/// \brief Parse the input file to lld::File.
-void addFiles(PECOFFLinkingContext &ctx, StringRef path, raw_ostream &diag,
- std::vector<std::unique_ptr<File>> &files) {
- for (std::unique_ptr<File> &file : loadFile(ctx, path, false)) {
- if (ctx.logInputFiles())
- diag << file->path() << "\n";
- ctx.getResolvableSymsFile()->add(file.get());
- files.push_back(std::move(file));
- }
-}
-
//
// Main driver
//
@@ -856,12 +847,6 @@ bool WinLinkDriver::linkPECOFF(int argc, const char **argv, raw_ostream &diag) {
return true;
PECOFFLinkingContext ctx;
- ctx.registry().addSupportCOFFObjects(ctx);
- ctx.registry().addSupportCOFFImportLibraries(ctx);
- ctx.registry().addSupportArchives(ctx.logInputFiles());
- ctx.registry().addSupportNativeObjects();
- ctx.registry().addSupportYamlFiles();
-
std::vector<const char *> newargv = processLinkEnv(ctx, argc, argv);
processLibEnv(ctx);
if (!parse(newargv.size() - 1, &newargv[0], ctx, diag))
@@ -872,6 +857,13 @@ bool WinLinkDriver::linkPECOFF(int argc, const char **argv, raw_ostream &diag) {
if (!createSideBySideManifestFile(ctx, diag))
return false;
+ // Register possible input file parsers.
+ ctx.registry().addSupportCOFFObjects(ctx);
+ ctx.registry().addSupportCOFFImportLibraries(ctx);
+ ctx.registry().addSupportArchives(ctx.logInputFiles());
+ ctx.registry().addSupportNativeObjects();
+ ctx.registry().addSupportYamlFiles();
+
return link(ctx, diag);
}
@@ -892,8 +884,8 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
return false;
// The list of input files.
- std::vector<std::unique_ptr<File>> files;
- std::vector<std::unique_ptr<File>> libraries;
+ std::vector<std::unique_ptr<FileNode> > files;
+ std::vector<std::unique_ptr<FileNode> > libraries;
// Handle /help
if (parsedArgs->getLastArg(OPT_help)) {
@@ -1371,9 +1363,11 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
for (StringRef path : inputFiles) {
path = ctx.allocate(path);
if (isLibraryFile(path)) {
- addFiles(ctx, getLibraryPath(ctx, path), diag, libraries);
+ libraries.push_back(std::unique_ptr<FileNode>(
+ new PECOFFFileNode(ctx, getLibraryPath(ctx, path))));
} else {
- addFiles(ctx, getObjectPath(ctx, path), diag, files);
+ files.push_back(std::unique_ptr<FileNode>(
+ new PECOFFFileNode(ctx, getObjectPath(ctx, path))));
}
}
@@ -1395,7 +1389,8 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
if (!ctx.getNoDefaultLibAll())
for (const StringRef path : defaultLibs)
if (!ctx.hasNoDefaultLib(path))
- addFiles(ctx, getLibraryPath(ctx, path.lower()), diag, libraries);
+ libraries.push_back(std::unique_ptr<FileNode>(
+ new PECOFFFileNode(ctx, getLibraryPath(ctx, path.lower()))));
if (files.empty() && !isReadingDirectiveSection) {
diag << "No input files\n";
@@ -1406,19 +1401,18 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
// constructed by replacing an extension of the first input file
// with ".exe".
if (ctx.outputPath().empty()) {
- StringRef path = files[0]->path();
+ StringRef path = *cast<FileNode>(&*files[0])->getPath(ctx);
ctx.setOutputPath(replaceExtension(ctx, path, ".exe"));
}
// Add the input files to the input graph.
if (!ctx.hasInputGraph())
ctx.setInputGraph(std::unique_ptr<InputGraph>(new InputGraph()));
- for (std::unique_ptr<File> &file : files) {
+ for (std::unique_ptr<FileNode> &file : files) {
if (isReadingDirectiveSection)
- if (file->parse())
+ if (file->parse(ctx, diag))
return false;
- ctx.getInputGraph().addInputElement(
- std::unique_ptr<InputElement>(new WrapperNode(std::move(file))));
+ ctx.getInputGraph().addInputElement(std::move(file));
}
// Add the library group to the input graph.
@@ -1433,13 +1427,12 @@ bool WinLinkDriver::parse(int argc, const char *argv[],
}
// Add the library files to the library group.
- for (std::unique_ptr<File> &file : libraries) {
- if (!hasLibrary(ctx, file.get())) {
+ for (std::unique_ptr<FileNode> &lib : libraries) {
+ if (!hasLibrary(ctx, lib.get())) {
if (isReadingDirectiveSection)
- if (file->parse())
+ if (lib->parse(ctx, diag))
return false;
- ctx.addLibraryFile(
- std::unique_ptr<FileNode>(new WrapperNode(std::move(file))));
+ ctx.addLibraryFile(std::move(lib));
}
}
OpenPOWER on IntegriCloud