From 2df314d17f83c6b7d47c8933d2954afc9e19439d Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 18 Jul 2018 21:46:09 +0000 Subject: [PATCH] [WebAssembly] Fix archive member display in error messages Add a test for this by causing a symbol collision between archive members. Differential Revision: https://reviews.llvm.org/D49343 llvm-svn: 337426 --- lld/test/wasm/Inputs/archive2.ll | 5 +++++ lld/test/wasm/Inputs/archive3.ll | 11 +++++++++++ lld/test/wasm/archive.ll | 16 ++++++++++++---- lld/wasm/InputFiles.cpp | 8 ++++---- lld/wasm/InputFiles.h | 2 +- 5 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 lld/test/wasm/Inputs/archive3.ll diff --git a/lld/test/wasm/Inputs/archive2.ll b/lld/test/wasm/Inputs/archive2.ll index c4903cb..66bfeac 100644 --- a/lld/test/wasm/Inputs/archive2.ll +++ b/lld/test/wasm/Inputs/archive2.ll @@ -7,3 +7,8 @@ entry: %call = tail call i32 @foo() #2 ret i32 %call } + +define void @archive2_symbol() local_unnamed_addr #0 { +entry: + ret void +} diff --git a/lld/test/wasm/Inputs/archive3.ll b/lld/test/wasm/Inputs/archive3.ll new file mode 100644 index 0000000..8c78a46 --- /dev/null +++ b/lld/test/wasm/Inputs/archive3.ll @@ -0,0 +1,11 @@ +target triple = "wasm32-unknown-unknown" + +define i32 @bar() local_unnamed_addr #0 { +entry: + ret i32 1 +} + +define void @archive3_symbol() local_unnamed_addr #0 { +entry: + ret void +} diff --git a/lld/test/wasm/archive.ll b/lld/test/wasm/archive.ll index b2499ea..50f72d6 100644 --- a/lld/test/wasm/archive.ll +++ b/lld/test/wasm/archive.ll @@ -1,8 +1,9 @@ ; RUN: llc -filetype=obj %s -o %t.o ; RUN: llc -filetype=obj %S/Inputs/archive1.ll -o %t.a1.o ; RUN: llc -filetype=obj %S/Inputs/archive2.ll -o %t.a2.o -; RUN: llc -filetype=obj %S/Inputs/hello.ll -o %t.a3.o -; RUN: llvm-ar rcs %t.a %t.a1.o %t.a2.o %t.a3.o +; RUN: llc -filetype=obj %S/Inputs/archive3.ll -o %t.a3.o +; RUN: llc -filetype=obj %S/Inputs/hello.ll -o %t.hello.o +; RUN: llvm-ar rcs %t.a %t.a1.o %t.a2.o %t.a3.o %t.hello.o ; RUN: rm -f %t.imports ; RUN: not wasm-ld %t.a %t.o -o %t.wasm 2>&1 | FileCheck -check-prefix=CHECK-UNDEFINED %s @@ -31,9 +32,10 @@ entry: ; TODO(ncw): Update LLD so that the symbol table is written out for ; non-relocatable output (with an option to strip it) -; CHECK: 00000003 T _start +; CHECK: 00000004 T _start +; CHECK-NEXT: 00000002 T archive2_symbol ; CHECK-NEXT: 00000001 T bar -; CHECK-NEXT: 00000002 T foo +; CHECK-NEXT: 00000003 T foo ; CHECK-NEXT: U missing_func ; Verify that symbols from unused objects don't appear in the symbol table @@ -41,3 +43,9 @@ entry: ; Specifying the same archive twice is allowed. ; RUN: wasm-ld %t.a %t.a %t.o -o %t.wasm + +; 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 +; 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/InputFiles.cpp b/lld/wasm/InputFiles.cpp index 55392cc..0396f29 100644 --- a/lld/wasm/InputFiles.cpp +++ b/lld/wasm/InputFiles.cpp @@ -372,7 +372,7 @@ void ArchiveFile::addMember(const Archive::Symbol *Sym) { return; } - Obj->ParentName = ParentName; + Obj->ArchiveName = getName(); Symtab->addFile(Obj); } @@ -407,7 +407,7 @@ static Symbol *createBitcodeSymbol(const lto::InputFile::Symbol &ObjSym, void BitcodeFile::parse() { Obj = check(lto::InputFile::create(MemoryBufferRef( - MB.getBuffer(), Saver.save(ParentName + MB.getBufferIdentifier())))); + MB.getBuffer(), Saver.save(ArchiveName + MB.getBufferIdentifier())))); Triple T(Obj->getTargetTriple()); if (T.getArch() != Triple::wasm32) { error(toString(MB.getBufferIdentifier()) + ": machine type must be wasm32"); @@ -423,8 +423,8 @@ std::string lld::toString(const wasm::InputFile *File) { if (!File) return ""; - if (File->ParentName.empty()) + if (File->ArchiveName.empty()) return File->getName(); - return (File->ParentName + "(" + File->getName() + ")").str(); + return (File->ArchiveName + "(" + File->getName() + ")").str(); } diff --git a/lld/wasm/InputFiles.h b/lld/wasm/InputFiles.h index 75d20e6..73cc32f 100644 --- a/lld/wasm/InputFiles.h +++ b/lld/wasm/InputFiles.h @@ -63,7 +63,7 @@ public: Kind kind() const { return FileKind; } // An archive file name if this file is created from an archive. - StringRef ParentName; + StringRef ArchiveName; ArrayRef getSymbols() const { return Symbols; } -- 2.7.4