[lld] r289086 - Revert r289084: Start using make() in COFF.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 8 10:49:04 PST 2016
Author: ruiu
Date: Thu Dec 8 12:49:04 2016
New Revision: 289086
URL: http://llvm.org/viewvc/llvm-project?rev=289086&view=rev
Log:
Revert r289084: Start using make() in COFF.
This reverts commit r289084 to appease buildbots.
Modified:
lld/trunk/COFF/Driver.cpp
lld/trunk/COFF/Error.cpp
lld/trunk/COFF/InputFiles.cpp
lld/trunk/COFF/InputFiles.h
lld/trunk/COFF/SymbolTable.cpp
lld/trunk/COFF/SymbolTable.h
lld/trunk/COFF/Symbols.cpp
lld/trunk/COFF/Symbols.h
Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=289086&r1=289085&r2=289086&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Thu Dec 8 12:49:04 2016
@@ -15,7 +15,6 @@
#include "Symbols.h"
#include "Writer.h"
#include "lld/Driver/Driver.h"
-#include "lld/Support/Memory.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/LibDriver/LibDriver.h"
@@ -44,8 +43,10 @@ Configuration *Config;
LinkerDriver *Driver;
bool link(llvm::ArrayRef<const char *> Args) {
- Config = make<Configuration>();
- Driver = make<LinkerDriver>();
+ Configuration C;
+ LinkerDriver D;
+ Config = &C;
+ Driver = &D;
Driver->link(Args);
return true;
}
@@ -68,7 +69,7 @@ MemoryBufferRef LinkerDriver::openFile(S
return MBRef;
}
-static InputFile *createFile(MemoryBufferRef MB) {
+static std::unique_ptr<InputFile> createFile(MemoryBufferRef MB) {
if (Driver->Cpio)
Driver->Cpio->append(relativeToRoot(MB.getBufferIdentifier()),
MB.getBuffer());
@@ -76,15 +77,15 @@ static InputFile *createFile(MemoryBuffe
// File type is detected by contents, not by file extension.
file_magic Magic = identify_magic(MB.getBuffer());
if (Magic == file_magic::archive)
- return make<ArchiveFile>(MB);
+ return std::unique_ptr<InputFile>(new ArchiveFile(MB));
if (Magic == file_magic::bitcode)
- return make<BitcodeFile>(MB);
+ return std::unique_ptr<InputFile>(new BitcodeFile(MB));
if (Magic == file_magic::coff_cl_gl_object)
fatal(MB.getBufferIdentifier() + ": is not a native COFF file. "
"Recompile without /GL");
if (Config->OutputFile == "")
Config->OutputFile = getOutputPath(MB.getBufferIdentifier());
- return make<ObjectFile>(MB);
+ return std::unique_ptr<InputFile>(new ObjectFile(MB));
}
static bool isDecorated(StringRef Sym) {
@@ -571,7 +572,7 @@ void LinkerDriver::link(llvm::ArrayRef<c
// Determine machine type and check if all object files are
// for the same CPU type. Note that this needs to be done before
// any call to mangle().
- for (InputFile *File : Symtab.getFiles()) {
+ for (std::unique_ptr<InputFile> &File : Symtab.getFiles()) {
MachineTypes MT = File->getMachineType();
if (MT == IMAGE_FILE_MACHINE_UNKNOWN)
continue;
@@ -580,7 +581,7 @@ void LinkerDriver::link(llvm::ArrayRef<c
continue;
}
if (Config->Machine != MT)
- fatal(toString(File) + ": machine type " + machineToStr(MT) +
+ fatal(toString(File.get()) + ": machine type " + machineToStr(MT) +
" conflicts with " + machineToStr(Config->Machine));
}
if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
Modified: lld/trunk/COFF/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Error.cpp?rev=289086&r1=289085&r2=289086&view=diff
==============================================================================
--- lld/trunk/COFF/Error.cpp (original)
+++ lld/trunk/COFF/Error.cpp Thu Dec 8 12:49:04 2016
@@ -14,10 +14,6 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/raw_ostream.h"
-#if !defined(_MSC_VER) && !defined(__MINGW32__)
-#include <unistd.h>
-#endif
-
using namespace llvm;
namespace lld {
@@ -33,10 +29,7 @@ void fatal(const Twine &Msg) {
}
errs() << Msg << "\n";
-
- outs().flush();
- errs().flush();
- _exit(1);
+ exit(1);
}
void fatal(std::error_code EC, const Twine &Msg) {
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=289086&r1=289085&r2=289086&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Thu Dec 8 12:49:04 2016
@@ -7,14 +7,12 @@
//
//===----------------------------------------------------------------------===//
-#include "InputFiles.h"
#include "Chunks.h"
#include "Config.h"
#include "Driver.h"
#include "Error.h"
+#include "InputFiles.h"
#include "Symbols.h"
-#include "lld/Support/Memory.h"
-#include "llvm-c/lto.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
@@ -29,6 +27,7 @@
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Target/TargetOptions.h"
+#include "llvm-c/lto.h"
#include <cstring>
#include <system_error>
#include <utility>
@@ -98,10 +97,14 @@ MutableArrayRef<Lazy> ArchiveFile::getLa
void ObjectFile::parse() {
// Parse a memory buffer as a COFF file.
- std::error_code EC;
- COFFObj = new COFFObjectFile(MB, EC);
- if (EC)
- fatal(EC, "failed to parse object");
+ std::unique_ptr<Binary> Bin = check(createBinary(MB), toString(this));
+
+ if (auto *Obj = dyn_cast<COFFObjectFile>(Bin.get())) {
+ Bin.release();
+ COFFObj.reset(Obj);
+ } else {
+ fatal(toString(this) + " is not a COFF file");
+ }
// Read section and symbol tables.
initializeChunks();
Modified: lld/trunk/COFF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.h?rev=289086&r1=289085&r2=289086&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.h (original)
+++ lld/trunk/COFF/InputFiles.h Thu Dec 8 12:49:04 2016
@@ -127,7 +127,7 @@ public:
}
// Returns the underying COFF file.
- COFFObjectFile *getCOFFObj() { return COFFObj; }
+ COFFObjectFile *getCOFFObj() { return COFFObj.get(); }
// True if this object file is compatible with SEH.
// COFF-specific and x86-only.
@@ -145,7 +145,7 @@ private:
Defined *createDefined(COFFSymbolRef Sym, const void *Aux, bool IsFirst);
Undefined *createUndefined(COFFSymbolRef Sym);
- COFFObjectFile *COFFObj;
+ std::unique_ptr<COFFObjectFile> COFFObj;
llvm::BumpPtrAllocator Alloc;
const coff_section *SXData = nullptr;
Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=289086&r1=289085&r2=289086&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Thu Dec 8 12:49:04 2016
@@ -24,14 +24,15 @@ using namespace llvm;
namespace lld {
namespace coff {
-void SymbolTable::addFile(InputFile *File) {
+void SymbolTable::addFile(std::unique_ptr<InputFile> FileP) {
#if LLVM_ENABLE_THREADS
std::launch Policy = std::launch::async;
#else
std::launch Policy = std::launch::deferred;
#endif
- Files.push_back(File);
+ InputFile *File = FileP.get();
+ Files.push_back(std::move(FileP));
if (auto *F = dyn_cast<ArchiveFile>(File)) {
ArchiveQueue.push_back(
std::async(Policy, [=]() { F->parse(); return F; }));
@@ -155,11 +156,11 @@ void SymbolTable::reportRemainingUndefin
for (Undefined *U : Config->GCRoot)
if (Undefs.count(U->repl()))
llvm::errs() << "<root>: undefined symbol: " << U->getName() << "\n";
- for (InputFile *File : Files)
- if (!isa<ArchiveFile>(File))
+ for (std::unique_ptr<InputFile> &File : Files)
+ if (!isa<ArchiveFile>(File.get()))
for (SymbolBody *Sym : File->getSymbols())
if (Undefs.count(Sym->repl()))
- llvm::errs() << toString(File)
+ llvm::errs() << toString(File.get())
<< ": undefined symbol: " << Sym->getName() << "\n";
if (!Config->Force)
fatal("link failed");
@@ -229,16 +230,16 @@ Symbol *SymbolTable::insert(SymbolBody *
// Reads an archive member file pointed by a given symbol.
void SymbolTable::addMemberFile(Lazy *Body) {
- InputFile *File = Body->getMember();
+ std::unique_ptr<InputFile> File = Body->getMember();
// getMember returns an empty buffer if the member was already
// read from the library.
if (!File)
return;
if (Config->Verbose)
- llvm::outs() << "Loaded " << toString(File) << " for " << Body->getName()
- << "\n";
- addFile(File);
+ llvm::outs() << "Loaded " << toString(File.get()) << " for "
+ << Body->getName() << "\n";
+ addFile(std::move(File));
}
std::vector<Chunk *> SymbolTable::getChunks() {
Modified: lld/trunk/COFF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.h?rev=289086&r1=289085&r2=289086&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.h (original)
+++ lld/trunk/COFF/SymbolTable.h Thu Dec 8 12:49:04 2016
@@ -49,8 +49,8 @@ struct Symbol;
// to replace the lazy symbol. The logic is implemented in resolve().
class SymbolTable {
public:
- void addFile(InputFile *File);
- std::vector<InputFile *> &getFiles() { return Files; }
+ void addFile(std::unique_ptr<InputFile> File);
+ std::vector<std::unique_ptr<InputFile>> &getFiles() { return Files; }
void step();
void run();
bool queueEmpty();
@@ -111,7 +111,7 @@ private:
llvm::DenseMap<StringRef, Symbol *> Symtab;
- std::vector<InputFile *> Files;
+ std::vector<std::unique_ptr<InputFile>> Files;
std::vector<std::future<ArchiveFile *>> ArchiveQueue;
std::vector<std::future<InputFile *>> ObjectQueue;
Modified: lld/trunk/COFF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.cpp?rev=289086&r1=289085&r2=289086&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.cpp (original)
+++ lld/trunk/COFF/Symbols.cpp Thu Dec 8 12:49:04 2016
@@ -11,7 +11,6 @@
#include "Error.h"
#include "InputFiles.h"
#include "Strings.h"
-#include "lld/Support/Memory.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@@ -182,23 +181,23 @@ DefinedImportThunk::DefinedImportThunk(S
}
}
-InputFile *Lazy::getMember() {
+std::unique_ptr<InputFile> Lazy::getMember() {
MemoryBufferRef MBRef = File->getMember(&Sym);
// getMember returns an empty buffer if the member was already
// read from the library.
if (MBRef.getBuffer().empty())
- return nullptr;
+ return std::unique_ptr<InputFile>(nullptr);
file_magic Magic = identify_magic(MBRef.getBuffer());
if (Magic == file_magic::coff_import_library)
- return make<ImportFile>(MBRef);
+ return std::unique_ptr<InputFile>(new ImportFile(MBRef));
- InputFile *Obj;
+ std::unique_ptr<InputFile> Obj;
if (Magic == file_magic::coff_object)
- Obj = make<ObjectFile>(MBRef);
+ Obj.reset(new ObjectFile(MBRef));
else if (Magic == file_magic::bitcode)
- Obj = make<BitcodeFile>(MBRef);
+ Obj.reset(new BitcodeFile(MBRef));
else
fatal("unknown file type: " + File->getName());
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=289086&r1=289085&r2=289086&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Thu Dec 8 12:49:04 2016
@@ -256,7 +256,7 @@ public:
// Returns an object file for this symbol, or a nullptr if the file
// was already returned.
- InputFile *getMember();
+ std::unique_ptr<InputFile> getMember();
int getFileIndex() { return File->Index; }
More information about the llvm-commits
mailing list