Revert r326911: Improve --warn-symbol-ordering.
authorRui Ueyama <ruiu@google.com>
Wed, 7 Mar 2018 17:24:46 +0000 (17:24 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 7 Mar 2018 17:24:46 +0000 (17:24 +0000)
This reverts commit r326911 because it was committed by accident.

llvm-svn: 326914

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

index b29c383007ac95a44a22025c2d3416dd2f3d811e..309022dbb92932d71e38dac1136cbbc9fefe0956 100644 (file)
@@ -1045,35 +1045,28 @@ static DenseMap<const InputSectionBase *, int> buildSectionOrder() {
       SymbolOrderEntry &Ent = It->second;
       Ent.Present = true;
 
-      auto Warning = [&](StringRef Msg) {
-        if (Config->WarnSymbolOrdering)
-          warn(File->getName() + ": " + Msg + ": " + Sym->getName());
-      };
-
-      if (Sym->isUndefined()) {
-        Warning("unable to order undefined symbol");
-        continue;
+      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());
       }
-      if (Sym->isShared()) {
-        Warning("unable to order shared symbol");
+      if (!D)
         continue;
-      }
 
-      auto *Sec = dyn_cast_or_null<InputSectionBase>(cast<Defined>(Sym)->Section);
-      if (!Sec) {
-        Warning("unable to order absolute symbol");
-        continue;
-      }
-      if (!Sec->Live) {
-        if (Sec->Repl == Sec)
-          Warning("unable to order discarded symbol");
-        else
-          Warning("unable to order a symbol merged by ICF");
-        continue;
+      if (auto *Sec = dyn_cast_or_null<InputSectionBase>(D->Section)) {
+        int &Priority = SectionOrder[cast<InputSectionBase>(Sec->Repl)];
+        Priority = std::min(Priority, Ent.Priority);
       }
-
-      int &Priority = SectionOrder[cast<InputSectionBase>(Sec->Repl)];
-      Priority = std::min(Priority, Ent.Priority);
     }
   }
 
index 14a835c18cccea24e473cca9e4a01ecffffa9583..93e377cb53b0871c57e2adf6b44c93cfe07259f6 100644 (file)
@@ -6,10 +6,11 @@
 # RUN: ld.lld --icf=all --symbol-ordering-file %t.order -shared %t.o -o %t.so
 # RUN: llvm-nm %t.so | FileCheck %s
 
-## Check that we do not sort ICF'ed symbols 'foo' and 'zed'.
-# CHECK-DAG: 0000000000001000 T bar
-# CHECK-DAG: 0000000000001004 T foo
-# CHECK-DAG: 0000000000001004 T zed
+## Check that after ICF merges 'foo' and 'zed' we still
+## place them before 'bar', in according to ordering file.
+# CHECK-DAG: 0000000000001000 T foo
+# CHECK-DAG: 0000000000001000 T zed
+# CHECK-DAG: 0000000000001004 T bar
 
 .section .text.foo,"ax",@progbits
 .align 4
index a41a9fc60718d18f77f31b8f7c4fa8733bd9a06e..aabac53b06bec2c528210ae1653f61a998d27cbc 100644 (file)
 # 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 a symbol merged by ICF: icf2
+# 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