xref: /freebsd-src/contrib/llvm-project/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric /*===- InstrProfilingPlatformDarwin.c - Profile data on Darwin ------------===*\
20b57cec5SDimitry Andric |*
30b57cec5SDimitry Andric |* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric |* See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric |*
70b57cec5SDimitry Andric \*===----------------------------------------------------------------------===*/
80b57cec5SDimitry Andric 
9e8d8bef9SDimitry Andric // Note: This is linked into the Darwin kernel, and must remain compatible
10e8d8bef9SDimitry Andric // with freestanding compilation. See `darwin_add_builtin_libraries`.
11e8d8bef9SDimitry Andric 
120b57cec5SDimitry Andric #include "InstrProfiling.h"
13fe6060f1SDimitry Andric #include "InstrProfilingInternal.h"
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #if defined(__APPLE__)
160b57cec5SDimitry Andric /* Use linker magic to find the bounds of the Data section. */
170b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
180b57cec5SDimitry Andric extern __llvm_profile_data
190b57cec5SDimitry Andric     DataStart __asm("section$start$__DATA$" INSTR_PROF_DATA_SECT_NAME);
200b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
210b57cec5SDimitry Andric extern __llvm_profile_data
220b57cec5SDimitry Andric     DataEnd __asm("section$end$__DATA$" INSTR_PROF_DATA_SECT_NAME);
230b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
240b57cec5SDimitry Andric extern char
250b57cec5SDimitry Andric     NamesStart __asm("section$start$__DATA$" INSTR_PROF_NAME_SECT_NAME);
260b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
270b57cec5SDimitry Andric extern char NamesEnd __asm("section$end$__DATA$" INSTR_PROF_NAME_SECT_NAME);
280b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
2904eeddc0SDimitry Andric extern char
300b57cec5SDimitry Andric     CountersStart __asm("section$start$__DATA$" INSTR_PROF_CNTS_SECT_NAME);
310b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
3204eeddc0SDimitry Andric extern char CountersEnd __asm("section$end$__DATA$" INSTR_PROF_CNTS_SECT_NAME);
330b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
345f757f3fSDimitry Andric extern char
355f757f3fSDimitry Andric     BitmapStart __asm("section$start$__DATA$" INSTR_PROF_BITS_SECT_NAME);
365f757f3fSDimitry Andric COMPILER_RT_VISIBILITY
375f757f3fSDimitry Andric extern char BitmapEnd __asm("section$end$__DATA$" INSTR_PROF_BITS_SECT_NAME);
385f757f3fSDimitry Andric COMPILER_RT_VISIBILITY
39*0fca6ea1SDimitry Andric extern VTableProfData
40*0fca6ea1SDimitry Andric     VTableProfStart __asm("section$start$__DATA$" INSTR_PROF_VTAB_SECT_NAME);
41*0fca6ea1SDimitry Andric COMPILER_RT_VISIBILITY
42*0fca6ea1SDimitry Andric extern VTableProfData
43*0fca6ea1SDimitry Andric     VTableProfEnd __asm("section$end$__DATA$" INSTR_PROF_VTAB_SECT_NAME);
44*0fca6ea1SDimitry Andric COMPILER_RT_VISIBILITY
45*0fca6ea1SDimitry Andric extern char
46*0fca6ea1SDimitry Andric     VNameStart __asm("section$start$__DATA$" INSTR_PROF_VNAME_SECT_NAME);
47*0fca6ea1SDimitry Andric COMPILER_RT_VISIBILITY
48*0fca6ea1SDimitry Andric extern char VNameEnd __asm("section$end$__DATA$" INSTR_PROF_VNAME_SECT_NAME);
49*0fca6ea1SDimitry Andric COMPILER_RT_VISIBILITY
500b57cec5SDimitry Andric extern uint32_t
510b57cec5SDimitry Andric     OrderFileStart __asm("section$start$__DATA$" INSTR_PROF_ORDERFILE_SECT_NAME);
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
540b57cec5SDimitry Andric extern ValueProfNode
550b57cec5SDimitry Andric     VNodesStart __asm("section$start$__DATA$" INSTR_PROF_VNODES_SECT_NAME);
560b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
570b57cec5SDimitry Andric extern ValueProfNode
580b57cec5SDimitry Andric     VNodesEnd __asm("section$end$__DATA$" INSTR_PROF_VNODES_SECT_NAME);
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
610b57cec5SDimitry Andric const __llvm_profile_data *__llvm_profile_begin_data(void) {
620b57cec5SDimitry Andric   return &DataStart;
630b57cec5SDimitry Andric }
640b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
650b57cec5SDimitry Andric const __llvm_profile_data *__llvm_profile_end_data(void) { return &DataEnd; }
660b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
670b57cec5SDimitry Andric const char *__llvm_profile_begin_names(void) { return &NamesStart; }
680b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
690b57cec5SDimitry Andric const char *__llvm_profile_end_names(void) { return &NamesEnd; }
700b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
7104eeddc0SDimitry Andric char *__llvm_profile_begin_counters(void) { return &CountersStart; }
720b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
7304eeddc0SDimitry Andric char *__llvm_profile_end_counters(void) { return &CountersEnd; }
740b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
755f757f3fSDimitry Andric char *__llvm_profile_begin_bitmap(void) { return &BitmapStart; }
765f757f3fSDimitry Andric COMPILER_RT_VISIBILITY
775f757f3fSDimitry Andric char *__llvm_profile_end_bitmap(void) { return &BitmapEnd; }
785f757f3fSDimitry Andric COMPILER_RT_VISIBILITY
79*0fca6ea1SDimitry Andric const VTableProfData *__llvm_profile_begin_vtables(void) {
80*0fca6ea1SDimitry Andric   return &VTableProfStart;
81*0fca6ea1SDimitry Andric }
82*0fca6ea1SDimitry Andric COMPILER_RT_VISIBILITY
83*0fca6ea1SDimitry Andric const VTableProfData *__llvm_profile_end_vtables(void) {
84*0fca6ea1SDimitry Andric   return &VTableProfEnd;
85*0fca6ea1SDimitry Andric }
86*0fca6ea1SDimitry Andric COMPILER_RT_VISIBILITY
87*0fca6ea1SDimitry Andric const char *__llvm_profile_begin_vtabnames(void) { return &VNameStart; }
88*0fca6ea1SDimitry Andric COMPILER_RT_VISIBILITY
89*0fca6ea1SDimitry Andric const char *__llvm_profile_end_vtabnames(void) { return &VNameEnd; }
90*0fca6ea1SDimitry Andric COMPILER_RT_VISIBILITY
910b57cec5SDimitry Andric uint32_t *__llvm_profile_begin_orderfile(void) { return &OrderFileStart; }
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
940b57cec5SDimitry Andric ValueProfNode *__llvm_profile_begin_vnodes(void) {
950b57cec5SDimitry Andric   return &VNodesStart;
960b57cec5SDimitry Andric }
970b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
980b57cec5SDimitry Andric ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &VNodesStart;
1010b57cec5SDimitry Andric COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &VNodesEnd;
102fe6060f1SDimitry Andric 
103fe6060f1SDimitry Andric COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
104fe6060f1SDimitry Andric   return 0;
105fe6060f1SDimitry Andric }
106fe6060f1SDimitry Andric 
1070b57cec5SDimitry Andric #endif
108