[WebAssembly] Handle object parsing more like the ELF backend
Differential Revision: https://reviews.llvm.org/D62886
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@362626 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/wasm/InputFiles.cpp b/wasm/InputFiles.cpp
index 23d3900..1d49f63 100644
--- a/wasm/InputFiles.cpp
+++ b/wasm/InputFiles.cpp
@@ -454,7 +454,7 @@
llvm_unreachable("unknown symbol kind");
}
-void ArchiveFile::parse(bool IgnoreComdats) {
+void ArchiveFile::parse() {
// Parse a MemoryBufferRef as an archive file.
LLVM_DEBUG(dbgs() << "Parsing library: " << toString(this) << "\n");
File = CHECK(Archive::create(MB), toString(this));
@@ -524,7 +524,7 @@
return Symtab->addDefinedData(Name, Flags, &F, nullptr, 0, 0);
}
-void BitcodeFile::parse(bool IgnoreComdats) {
+void BitcodeFile::parse() {
Obj = check(lto::InputFile::create(MemoryBufferRef(
MB.getBuffer(), Saver.save(ArchiveName + MB.getBufferIdentifier()))));
Triple T(Obj->getTargetTriple());
diff --git a/wasm/InputFiles.h b/wasm/InputFiles.h
index f5b4532..57d36a8 100644
--- a/wasm/InputFiles.h
+++ b/wasm/InputFiles.h
@@ -51,9 +51,6 @@
// Returns the filename.
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; }
// An archive file name if this file is created from an archive.
@@ -82,7 +79,7 @@
void addMember(const llvm::object::Archive::Symbol *Sym);
- void parse(bool IgnoreComdats) override;
+ void parse();
private:
std::unique_ptr<llvm::object::Archive> File;
@@ -98,7 +95,7 @@
}
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.
const WasmObjectFile *getWasmObj() const { return WasmObj.get(); }
@@ -150,8 +147,6 @@
public:
explicit SharedFile(MemoryBufferRef M) : InputFile(SharedKind, M) {}
static bool classof(const InputFile *F) { return F->kind() == SharedKind; }
-
- void parse(bool IgnoreComdats) override {}
};
// .bc file
@@ -163,7 +158,7 @@
}
static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
- void parse(bool IgnoreComdats) override;
+ void parse();
std::unique_ptr<llvm::lto::InputFile> Obj;
};
diff --git a/wasm/SymbolTable.cpp b/wasm/SymbolTable.cpp
index c4a460f..74d3132 100644
--- a/wasm/SymbolTable.cpp
+++ b/wasm/SymbolTable.cpp
@@ -28,17 +28,33 @@
void SymbolTable::addFile(InputFile *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)
message(toString(File));
- File->parse();
// LLVM bitcode file
- if (auto *F = dyn_cast<BitcodeFile>(File))
+ if (auto *F = dyn_cast<BitcodeFile>(File)) {
+ F->parse();
BitcodeFiles.push_back(F);
- else if (auto *F = dyn_cast<ObjFile>(File))
- ObjectFiles.push_back(F);
- else if (auto *F = dyn_cast<SharedFile>(File))
- SharedFiles.push_back(F);
+ return;
+ }
+
+ // 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