[lld] r344195 - [ELF] Don't warn on undefined symbols if UnresolvedPolicy::Ignore is used

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 10 15:48:57 PDT 2018


Author: maskray
Date: Wed Oct 10 15:48:57 2018
New Revision: 344195

URL: http://llvm.org/viewvc/llvm-project?rev=344195&view=rev
Log:
[ELF] Don't warn on undefined symbols if UnresolvedPolicy::Ignore is used

Summary:
Add a condition UnresolvedPolicy::Ignore to elf::warnUnorderedSymbol to suppress Sym->isUndefined() warnings from both

1) --symbol-ordering-file=
2) .llvm.call-graph-profile

If --unresolved-symbols=ignore-all is used,

  no "undefined symbol" error/warning is emitted. It makes sense to not warn unorderable symbols.

Otherwise,

  If an executable is linked, the default policy UnresolvedPolicy::ErrorOrWarn will issue a "undefined symbol" error. The unorderable symbol warning is redundant.

  If a shared object is linked, it is possible that only part of object files are used and some symbols are left undefined. The warning is not very necessary.
    In particular for .llvm.call-graph-profile, when linking a shared object, a call graph profile may contain undefined symbols. This case generated a warning before but it will be suppressed by this patch.

Reviewers: ruiu, davidxl, espindola

Reviewed By: ruiu

Subscribers: grimar, emaste, arichardson, llvm-commits

Differential Revision: https://reviews.llvm.org/D53044

Added:
    lld/trunk/test/ELF/cgprofile-shared-warn.s
Modified:
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/test/ELF/symbol-ordering-file-warnings.s

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=344195&r1=344194&r2=344195&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Wed Oct 10 15:48:57 2018
@@ -263,6 +263,15 @@ void elf::warnUnorderableSymbol(const Sy
   if (!Config->WarnSymbolOrdering)
     return;
 
+  // If UnresolvedPolicy::Ignore is used, no "undefined symbol" error/warning
+  // is emitted. It makes sense to not warn on undefined symbols.
+  //
+  // Note, ld.bfd --symbol-ordering-file= does not warn on undefined symbols,
+  // but we don't have to be compatible here.
+  if (Sym->isUndefined() &&
+      Config->UnresolvedSymbols == UnresolvedPolicy::Ignore)
+    return;
+
   const InputFile *File = Sym->File;
   auto *D = dyn_cast<Defined>(Sym);
 

Added: lld/trunk/test/ELF/cgprofile-shared-warn.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/cgprofile-shared-warn.s?rev=344195&view=auto
==============================================================================
--- lld/trunk/test/ELF/cgprofile-shared-warn.s (added)
+++ lld/trunk/test/ELF/cgprofile-shared-warn.s Wed Oct 10 15:48:57 2018
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld --shared %t.o -o /dev/null 2>&1 | count 0
+# RUN: ld.lld -e A --unresolved-symbols=ignore-all %t.o -o /dev/null 2>&1 | count 0
+    .section    .text.A,"ax", at progbits
+    .globl  A
+A:
+    callq B
+
+    .cg_profile A, B, 10

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=344195&r1=344194&r2=344195&view=diff
==============================================================================
--- lld/trunk/test/ELF/symbol-ordering-file-warnings.s (original)
+++ lld/trunk/test/ELF/symbol-ordering-file-warnings.s Wed Oct 10 15:48:57 2018
@@ -19,11 +19,6 @@
 # RUN:   --unresolved-symbols=ignore-all --no-warn-symbol-ordering --warn-symbol-ordering 2>&1 | \
 # RUN:   FileCheck %s --check-prefixes=WARN,MISSING
 
-# Check that a warning is emitted for undefined symbols.
-# RUN: echo "undefined" > %t-order-undef.txt
-# RUN: ld.lld %t1.o %t3.o -o %t --symbol-ordering-file %t-order-undef.txt \
-# RUN:   --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,UNDEFINED
-
 # Check that a warning is emitted for imported shared symbols.
 # RUN: echo "shared" > %t-order-shared.txt
 # RUN: ld.lld %t1.o %t.so -o %t --symbol-ordering-file %t-order-shared.txt \
@@ -97,7 +92,7 @@
 # RUN: echo "_GLOBAL_OFFSET_TABLE_" >> %t-order-multi.txt
 # RUN: echo "_start" >> %t-order-multi.txt
 # RUN: ld.lld %t1.o %t3.o %t.so -o %t --symbol-ordering-file %t-order-multi.txt --gc-sections -T %t.script \
-# RUN:   --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SAMESYM,ABSOLUTE,SHARED,UNDEFINED,GC,DISCARD,MISSING2,SYNTHETIC
+# RUN:   2>&1 | FileCheck %s --check-prefixes=WARN,SAMESYM,ABSOLUTE,SHARED,UNDEFINED,GC,DISCARD,MISSING2,SYNTHETIC
 
 # WARN-NOT:    warning:
 # SAMESYM:     warning: {{.*}}.txt: duplicate ordered symbol: _start
@@ -115,10 +110,12 @@
 # ABSOLUTE:    warning: {{.*}}1.o: unable to order absolute symbol: absolute
 # WARN-NOT:    warning:
 # MISSING:     warning: symbol ordering file: no such symbol: missing
+# WARN-NOT:    warning:
 # MISSING2:    warning: symbol ordering file: no such symbol: missing_sym
+# WARN-NOT:    warning:
 # COMDAT:      warning: {{.*}}1.o: unable to order discarded symbol: comdat
-# MULTI:       warning: {{.*}}3.o: unable to order undefined symbol: multi
-# MULTI-NEXT:  warning: {{.*}}2.o: unable to order absolute symbol: multi
+# WARN-NOT:    warning:
+# MULTI:       warning: {{.*}}2.o: unable to order absolute symbol: multi
 # WARN-NOT:    warning:
 
 absolute = 0x1234




More information about the llvm-commits mailing list