ELF2: Define Driver::addFile() as a one-stop place to open a file.
Opening a file and dispatching to readLinkerScript() or createFile()
is a common operation. We want to use that at least from Driver and
from LinkerScript. In COFF, we had the same problem. This patch
resolves the problem in the same way as we did for COFF.
Now, if you have a path that you want to open, just call
Driver->addFile(StringRef). That function opens the file and handles
that as if that were given by command line. This function is the
only place we call identify_magic().
llvm-svn: 249023
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 746af74..44c045a 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -26,7 +26,7 @@
namespace {
class LinkerScript {
public:
- LinkerScript(SymbolTable *T, StringRef S) : Symtab(T), Tokens(tokenize(S)) {}
+ LinkerScript(StringRef S) : Tokens(tokenize(S)) {}
void run();
private:
@@ -40,7 +40,6 @@
void readGroup();
void readOutputFormat();
- SymbolTable *Symtab;
std::vector<StringRef> Tokens;
size_t Pos = 0;
};
@@ -125,7 +124,7 @@
StringRef Tok = next();
if (Tok == ")")
return;
- Symtab->addFile(createFile(openFile(Tok)));
+ Driver->addFile(Tok);
}
}
@@ -139,7 +138,7 @@
readAsNeeded();
continue;
}
- Symtab->addFile(createFile(openFile(Tok)));
+ Driver->addFile(Tok);
}
}
@@ -151,6 +150,6 @@
}
// Entry point. The other functions or classes are private to this file.
-void lld::elf2::readLinkerScript(SymbolTable *Symtab, MemoryBufferRef MB) {
- LinkerScript(Symtab, MB.getBuffer()).run();
+void lld::elf2::readLinkerScript(MemoryBufferRef MB) {
+ LinkerScript(MB.getBuffer()).run();
}