[lld] r309239 - Add {Obj, Import, Bitcode}File::Instances to COFF input files.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 26 17:45:26 PDT 2017
Author: ruiu
Date: Wed Jul 26 17:45:26 2017
New Revision: 309239
URL: http://llvm.org/viewvc/llvm-project?rev=309239&view=rev
Log:
Add {Obj,Import,Bitcode}File::Instances to COFF input files.
We did the same thing for ELF in r309152, and I want to maintain
COFF and ELF as close as possible.
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/InputFiles.cpp
lld/trunk/COFF/InputFiles.h
lld/trunk/COFF/MapFile.cpp
lld/trunk/COFF/PDB.cpp
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/SymbolTable.h
lld/trunk/COFF/Writer.cpp
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=309239&r1=309238&r2=309239&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Jul 26 17:45:26 2017
@@ -610,16 +610,16 @@ void LinkerDriver::invokeMSVC(opt::Input
// Write out archive members that we used in symbol resolution and pass these
// to MSVC before any archives, so that MSVC uses the same objects to satisfy
// references.
- for (const auto *O : Symtab.ObjFiles) {
- if (O->ParentName.empty())
+ for (ObjFile *Obj : ObjFile::Instances) {
+ if (Obj->ParentName.empty())
continue;
SmallString<128> S;
int Fd;
if (auto EC = sys::fs::createTemporaryFile(
- "lld-" + sys::path::filename(O->ParentName), ".obj", Fd, S))
+ "lld-" + sys::path::filename(Obj->ParentName), ".obj", Fd, S))
fatal(EC, "cannot create a temporary file");
raw_fd_ostream OS(Fd, /*shouldClose*/ true);
- OS << O->MB.getBuffer();
+ OS << Obj->MB.getBuffer();
Temps.push_back(S.str());
Rsp += quote(S) + "\n";
}
@@ -1143,7 +1143,7 @@ void LinkerDriver::link(ArrayRef<const c
// Handle /safeseh.
if (Args.hasArg(OPT_safeseh)) {
- for (ObjFile *File : Symtab.ObjFiles)
+ for (ObjFile *File : ObjFile::Instances)
if (!File->SEHCompat)
error("/safeseh: " + File->getName() + " is not compatible with SEH");
if (ErrorCount)
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=309239&r1=309238&r2=309239&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Wed Jul 26 17:45:26 2017
@@ -43,6 +43,10 @@ using llvm::support::ulittle32_t;
namespace lld {
namespace coff {
+std::vector<ObjFile *> ObjFile::Instances;
+std::vector<ImportFile *> ImportFile::Instances;
+std::vector<BitcodeFile *> BitcodeFile::Instances;
+
/// Checks that Source is compatible with being a weak alias to Target.
/// If Source is Undefined and has no weak alias set, makes it a weak
/// alias to Target.
Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=309239&r1=309238&r2=309239&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Wed Jul 26 17:45:26 2017
@@ -120,6 +120,8 @@ public:
// Returns the underying COFF file.
COFFObjectFile *getCOFFObj() { return COFFObj.get(); }
+ static std::vector<ObjFile *> Instances;
+
// True if this object file is compatible with SEH.
// COFF-specific and x86-only.
bool SEHCompat = false;
@@ -179,6 +181,8 @@ public:
static bool classof(const InputFile *F) { return F->kind() == ImportKind; }
+ static std::vector<ImportFile *> Instances;
+
DefinedImportData *ImpSym = nullptr;
DefinedImportData *ConstSym = nullptr;
DefinedImportThunk *ThunkSym = nullptr;
@@ -208,6 +212,7 @@ public:
static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
std::vector<SymbolBody *> &getSymbols() { return SymbolBodies; }
MachineTypes getMachineType() override;
+ static std::vector<BitcodeFile *> Instances;
std::unique_ptr<llvm::lto::InputFile> Obj;
private:
Modified: lld/trunk/COFF/MapFile.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/MapFile.cpp?rev=309239&r1=309238&r2=309239&view=diff
==============================================================================
--- lld/trunk/COFF/MapFile.cpp (original)
+++ lld/trunk/COFF/MapFile.cpp Wed Jul 26 17:45:26 2017
@@ -48,7 +48,7 @@ static std::string indent(int Depth) { r
// Returns a list of all symbols that we want to print out.
static std::vector<DefinedRegular *> getSymbols() {
std::vector<DefinedRegular *> V;
- for (ObjFile *File : Symtab->ObjFiles)
+ for (ObjFile *File : ObjFile::Instances)
for (SymbolBody *B : File->getSymbols())
if (auto *Sym = dyn_cast<DefinedRegular>(B))
if (Sym && !Sym->getCOFFSymbol().isSectionDefinition())
Modified: lld/trunk/COFF/PDB.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/PDB.cpp?rev=309239&r1=309238&r2=309239&view=diff
==============================================================================
--- lld/trunk/COFF/PDB.cpp (original)
+++ lld/trunk/COFF/PDB.cpp Wed Jul 26 17:45:26 2017
@@ -548,7 +548,7 @@ void PDBLinker::addObjFile(ObjFile *File
// Add all object files to the PDB. Merge .debug$T sections into IpiData and
// TpiData.
void PDBLinker::addObjectsToPDB() {
- for (ObjFile *File : Symtab->ObjFiles)
+ for (ObjFile *File : ObjFile::Instances)
addObjFile(File);
Builder.getStringTableBuilder().setStrings(PDBStrTab);
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=309239&r1=309238&r2=309239&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Wed Jul 26 17:45:26 2017
@@ -69,11 +69,11 @@ void SymbolTable::addFile(InputFile *Fil
}
if (auto *F = dyn_cast<ObjFile>(File)) {
- ObjFiles.push_back(F);
+ ObjFile::Instances.push_back(F);
} else if (auto *F = dyn_cast<BitcodeFile>(File)) {
- BitcodeFiles.push_back(F);
+ BitcodeFile::Instances.push_back(F);
} else if (auto *F = dyn_cast<ImportFile>(File)) {
- ImportFiles.push_back(F);
+ ImportFile::Instances.push_back(F);
}
StringRef S = File->getDirectives();
@@ -135,7 +135,7 @@ void SymbolTable::reportRemainingUndefin
for (SymbolBody *B : Config->GCRoot)
if (Undefs.count(B))
warn("<root>: undefined symbol: " + B->getName());
- for (ObjFile *File : ObjFiles)
+ for (ObjFile *File : ObjFile::Instances)
for (SymbolBody *Sym : File->getSymbols())
if (Undefs.count(Sym))
warn(toString(File) + ": undefined symbol: " + Sym->getName());
@@ -296,7 +296,7 @@ Symbol *SymbolTable::addImportThunk(Stri
std::vector<Chunk *> SymbolTable::getChunks() {
std::vector<Chunk *> Res;
- for (ObjFile *File : ObjFiles) {
+ for (ObjFile *File : ObjFile::Instances) {
std::vector<Chunk *> &V = File->getChunks();
Res.insert(Res.end(), V.begin(), V.end());
}
@@ -356,18 +356,18 @@ SymbolBody *SymbolTable::addUndefined(St
std::vector<StringRef> SymbolTable::compileBitcodeFiles() {
LTO.reset(new BitcodeCompiler);
- for (BitcodeFile *F : BitcodeFiles)
+ for (BitcodeFile *F : BitcodeFile::Instances)
LTO->add(*F);
return LTO->compile();
}
void SymbolTable::addCombinedLTOObjects() {
- if (BitcodeFiles.empty())
+ if (BitcodeFile::Instances.empty())
return;
for (StringRef Object : compileBitcodeFiles()) {
auto *Obj = make<ObjFile>(MemoryBufferRef(Object, "lto.tmp"));
Obj->parse();
- ObjFiles.push_back(Obj);
+ ObjFile::Instances.push_back(Obj);
}
}
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=309239&r1=309238&r2=309239&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Wed Jul 26 17:45:26 2017
@@ -75,13 +75,6 @@ public:
void addCombinedLTOObjects();
std::vector<StringRef> compileBitcodeFiles();
- // The writer needs to handle DLL import libraries specially in
- // order to create the import descriptor table.
- std::vector<ImportFile *> ImportFiles;
-
- // The writer needs to infer the machine type from the object files.
- std::vector<ObjFile *> ObjFiles;
-
// Creates an Undefined symbol for a given name.
SymbolBody *addUndefined(StringRef Name);
@@ -111,8 +104,6 @@ private:
StringRef findByPrefix(StringRef Prefix);
llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> Symtab;
-
- std::vector<BitcodeFile *> BitcodeFiles;
std::unique_ptr<BitcodeCompiler> LTO;
};
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=309239&r1=309238&r2=309239&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Jul 26 17:45:26 2017
@@ -322,7 +322,7 @@ void Writer::createMiscChunks() {
std::set<Defined *> Handlers;
- for (ObjFile *File : Symtab->ObjFiles) {
+ for (ObjFile *File : ObjFile::Instances) {
if (!File->SEHCompat)
return;
for (SymbolBody *B : File->SEHandlers) {
@@ -345,13 +345,13 @@ void Writer::createMiscChunks() {
// IdataContents class abstracted away the details for us,
// so we just let it create chunks and add them to the section.
void Writer::createImportTables() {
- if (Symtab->ImportFiles.empty())
+ if (ImportFile::Instances.empty())
return;
// Initialize DLLOrder so that import entries are ordered in
// the same order as in the command line. (That affects DLL
// initialization order, and this ordering is MSVC-compatible.)
- for (ImportFile *File : Symtab->ImportFiles) {
+ for (ImportFile *File : ImportFile::Instances) {
if (!File->Live)
continue;
@@ -361,7 +361,7 @@ void Writer::createImportTables() {
}
OutputSection *Text = createSection(".text");
- for (ImportFile *File : Symtab->ImportFiles) {
+ for (ImportFile *File : ImportFile::Instances) {
if (!File->Live)
continue;
@@ -501,7 +501,7 @@ void Writer::createSymbolAndStringTable(
Sec->setStringTableOff(addEntryToStringTable(Name));
}
- for (ObjFile *File : Symtab->ObjFiles) {
+ for (ObjFile *File : ObjFile::Instances) {
for (SymbolBody *B : File->getSymbols()) {
auto *D = dyn_cast<Defined>(B);
if (!D || D->WrittenToSymtab)
More information about the llvm-commits
mailing list