Skip to content

Commit 5eca8b6

Browse files
authored
[PGO][HIP] Fix profile-only Windows link by gating ROCm interceptor macro (llvm#200859)
PR llvm#200111 stops compiling InstrProfilingPlatformROCm.cpp (which defines the HIP GPU helper __llvm_profile_hip_collect_device_data) in profile-only builds. But the compile define -DCOMPILER_RT_BUILD_PROFILE_ROCM=1 was still added whenever the COMPILER_RT_BUILD_PROFILE_ROCM option was on (the default), so InstrProfilingFile.c still referenced the helper from __llvm_profile_write_file even though it was never built. On ELF the declaration is weak, so the undefined symbol folds to null and the address-guarded call is skipped. COFF/Windows has no such fallback: error LNK2019: unresolved external symbol __llvm_profile_hip_collect_device_data referenced in function __llvm_profile_write_file Add the define only when PROFILE_HAS_HIP_INTERCEPTOR is true, i.e. the same condition that keeps InstrProfilingPlatformROCm.cpp in the archive, so the macro is defined iff the helper is actually compiled in. Reported by zmodem: llvm#200111 (comment)
1 parent 09f30ef commit 5eca8b6

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

compiler-rt/lib/profile/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ if(COMPILER_RT_PROFILE_BAREMETAL)
158158
-DCOMPILER_RT_PROFILE_BAREMETAL=1)
159159
endif()
160160

161-
if(COMPILER_RT_BUILD_PROFILE_ROCM)
162-
set(EXTRA_FLAGS
163-
${EXTRA_FLAGS}
164-
-DCOMPILER_RT_BUILD_PROFILE_ROCM=1)
165-
endif()
166-
167161
# The HIP host interceptor in InstrProfilingPlatformROCm.cpp pulls in
168162
# RTInterception + sanitizer_common object libs. Those targets are only created
169163
# when COMPILER_RT_BUILD_SANITIZERS / _MEMPROF / _XRAY / _CTX_PROFILE is enabled
@@ -190,6 +184,17 @@ if(NOT PROFILE_HAS_HIP_INTERCEPTOR)
190184
list(REMOVE_ITEM PROFILE_SOURCES InstrProfilingPlatformROCm.cpp)
191185
endif()
192186

187+
# Only advertise the ROCm interceptor to InstrProfilingFile.c when its
188+
# definition (InstrProfilingPlatformROCm.cpp) is actually compiled into the
189+
# archive. Otherwise InstrProfilingFile.c references
190+
# __llvm_profile_hip_collect_device_data with no definition; on COFF/Windows
191+
# there is no weak-undefined fallback, so the link fails (see PR #200111).
192+
if(COMPILER_RT_BUILD_PROFILE_ROCM AND PROFILE_HAS_HIP_INTERCEPTOR)
193+
set(EXTRA_FLAGS
194+
${EXTRA_FLAGS}
195+
-DCOMPILER_RT_BUILD_PROFILE_ROCM=1)
196+
endif()
197+
193198
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx")
194199
append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding EXTRA_FLAGS)
195200
append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib EXTRA_FLAGS)

0 commit comments

Comments
 (0)