1 /*===- InstrProfilingPlatformLinux.c - Profile data Linux platform ------===*\
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 #if defined(__linux__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \
10     (defined(__sun__) && defined(__svr4__)) || defined(__NetBSD__)
11 
12 #include <stdlib.h>
13 
14 #include "InstrProfiling.h"
15 
16 #define PROF_DATA_START INSTR_PROF_SECT_START(INSTR_PROF_DATA_COMMON)
17 #define PROF_DATA_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_DATA_COMMON)
18 #define PROF_NAME_START INSTR_PROF_SECT_START(INSTR_PROF_NAME_COMMON)
19 #define PROF_NAME_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_NAME_COMMON)
20 #define PROF_CNTS_START INSTR_PROF_SECT_START(INSTR_PROF_CNTS_COMMON)
21 #define PROF_CNTS_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_CNTS_COMMON)
22 #define PROF_ORDERFILE_START INSTR_PROF_SECT_START(INSTR_PROF_ORDERFILE_COMMON)
23 #define PROF_VNODES_START INSTR_PROF_SECT_START(INSTR_PROF_VNODES_COMMON)
24 #define PROF_VNODES_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_VNODES_COMMON)
25 
26 /* Declare section start and stop symbols for various sections
27  * generated by compiler instrumentation. These symbols are
28  * declared as weak, which means that they'll end up as NULL if
29  * those sections are empty, and any code that iterates over the
30  * content using __llvm_profile_begin_* and __llvm_profile_end_*
31  * functions defined below will be a no-op.
32  */
33 extern __llvm_profile_data PROF_DATA_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
34 extern __llvm_profile_data PROF_DATA_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
35 extern uint64_t PROF_CNTS_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
36 extern uint64_t PROF_CNTS_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
37 extern uint32_t PROF_ORDERFILE_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
38 extern char PROF_NAME_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
39 extern char PROF_NAME_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
40 extern ValueProfNode PROF_VNODES_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
41 extern ValueProfNode PROF_VNODES_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK;
42 
43 COMPILER_RT_VISIBILITY const __llvm_profile_data *
44 __llvm_profile_begin_data(void) {
45   return &PROF_DATA_START;
46 }
47 COMPILER_RT_VISIBILITY const __llvm_profile_data *
48 __llvm_profile_end_data(void) {
49   return &PROF_DATA_STOP;
50 }
51 COMPILER_RT_VISIBILITY const char *__llvm_profile_begin_names(void) {
52   return &PROF_NAME_START;
53 }
54 COMPILER_RT_VISIBILITY const char *__llvm_profile_end_names(void) {
55   return &PROF_NAME_STOP;
56 }
57 COMPILER_RT_VISIBILITY uint64_t *__llvm_profile_begin_counters(void) {
58   return &PROF_CNTS_START;
59 }
60 COMPILER_RT_VISIBILITY uint64_t *__llvm_profile_end_counters(void) {
61   return &PROF_CNTS_STOP;
62 }
63 COMPILER_RT_VISIBILITY uint32_t *__llvm_profile_begin_orderfile(void) {
64   return &PROF_ORDERFILE_START;
65 }
66 
67 COMPILER_RT_VISIBILITY ValueProfNode *
68 __llvm_profile_begin_vnodes(void) {
69   return &PROF_VNODES_START;
70 }
71 COMPILER_RT_VISIBILITY ValueProfNode *__llvm_profile_end_vnodes(void) {
72   return &PROF_VNODES_STOP;
73 }
74 COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = &PROF_VNODES_START;
75 COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = &PROF_VNODES_STOP;
76 
77 #endif
78