1 /*===- InstrProfilingPlatformDarwin.c - Profile data on Darwin ------------===*\
2 |*
3 |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 |* See https://llvm.org/LICENSE.txt for license information.
5 |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 |*
7 \*===----------------------------------------------------------------------===*/
8 
9 // Note: This is linked into the Darwin kernel, and must remain compatible
10 // with freestanding compilation. See `darwin_add_builtin_libraries`.
11 
12 #include "InstrProfiling.h"
13 
14 #if defined(__APPLE__)
15 /* Use linker magic to find the bounds of the Data section. */
16 COMPILER_RT_VISIBILITY
17 extern __llvm_profile_data
18     DataStart __asm("section$start$__DATA$" INSTR_PROF_DATA_SECT_NAME);
19 COMPILER_RT_VISIBILITY
20 extern __llvm_profile_data
21     DataEnd __asm("section$end$__DATA$" INSTR_PROF_DATA_SECT_NAME);
22 COMPILER_RT_VISIBILITY
23 extern char
24     NamesStart __asm("section$start$__DATA$" INSTR_PROF_NAME_SECT_NAME);
25 COMPILER_RT_VISIBILITY
26 extern char NamesEnd __asm("section$end$__DATA$" INSTR_PROF_NAME_SECT_NAME);
27 COMPILER_RT_VISIBILITY
28 extern uint64_t
29     CountersStart __asm("section$start$__DATA$" INSTR_PROF_CNTS_SECT_NAME);
30 COMPILER_RT_VISIBILITY
31 extern uint64_t
32     CountersEnd __asm("section$end$__DATA$" INSTR_PROF_CNTS_SECT_NAME);
33 COMPILER_RT_VISIBILITY
34 extern uint32_t
35     OrderFileStart __asm("section$start$__DATA$" INSTR_PROF_ORDERFILE_SECT_NAME);
36 
37 COMPILER_RT_VISIBILITY
38 extern ValueProfNode
39     VNodesStart __asm("section$start$__DATA$" INSTR_PROF_VNODES_SECT_NAME);
40 COMPILER_RT_VISIBILITY
41 extern ValueProfNode
42     VNodesEnd __asm("section$end$__DATA$" INSTR_PROF_VNODES_SECT_NAME);
43 
44 COMPILER_RT_VISIBILITY
45 const __llvm_profile_data *__llvm_profile_begin_data(void) {
46   return &DataStart;
47 }
48 COMPILER_RT_VISIBILITY
49 const __llvm_profile_data *__llvm_profile_end_data(void) { return &DataEnd; }
50 COMPILER_RT_VISIBILITY
51 const char *__llvm_profile_begin_names(void) { return &NamesStart; }
52 COMPILER_RT_VISIBILITY
53 const char *__llvm_profile_end_names(void) { return &NamesEnd; }
54 COMPILER_RT_VISIBILITY
55 uint64_t *__llvm_profile_begin_counters(void) { return &CountersStart; }
56 COMPILER_RT_VISIBILITY
57 uint64_t *__llvm_profile_end_counters(void) { return &CountersEnd; }
58 COMPILER_RT_VISIBILITY
59 uint32_t *__llvm_profile_begin_orderfile(void) { return &OrderFileStart; }
60 
61 COMPILER_RT_VISIBILITY
62 ValueProfNode *__llvm_profile_begin_vnodes(void) {
63   return &VNodesStart;
64 }
65 COMPILER_RT_VISIBILITY
66 ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
67 
68 COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &VNodesStart;
69 COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &VNodesEnd;
70 #endif
71