Skip to content

Commit 6970847

Browse files
[compiler-rt/profile] Hide __llvm_profile_raw_version
Hide __llvm_profile_raw_version so as not to resolve reference from a dependent shared object. Since libclang_rt.profile is added later in the command line, a definition of __llvm_profile_raw_version is not included if it is provided from an earlier object, e.g. from a shared dependency. This causes an extra dependence edge where if libA.so depends on libB.so and both are coverage-instrumented, libA.so uses libB.so's definition of __llvm_profile_raw_version. This leads to a runtime link failure if the libB.so available at runtime does not provide this symbol (but provides the other dependent symbols). Such a scenario can occur in Android's mainline modules. E.g.: ld -o libB.so libclang_rt.profile-x86_64.a ld -o libA.so -l B libclang_rt.profile-x86_64.a libB.so has a global definition of __llvm_profile_raw_version. libA.so uses libB.so's definition of __llvm_profile_raw_version. At runtime, libB.so may not be coverage-instrumented (i.e. not export __llvm_profile_raw_version) so runtime linking of libA.so will fail. Marking this symbol as hidden forces each binary to use the definition of __llvm_profile_raw_version from libclang_rt.profile. Differential Revision: https://reviews.llvm.org/D111759
1 parent 659a083 commit 6970847

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

compiler-rt/lib/profile/InstrProfiling.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,11 @@ void __llvm_profile_set_dumped();
301301
COMPILER_RT_VISIBILITY extern int INSTR_PROF_PROFILE_RUNTIME_VAR;
302302

303303
/*!
304-
* This variable is defined in InstrProfiling.c. Its main purpose is to
305-
* encode the raw profile version value and other format related information
306-
* such as whether the profile is from IR based instrumentation. The variable
307-
* is defined as weak so that compiler can emit an overriding definition
308-
* depending on user option. Since we don't support mixing FE and IR based
309-
* data in the same raw profile data file (in other words, shared libs and
310-
* main program are expected to be instrumented in the same way), there is
311-
* no need for this variable to be hidden.
304+
* This variable is defined in InstrProfilingVersionVar.c as a hidden symbol.
305+
* Its main purpose is to encode the raw profile version value and other format
306+
* related information such as whether the profile is from IR based
307+
* instrumentation. The variable is defined as weak so that compiler can emit an
308+
* overriding definition depending on user option.
312309
*/
313310
extern uint64_t INSTR_PROF_RAW_VERSION_VAR; /* __llvm_profile_raw_version */
314311

compiler-rt/lib/profile/InstrProfilingVersionVar.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@
1414
* user has not specified one. Set this up by moving the runtime's copy of this
1515
* symbol to an object file within the archive.
1616
*/
17-
COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR = INSTR_PROF_RAW_VERSION;
17+
COMPILER_RT_VISIBILITY COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR =
18+
INSTR_PROF_RAW_VERSION;

0 commit comments

Comments
 (0)