[PATCH] D44180: Improve --warn-symbol-ordering.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 6 16:20:52 PST 2018


ruiu created this revision.
ruiu added reviewers: jhenderson, rafael.
Herald added subscribers: arichardson, emaste.

I originally tried to simplify code and then noticed that lld doesn't
do what it tells to the user by warn(). It says "unable to order
discarded symbol" but it actually can for sections eliminated by ICF.


https://reviews.llvm.org/D44180

Files:
  lld/ELF/Writer.cpp
  lld/test/ELF/symbol-ordering-file-warnings.s


Index: lld/test/ELF/symbol-ordering-file-warnings.s
===================================================================
--- lld/test/ELF/symbol-ordering-file-warnings.s
+++ lld/test/ELF/symbol-ordering-file-warnings.s
@@ -39,11 +39,11 @@
 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-gc.txt --gc-sections \
 # RUN:   --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,GC
 
-# Check that a warning is emitted for the symbol removed due to --icf.
+# Check that a warning is not emitted for the symbol removed due to --icf.
 # RUN: echo "icf1" > %t-order-icf.txt
 # RUN: echo "icf2" >> %t-order-icf.txt
 # RUN: ld.lld %t1.o -o %t --symbol-ordering-file %t-order-icf.txt --icf=all \
-# RUN:   --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,ICF
+# RUN:   --fatal-warnings --unresolved-symbols=ignore-all
 
 # Check that a warning is emitted for symbols discarded due to a linker script /DISCARD/ section.
 # RUN: echo "discard" > %t-order-discard.txt
@@ -109,7 +109,6 @@
 # WARN-NOT:    warning:
 # MISSING:     warning: symbol ordering file: no such symbol: missing
 # MISSING2:    warning: symbol ordering file: no such symbol: missing_sym
-# ICF:         warning: {{.*}}1.o: unable to order discarded symbol: icf2
 # COMDAT:      warning: {{.*}}1.o: unable to order discarded symbol: comdat
 # COMDAT-NEXT: warning: {{.*}}2.o: unable to order discarded symbol: comdat
 # MULTI:       warning: {{.*}}2.o: unable to order absolute symbol: multi
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -1045,28 +1045,32 @@
       SymbolOrderEntry &Ent = It->second;
       Ent.Present = true;
 
-      auto *D = dyn_cast<Defined>(Sym);
-      if (Config->WarnSymbolOrdering) {
-        if (Sym->isUndefined())
-          warn(File->getName() +
-               ": unable to order undefined symbol: " + Sym->getName());
-        else if (Sym->isShared())
-          warn(File->getName() +
-               ": unable to order shared symbol: " + Sym->getName());
-        else if (D && !D->Section)
-          warn(File->getName() +
-               ": unable to order absolute symbol: " + Sym->getName());
-        else if (D && !D->Section->Live)
-          warn(File->getName() +
-               ": unable to order discarded symbol: " + Sym->getName());
+      auto Warn = [&](StringRef Msg) {
+        if (Config->WarnSymbolOrdering)
+          warn(File->getName() + ": " + Msg + ": " + Sym->getName());
+      };
+
+      if (Sym->isUndefined()) {
+        Warn("unable to order undefined symbol");
+        continue;
       }
-      if (!D)
+      if (Sym->isShared()) {
+        Warn("unable to order shared symbol");
         continue;
+      }
 
-      if (auto *Sec = dyn_cast_or_null<InputSectionBase>(D->Section)) {
-        int &Priority = SectionOrder[cast<InputSectionBase>(Sec->Repl)];
-        Priority = std::min(Priority, Ent.Priority);
+      auto *Sec = dyn_cast_or_null<InputSectionBase>(cast<Defined>(Sym)->Section);
+      if (!Sec) {
+        Warn("unable to order absolute symbol");
+        continue;
+      }
+      if (!Sec->Live && Sec->Repl == Sec) {
+        Warn("unable to order discarded symbol");
+        continue;
       }
+
+      int &Priority = SectionOrder[cast<InputSectionBase>(Sec->Repl)];
+      Priority = std::min(Priority, Ent.Priority);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44180.137292.patch
Type: text/x-patch
Size: 3441 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180307/24dcb172/attachment.bin>


More information about the llvm-commits mailing list