1/*===- InstrProfilingPlatformOther.c - Profile data default 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(__APPLE__) && !defined(__linux__) && !defined(__FreeBSD__) && \
10 !defined(__Fuchsia__) && !(defined(__sun__) && defined(__svr4__)) && \
11 !defined(__NetBSD__) && !defined(_WIN32) && !defined(_AIX)
12
13#include <stdlib.h>
14#include <stdio.h>
15
16#include "InstrProfiling.h"
17#include "InstrProfilingInternal.h"
18
19static const __llvm_profile_data *DataFirst = NULL;
20static const __llvm_profile_data *DataLast = NULL;
21static const VTableProfData *VTableProfDataFirst = NULL;
22static const VTableProfData *VTableProfDataLast = NULL;
23static const char *NamesFirst = NULL;
24static const char *NamesLast = NULL;
25static const char *VNamesFirst = NULL;
26static const char *VNamesLast = NULL;
27static char *CountersFirst = NULL;
28static char *CountersLast = NULL;
29static uint32_t *OrderFileFirst = NULL;
30
31static const void *getMinAddr(const void *A1, const void *A2) {
32 return A1 < A2 ? A1 : A2;
33}
34
35static const void *getMaxAddr(const void *A1, const void *A2) {
36 return A1 > A2 ? A1 : A2;
37}
38
39/*!
40 * \brief Register an instrumented function.
41 *
42 * Calls to this are emitted by clang with -fprofile-instr-generate. Such
43 * calls are only required (and only emitted) on targets where we haven't
44 * implemented linker magic to find the bounds of the sections.
45 */
46COMPILER_RT_VISIBILITY
47void __llvm_profile_register_function(void *Data_) {
48 /* TODO: Only emit this function if we can't use linker magic. */
49 const __llvm_profile_data *Data = (__llvm_profile_data *)Data_;
50 if (!DataFirst) {
51 DataFirst = Data;
52 DataLast = Data + 1;
53 CountersFirst = (char *)((uintptr_t)Data_ + Data->CounterPtr);
54 CountersLast =
55 CountersFirst + Data->NumCounters * __llvm_profile_counter_entry_size();
56 return;
57 }
58
59 DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);
60 CountersFirst = (char *)getMinAddr(
61 CountersFirst, (char *)((uintptr_t)Data_ + Data->CounterPtr));
62
63 DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);
64 CountersLast = (char *)getMaxAddr(
65 CountersLast,
66 (char *)((uintptr_t)Data_ + Data->CounterPtr) +
67 Data->NumCounters * __llvm_profile_counter_entry_size());
68}
69
70COMPILER_RT_VISIBILITY
71void __llvm_profile_register_names_function(void *NamesStart,
72 uint64_t NamesSize) {
73 if (!NamesFirst) {
74 NamesFirst = (const char *)NamesStart;
75 NamesLast = (const char *)NamesStart + NamesSize;
76 return;
77 }
78 NamesFirst = (const char *)getMinAddr(NamesFirst, NamesStart);
79 NamesLast =
80 (const char *)getMaxAddr(NamesLast, (const char *)NamesStart + NamesSize);
81}
82
83COMPILER_RT_VISIBILITY
84const __llvm_profile_data *__llvm_profile_begin_data(void) { return DataFirst; }
85COMPILER_RT_VISIBILITY
86const __llvm_profile_data *__llvm_profile_end_data(void) { return DataLast; }
87COMPILER_RT_VISIBILITY const VTableProfData *
88__llvm_profile_begin_vtables(void) {
89 return VTableProfDataFirst;
90}
91COMPILER_RT_VISIBILITY const VTableProfData *__llvm_profile_end_vtables(void) {
92 return VTableProfDataLast;
93}
94COMPILER_RT_VISIBILITY
95const char *__llvm_profile_begin_names(void) { return NamesFirst; }
96COMPILER_RT_VISIBILITY
97const char *__llvm_profile_end_names(void) { return NamesLast; }
98COMPILER_RT_VISIBILITY
99const char *__llvm_profile_begin_vtabnames(void) { return VNamesFirst; }
100COMPILER_RT_VISIBILITY
101const char *__llvm_profile_end_vtabnames(void) { return VNamesLast; }
102COMPILER_RT_VISIBILITY
103char *__llvm_profile_begin_counters(void) { return CountersFirst; }
104COMPILER_RT_VISIBILITY
105char *__llvm_profile_end_counters(void) { return CountersLast; }
106COMPILER_RT_VISIBILITY
107char *__llvm_profile_begin_bitmap(void) { return BitmapFirst; }
108COMPILER_RT_VISIBILITY
109char *__llvm_profile_end_bitmap(void) { return BitmapLast; }
110/* TODO: correctly set up OrderFileFirst. */
111COMPILER_RT_VISIBILITY
112uint32_t *__llvm_profile_begin_orderfile(void) { return OrderFileFirst; }
113
114COMPILER_RT_VISIBILITY
115ValueProfNode *__llvm_profile_begin_vnodes(void) {
116 return 0;
117}
118COMPILER_RT_VISIBILITY
119ValueProfNode *__llvm_profile_end_vnodes(void) { return 0; }
120
121COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
122COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;
123
124COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer) {
125 return 0;
126}
127
128#endif
129