[WebAssembly] Handle object parsing more like the ELF backend

Differential Revision: https://reviews.llvm.org/D62886

llvm-svn: 362626
This commit is contained in:
Sam Clegg 2019-06-05 17:50:45 +00:00
parent 579c8df701
commit a282a61ba3
3 changed files with 27 additions and 16 deletions

View File

@ -454,7 +454,7 @@ Symbol *ObjFile::createUndefined(const WasmSymbol &Sym, bool IsCalledDirectly) {
llvm_unreachable("unknown symbol kind"); llvm_unreachable("unknown symbol kind");
} }
void ArchiveFile::parse(bool IgnoreComdats) { void ArchiveFile::parse() {
// Parse a MemoryBufferRef as an archive file. // Parse a MemoryBufferRef as an archive file.
LLVM_DEBUG(dbgs() << "Parsing library: " << toString(this) << "\n"); LLVM_DEBUG(dbgs() << "Parsing library: " << toString(this) << "\n");
File = CHECK(Archive::create(MB), toString(this)); File = CHECK(Archive::create(MB), toString(this));
@ -524,7 +524,7 @@ static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
return Symtab->addDefinedData(Name, Flags, &F, nullptr, 0, 0); return Symtab->addDefinedData(Name, Flags, &F, nullptr, 0, 0);
} }
void BitcodeFile::parse(bool IgnoreComdats) { void BitcodeFile::parse() {
Obj = check(lto::InputFile::create(MemoryBufferRef( Obj = check(lto::InputFile::create(MemoryBufferRef(
MB.getBuffer(), Saver.save(ArchiveName + MB.getBufferIdentifier())))); MB.getBuffer(), Saver.save(ArchiveName + MB.getBufferIdentifier()))));
Triple T(Obj->getTargetTriple()); Triple T(Obj->getTargetTriple());

View File

@ -51,9 +51,6 @@ public:
// Returns the filename. // Returns the filename.
StringRef getName() const { return MB.getBufferIdentifier(); } StringRef getName() const { return MB.getBufferIdentifier(); }
// Reads a file (the constructor doesn't do that).
virtual void parse(bool IgnoreComdats = false) = 0;
Kind kind() const { return FileKind; } Kind kind() const { return FileKind; }
// An archive file name if this file is created from an archive. // An archive file name if this file is created from an archive.
@ -82,7 +79,7 @@ public:
void addMember(const llvm::object::Archive::Symbol *Sym); void addMember(const llvm::object::Archive::Symbol *Sym);
void parse(bool IgnoreComdats) override; void parse();
private: private:
std::unique_ptr<llvm::object::Archive> File; std::unique_ptr<llvm::object::Archive> File;
@ -98,7 +95,7 @@ public:
} }
static bool classof(const InputFile *F) { return F->kind() == ObjectKind; } static bool classof(const InputFile *F) { return F->kind() == ObjectKind; }
void parse(bool IgnoreComdats) override; void parse(bool IgnoreComdats = false);
// Returns the underlying wasm file. // Returns the underlying wasm file.
const WasmObjectFile *getWasmObj() const { return WasmObj.get(); } const WasmObjectFile *getWasmObj() const { return WasmObj.get(); }
@ -150,8 +147,6 @@ class SharedFile : public InputFile {
public: public:
explicit SharedFile(MemoryBufferRef M) : InputFile(SharedKind, M) {} explicit SharedFile(MemoryBufferRef M) : InputFile(SharedKind, M) {}
static bool classof(const InputFile *F) { return F->kind() == SharedKind; } static bool classof(const InputFile *F) { return F->kind() == SharedKind; }
void parse(bool IgnoreComdats) override {}
}; };
// .bc file // .bc file
@ -163,7 +158,7 @@ public:
} }
static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; } static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
void parse(bool IgnoreComdats) override; void parse();
std::unique_ptr<llvm::lto::InputFile> Obj; std::unique_ptr<llvm::lto::InputFile> Obj;
}; };

View File

@ -28,17 +28,33 @@ SymbolTable *lld::wasm::Symtab;
void SymbolTable::addFile(InputFile *File) { void SymbolTable::addFile(InputFile *File) {
log("Processing: " + toString(File)); log("Processing: " + toString(File));
// .a file
if (auto *F = dyn_cast<ArchiveFile>(File)) {
F->parse();
return;
}
// .so file
if (auto *F = dyn_cast<SharedFile>(File)) {
SharedFiles.push_back(F);
return;
}
if (Config->Trace) if (Config->Trace)
message(toString(File)); message(toString(File));
File->parse();
// LLVM bitcode file // LLVM bitcode file
if (auto *F = dyn_cast<BitcodeFile>(File)) if (auto *F = dyn_cast<BitcodeFile>(File)) {
F->parse();
BitcodeFiles.push_back(F); BitcodeFiles.push_back(F);
else if (auto *F = dyn_cast<ObjFile>(File)) return;
ObjectFiles.push_back(F); }
else if (auto *F = dyn_cast<SharedFile>(File))
SharedFiles.push_back(F); // Regular object file
auto *F = cast<ObjFile>(File);
F->parse(false);
ObjectFiles.push_back(F);
} }
// This function is where all the optimizations of link-time // This function is where all the optimizations of link-time