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 #include "InstrProfilingInternal.h"
14 
15 #if defined(__APPLE__)
16 /* Use linker magic to find the bounds of the Data section. */
17 COMPILER_RT_VISIBILITY
18 extern __llvm_profile_data
19     DataStart __asm("section$start$__DATA$" INSTR_PROF_DATA_SECT_NAME);
20 COMPILER_RT_VISIBILITY
21 extern __llvm_profile_data
22     DataEnd __asm("section$end$__DATA$" INSTR_PROF_DATA_SECT_NAME);
23 COMPILER_RT_VISIBILITY
24 extern char
25     NamesStart __asm("section$start$__DATA$" INSTR_PROF_NAME_SECT_NAME);
26 COMPILER_RT_VISIBILITY
27 extern char NamesEnd __asm("section$end$__DATA$" INSTR_PROF_NAME_SECT_NAME);
28 COMPILER_RT_VISIBILITY
29 extern uint64_t
30     CountersStart __asm("section$start$__DATA$" INSTR_PROF_CNTS_SECT_NAME);
31 COMPILER_RT_VISIBILITY
32 extern uint64_t
33     CountersEnd __asm("section$end$__DATA$" INSTR_PROF_CNTS_SECT_NAME);
34 COMPILER_RT_VISIBILITY
35 extern uint32_t
36     OrderFileStart __asm("section$start$__DATA$" INSTR_PROF_ORDERFILE_SECT_NAME);
37 
38 COMPILER_RT_VISIBILITY
39 extern ValueProfNode
40     VNodesStart __asm("section$start$__DATA$" INSTR_PROF_VNODES_SECT_NAME);
41 COMPILER_RT_VISIBILITY
42 extern ValueProfNode
43     VNodesEnd __asm("section$end$__DATA$" INSTR_PROF_VNODES_SECT_NAME);
44 
45 COMPILER_RT_VISIBILITY
__llvm_profile_begin_data(void)46 const __llvm_profile_data *__llvm_profile_begin_data(void) {
47   return &DataStart;
48 }
49 COMPILER_RT_VISIBILITY
__llvm_profile_end_data(void)50 const __llvm_profile_data *__llvm_profile_end_data(void) { return &DataEnd; }
51 COMPILER_RT_VISIBILITY
__llvm_profile_begin_names(void)52 const char *__llvm_profile_begin_names(void) { return &NamesStart; }
53 COMPILER_RT_VISIBILITY
__llvm_profile_end_names(void)54 const char *__llvm_profile_end_names(void) { return &NamesEnd; }
55 COMPILER_RT_VISIBILITY
__llvm_profile_begin_counters(void)56 uint64_t *__llvm_profile_begin_counters(void) { return &CountersStart; }
57 COMPILER_RT_VISIBILITY
__llvm_profile_end_counters(void)58 uint64_t *__llvm_profile_end_counters(void) { return &CountersEnd; }
59 COMPILER_RT_VISIBILITY
__llvm_profile_begin_orderfile(void)60 uint32_t *__llvm_profile_begin_orderfile(void) { return &OrderFileStart; }
61 
62 COMPILER_RT_VISIBILITY
__llvm_profile_begin_vnodes(void)63 ValueProfNode *__llvm_profile_begin_vnodes(void) {
64   return &VNodesStart;
65 }
66 COMPILER_RT_VISIBILITY
__llvm_profile_end_vnodes(void)67 ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
68 
69 COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &VNodesStart;
70 COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &VNodesEnd;
71 
__llvm_write_binary_ids(ProfDataWriter * Writer)72 COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
73   return 0;
74 }
75 
76 #endif
77