[lld] r259233 - ELF: Report duplicate symbols as many as possible instead of the first one.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 29 11:41:14 PST 2016


Author: ruiu
Date: Fri Jan 29 13:41:13 2016
New Revision: 259233

URL: http://llvm.org/viewvc/llvm-project?rev=259233&view=rev
Log:
ELF: Report duplicate symbols as many as possible instead of the first one.

http://reviews.llvm.org/D16647

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/test/ELF/conflict.s

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=259233&r1=259232&r2=259233&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Jan 29 13:41:13 2016
@@ -335,6 +335,8 @@ template <class ELFT> void LinkerDriver:
 
   for (std::unique_ptr<InputFile> &F : Files)
     Symtab.addFile(std::move(F));
+  if (HasError)
+    return; // There were duplicate symbols or incompatible files
 
   for (StringRef S : Config->Undefined)
     Symtab.addUndefinedOpt(S);

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=259233&r1=259232&r2=259233&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Fri Jan 29 13:41:13 2016
@@ -30,25 +30,26 @@ using namespace lld::elf2;
 // All input object files must be for the same architecture
 // (e.g. it does not make sense to link x86 object files with
 // MIPS object files.) This function checks for that error.
-template <class ELFT>
-static void checkCompatibility(InputFile *FileP) {
+template <class ELFT> static bool isCompatible(InputFile *FileP) {
   auto *F = dyn_cast<ELFFileBase<ELFT>>(FileP);
   if (!F)
-    return;
+    return true;
   if (F->getELFKind() == Config->EKind && F->getEMachine() == Config->EMachine)
-    return;
+    return true;
   StringRef A = F->getName();
   StringRef B = Config->Emulation;
   if (B.empty())
     B = Config->FirstElf->getName();
-  fatal(A + " is incompatible with " + B);
+  error(A + " is incompatible with " + B);
+  return false;
 }
 
 // Add symbols in File to the symbol table.
 template <class ELFT>
 void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
   InputFile *FileP = File.get();
-  checkCompatibility<ELFT>(FileP);
+  if (!isCompatible<ELFT>(FileP))
+    return;
 
   // .a file
   if (auto *F = dyn_cast<ArchiveFile>(FileP)) {
@@ -181,17 +182,20 @@ template <class ELFT> void SymbolTable<E
     return;
   }
 
-  if (New->isTls() != Existing->isTls())
-    fatal("TLS attribute mismatch for symbol: " + conflictMsg(Existing, New));
+  if (New->isTls() != Existing->isTls()) {
+    error("TLS attribute mismatch for symbol: " + conflictMsg(Existing, New));
+    return;
+  }
 
   // compare() returns -1, 0, or 1 if the lhs symbol is less preferable,
   // equivalent (conflicting), or more preferable, respectively.
   int Comp = Existing->compare<ELFT>(New);
   if (Comp == 0) {
     std::string S = "duplicate symbol: " + conflictMsg(Existing, New);
-    if (!Config->AllowMultipleDefinition)
-      fatal(S);
-    warning(S);
+    if (Config->AllowMultipleDefinition)
+      warning(S);
+    else
+      error(S);
     return;
   }
   if (Comp < 0)

Modified: lld/trunk/test/ELF/conflict.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/conflict.s?rev=259233&r1=259232&r2=259233&view=diff
==============================================================================
--- lld/trunk/test/ELF/conflict.s (original)
+++ lld/trunk/test/ELF/conflict.s Fri Jan 29 13:41:13 2016
@@ -7,10 +7,14 @@
 # RUN:   FileCheck -check-prefix=NO_DEMANGLE %s
 
 # DEMANGLE:    duplicate symbol: {{mul\(double, double\)|_Z3muldd}} in
+# DEMANGLE:    duplicate symbol: foo in
+
 # NO_DEMANGLE: duplicate symbol: _Z3muldd in
+# NO_DEMANGLE: duplicate symbol: foo in
 
-.globl _Z3muldd
+.globl _Z3muldd, foo
 _Z3muldd:
+foo:
   mov $60, %rax
   mov $42, %rdi
   syscall




More information about the llvm-commits mailing list