Skip to content

Commit bbb8129

Browse files
committed
Set hidden attribute on lprofMergeValueProfData
Summary: The changes in https://reviews.llvm.org/D44847 cause load time failure due to lprofMergeValueProfData in Android libs enabled with profile generation: "dlopen failed: cannot locate symbol "lprofMergeValueProfData" referenced by..." Marking lprofMergeValueProfData as hidden so the correct in-module definition is picked by the linker. Reviewers: davidxl Reviewed By: davidxl Subscribers: efriedma, xur, davidxl, llvm-commits Differential Revision: https://reviews.llvm.org/D55893 llvm-svn: 354064
1 parent 48d680d commit bbb8129

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

compiler-rt/lib/profile/InstrProfilingMergeFile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
/* Merge value profile data pointed to by SrcValueProfData into
2222
* in-memory profile counters pointed by to DstData. */
23+
COMPILER_RT_VISIBILITY
2324
void lprofMergeValueProfData(ValueProfData *SrcValueProfData,
2425
__llvm_profile_data *DstData) {
2526
unsigned I, S, V, DstIndex = 0;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <string.h>
4+
#ifdef DLOPEN_FUNC_DIR
5+
#include <dlfcn.h>
6+
#endif
7+
8+
int __llvm_profile_runtime = 0;
9+
int __llvm_profile_write_file();
10+
void __llvm_profile_reset_counters(void);
11+
void __llvm_profile_initialize_file(void);
12+
struct __llvm_profile_data;
13+
struct ValueProfData;
14+
void lprofMergeValueProfData(struct ValueProfData *, struct __llvm_profile_data *);
15+
/* Force the vp merger module to be linked in. */
16+
void *Dummy = &lprofMergeValueProfData;
17+
18+
void callee1() {}
19+
void callee2() {}
20+
21+
typedef void (*FP)(void);
22+
FP Fps[2] = {callee1, callee2};
23+
24+
int 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+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This tests that lprofMergeValueProfData is not accessed from outside a module
2+
RUN: mkdir -p %t.d
3+
RUN: %clang_profgen -o %t.d/func.shared -fPIC -shared -fuse-ld=gold -mllvm --enable-value-profiling=true %S/../Inputs/instrprof-value-prof-visibility.c -fdata-sections -ffunction-sections -fuse-ld=gold -Wl,--gc-sections
4+
RUN: %clang_profgen -o %t.d/main -fuse-ld=gold -mllvm --enable-value-profiling=true -DDLOPEN_FUNC_DIR=\"%t.d\" %S/../Inputs/instrprof-value-prof-visibility.c -fdata-sections -ffunction-sections -fuse-ld=gold -Wl,--gc-sections
5+
RUN: env LLVM_PROFILE_FILE=%t.profraw %run %t.d/main
6+

0 commit comments

Comments
 (0)