Skip to content

Commit cc0d7ee

Browse files
committed
profile: Avoid name collisions between instrumentation and runtime
The naming scheme we're using for counters in profile data shares a prefix with some fixed names we use for the runtime, notably __llvm_profile_data_begin and _end. Embarrassingly, this means a function called begin() can't be instrumented. This modifies the runtime names so as not to collide with the instrumentation. llvm-svn: 217166
1 parent 7c3d581 commit cc0d7ee

File tree

7 files changed

+54
-35
lines changed

7 files changed

+54
-35
lines changed

compiler-rt/lib/profile/InstrProfiling.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ uint64_t __llvm_profile_get_version(void) {
4141

4242
__attribute__((visibility("hidden")))
4343
void __llvm_profile_reset_counters(void) {
44-
uint64_t *I = __llvm_profile_counters_begin();
45-
uint64_t *E = __llvm_profile_counters_end();
44+
uint64_t *I = __llvm_profile_begin_counters();
45+
uint64_t *E = __llvm_profile_end_counters();
4646

4747
memset(I, 0, sizeof(uint64_t)*(E - I));
4848
}

compiler-rt/lib/profile/InstrProfiling.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ uint64_t __llvm_profile_get_size_for_buffer(void);
5050
*/
5151
int __llvm_profile_write_buffer(char *Buffer);
5252

53-
const __llvm_profile_data *__llvm_profile_data_begin(void);
54-
const __llvm_profile_data *__llvm_profile_data_end(void);
55-
const char *__llvm_profile_names_begin(void);
56-
const char *__llvm_profile_names_end(void);
57-
uint64_t *__llvm_profile_counters_begin(void);
58-
uint64_t *__llvm_profile_counters_end(void);
53+
const __llvm_profile_data *__llvm_profile_begin_data(void);
54+
const __llvm_profile_data *__llvm_profile_end_data(void);
55+
const char *__llvm_profile_begin_names(void);
56+
const char *__llvm_profile_end_names(void);
57+
uint64_t *__llvm_profile_begin_counters(void);
58+
uint64_t *__llvm_profile_end_counters(void);
5959

6060
#define PROFILE_RANGE_SIZE(Range) \
61-
(__llvm_profile_ ## Range ## _end() - __llvm_profile_ ## Range ## _begin())
61+
(__llvm_profile_end_ ## Range () - __llvm_profile_begin_ ## Range ())
6262

6363
/*!
6464
* \brief Write instrumentation data to the current file.

compiler-rt/lib/profile/InstrProfilingBuffer.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ int __llvm_profile_write_buffer(char *Buffer) {
2626
/* Match logic in __llvm_profile_get_size_for_buffer().
2727
* Match logic in __llvm_profile_write_file().
2828
*/
29-
const __llvm_profile_data *DataBegin = __llvm_profile_data_begin();
30-
const __llvm_profile_data *DataEnd = __llvm_profile_data_end();
31-
const uint64_t *CountersBegin = __llvm_profile_counters_begin();
32-
const uint64_t *CountersEnd = __llvm_profile_counters_end();
33-
const char *NamesBegin = __llvm_profile_names_begin();
34-
const char *NamesEnd = __llvm_profile_names_end();
29+
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
30+
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
31+
const uint64_t *CountersBegin = __llvm_profile_begin_counters();
32+
const uint64_t *CountersEnd = __llvm_profile_end_counters();
33+
const char *NamesBegin = __llvm_profile_begin_names();
34+
const char *NamesEnd = __llvm_profile_end_names();
3535

3636
/* Calculate size of sections. */
3737
const uint64_t DataSize = DataEnd - DataBegin;

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
static int writeFile(FILE *File) {
1818
/* Match logic in __llvm_profile_write_buffer(). */
19-
const __llvm_profile_data *DataBegin = __llvm_profile_data_begin();
20-
const __llvm_profile_data *DataEnd = __llvm_profile_data_end();
21-
const uint64_t *CountersBegin = __llvm_profile_counters_begin();
22-
const uint64_t *CountersEnd = __llvm_profile_counters_end();
23-
const char *NamesBegin = __llvm_profile_names_begin();
24-
const char *NamesEnd = __llvm_profile_names_end();
19+
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
20+
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
21+
const uint64_t *CountersBegin = __llvm_profile_begin_counters();
22+
const uint64_t *CountersEnd = __llvm_profile_end_counters();
23+
const char *NamesBegin = __llvm_profile_begin_names();
24+
const char *NamesEnd = __llvm_profile_end_names();
2525

2626
/* Calculate size of sections. */
2727
const uint64_t DataSize = DataEnd - DataBegin;

compiler-rt/lib/profile/InstrProfilingPlatformDarwin.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ __attribute__((visibility("hidden")))
2525
extern uint64_t CountersEnd __asm("section$end$__DATA$__llvm_prf_cnts");
2626

2727
__attribute__((visibility("hidden")))
28-
const __llvm_profile_data *__llvm_profile_data_begin(void) {
28+
const __llvm_profile_data *__llvm_profile_begin_data(void) {
2929
return &DataStart;
3030
}
3131
__attribute__((visibility("hidden")))
32-
const __llvm_profile_data *__llvm_profile_data_end(void) {
32+
const __llvm_profile_data *__llvm_profile_end_data(void) {
3333
return &DataEnd;
3434
}
3535
__attribute__((visibility("hidden")))
36-
const char *__llvm_profile_names_begin(void) { return &NamesStart; }
36+
const char *__llvm_profile_begin_names(void) { return &NamesStart; }
3737
__attribute__((visibility("hidden")))
38-
const char *__llvm_profile_names_end(void) { return &NamesEnd; }
38+
const char *__llvm_profile_end_names(void) { return &NamesEnd; }
3939
__attribute__((visibility("hidden")))
40-
uint64_t *__llvm_profile_counters_begin(void) { return &CountersStart; }
40+
uint64_t *__llvm_profile_begin_counters(void) { return &CountersStart; }
4141
__attribute__((visibility("hidden")))
42-
uint64_t *__llvm_profile_counters_end(void) { return &CountersEnd; }
42+
uint64_t *__llvm_profile_end_counters(void) { return &CountersEnd; }
4343
#endif

compiler-rt/lib/profile/InstrProfilingPlatformOther.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,19 @@ void __llvm_profile_register_function(void *Data_) {
5656
}
5757

5858
__attribute__((visibility("hidden")))
59-
const __llvm_profile_data *__llvm_profile_data_begin(void) {
59+
const __llvm_profile_data *__llvm_profile_begin_data(void) {
6060
return DataFirst;
6161
}
6262
__attribute__((visibility("hidden")))
63-
const __llvm_profile_data *__llvm_profile_data_end(void) {
63+
const __llvm_profile_data *__llvm_profile_end_data(void) {
6464
return DataLast;
6565
}
6666
__attribute__((visibility("hidden")))
67-
const char *__llvm_profile_names_begin(void) { return NamesFirst; }
67+
const char *__llvm_profile_begin_names(void) { return NamesFirst; }
6868
__attribute__((visibility("hidden")))
69-
const char *__llvm_profile_names_end(void) { return NamesLast; }
69+
const char *__llvm_profile_end_names(void) { return NamesLast; }
7070
__attribute__((visibility("hidden")))
71-
uint64_t *__llvm_profile_counters_begin(void) { return CountersFirst; }
71+
uint64_t *__llvm_profile_begin_counters(void) { return CountersFirst; }
7272
__attribute__((visibility("hidden")))
73-
uint64_t *__llvm_profile_counters_end(void) { return CountersLast; }
73+
uint64_t *__llvm_profile_end_counters(void) { return CountersLast; }
7474
#endif

compiler-rt/test/profile/instrprof-basic.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,29 @@
33
// RUN: llvm-profdata merge -o %t.profdata %t.profraw
44
// RUN: %clang_profuse=%t.profdata -o - -S -emit-llvm %s | FileCheck %s
55

6-
int main(int argc, const char *argv[]) {
6+
int begin(int i) {
77
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !1
8+
if (i)
9+
return 0;
10+
return 1;
11+
}
12+
13+
int end(int i) {
14+
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !2
15+
if (i)
16+
return 0;
17+
return 1;
18+
}
19+
20+
int main(int argc, const char *argv[]) {
21+
begin(0);
22+
end(1);
23+
24+
// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !prof !2
825
if (argc)
926
return 0;
1027
return 1;
1128
}
12-
// CHECK: !1 = metadata !{metadata !"branch_weights", i32 2, i32 1}
29+
30+
// CHECK: !1 = metadata !{metadata !"branch_weights", i32 1, i32 2}
31+
// CHECK: !2 = metadata !{metadata !"branch_weights", i32 2, i32 1}

0 commit comments

Comments
 (0)