1 /*===- InstrProfilingPlatformLinux.c - Profile data Linux platform ------===*\
2 |*
3 |*                     The LLVM Compiler Infrastructure
4 |*
5 |* This file is distributed under the University of Illinois Open Source
6 |* License. See LICENSE.TXT for details.
7 |*
8 \*===----------------------------------------------------------------------===*/
9 
10 #include "InstrProfiling.h"
11 
12 #if defined(__linux__) || defined(__FreeBSD__)
13 #include <stdlib.h>
14 
15 #define PROF_DATA_START INSTR_PROF_SECT_START(INSTR_PROF_DATA_SECT_NAME)
16 #define PROF_DATA_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_DATA_SECT_NAME)
17 #define PROF_NAME_START INSTR_PROF_SECT_START(INSTR_PROF_NAME_SECT_NAME)
18 #define PROF_NAME_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_NAME_SECT_NAME)
19 #define PROF_CNTS_START INSTR_PROF_SECT_START(INSTR_PROF_CNTS_SECT_NAME)
20 #define PROF_CNTS_STOP INSTR_PROF_SECT_STOP(INSTR_PROF_CNTS_SECT_NAME)
21 
22 /* Declare section start and stop symbols for various sections
23  * generated by compiler instrumentation.
24  */
25 extern __llvm_profile_data PROF_DATA_START LLVM_LIBRARY_VISIBILITY;
26 extern __llvm_profile_data PROF_DATA_STOP LLVM_LIBRARY_VISIBILITY;
27 extern uint64_t PROF_CNTS_START LLVM_LIBRARY_VISIBILITY;
28 extern uint64_t PROF_CNTS_STOP LLVM_LIBRARY_VISIBILITY;
29 extern char PROF_NAME_START LLVM_LIBRARY_VISIBILITY;
30 extern char PROF_NAME_STOP LLVM_LIBRARY_VISIBILITY;
31 
32 /* Add dummy data to ensure the section is always created. */
33 __llvm_profile_data
34     __prof_data_sect_data[0] LLVM_SECTION(INSTR_PROF_DATA_SECT_NAME_STR);
35 uint64_t __prof_cnts_sect_data[0] LLVM_SECTION(INSTR_PROF_CNTS_SECT_NAME_STR);
36 char __prof_nms_sect_data[0] LLVM_SECTION(INSTR_PROF_NAME_SECT_NAME_STR);
37 
38 LLVM_LIBRARY_VISIBILITY const __llvm_profile_data *
39 __llvm_profile_begin_data(void) {
40   return &PROF_DATA_START;
41 }
42 LLVM_LIBRARY_VISIBILITY const __llvm_profile_data *
43 __llvm_profile_end_data(void) {
44   return &PROF_DATA_STOP;
45 }
46 LLVM_LIBRARY_VISIBILITY const char *__llvm_profile_begin_names(void) {
47   return &PROF_NAME_START;
48 }
49 LLVM_LIBRARY_VISIBILITY const char *__llvm_profile_end_names(void) {
50   return &PROF_NAME_STOP;
51 }
52 LLVM_LIBRARY_VISIBILITY uint64_t *__llvm_profile_begin_counters(void) {
53   return &PROF_CNTS_START;
54 }
55 LLVM_LIBRARY_VISIBILITY uint64_t *__llvm_profile_end_counters(void) {
56   return &PROF_CNTS_STOP;
57 }
58 #endif
59