From 0cfaa2470f5552a33352454fec08fea66dcba071 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 9 Apr 2019 05:41:52 +0000 Subject: [PATCH] [WebAssembly] Ensure ArchiveName is set even in the presence of --whole-archive. Differential Revision: https://reviews.llvm.org/D60431 llvm-svn: 357966 --- lld/test/wasm/archive.ll | 2 ++ lld/wasm/Driver.cpp | 2 +- lld/wasm/InputFiles.cpp | 10 +++++----- lld/wasm/InputFiles.h | 12 +++++++++--- lld/wasm/SymbolTable.cpp | 2 +- lld/wasm/SymbolTable.h | 2 +- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lld/test/wasm/archive.ll b/lld/test/wasm/archive.ll index f2eee96..8405453 100644 --- a/lld/test/wasm/archive.ll +++ b/lld/test/wasm/archive.ll @@ -47,6 +47,8 @@ entry: ; Verfiy errors include library name ; RUN: not wasm-ld -u archive2_symbol -u archive3_symbol %t.a %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-DUP %s +; And that this also works with --whole-archive +; RUN: not wasm-ld -u archive2_symbol -u archive3_symbol --whole-archive %t.a %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-DUP %s ; CHECK-DUP: error: duplicate symbol: bar ; CHECK-DUP: >>> defined in {{.*}}.a({{.*}}.a2.o) ; CHECK-DUP: >>> defined in {{.*}}.a({{.*}}.a3.o) diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index c102bca..f65722f 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -226,7 +226,7 @@ void LinkerDriver::addFile(StringRef Path) { // Handle -whole-archive. if (InWholeArchive) { for (MemoryBufferRef &M : getArchiveMembers(MBRef)) - Files.push_back(createObjectFile(M)); + Files.push_back(createObjectFile(M, Path)); return; } diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 914b731..e118b04 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -42,18 +42,19 @@ Optional lld::wasm::readFile(StringRef Path) { return MBRef; } -InputFile *lld::wasm::createObjectFile(MemoryBufferRef MB) { +InputFile *lld::wasm::createObjectFile(MemoryBufferRef MB, + StringRef ArchiveName) { file_magic Magic = identify_magic(MB.getBuffer()); if (Magic == file_magic::wasm_object) { std::unique_ptr Bin = check(createBinary(MB)); auto *Obj = cast(Bin.get()); if (Obj->isSharedObject()) return make(MB); - return make(MB); + return make(MB, ArchiveName); } if (Magic == file_magic::bitcode) - return make(MB); + return make(MB, ArchiveName); fatal("unknown file type: " + MB.getBufferIdentifier()); } @@ -435,8 +436,7 @@ void ArchiveFile::addMember(const Archive::Symbol *Sym) { "could not get the buffer for the member defining symbol " + Sym->getName()); - InputFile *Obj = createObjectFile(MB); - Obj->ArchiveName = getName(); + InputFile *Obj = createObjectFile(MB, getName()); Symtab->addFile(Obj); } diff --git a/lld/wasm/InputFiles.h b/lld/wasm/InputFiles.h index ac1e273..7b2c4d5 100644 --- a/lld/wasm/InputFiles.h +++ b/lld/wasm/InputFiles.h @@ -82,7 +82,10 @@ private: // .o file (wasm object file) class ObjFile : public InputFile { public: - explicit ObjFile(MemoryBufferRef M) : InputFile(ObjectKind, M) {} + explicit ObjFile(MemoryBufferRef M, StringRef ArchiveName) + : InputFile(ObjectKind, M) { + this->ArchiveName = ArchiveName; + } static bool classof(const InputFile *F) { return F->kind() == ObjectKind; } void parse() override; @@ -144,7 +147,10 @@ public: // .bc file class BitcodeFile : public InputFile { public: - explicit BitcodeFile(MemoryBufferRef M) : InputFile(BitcodeKind, M) {} + explicit BitcodeFile(MemoryBufferRef M, StringRef ArchiveName) + : InputFile(BitcodeKind, M) { + this->ArchiveName = ArchiveName; + } static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; } void parse() override; @@ -153,7 +159,7 @@ public: // Will report a fatal() error if the input buffer is not a valid bitcode // or wasm object file. -InputFile *createObjectFile(MemoryBufferRef MB); +InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = ""); // Opens a given file. llvm::Optional readFile(StringRef Path); diff --git a/lld/wasm/SymbolTable.cpp b/lld/wasm/SymbolTable.cpp index 4fe455a..bbce074 100644 --- a/lld/wasm/SymbolTable.cpp +++ b/lld/wasm/SymbolTable.cpp @@ -58,7 +58,7 @@ void SymbolTable::addCombinedLTOObject() { LTO->add(*F); for (StringRef Filename : LTO->compile()) { - auto *Obj = make(MemoryBufferRef(Filename, "lto.tmp")); + auto *Obj = make(MemoryBufferRef(Filename, "lto.tmp"), ""); Obj->parse(); ObjectFiles.push_back(Obj); } diff --git a/lld/wasm/SymbolTable.h b/lld/wasm/SymbolTable.h index afb1bb9..22cae65 100644 --- a/lld/wasm/SymbolTable.h +++ b/lld/wasm/SymbolTable.h @@ -39,7 +39,7 @@ public: void addCombinedLTOObject(); std::vector ObjectFiles; - std::vector SharedFiles; + std::vector SharedFiles; std::vector BitcodeFiles; std::vector SyntheticFunctions; std::vector SyntheticGlobals; -- 2.7.4