forked from OSchip/llvm-project
COFF: Use make() to create a new file object in createFile.
llvm-svn: 289097
This commit is contained in:
parent
e96d03745d
commit
bf4ad1d63d
|
@ -68,7 +68,7 @@ MemoryBufferRef LinkerDriver::openFile(StringRef Path) {
|
|||
return MBRef;
|
||||
}
|
||||
|
||||
static std::unique_ptr<InputFile> createFile(MemoryBufferRef MB) {
|
||||
static InputFile *createFile(MemoryBufferRef MB) {
|
||||
if (Driver->Cpio)
|
||||
Driver->Cpio->append(relativeToRoot(MB.getBufferIdentifier()),
|
||||
MB.getBuffer());
|
||||
|
@ -76,15 +76,15 @@ static std::unique_ptr<InputFile> createFile(MemoryBufferRef MB) {
|
|||
// File type is detected by contents, not by file extension.
|
||||
file_magic Magic = identify_magic(MB.getBuffer());
|
||||
if (Magic == file_magic::archive)
|
||||
return std::unique_ptr<InputFile>(new ArchiveFile(MB));
|
||||
return make<ArchiveFile>(MB);
|
||||
if (Magic == file_magic::bitcode)
|
||||
return std::unique_ptr<InputFile>(new BitcodeFile(MB));
|
||||
return make<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 std::unique_ptr<InputFile>(new ObjectFile(MB));
|
||||
return make<ObjectFile>(MB);
|
||||
}
|
||||
|
||||
static bool isDecorated(StringRef Sym) {
|
||||
|
@ -571,7 +571,7 @@ void LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
|
|||
// 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 (std::unique_ptr<InputFile> &File : Symtab.getFiles()) {
|
||||
for (InputFile *File : Symtab.getFiles()) {
|
||||
MachineTypes MT = File->getMachineType();
|
||||
if (MT == IMAGE_FILE_MACHINE_UNKNOWN)
|
||||
continue;
|
||||
|
@ -580,7 +580,7 @@ void LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
|
|||
continue;
|
||||
}
|
||||
if (Config->Machine != MT)
|
||||
fatal(toString(File.get()) + ": machine type " + machineToStr(MT) +
|
||||
fatal(toString(File) + ": machine type " + machineToStr(MT) +
|
||||
" conflicts with " + machineToStr(Config->Machine));
|
||||
}
|
||||
if (Config->Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "SymbolTable.h"
|
||||
#include "Config.h"
|
||||
#include "Driver.h"
|
||||
#include "Error.h"
|
||||
#include "SymbolTable.h"
|
||||
#include "Symbols.h"
|
||||
#include "lld/Core/Parallel.h"
|
||||
#include "lld/Support/Memory.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/LTO/legacy/LTOCodeGenerator.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
|
@ -24,15 +25,14 @@ using namespace llvm;
|
|||
namespace lld {
|
||||
namespace coff {
|
||||
|
||||
void SymbolTable::addFile(std::unique_ptr<InputFile> FileP) {
|
||||
void SymbolTable::addFile(InputFile *File) {
|
||||
#if LLVM_ENABLE_THREADS
|
||||
std::launch Policy = std::launch::async;
|
||||
#else
|
||||
std::launch Policy = std::launch::deferred;
|
||||
#endif
|
||||
|
||||
InputFile *File = FileP.get();
|
||||
Files.push_back(std::move(FileP));
|
||||
Files.push_back(File);
|
||||
if (auto *F = dyn_cast<ArchiveFile>(File)) {
|
||||
ArchiveQueue.push_back(
|
||||
std::async(Policy, [=]() { F->parse(); return F; }));
|
||||
|
@ -156,11 +156,11 @@ void SymbolTable::reportRemainingUndefines(bool Resolve) {
|
|||
for (Undefined *U : Config->GCRoot)
|
||||
if (Undefs.count(U->repl()))
|
||||
llvm::errs() << "<root>: undefined symbol: " << U->getName() << "\n";
|
||||
for (std::unique_ptr<InputFile> &File : Files)
|
||||
if (!isa<ArchiveFile>(File.get()))
|
||||
for (InputFile *File : Files)
|
||||
if (!isa<ArchiveFile>(File))
|
||||
for (SymbolBody *Sym : File->getSymbols())
|
||||
if (Undefs.count(Sym->repl()))
|
||||
llvm::errs() << toString(File.get())
|
||||
llvm::errs() << toString(File)
|
||||
<< ": undefined symbol: " << Sym->getName() << "\n";
|
||||
if (!Config->Force)
|
||||
fatal("link failed");
|
||||
|
@ -230,16 +230,16 @@ Symbol *SymbolTable::insert(SymbolBody *New) {
|
|||
|
||||
// Reads an archive member file pointed by a given symbol.
|
||||
void SymbolTable::addMemberFile(Lazy *Body) {
|
||||
std::unique_ptr<InputFile> File = Body->getMember();
|
||||
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.get()) << " for "
|
||||
<< Body->getName() << "\n";
|
||||
addFile(std::move(File));
|
||||
llvm::outs() << "Loaded " << toString(File) << " for " << Body->getName()
|
||||
<< "\n";
|
||||
addFile(File);
|
||||
}
|
||||
|
||||
std::vector<Chunk *> SymbolTable::getChunks() {
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace coff {
|
|||
|
||||
class Chunk;
|
||||
class Defined;
|
||||
class DefinedAbsolute;
|
||||
class DefinedRelative;
|
||||
class Lazy;
|
||||
class SectionChunk;
|
||||
class SymbolBody;
|
||||
|
@ -49,8 +51,8 @@ struct Symbol;
|
|||
// to replace the lazy symbol. The logic is implemented in resolve().
|
||||
class SymbolTable {
|
||||
public:
|
||||
void addFile(std::unique_ptr<InputFile> File);
|
||||
std::vector<std::unique_ptr<InputFile>> &getFiles() { return Files; }
|
||||
void addFile(InputFile *File);
|
||||
std::vector<InputFile *> &getFiles() { return Files; }
|
||||
void step();
|
||||
void run();
|
||||
bool queueEmpty();
|
||||
|
@ -111,7 +113,7 @@ private:
|
|||
|
||||
llvm::DenseMap<StringRef, Symbol *> Symtab;
|
||||
|
||||
std::vector<std::unique_ptr<InputFile>> Files;
|
||||
std::vector<InputFile *> Files;
|
||||
std::vector<std::future<ArchiveFile *>> ArchiveQueue;
|
||||
std::vector<std::future<InputFile *>> ObjectQueue;
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#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"
|
||||
|
@ -181,23 +182,23 @@ DefinedImportThunk::DefinedImportThunk(StringRef Name, DefinedImportData *S,
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<InputFile> Lazy::getMember() {
|
||||
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 std::unique_ptr<InputFile>(nullptr);
|
||||
return nullptr;
|
||||
|
||||
file_magic Magic = identify_magic(MBRef.getBuffer());
|
||||
if (Magic == file_magic::coff_import_library)
|
||||
return std::unique_ptr<InputFile>(new ImportFile(MBRef));
|
||||
return make<ImportFile>(MBRef);
|
||||
|
||||
std::unique_ptr<InputFile> Obj;
|
||||
InputFile *Obj;
|
||||
if (Magic == file_magic::coff_object)
|
||||
Obj.reset(new ObjectFile(MBRef));
|
||||
Obj = make<ObjectFile>(MBRef);
|
||||
else if (Magic == file_magic::bitcode)
|
||||
Obj.reset(new BitcodeFile(MBRef));
|
||||
Obj = make<BitcodeFile>(MBRef);
|
||||
else
|
||||
fatal("unknown file type: " + File->getName());
|
||||
|
||||
|
|
|
@ -256,7 +256,7 @@ public:
|
|||
|
||||
// Returns an object file for this symbol, or a nullptr if the file
|
||||
// was already returned.
|
||||
std::unique_ptr<InputFile> getMember();
|
||||
InputFile *getMember();
|
||||
|
||||
int getFileIndex() { return File->Index; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue