diff options
| author | Fangrui Song <maskray@google.com> | 2018-10-22 23:43:53 +0000 |
|---|---|---|
| committer | Fangrui Song <maskray@google.com> | 2018-10-22 23:43:53 +0000 |
| commit | efc0fe5a72f80234ac66ebff0d2431616ea86180 (patch) | |
| tree | 8da74ac52d1bdde13f8a10e2589f2398c2199934 | |
| parent | 96cd3cc312d4498e730f348fac31ec4b3432d817 (diff) | |
| download | bcm5719-llvm-efc0fe5a72f80234ac66ebff0d2431616ea86180.tar.gz bcm5719-llvm-efc0fe5a72f80234ac66ebff0d2431616ea86180.zip | |
[ELF] Don't warn on two legitimate cases when reading .llvm.call-graph-profile
Summary:
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
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.
Reviewers: ruiu, davidxl, espindola, Bigcheese
Reviewed By: ruiu
Subscribers: emaste, arichardson, llvm-commits
Differential Revision: https://reviews.llvm.org/D53470
llvm-svn: 344974
| -rw-r--r-- | lld/ELF/Driver.cpp | 35 | ||||
| -rw-r--r-- | lld/test/ELF/cgprofile-obj-warn.s | 3 | ||||
| -rw-r--r-- | lld/test/ELF/cgprofile-shared-warn.s | 18 |
3 files changed, 37 insertions, 19 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 147675e4826..ac70cb1a8a8 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -681,22 +681,33 @@ static void readCallGraph(MemoryBufferRef MB) { } 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; } } } diff --git a/lld/test/ELF/cgprofile-obj-warn.s b/lld/test/ELF/cgprofile-obj-warn.s index 188216091a6..129c713dfe8 100644 --- a/lld/test/ELF/cgprofile-obj-warn.s +++ b/lld/test/ELF/cgprofile-obj-warn.s @@ -27,9 +27,6 @@ A: .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 \ diff --git a/lld/test/ELF/cgprofile-shared-warn.s b/lld/test/ELF/cgprofile-shared-warn.s index 74cfb031baa..86312770d1d 100644 --- a/lld/test/ELF/cgprofile-shared-warn.s +++ b/lld/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",@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",@progbits +.globl A A: - callq B + callq B - .cg_profile A, B, 10 +.cg_profile A, B, 10 |

