Skip to content

Commit 70a19ad

Browse files
authored
[profile] Change __llvm_profile_counter_bias etc. types to match llvm (#102747)
As detailed in Issue #101667, two `profile` tests `FAIL` on 32-bit SPARC, both Linux/sparc64 and Solaris/sparcv9 (where the tests work when enabled): ``` Profile-sparc :: ContinuousSyncMode/runtime-counter-relocation.c Profile-sparc :: ContinuousSyncMode/set-file-object.c ``` The Solaris linker provides the crucial clue as to what's wrong: ``` ld: warning: symbol '__llvm_profile_counter_bias' has differing sizes: (file runtime-counter-relocation-17ff25.o value=0x8; file libclang_rt.profile-sparc.a(InstrProfilingFile.c.o) value=0x4); runtime-counter-relocation-17ff25.o definition taken ``` In fact, the types in `llvm` and `compiler-rt` differ: - `__llvm_profile_counter_bias`/`INSTR_PROF_PROFILE_COUNTER_BIAS_VAR` is created in `llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp` (`InstrLowerer::getCounterAddress`) as `int64_t`, while `compiler-rt/lib/profile/InstrProfilingFile.c` uses `intptr_t`. While this doesn't matter in the 64-bit case, the type sizes differ for 32-bit. - `__llvm_profile_bitmap_bias`/`INSTR_PROF_PROFILE_BITMAP_BIAS_VAR` has the same issue: created in `InstrProfiling.cpp` (`InstrLowerer::getBitmapAddress`) as `int64_t`, while `InstrProfilingFile.c` again uses `intptr_t`. This patch changes the `compiler-rt` types to match `llvm`. At the same time, the affected testcases are enabled on Solaris, too, where they now just `PASS`. Tested on `sparc64-unknown-linux-gnu`, `sparcv9-sun-solaris2.11`, `x86_64-pc-linux-gnu`, and `amd64-pc-solaris2.11.
1 parent 1a0cf24 commit 70a19ad

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

compiler-rt/lib/profile/InstrProfilingFile.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,16 @@ static int mmapForContinuousMode(uint64_t CurrentFileOffset, FILE *File) {
200200

201201
#define INSTR_PROF_PROFILE_COUNTER_BIAS_DEFAULT_VAR \
202202
INSTR_PROF_CONCAT(INSTR_PROF_PROFILE_COUNTER_BIAS_VAR, _default)
203-
COMPILER_RT_VISIBILITY intptr_t INSTR_PROF_PROFILE_COUNTER_BIAS_DEFAULT_VAR = 0;
203+
COMPILER_RT_VISIBILITY int64_t INSTR_PROF_PROFILE_COUNTER_BIAS_DEFAULT_VAR = 0;
204204
#define INSTR_PROF_PROFILE_BITMAP_BIAS_DEFAULT_VAR \
205205
INSTR_PROF_CONCAT(INSTR_PROF_PROFILE_BITMAP_BIAS_VAR, _default)
206-
COMPILER_RT_VISIBILITY intptr_t INSTR_PROF_PROFILE_BITMAP_BIAS_DEFAULT_VAR = 0;
206+
COMPILER_RT_VISIBILITY int64_t INSTR_PROF_PROFILE_BITMAP_BIAS_DEFAULT_VAR = 0;
207207

208208
/* This variable is a weak external reference which could be used to detect
209209
* whether or not the compiler defined this symbol. */
210210
#if defined(_MSC_VER)
211-
COMPILER_RT_VISIBILITY extern intptr_t INSTR_PROF_PROFILE_COUNTER_BIAS_VAR;
212-
COMPILER_RT_VISIBILITY extern intptr_t INSTR_PROF_PROFILE_BITMAP_BIAS_VAR;
211+
COMPILER_RT_VISIBILITY extern int64_t INSTR_PROF_PROFILE_COUNTER_BIAS_VAR;
212+
COMPILER_RT_VISIBILITY extern int64_t INSTR_PROF_PROFILE_BITMAP_BIAS_VAR;
213213
#if defined(_M_IX86) || defined(__i386__)
214214
#define WIN_SYM_PREFIX "_"
215215
#else
@@ -224,10 +224,10 @@ COMPILER_RT_VISIBILITY extern intptr_t INSTR_PROF_PROFILE_BITMAP_BIAS_VAR;
224224
INSTR_PROF_PROFILE_BITMAP_BIAS_VAR) "=" WIN_SYM_PREFIX \
225225
INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_BITMAP_BIAS_DEFAULT_VAR))
226226
#else
227-
COMPILER_RT_VISIBILITY extern intptr_t INSTR_PROF_PROFILE_COUNTER_BIAS_VAR
227+
COMPILER_RT_VISIBILITY extern int64_t INSTR_PROF_PROFILE_COUNTER_BIAS_VAR
228228
__attribute__((weak, alias(INSTR_PROF_QUOTE(
229229
INSTR_PROF_PROFILE_COUNTER_BIAS_DEFAULT_VAR))));
230-
COMPILER_RT_VISIBILITY extern intptr_t INSTR_PROF_PROFILE_BITMAP_BIAS_VAR
230+
COMPILER_RT_VISIBILITY extern int64_t INSTR_PROF_PROFILE_BITMAP_BIAS_VAR
231231
__attribute__((weak, alias(INSTR_PROF_QUOTE(
232232
INSTR_PROF_PROFILE_BITMAP_BIAS_DEFAULT_VAR))));
233233
#endif

compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "InstrProfilingUtil.h"
3636

3737
/* This variable is an external reference to symbol defined by the compiler. */
38-
COMPILER_RT_VISIBILITY extern intptr_t INSTR_PROF_PROFILE_COUNTER_BIAS_VAR;
38+
COMPILER_RT_VISIBILITY extern int64_t INSTR_PROF_PROFILE_COUNTER_BIAS_VAR;
3939

4040
COMPILER_RT_VISIBILITY unsigned lprofProfileDumped(void) {
4141
return 1;

compiler-rt/test/profile/ContinuousSyncMode/runtime-counter-relocation.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: linux || windows
1+
// REQUIRES: target={{.*(linux|solaris|windows-msvc).*}}
22

33
// RUN: %clang -fprofile-instr-generate -fcoverage-mapping -mllvm -runtime-counter-relocation=true -o %t.exe %s
44
// RUN: echo "garbage" > %t.profraw

compiler-rt/test/profile/ContinuousSyncMode/set-file-object.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: darwin || linux
1+
// REQUIRES: target={{.*(darwin|linux|solaris).*}}
22

33
// Test using __llvm_profile_set_file_object in continuous mode (%c).
44
// Create & cd into a temporary directory.

0 commit comments

Comments
 (0)