[lld] r329371 - Change which file we print when a symbol cannot be ordered.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 5 20:36:19 PDT 2018


Author: rafael
Date: Thu Apr  5 20:36:19 2018
New Revision: 329371

URL: http://llvm.org/viewvc/llvm-project?rev=329371&view=rev
Log:
Change which file we print when a symbol cannot be ordered.

Currently there are a few odd things about the warning about symbols
that cannot be ordered. This patch fixes:

* When there is an undefined symbol that resolves to a shared file, we
  were printing the location of the undefined reference.

* If there are multiple comdats, we were reporting them all.

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

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=329371&r1=329370&r2=329371&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Apr  5 20:36:19 2018
@@ -1046,38 +1046,46 @@ static DenseMap<const InputSectionBase *
     SymbolOrder.insert({S, {Priority++, false}});
 
   // Build a map from sections to their priorities.
-  for (InputFile *File : ObjectFiles) {
-    for (Symbol *Sym : File->getSymbols()) {
-      auto It = SymbolOrder.find(Sym->getName());
-      if (It == SymbolOrder.end())
-        continue;
-      SymbolOrderEntry &Ent = It->second;
-      Ent.Present = true;
+  auto AddSym = [&](Symbol &Sym) {
+    auto It = SymbolOrder.find(Sym.getName());
+    if (It == SymbolOrder.end())
+      return;
+    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());
-      }
-      if (!D)
-        continue;
+    if (Config->WarnSymbolOrdering) {
+      auto *D = dyn_cast<Defined>(&Sym);
+      InputFile *File = Sym.File;
+      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 (auto *D = dyn_cast<Defined>(&Sym)) {
       if (auto *Sec = dyn_cast_or_null<InputSectionBase>(D->Section)) {
         int &Priority = SectionOrder[cast<InputSectionBase>(Sec->Repl)];
         Priority = std::min(Priority, Ent.Priority);
       }
     }
-  }
+  };
+  // We want both global and local symbols. We get the global ones from the
+  // symbol table and iterate the object files for the local ones.
+  for (Symbol *Sym : Symtab->getSymbols())
+    if (!Sym->isLazy())
+      AddSym(*Sym);
+  for (InputFile *File : ObjectFiles)
+    for (Symbol *Sym : File->getSymbols())
+      if (Sym->isLocal())
+        AddSym(*Sym);
 
   if (Config->WarnSymbolOrdering)
     for (auto OrderEntry : SymbolOrder)

Modified: lld/trunk/test/ELF/symbol-ordering-file-warnings.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/symbol-ordering-file-warnings.s?rev=329371&r1=329370&r2=329371&view=diff
==============================================================================
--- lld/trunk/test/ELF/symbol-ordering-file-warnings.s (original)
+++ lld/trunk/test/ELF/symbol-ordering-file-warnings.s Thu Apr  5 20:36:19 2018
@@ -97,23 +97,22 @@
 # WARN-NOT:    warning:
 # SAMESYM:     warning: {{.*}}.txt: duplicate ordered symbol: _start
 # WARN-NOT:    warning:
-# ABSOLUTE:    warning: {{.*}}1.o: unable to order absolute symbol: absolute
-# WARN-NOT:    warning:
 # DISCARD:     warning: {{.*}}1.o: unable to order discarded symbol: discard
 # WARN-NOT:    warning:
 # GC:          warning: {{.*}}1.o: unable to order discarded symbol: gc
 # WARN-NOT:    warning:
-# SHARED:      warning: {{.*}}1.o: unable to order shared symbol: shared
+# SHARED:      warning: {{.*}}.so: unable to order shared symbol: shared
 # WARN-NOT:    warning:
 # UNDEFINED:   warning: {{.*}}3.o: unable to order undefined symbol: undefined
 # WARN-NOT:    warning:
+# ABSOLUTE:    warning: {{.*}}1.o: unable to order absolute symbol: absolute
+# 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
-# MULTI-NEXT:  warning: {{.*}}3.o: unable to order undefined symbol: multi
+# MULTI:       warning: {{.*}}3.o: unable to order undefined symbol: multi
+# MULTI-NEXT:  warning: {{.*}}2.o: unable to order absolute symbol: multi
 # WARN-NOT:    warning:
 
 absolute = 0x1234




More information about the llvm-commits mailing list