[WebAssembly] Ensure ArchiveName is set even in the presence of --whole-archive.

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

llvm-svn: 357966
This commit is contained in:
Sam Clegg 2019-04-09 05:41:52 +00:00
parent 3f2096833a
commit 0cfaa2470f
6 changed files with 19 additions and 11 deletions

View File

@ -47,6 +47,8 @@ entry:
; Verfiy errors include library name ; 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 ; 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: error: duplicate symbol: bar
; CHECK-DUP: >>> defined in {{.*}}.a({{.*}}.a2.o) ; CHECK-DUP: >>> defined in {{.*}}.a({{.*}}.a2.o)
; CHECK-DUP: >>> defined in {{.*}}.a({{.*}}.a3.o) ; CHECK-DUP: >>> defined in {{.*}}.a({{.*}}.a3.o)

View File

@ -226,7 +226,7 @@ void LinkerDriver::addFile(StringRef Path) {
// Handle -whole-archive. // Handle -whole-archive.
if (InWholeArchive) { if (InWholeArchive) {
for (MemoryBufferRef &M : getArchiveMembers(MBRef)) for (MemoryBufferRef &M : getArchiveMembers(MBRef))
Files.push_back(createObjectFile(M)); Files.push_back(createObjectFile(M, Path));
return; return;
} }

View File

@ -42,18 +42,19 @@ Optional<MemoryBufferRef> lld::wasm::readFile(StringRef Path) {
return MBRef; return MBRef;
} }
InputFile *lld::wasm::createObjectFile(MemoryBufferRef MB) { InputFile *lld::wasm::createObjectFile(MemoryBufferRef MB,
StringRef ArchiveName) {
file_magic Magic = identify_magic(MB.getBuffer()); file_magic Magic = identify_magic(MB.getBuffer());
if (Magic == file_magic::wasm_object) { if (Magic == file_magic::wasm_object) {
std::unique_ptr<Binary> Bin = check(createBinary(MB)); std::unique_ptr<Binary> Bin = check(createBinary(MB));
auto *Obj = cast<WasmObjectFile>(Bin.get()); auto *Obj = cast<WasmObjectFile>(Bin.get());
if (Obj->isSharedObject()) if (Obj->isSharedObject())
return make<SharedFile>(MB); return make<SharedFile>(MB);
return make<ObjFile>(MB); return make<ObjFile>(MB, ArchiveName);
} }
if (Magic == file_magic::bitcode) if (Magic == file_magic::bitcode)
return make<BitcodeFile>(MB); return make<BitcodeFile>(MB, ArchiveName);
fatal("unknown file type: " + MB.getBufferIdentifier()); 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 " + "could not get the buffer for the member defining symbol " +
Sym->getName()); Sym->getName());
InputFile *Obj = createObjectFile(MB); InputFile *Obj = createObjectFile(MB, getName());
Obj->ArchiveName = getName();
Symtab->addFile(Obj); Symtab->addFile(Obj);
} }

View File

@ -82,7 +82,10 @@ private:
// .o file (wasm object file) // .o file (wasm object file)
class ObjFile : public InputFile { class ObjFile : public InputFile {
public: 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; } static bool classof(const InputFile *F) { return F->kind() == ObjectKind; }
void parse() override; void parse() override;
@ -144,7 +147,10 @@ public:
// .bc file // .bc file
class BitcodeFile : public InputFile { class BitcodeFile : public InputFile {
public: 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; } static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
void parse() override; void parse() override;
@ -153,7 +159,7 @@ public:
// Will report a fatal() error if the input buffer is not a valid bitcode // Will report a fatal() error if the input buffer is not a valid bitcode
// or wasm object file. // or wasm object file.
InputFile *createObjectFile(MemoryBufferRef MB); InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "");
// Opens a given file. // Opens a given file.
llvm::Optional<MemoryBufferRef> readFile(StringRef Path); llvm::Optional<MemoryBufferRef> readFile(StringRef Path);

View File

@ -58,7 +58,7 @@ void SymbolTable::addCombinedLTOObject() {
LTO->add(*F); LTO->add(*F);
for (StringRef Filename : LTO->compile()) { for (StringRef Filename : LTO->compile()) {
auto *Obj = make<ObjFile>(MemoryBufferRef(Filename, "lto.tmp")); auto *Obj = make<ObjFile>(MemoryBufferRef(Filename, "lto.tmp"), "");
Obj->parse(); Obj->parse();
ObjectFiles.push_back(Obj); ObjectFiles.push_back(Obj);
} }

View File

@ -39,7 +39,7 @@ public:
void addCombinedLTOObject(); void addCombinedLTOObject();
std::vector<ObjFile *> ObjectFiles; std::vector<ObjFile *> ObjectFiles;
std::vector<InputFile *> SharedFiles; std::vector<SharedFile *> SharedFiles;
std::vector<BitcodeFile *> BitcodeFiles; std::vector<BitcodeFile *> BitcodeFiles;
std::vector<InputFunction *> SyntheticFunctions; std::vector<InputFunction *> SyntheticFunctions;
std::vector<InputGlobal *> SyntheticGlobals; std::vector<InputGlobal *> SyntheticGlobals;