[lld] r337426 - [WebAssembly] Fix archive member display in error messages

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 18 14:46:09 PDT 2018


Author: sbc
Date: Wed Jul 18 14:46:09 2018
New Revision: 337426

URL: http://llvm.org/viewvc/llvm-project?rev=337426&view=rev
Log:
[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

Added:
    lld/trunk/test/wasm/Inputs/archive3.ll
      - copied, changed from r337314, lld/trunk/test/wasm/Inputs/archive2.ll
Modified:
    lld/trunk/test/wasm/Inputs/archive2.ll
    lld/trunk/test/wasm/archive.ll
    lld/trunk/wasm/InputFiles.cpp
    lld/trunk/wasm/InputFiles.h

Modified: lld/trunk/test/wasm/Inputs/archive2.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/Inputs/archive2.ll?rev=337426&r1=337425&r2=337426&view=diff
==============================================================================
--- lld/trunk/test/wasm/Inputs/archive2.ll (original)
+++ lld/trunk/test/wasm/Inputs/archive2.ll Wed Jul 18 14:46:09 2018
@@ -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
+}

Copied: lld/trunk/test/wasm/Inputs/archive3.ll (from r337314, lld/trunk/test/wasm/Inputs/archive2.ll)
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/Inputs/archive3.ll?p2=lld/trunk/test/wasm/Inputs/archive3.ll&p1=lld/trunk/test/wasm/Inputs/archive2.ll&r1=337314&r2=337426&rev=337426&view=diff
==============================================================================
--- lld/trunk/test/wasm/Inputs/archive2.ll (original)
+++ lld/trunk/test/wasm/Inputs/archive3.ll Wed Jul 18 14:46:09 2018
@@ -1,9 +1,11 @@
 target triple = "wasm32-unknown-unknown"
 
-declare i32 @foo() local_unnamed_addr #1
-
 define i32 @bar() local_unnamed_addr #0 {
 entry:
-  %call = tail call i32 @foo() #2
-  ret i32 %call
+  ret i32 1
+}
+
+define void @archive3_symbol() local_unnamed_addr #0 {
+entry:
+  ret void
 }

Modified: lld/trunk/test/wasm/archive.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/archive.ll?rev=337426&r1=337425&r2=337426&view=diff
==============================================================================
--- lld/trunk/test/wasm/archive.ll (original)
+++ lld/trunk/test/wasm/archive.ll Wed Jul 18 14:46:09 2018
@@ -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)

Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=337426&r1=337425&r2=337426&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Wed Jul 18 14:46:09 2018
@@ -372,7 +372,7 @@ void ArchiveFile::addMember(const Archiv
     return;
   }
 
-  Obj->ParentName = ParentName;
+  Obj->ArchiveName = getName();
   Symtab->addFile(Obj);
 }
 
@@ -407,7 +407,7 @@ static Symbol *createBitcodeSymbol(const
 
 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::In
   if (!File)
     return "<internal>";
 
-  if (File->ParentName.empty())
+  if (File->ArchiveName.empty())
     return File->getName();
 
-  return (File->ParentName + "(" + File->getName() + ")").str();
+  return (File->ArchiveName + "(" + File->getName() + ")").str();
 }

Modified: lld/trunk/wasm/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.h?rev=337426&r1=337425&r2=337426&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.h (original)
+++ lld/trunk/wasm/InputFiles.h Wed Jul 18 14:46:09 2018
@@ -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<Symbol *> getSymbols() const { return Symbols; }
 




More information about the llvm-commits mailing list