[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
Mon Oct 22 16:45:58 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL344974: [ELF] Don't warn on two legitimate cases when reading .llvm.call-graph-profile (authored by MaskRay, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D53470

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


Index: lld/trunk/test/ELF/cgprofile-shared-warn.s
===================================================================
--- lld/trunk/test/ELF/cgprofile-shared-warn.s
+++ lld/trunk/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: echo '.globl B; B: ret' | llvm-mc -filetype=obj -triple=x86_64-unknown-linux - -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: lld/trunk/test/ELF/cgprofile-obj-warn.s
===================================================================
--- lld/trunk/test/ELF/cgprofile-obj-warn.s
+++ lld/trunk/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: lld/trunk/ELF/Driver.cpp
===================================================================
--- lld/trunk/ELF/Driver.cpp
+++ lld/trunk/ELF/Driver.cpp
@@ -681,22 +681,33 @@
 }
 
 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 *FromSym = dyn_cast<Defined>(&Obj->getSymbol(CGPE.cgp_from));
+      auto *ToSym = dyn_cast<Defined>(&Obj->getSymbol(CGPE.cgp_to));
+      if (!FromSym || !ToSym)
         continue;
-      Config->CallGraphProfile[{FromSB, ToSB}] += CGPE.cgp_weight;
+      auto *FromSec = dyn_cast_or_null<InputSectionBase>(FromSym->Section);
+      auto *ToSec = dyn_cast_or_null<InputSectionBase>(ToSym->Section);
+
+      // The profile from .llvm.call-graph-profile is conceptually affiliated to
+      // FromSec. Don't warn unorderable symbol if FromSym is not absolute
+      // (FromSec isn't null) and the section is discarded
+      // (!FromSec->Repl->Live).
+      //
+      // We also don't want to warn when ToSym is undefined or is in a shared
+      // object (as symbols in shared objects are fixed and unorderable).
+      //
+      // The check used here is more relaxed (no warning if either FromSym or
+      // ToSym is not Defined) for simplicity and there is no compelling reason
+      // to warn on more cases.
+      if (!FromSec || FromSec->Repl->Live) {
+        warnUnorderableSymbol(FromSym);
+        warnUnorderableSymbol(ToSym);
+      }
+      if (FromSec && ToSec)
+        Config->CallGraphProfile[{FromSec, ToSec}] += CGPE.cgp_weight;
     }
   }
 }


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


More information about the llvm-commits mailing list