xref: /freebsd/contrib/llvm-project/compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
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 
9*e8d8bef9SDimitry Andric // Note: This is linked into the Darwin kernel, and must remain compatible
10*e8d8bef9SDimitry Andric // with freestanding compilation. See `darwin_add_builtin_libraries`.
11*e8d8bef9SDimitry Andric 
120b57cec5SDimitry Andric #include "InstrProfiling.h"
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric #if defined(__APPLE__)
150b57cec5SDimitry Andric /* Use linker magic to find the bounds of the Data section. */
160b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
170b57cec5SDimitry Andric extern __llvm_profile_data
180b57cec5SDimitry Andric     DataStart __asm("section$start$__DATA$" INSTR_PROF_DATA_SECT_NAME);
190b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
200b57cec5SDimitry Andric extern __llvm_profile_data
210b57cec5SDimitry Andric     DataEnd __asm("section$end$__DATA$" INSTR_PROF_DATA_SECT_NAME);
220b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
230b57cec5SDimitry Andric extern char
240b57cec5SDimitry Andric     NamesStart __asm("section$start$__DATA$" INSTR_PROF_NAME_SECT_NAME);
250b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
260b57cec5SDimitry Andric extern char NamesEnd __asm("section$end$__DATA$" INSTR_PROF_NAME_SECT_NAME);
270b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
280b57cec5SDimitry Andric extern uint64_t
290b57cec5SDimitry Andric     CountersStart __asm("section$start$__DATA$" INSTR_PROF_CNTS_SECT_NAME);
300b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
310b57cec5SDimitry Andric extern uint64_t
320b57cec5SDimitry Andric     CountersEnd __asm("section$end$__DATA$" INSTR_PROF_CNTS_SECT_NAME);
330b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
340b57cec5SDimitry Andric extern uint32_t
350b57cec5SDimitry Andric     OrderFileStart __asm("section$start$__DATA$" INSTR_PROF_ORDERFILE_SECT_NAME);
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
380b57cec5SDimitry Andric extern ValueProfNode
390b57cec5SDimitry Andric     VNodesStart __asm("section$start$__DATA$" INSTR_PROF_VNODES_SECT_NAME);
400b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
410b57cec5SDimitry Andric extern ValueProfNode
420b57cec5SDimitry Andric     VNodesEnd __asm("section$end$__DATA$" INSTR_PROF_VNODES_SECT_NAME);
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
450b57cec5SDimitry Andric const __llvm_profile_data *__llvm_profile_begin_data(void) {
460b57cec5SDimitry Andric   return &DataStart;
470b57cec5SDimitry Andric }
480b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
490b57cec5SDimitry Andric const __llvm_profile_data *__llvm_profile_end_data(void) { return &DataEnd; }
500b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
510b57cec5SDimitry Andric const char *__llvm_profile_begin_names(void) { return &NamesStart; }
520b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
530b57cec5SDimitry Andric const char *__llvm_profile_end_names(void) { return &NamesEnd; }
540b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
550b57cec5SDimitry Andric uint64_t *__llvm_profile_begin_counters(void) { return &CountersStart; }
560b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
570b57cec5SDimitry Andric uint64_t *__llvm_profile_end_counters(void) { return &CountersEnd; }
580b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
590b57cec5SDimitry Andric uint32_t *__llvm_profile_begin_orderfile(void) { return &OrderFileStart; }
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
620b57cec5SDimitry Andric ValueProfNode *__llvm_profile_begin_vnodes(void) {
630b57cec5SDimitry Andric   return &VNodesStart;
640b57cec5SDimitry Andric }
650b57cec5SDimitry Andric COMPILER_RT_VISIBILITY
660b57cec5SDimitry Andric ValueProfNode *__llvm_profile_end_vnodes(void) { return &VNodesEnd; }
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &VNodesStart;
690b57cec5SDimitry Andric COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &VNodesEnd;
700b57cec5SDimitry Andric #endif
71