1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#ifdef DLOPEN_FUNC_DIR
5#include <dlfcn.h>
6#endif
7
8int __llvm_profile_runtime = 0;
9int __llvm_profile_write_file();
10void __llvm_profile_reset_counters(void);
11void __llvm_profile_initialize_file(void);
12struct __llvm_profile_data;
13struct ValueProfData;
14void lprofMergeValueProfData(struct ValueProfData *, struct __llvm_profile_data *);
15/* Force the vp merger module to be linked in. */
16void *Dummy = &lprofMergeValueProfData;
17
18void callee1() {}
19void callee2() {}
20
21typedef void (*FP)(void);
22FP Fps[2] = {callee1, callee2};
23
24int main(int argc, char *argv[]) {
25 __llvm_profile_initialize_file();
26 __llvm_profile_write_file();
27 __llvm_profile_reset_counters();
28
29#ifdef DLOPEN_FUNC_DIR
30 void *Handle = dlopen(DLOPEN_FUNC_DIR "/func.shared", RTLD_NOW);
31 if (!Handle) {
32 fprintf(stderr, "unable to open '" DLOPEN_FUNC_DIR "/func.shared': %s\n",
33 dlerror());
34 return EXIT_FAILURE;
35 }
36
37 // This tests that lprofMergeValueProfData is not accessed
38 // from outside a module
39 void (*SymHandle)(struct ValueProfData *, struct __llvm_profile_data *) =
40 (void (*)(struct ValueProfData *, struct __llvm_profile_data *))dlsym(
41 Handle, "lprofMergeValueProfData");
42 if (SymHandle) {
43 fprintf(stderr,
44 "should not be able to lookup symbol 'lprofMergeValueProfData': %s\n",
45 dlerror());
46 return EXIT_FAILURE;
47 }
48
49 dlclose(Handle);
50
51#endif
52
53 Fps[0]();
54 Fps[1]();
55
56 __llvm_profile_write_file();
57 __llvm_profile_reset_counters();
58
59 return EXIT_SUCCESS;
60}
61

source code of compiler-rt/test/profile/Inputs/instrprof-value-prof-visibility.c