[PATCH] D44549: allow-multiple-definitions should completely suppress errors instead of making them warnings.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 16 12:24:13 PDT 2018


ruiu updated this revision to Diff 138744.
ruiu added a comment.

- address review comment.


https://reviews.llvm.org/D44549

Files:
  lld/ELF/SymbolTable.cpp
  lld/test/ELF/allow-multiple-definition.s


Index: lld/test/ELF/allow-multiple-definition.s
===================================================================
--- lld/test/ELF/allow-multiple-definition.s
+++ lld/test/ELF/allow-multiple-definition.s
@@ -4,13 +4,13 @@
 # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/allow-multiple-definition.s -o %t2
 # RUN: not ld.lld %t1 %t2 -o %t3
 # RUN: not ld.lld --allow-multiple-definition --no-allow-multiple-definition %t1 %t2 -o %t3
-# RUN: ld.lld --allow-multiple-definition %t1 %t2 -o %t3
-# RUN: ld.lld --allow-multiple-definition %t2 %t1 -o %t4
+# RUN: ld.lld --allow-multiple-definition --fatal-warnings %t1 %t2 -o %t3
+# RUN: ld.lld --allow-multiple-definition --fatal-warnings %t2 %t1 -o %t4
 # RUN: llvm-objdump -d %t3 | FileCheck %s
 # RUN: llvm-objdump -d %t4 | FileCheck -check-prefix=REVERT %s
 
-# RUN: ld.lld -z muldefs %t1 %t2 -o %t3
-# RUN: ld.lld -z muldefs %t2 %t1 -o %t4
+# RUN: ld.lld -z muldefs --fatal-warnings  %t1 %t2 -o %t3
+# RUN: ld.lld -z muldefs --fatal-warnings  %t2 %t1 -o %t4
 # RUN: llvm-objdump -d %t3 | FileCheck %s
 # RUN: llvm-objdump -d %t4 | FileCheck -check-prefix=REVERT %s
 
Index: lld/ELF/SymbolTable.cpp
===================================================================
--- lld/ELF/SymbolTable.cpp
+++ lld/ELF/SymbolTable.cpp
@@ -410,20 +410,16 @@
   return S;
 }
 
-static void warnOrError(const Twine &Msg) {
-  if (Config->AllowMultipleDefinition)
-    warn(Msg);
-  else
-    error(Msg);
-}
-
 static void reportDuplicate(Symbol *Sym, InputFile *NewFile) {
-  warnOrError("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " +
-              toString(Sym->File) + "\n>>> defined in " + toString(NewFile));
+  error("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " +
+        toString(Sym->File) + "\n>>> defined in " + toString(NewFile));
 }
 
 static void reportDuplicate(Symbol *Sym, InputFile *NewFile,
                             InputSectionBase *ErrSec, uint64_t ErrOffset) {
+  if (Config->AllowMultipleDefinition)
+    return;
+
   Defined *D = cast<Defined>(Sym);
   if (!D->Section || !ErrSec) {
     reportDuplicate(Sym, NewFile);
@@ -450,7 +446,7 @@
   if (!Src2.empty())
     Msg += Src2 + "\n>>>            ";
   Msg += Obj2;
-  warnOrError(Msg);
+  error(Msg);
 }
 
 Symbol *SymbolTable::addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
@@ -510,11 +506,13 @@
   bool WasInserted;
   std::tie(S, WasInserted) =
       insert(Name, Type, getVisibility(StOther), CanOmitFromDynSym, &F);
+
   int Cmp = compareDefinedNonCommon(S, WasInserted, Binding,
                                     /*IsAbs*/ false, /*Value*/ 0, Name);
+
   if (Cmp > 0)
     replaceSymbol<Defined>(S, &F, Name, Binding, StOther, Type, 0, 0, nullptr);
-  else if (Cmp == 0)
+  else if (Cmp == 0 && !Config->AllowMultipleDefinition)
     reportDuplicate(S, &F);
   return S;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44549.138744.patch
Type: text/x-patch
Size: 2861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180316/57fe34df/attachment.bin>


More information about the llvm-commits mailing list