[PATCH] D25457: [profile] Add test for dead_strip+live_support functionality

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 10 17:32:19 PDT 2016


vsk created this revision.
vsk added reviewers: davidxl, mehdi_amini.
vsk added a subscriber: llvm-commits.
vsk added a dependency: D25456: [InstrProf] Add support for dead_strip+live_support functionality.

On Darwin, marking a section as "regular,live_support" means that a
symbol in the section should only be kept live if it has a reference to
something that is live. Otherwise, the linker is free to dead-strip it.

Add a test for dead_strip+live_support functionality for profile data.

Depends on https://reviews.llvm.org/D25456.


https://reviews.llvm.org/D25457

Files:
  test/profile/instrprof-darwin-dead-strip.c
  test/profile/lit.cfg


Index: test/profile/lit.cfg
===================================================================
--- test/profile/lit.cfg
+++ test/profile/lit.cfg
@@ -49,8 +49,13 @@
 clang_cflags = target_cflags + extra_linkflags
 clang_cxxflags = config.cxx_mode_flags + clang_cflags
 
-def build_invocation(compile_flags):
-  return " " + " ".join([config.clang] + compile_flags) + " "
+def build_invocation(compile_flags, with_lto = False):
+  lto_flags = []
+  lto_prefix = []
+  if with_lto and config.lto_supported:
+    lto_flags += config.lto_flags
+    lto_prefix += config.lto_launch
+  return " " + " ".join(lto_prefix + [config.clang] + lto_flags + compile_flags) + " "
 
 # Add clang substitutions.
 config.substitutions.append( ("%clang ", build_invocation(clang_cflags)) )
@@ -71,6 +76,8 @@
 config.substitutions.append( ("%clang_profuse=", build_invocation(clang_cflags) + " -fprofile-instr-use=") )
 config.substitutions.append( ("%clangxx_profuse=", build_invocation(clang_cxxflags) + " -fprofile-instr-use=") )
 
+config.substitutions.append( ("%clang_lto_profgen=", build_invocation(clang_cflags, True) + " -fprofile-instr-generate=") )
+
 if config.host_os not in ['Darwin', 'FreeBSD', 'Linux']:
   config.unsupported = True
 
Index: test/profile/instrprof-darwin-dead-strip.c
===================================================================
--- /dev/null
+++ test/profile/instrprof-darwin-dead-strip.c
@@ -0,0 +1,34 @@
+// REQUIRES: lto
+// REQUIRES: osx-ld64-live_support
+
+// RUN: %clang_profgen=%t.profraw -fcoverage-mapping -Wl,-dead_strip -o %t %s
+// RUN: %run %t
+// RUN: llvm-profdata merge -o %t.profdata %t.profraw
+// RUN: llvm-profdata show --all-functions %t.profdata | FileCheck %s -check-prefix=PROF
+// RUN: llvm-cov show %t -instr-profile %t.profdata | FileCheck %s -check-prefix=COV
+// RUN: nm %t | FileCheck %s -check-prefix=NM
+
+// RUN: %clang_lto_profgen=%t.lto.profraw -fcoverage-mapping -Wl,-dead_strip -flto -o %t.lto %s
+// RUN: %run %t.lto
+// RUN: llvm-profdata merge -o %t.lto.profdata %t.lto.profraw
+// RUN: llvm-profdata show --all-functions %t.lto.profdata | FileCheck %s -check-prefix=PROF
+// RUN: llvm-cov show %t.lto -instr-profile %t.lto.profdata | FileCheck %s -check-prefix=COV
+// RUN: nm %t.lto | FileCheck %s -check-prefix=NM
+
+// COV: [[@LINE+1]]{{ *}}|{{ *}}0|void foo()
+void foo() {}
+
+// NM-NOT: foo
+
+// PROF: Counters:
+// PROF-NEXT:   main:
+// PROF-NEXT:     Hash:
+// PROF-NEXT:     Counters: 1
+// PROF-NEXT:     Function count: 1
+// PROF-NEXT: Functions shown: 1
+// PROF-NEXT: Total functions: 1
+// PROF-NEXT: Maximum function count: 1
+// PROF-NEXT: Maximum internal block count: 0
+
+// COV: [[@LINE+1]]{{ *}}|{{ *}}1|int main
+int main() { return 0; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25457.74192.patch
Type: text/x-patch
Size: 2726 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161011/84758cba/attachment.bin>


More information about the llvm-commits mailing list