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>

llvm-svn: 204302
This commit is contained in:
Duncan P. N. Exon Smith 2014-03-20 03:57:33 +00:00
parent 780443e83b
commit ecf2256dfe
3 changed files with 38 additions and 7 deletions

View File

@ -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}

View File

@ -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; }

View File

@ -223,7 +223,7 @@ FUNCTIONS.ios.x86_64h := $(FUNCTIONS.ios.x86_64)
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) \