[PATCH] D53470: [ELF] Don't warn on two legitimate cases when reading .llvm.call-graph-profile

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 19 21:06:12 PDT 2018


MaskRay created this revision.
MaskRay added reviewers: ruiu, davidxl.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.

Before, superfluous warnings were emitted for the following two cases:

1. When from symbol was in a discarded section. The profile should be thought of as affiliated to the section. It makes sense to ignore the profile if the section is discarded.

2. When to symbol was in a shared object. The object file containing the profile may not know about the to symbol, which can reside in another object file (useful profile) or a shared object (not useful as symbols in the shared object are fixed and unorderable). It makes sense to ignore the profile from the object file.

  Note, the warning when to symbol was undefined was suppressed in https://reviews.llvm.org/D53044, which is still useful for --symbol-ordering-file=

This patch silences the warnings. The check is actually more relaxed (no
warnings if either From or To is not Defined) for simplicity and I don't
see a compelling reason to warn on more cases.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D53470

Files:
  ELF/Driver.cpp
  test/ELF/Inputs/cgprofile-shared-warn.s
  test/ELF/cgprofile-obj-warn.s
  test/ELF/cgprofile-shared-warn.s


Index: test/ELF/cgprofile-shared-warn.s
===================================================================
--- test/ELF/cgprofile-shared-warn.s
+++ test/ELF/cgprofile-shared-warn.s
@@ -3,9 +3,19 @@
 # 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
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/cgprofile-shared-warn.s -o %t1.o
+# RUN: ld.lld --shared %t1.o -o %t1.so
+# RUN: ld.lld -e A %t.o %t1.so -o /dev/null 2>&1 | count 0
+
+# RUN: ld.lld --gc-sections %t.o %t1.so -o /dev/null 2>&1 | count 0
+.globl _start
+_start:
+  ret
+
+.section .text.A,"ax", at progbits
+.globl A
 A:
-    callq B
+  callq B
 
-    .cg_profile A, B, 10
+.cg_profile A, B, 10
Index: test/ELF/cgprofile-obj-warn.s
===================================================================
--- test/ELF/cgprofile-obj-warn.s
+++ test/ELF/cgprofile-obj-warn.s
@@ -27,9 +27,6 @@
     .cg_profile poppy, A, 30
 
 # CHECK: unable to order absolute symbol: B
-# CHECK: unable to order undefined symbol: adena1
-# CHECK: unable to order undefined symbol: adena2
-# CHECK: unable to order undefined symbol: poppy
 
 # RUN: ld.lld %t -o /dev/null \
 # RUN:   -noinhibit-exec -icf=all --no-warn-symbol-ordering 2>&1 \
Index: test/ELF/Inputs/cgprofile-shared-warn.s
===================================================================
--- /dev/null
+++ test/ELF/Inputs/cgprofile-shared-warn.s
@@ -0,0 +1,3 @@
+.globl B
+B:
+  ret
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -681,22 +681,21 @@
 }
 
 template <class ELFT> static void readCallGraphsFromObjectFiles() {
-  auto FindSection = [&](const Symbol *Sym) -> const InputSectionBase * {
-    warnUnorderableSymbol(Sym);
-    if (const auto *SymD = dyn_cast<Defined>(Sym))
-      return dyn_cast_or_null<InputSectionBase>(SymD->Section);
-    return nullptr;
-  };
-
   for (auto File : ObjectFiles) {
     auto *Obj = cast<ObjFile<ELFT>>(File);
     for (const Elf_CGProfile_Impl<ELFT> &CGPE : Obj->CGProfile) {
-      const InputSectionBase *FromSB =
-          FindSection(&Obj->getSymbol(CGPE.cgp_from));
-      const InputSectionBase *ToSB = FindSection(&Obj->getSymbol(CGPE.cgp_to));
-      if (!FromSB || !ToSB)
+      auto *FromSymD = dyn_cast<Defined>(&Obj->getSymbol(CGPE.cgp_from));
+      auto *ToSymD = dyn_cast<Defined>(&Obj->getSymbol(CGPE.cgp_to));
+      if (!FromSymD || !ToSymD)
         continue;
-      Config->CallGraphProfile[{FromSB, ToSB}] += CGPE.cgp_weight;
+      auto *FromSB = dyn_cast_or_null<InputSectionBase>(FromSymD->Section);
+      auto *ToSB = dyn_cast_or_null<InputSectionBase>(ToSymD->Section);
+      if (!FromSB || FromSB->Repl->Live) {
+        warnUnorderableSymbol(FromSymD);
+        warnUnorderableSymbol(ToSymD);
+      }
+      if (FromSB && ToSB)
+        Config->CallGraphProfile[{FromSB, ToSB}] += CGPE.cgp_weight;
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53470.170300.patch
Type: text/x-patch
Size: 3121 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181020/e9244800/attachment.bin>


More information about the llvm-commits mailing list