diff options
author | Sam Clegg <sbc@chromium.org> | 2019-06-05 17:50:45 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2019-06-05 17:50:45 +0000 |
commit | a282a61ba3a144a8f820c96446ba51a90134efcc (patch) | |
tree | 51684a25a7a258ab1e697fb49bca4c651949b969 | |
parent | 579c8df70130c4d41391d62f8f03e2404778945f (diff) | |
download | llvm-a282a61ba3a144a8f820c96446ba51a90134efcc.zip llvm-a282a61ba3a144a8f820c96446ba51a90134efcc.tar.gz llvm-a282a61ba3a144a8f820c96446ba51a90134efcc.tar.bz2 |
[WebAssembly] Handle object parsing more like the ELF backend
Differential Revision: https://reviews.llvm.org/D62886
llvm-svn: 362626
-rw-r--r-- | lld/wasm/InputFiles.cpp | 4 | ||||
-rw-r--r-- | lld/wasm/InputFiles.h | 11 | ||||
-rw-r--r-- | lld/wasm/SymbolTable.cpp | 28 |
3 files changed, 27 insertions, 16 deletions
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 23d3900..1d49f63 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -454,7 +454,7 @@ Symbol *ObjFile::createUndefined(const WasmSymbol &Sym, bool IsCalledDirectly) { 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 @@ static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats, 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/lld/wasm/InputFiles.h b/lld/wasm/InputFiles.h index f5b4532..57d36a8 100644 --- a/lld/wasm/InputFiles.h +++ b/lld/wasm/InputFiles.h @@ -51,9 +51,6 @@ public: // 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 @@ public: 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 @@ public: } 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 @@ class SharedFile : public InputFile { 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 @@ public: } 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/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index c4a460f..74d3132 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -28,17 +28,33 @@ SymbolTable *lld::wasm::Symtab; 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 |