[compiler-rt] r204302 - PGO: Implement Darwin linker magic for instrumentation

Duncan P. N. Exon Smith dexonsmith at apple.com
Wed Mar 19 20:57:33 PDT 2014


Author: dexonsmith
Date: Wed Mar 19 22:57:33 2014
New Revision: 204302

URL: http://llvm.org/viewvc/llvm-project?rev=204302&view=rev
Log:
PGO: Implement Darwin linker magic for instrumentation

Use Darwin linker magic to find bounds of instrumentation data sections
at link time instead of runtime.

<rdar://problem/15943240>

Added:
    compiler-rt/trunk/lib/profile/InstrProfilingDarwin.c
Modified:
    compiler-rt/trunk/lib/profile/CMakeLists.txt
    compiler-rt/trunk/make/platform/clang_darwin.mk

Modified: compiler-rt/trunk/lib/profile/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/CMakeLists.txt?rev=204302&r1=204301&r2=204302&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/profile/CMakeLists.txt Wed Mar 19 22:57:33 2014
@@ -1,19 +1,25 @@
-set(PROFILE_SOURCES
-  GCDAProfiling.c
-  InstrProfiling.c
-  InstrProfilingDefault.c
-  InstrProfilingExtras.c)
-
 filter_available_targets(PROFILE_SUPPORTED_ARCH x86_64 i386 arm)
 
 add_custom_target(profile)
 
 if(APPLE)
+  set(PROFILE_SOURCES
+    GCDAProfiling.c
+    InstrProfiling.c
+    InstrProfilingDarwin.c
+    InstrProfilingExtras.c)
+
   add_compiler_rt_osx_static_runtime(clang_rt.profile_osx
     ARCH ${PROFILE_SUPPORTED_ARCH}
     SOURCES ${PROFILE_SOURCES})
   add_dependencies(profile clang_rt.profile_osx)
 else()
+  set(PROFILE_SOURCES
+    GCDAProfiling.c
+    InstrProfiling.c
+    InstrProfilingDefault.c
+    InstrProfilingExtras.c)
+
   foreach(arch ${PROFILE_SUPPORTED_ARCH})
     add_compiler_rt_static_runtime(clang_rt.profile-${arch}
       ${arch}

Added: compiler-rt/trunk/lib/profile/InstrProfilingDarwin.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingDarwin.c?rev=204302&view=auto
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingDarwin.c (added)
+++ compiler-rt/trunk/lib/profile/InstrProfilingDarwin.c Wed Mar 19 22:57:33 2014
@@ -0,0 +1,25 @@
+/*===- InstrProfilingDarwin.c - Profile data on Darwin --------------------===*\
+|*
+|*                     The LLVM Compiler Infrastructure
+|*
+|* This file is distributed under the University of Illinois Open Source
+|* License. See LICENSE.TXT for details.
+|*
+\*===----------------------------------------------------------------------===*/
+
+#include "InstrProfiling.h"
+
+/* Use linker magic to find the bounds of the Data section. */
+extern __llvm_pgo_data DataStart __asm("section$start$__DATA$__llvm_pgo_data");
+extern __llvm_pgo_data DataEnd   __asm("section$end$__DATA$__llvm_pgo_data");
+extern char NamesStart __asm("section$start$__DATA$__llvm_pgo_names");
+extern char NamesEnd   __asm("section$end$__DATA$__llvm_pgo_names");
+extern uint64_t CountersStart __asm("section$start$__DATA$__llvm_pgo_cnts");
+extern uint64_t CountersEnd   __asm("section$end$__DATA$__llvm_pgo_cnts");
+
+const __llvm_pgo_data *__llvm_pgo_data_begin() { return &DataStart; }
+const __llvm_pgo_data *__llvm_pgo_data_end()   { return &DataEnd; }
+const char *__llvm_pgo_names_begin() { return &NamesStart; }
+const char *__llvm_pgo_names_end()   { return &NamesEnd; }
+const uint64_t *__llvm_pgo_counters_begin() { return &CountersStart; }
+const uint64_t *__llvm_pgo_counters_end()   { return &CountersEnd; }

Modified: compiler-rt/trunk/make/platform/clang_darwin.mk
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/make/platform/clang_darwin.mk?rev=204302&r1=204301&r2=204302&view=diff
==============================================================================
--- compiler-rt/trunk/make/platform/clang_darwin.mk (original)
+++ compiler-rt/trunk/make/platform/clang_darwin.mk Wed Mar 19 22:57:33 2014
@@ -223,7 +223,7 @@ FUNCTIONS.ios.x86_64h := $(FUNCTIONS.ios
 FUNCTIONS.osx	:= mulosi4 mulodi4 muloti4
 
 FUNCTIONS.profile_osx := GCDAProfiling InstrProfiling \
-                         InstrProfilingDefault InstrProfilingExtras
+                         InstrProfilingDarwin InstrProfilingExtras
 FUNCTIONS.profile_ios := $(FUNCTIONS.profile_osx)
 
 FUNCTIONS.asan_osx_dynamic := $(AsanFunctions) $(InterceptionFunctions) \





More information about the llvm-commits mailing list