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