[PATCH] D53044: [ELF] Don't warn on undefined symbols if UnresolvedPolicy::Ignore is used

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 10 15:35:45 PDT 2018


MaskRay updated this revision to Diff 169114.
MaskRay added a comment.

Use early exit

  if (!Config->WarnSymbolOrdering ||
      (Sym->isUndefined() &&
       Config->UnresolvedSymbols == UnresolvedPolicy::Ignore))


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D53044

Files:
  ELF/Symbols.cpp
  test/ELF/cgprofile-shared-warn.s
  test/ELF/symbol-ordering-file-warnings.s


Index: test/ELF/symbol-ordering-file-warnings.s
===================================================================
--- test/ELF/symbol-ordering-file-warnings.s
+++ test/ELF/symbol-ordering-file-warnings.s
@@ -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
Index: test/ELF/cgprofile-shared-warn.s
===================================================================
--- /dev/null
+++ test/ELF/cgprofile-shared-warn.s
@@ -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
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -260,7 +260,14 @@
 }
 
 void elf::warnUnorderableSymbol(const Symbol *Sym) {
-  if (!Config->WarnSymbolOrdering)
+  // 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 (!Config->WarnSymbolOrdering ||
+      (Sym->isUndefined() &&
+       Config->UnresolvedSymbols == UnresolvedPolicy::Ignore))
     return;
 
   const InputFile *File = Sym->File;
@@ -272,7 +279,7 @@
     Warn(": unable to order undefined symbol: ");
   else if (Sym->isShared())
     Warn(": unable to order shared symbol: ");
-  else if (D && !D->Section)
+  if (D && !D->Section)
     Warn(": unable to order absolute symbol: ");
   else if (D && isa<OutputSection>(D->Section))
     Warn(": unable to order synthetic symbol: ");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53044.169114.patch
Type: text/x-patch
Size: 3700 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181010/bad661fc/attachment.bin>


More information about the llvm-commits mailing list