Skip to content

Commit 0f6220d

Browse files
committed
[profile] Move __llvm_profile_raw_version into a separate file
Similar to the reason behind moving __llvm_profile_filename into a separate file[1]. When users try to use Full LTO with BFD linker to generate IR level PGO profile, the __llvm_profile_raw_version variable, which is used for marking instrumentation level, generated by frontend would somehow conflict with the weak symbol provided by profiling runtime. In most of the cases, BFD linkers will pick profiling runtime's weak symbol as the real definition and thus generate the incorrect instrumentation level metadata in the final executables. Moving __llvm_profile_raw_version into a separate file would make linkers not seeing the weak symbol in the archive unless the frontend doesn't generate one. [1] https://reviews.llvm.org/D34797 Differential Revision: https://reviews.llvm.org/D83967
1 parent 2cf3458 commit 0f6220d

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

compiler-rt/lib/profile/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ set(PROFILE_SOURCES
5959
InstrProfilingMerge.c
6060
InstrProfilingMergeFile.c
6161
InstrProfilingNameVar.c
62+
InstrProfilingVersionVar.c
6263
InstrProfilingWriter.c
6364
InstrProfilingPlatformDarwin.c
6465
InstrProfilingPlatformFuchsia.c

compiler-rt/lib/profile/InstrProfiling.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include "profile/InstrProfData.inc"
1919

2020

21-
COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR = INSTR_PROF_RAW_VERSION;
22-
2321
COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_magic(void) {
2422
return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64)
2523
: (INSTR_PROF_RAW_MAGIC_32);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*===- InstrProfilingVersionVar.c - profile version variable setup -------===*\
2+
|*
3+
|* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
|* See https://llvm.org/LICENSE.txt for license information.
5+
|* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
|*
7+
\*===----------------------------------------------------------------------===*/
8+
9+
#include "InstrProfiling.h"
10+
11+
/* uint64 __llvm_profile_raw_version
12+
*
13+
* The runtime should only provide its own definition of this symbol when the
14+
* user has not specified one. Set this up by moving the runtime's copy of this
15+
* symbol to an object file within the archive.
16+
*/
17+
COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR = INSTR_PROF_RAW_VERSION;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// REQUIRES: lto
2+
3+
// RUN: %clang_pgogen=%t.profraw -flto %s -o %t
4+
// RUN: %run %t
5+
// RUN: llvm-profdata merge %t.profraw -o %t.profdata
6+
// RUN: llvm-profdata show %t.profdata | FileCheck %s
7+
8+
// Testing a bug that happens when trying to generate IR
9+
// profile with BFD linker + LTO plugin
10+
11+
// CHECK: Instrumentation level: IR
12+
int main() { return 0; }

0 commit comments

Comments
 (0)