Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions compiler-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "hexagon")
list(APPEND SANITIZER_COMMON_CFLAGS -fno-emulated-tls)
string(APPEND COMPILER_RT_TEST_COMPILER_CFLAGS " -fno-emulated-tls")
endif()
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx")
append_list_if(UBSAN_COMMON_SUPPORTED_ARCH -ffreestanding SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib SANITIZER_COMMON_CFLAGS)
append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto SANITIZER_COMMON_CFLAGS)
if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn")
append_list_if(COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG
"SHELL:-Xclang -mcode-object-version=none" SANITIZER_COMMON_CFLAGS)
endif()
endif()

if(NOT WIN32)
append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC SANITIZER_COMMON_CFLAGS)
endif()
Expand All @@ -377,7 +387,9 @@ append_list_if(COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG -fvisibility=hidden SANIT
if(NOT COMPILER_RT_HAS_FVISIBILITY_HIDDEN_FLAG)
append_list_if(COMPILER_RT_HAS_FVISIBILITY_INLINES_HIDDEN_FLAG -fvisibility-inlines-hidden SANITIZER_COMMON_CFLAGS)
endif()
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
if(NOT "${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx")
append_list_if(COMPILER_RT_HAS_FNO_LTO_FLAG -fno-lto SANITIZER_COMMON_CFLAGS)
endif()

# By default do not instrument or use profdata for compiler-rt.
if(NOT COMPILER_RT_ENABLE_PGO)
Expand Down Expand Up @@ -479,7 +491,7 @@ else()
set(SANITIZER_LIMIT_FRAME_SIZE FALSE)
endif()

if(FUCHSIA OR UNIX)
if(NOT COMPILER_RT_GPU_BUILD AND (FUCHSIA OR UNIX))
set(SANITIZER_USE_SYMBOLS TRUE)
else()
set(SANITIZER_USE_SYMBOLS FALSE)
Expand Down Expand Up @@ -520,20 +532,20 @@ elseif(COMPILER_RT_HAS_G_FLAG)
list(APPEND SANITIZER_COMMON_CFLAGS -g)
endif()

if(SANITIZER_AMDGPU)
list(APPEND SANITIZER_COMMON_CFLAGS -DSANITIZER_AMDGPU=1)
if(SANITIZER_AMDHSA)
list(APPEND SANITIZER_COMMON_CFLAGS -DSANITIZER_AMDHSA=1)
message(STATUS "Looking 'hsa' and 'amd_comgr' header")
find_path(HSA_INCLUDE NAMES hsa.h HINTS ${SANITIZER_HSA_INCLUDE_PATH} /opt/rocm/include PATH_SUFFIXES hsa)
if(NOT HSA_INCLUDE)
message(FATAL_ERROR "Required header 'hsa.h' not found in path ${HSA_INCLUDE}. Aborting SANITIZER_AMDGPU build")
message(FATAL_ERROR "Required header 'hsa.h' not found in path ${HSA_INCLUDE}. Aborting SANITIZER_AMDHSA build")
endif()
message(STATUS "Found 'hsa.h' in ${HSA_INCLUDE}")
include_directories(${HSA_INCLUDE})
find_path(COMgr_INCLUDE NAMES amd_comgr.h.in HINTS ${SANITIZER_COMGR_INCLUDE_PATH} PATH_SUFFIXES amd_comgr)
if(NOT COMgr_INCLUDE)
find_path(COMgr_INCLUDE NAMES amd_comgr.h HINTS /opt/rocm/include PATH_SUFFIXES amd_comgr)
if(NOT COMgr_INCLUDE)
message(FATAL_ERROR "Required header 'amd_comgr.h/amd_comgr.h.in' not found in path ${COMgr_INCLUDE}. Aborting SANITIZER_AMDGPU build")
message(FATAL_ERROR "Required header 'amd_comgr.h/amd_comgr.h.in' not found in path ${COMgr_INCLUDE}. Aborting SANITIZER_AMDHSA build")
endif()
endif()
message(STATUS "Found 'amd_comgr.h.in/amd_comgr.h' in ${COMgr_INCLUDE}")
Expand Down
6 changes: 6 additions & 0 deletions compiler-rt/cmake/Modules/AddCompilerRT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ function(add_compiler_rt_runtime name type)
set(NO_LTO_FLAGS "")
endif()

# The GPU build does not support shared libraries, just suppress them here as
# there is no global config for this.
if(COMPILER_RT_GPU_BUILD AND type MATCHES "SHARED")
return()
endif()

# By default do not instrument or use profdata for compiler-rt.
set(NO_PGO_FLAGS "")
if(NOT COMPILER_RT_ENABLE_PGO)
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ endif()
set(ALL_TYSAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${S390X})
set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
${LOONGARCH64})
${LOONGARCH64} ${AMDGPU} ${NVPTX})
if (OS_NAME MATCHES "FreeBSD")
set(ALL_SAFESTACK_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM64})
else()
Expand Down
3 changes: 2 additions & 1 deletion compiler-rt/cmake/caches/GPU.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ set(COMPILER_RT_HAS_SAFESTACK OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_BUILTINS ON CACHE BOOL "")
set(COMPILER_RT_BAREMETAL_BUILD ON CACHE BOOL "")
set(COMPILER_RT_BUILD_CRT OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_SANITIZERS ON CACHE BOOL "")
set(COMPILER_RT_SANITIZERS_TO_BUILD "ubsan_minimal" CACHE STRING "")
set(COMPILER_RT_BUILD_XRAY OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_LIBFUZZER OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_PROFILE OFF CACHE BOOL "")
Expand Down
7 changes: 4 additions & 3 deletions compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ else()
filter_available_targets(LSAN_COMMON_SUPPORTED_ARCH
${SANITIZER_COMMON_SUPPORTED_ARCH})
filter_available_targets(UBSAN_COMMON_SUPPORTED_ARCH
${SANITIZER_COMMON_SUPPORTED_ARCH})
${ALL_UBSAN_SUPPORTED_ARCH})
filter_available_targets(ASAN_SUPPORTED_ARCH ${ALL_ASAN_SUPPORTED_ARCH})
filter_available_targets(RTSAN_SUPPORTED_ARCH ${ALL_RTSAN_SUPPORTED_ARCH})
filter_available_targets(FUZZER_SUPPORTED_ARCH ${ALL_FUZZER_SUPPORTED_ARCH})
Expand Down Expand Up @@ -888,8 +888,9 @@ else()
set(COMPILER_RT_HAS_UBSAN FALSE)
endif()

if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
OS_NAME MATCHES "Linux|FreeBSD|NetBSD|Android|Darwin|SunOS")
if (UBSAN_SUPPORTED_ARCH AND
(OS_NAME MATCHES "Linux|FreeBSD|NetBSD|Android|Darwin|SunOS" OR
"${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx"))
set(COMPILER_RT_HAS_UBSAN_MINIMAL TRUE)
else()
set(COMPILER_RT_HAS_UBSAN_MINIMAL FALSE)
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/asan/asan_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ struct Allocator {

void InitLinkerInitialized(const AllocatorOptions &options) {
SetAllocatorMayReturnNull(options.may_return_null);
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
allocator.InitLinkerInitialized(options.release_to_os_interval_ms, 0, true);
#else
allocator.InitLinkerInitialized(options.release_to_os_interval_ms);
Expand Down Expand Up @@ -1469,7 +1469,7 @@ int __asan_update_allocation_context(void* addr) {
return instance.UpdateAllocationStack((uptr)addr, &stack);
}

#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
DECLARE_REAL(hsa_status_t, hsa_init);
DECLARE_REAL(hsa_status_t, hsa_amd_agents_allow_access, uint32_t num_agents,
const hsa_agent_t *agents, const uint32_t *flags, const void *ptr)
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void AsanSoftRssLimitExceededCallback(bool exceeded);

} // namespace __asan

#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
#include <hsa.h>
#include <hsa_ext_amd.h>

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ ErrorNonSelfAMDGPU::ErrorNonSelfAMDGPU(uptr *dev_callstack, u32 n_callstack,
void ErrorNonSelfAMDGPU::PrintStack() {
InternalScopedString source_location;
source_location.AppendF(" #0 %p", (void *)callstack[0]);
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
source_location.Append(" in ");
__sanitizer::AMDGPUCodeObjectSymbolizer symbolizer;
symbolizer.Init(cb_loc.fd, cb_loc.offset, cb_loc.size);
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/asan/asan_globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static u32 FindRegistrationSite(const Global *g) {
return 0;
}

#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
static bool IsValidGlobal(const Global *g) {
return
*(u8 *)MEM_TO_SHADOW((uptr)g) == kAsanGlobalRedzoneMagic &&
Expand All @@ -190,7 +190,7 @@ int GetGlobalsForAddress(uptr addr, Global *globals, u32 *reg_sites,
Lock lock(&mu_for_globals);
int res = 0;
for (const auto &l : list_of_all_globals) {
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
if (!IsValidGlobal(l.g))
continue;
#endif
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/asan/asan_interceptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ DEFINE_REAL(int, vfork, )
DECLARE_EXTERN_INTERCEPTOR_AND_WRAPPER(int, vfork, )
# endif

#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
void ENSURE_HSA_INITED();

INTERCEPTOR(hsa_status_t, hsa_amd_memory_pool_allocate,
Expand Down Expand Up @@ -1170,7 +1170,7 @@ void InitializeAsanInterceptors() {
ASAN_INTERCEPT_FUNC(vfork);
# endif

#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
InitializeAmdgpuInterceptors();
#endif

Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ void ReportNonselfLeak(u64 alloc_pc, u64 alloc_size, int device_id,

InternalScopedString source_location;
source_location.AppendF(" #0 0x%llx", e->alloc_pc);
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
source_location.Append(" in ");
__sanitizer::AMDGPUCodeObjectSymbolizer symbolizer;
symbolizer.Init(e->fd, e->file_extent_start, e->file_extent_size);
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "sanitizer_procmaps.h"
#include "sanitizer_type_traits.h"

#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
#include <hsa.h>
#include <hsa_ext_amd.h>
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Part of the Sanitizer Allocator.
//
//===----------------------------------------------------------------------===//
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
# include <dlfcn.h> // For dlsym
# include "sanitizer_allocator.h"
# include "sanitizer_atomic.h"
Expand Down Expand Up @@ -205,4 +205,4 @@ void AmdgpuMemFuncs::RegisterSystemEventHandlers() {

uptr AmdgpuMemFuncs::GetPageSize() { return kPageSize_; }
} // namespace __sanitizer
#endif // SANITIZER_AMDGPU
#endif // SANITIZER_AMDHSA
4 changes: 2 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator_amdgpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# error This file must be included inside sanitizer_allocator_device.h
#endif

#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
class AmdgpuMemFuncs {
public:
static bool Init();
Expand Down Expand Up @@ -45,4 +45,4 @@ struct AmdgpuAllocationInfo : public DeviceAllocationInfo {
u32 flags;
void *ptr;
};
#endif // SANITIZER_AMDGPU
#endif // SANITIZER_AMDHSA
32 changes: 16 additions & 16 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator_combined.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CombinedAllocator {
LargeMmapAllocator<typename PrimaryAllocator::MapUnmapCallback,
LargeMmapAllocatorPtrArray,
typename PrimaryAllocator::AddressSpaceView>;
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
using DeviceAllocator =
DeviceAllocatorT<typename PrimaryAllocator::MapUnmapCallback>;
#endif
Expand All @@ -38,7 +38,7 @@ class CombinedAllocator {
bool enable_device_allocator = false) {
primary_.Init(release_to_os_interval_ms, heap_start);
secondary_.InitLinkerInitialized();
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
device_.Init(enable_device_allocator, primary_.kMetadataSize);
#endif
}
Expand All @@ -48,7 +48,7 @@ class CombinedAllocator {
stats_.Init();
primary_.Init(release_to_os_interval_ms, heap_start);
secondary_.Init();
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
device_.Init(enable_device_allocator, primary_.kMetadataSize);
#endif
}
Expand Down Expand Up @@ -78,7 +78,7 @@ class CombinedAllocator {
// alignment without such requirement, and allocating 'size' would use
// extraneous memory, so we employ 'original_size'.
void *res;
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
if (da_info)
res = device_.Allocate(&stats_, original_size, alignment, da_info);
else
Expand Down Expand Up @@ -110,7 +110,7 @@ class CombinedAllocator {
cache->Deallocate(&primary_, primary_.GetSizeClass(p), p);
else if (secondary_.PointerIsMine(p))
secondary_.Deallocate(&stats_, p);
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
else if (device_.PointerIsMine(p))
device_.Deallocate(&stats_, p);
#endif
Expand Down Expand Up @@ -139,7 +139,7 @@ class CombinedAllocator {
return true;
if (secondary_.PointerIsMine(p))
return true;
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
if (device_.PointerIsMine(p))
return true;
#endif
Expand All @@ -153,7 +153,7 @@ class CombinedAllocator {
return primary_.GetMetaData(p);
if (secondary_.PointerIsMine(p))
return secondary_.GetMetaData(p);
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
if (device_.PointerIsMine(p))
return device_.GetMetaData(p);
#endif
Expand All @@ -165,7 +165,7 @@ class CombinedAllocator {
return primary_.GetBlockBegin(p);
if (secondary_.PointerIsMine(p))
return secondary_.GetBlockBegin(p);
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
if (device_.PointerIsMine(p))
return device_.GetBlockBegin(p);
#endif
Expand All @@ -180,7 +180,7 @@ class CombinedAllocator {
return primary_.GetBlockBegin(p);
if ((beg = secondary_.GetBlockBeginFastLocked(p)))
return beg;
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
if ((beg = device_.GetBlockBeginFastLocked(p)))
return beg;
#endif
Expand All @@ -192,7 +192,7 @@ class CombinedAllocator {
return primary_.GetActuallyAllocatedSize(p);
if (secondary_.PointerIsMine(p))
return secondary_.GetActuallyAllocatedSize(p);
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
if (device_.PointerIsMine(p))
return device_.GetActuallyAllocatedSize(p);
#endif
Expand All @@ -201,7 +201,7 @@ class CombinedAllocator {

uptr TotalMemoryUsed() {
return primary_.TotalMemoryUsed() + secondary_.TotalMemoryUsed()
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
+ device_.TotalMemoryUsed()
#endif
;
Expand All @@ -228,15 +228,15 @@ class CombinedAllocator {
void PrintStats() {
primary_.PrintStats();
secondary_.PrintStats();
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
device_.PrintStats();
#endif
}

// ForceLock() and ForceUnlock() are needed to implement Darwin malloc zone
// introspection API.
void ForceLock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
device_.ForceLock();
#endif
primary_.ForceLock();
Expand All @@ -246,7 +246,7 @@ class CombinedAllocator {
void ForceUnlock() SANITIZER_NO_THREAD_SAFETY_ANALYSIS {
secondary_.ForceUnlock();
primary_.ForceUnlock();
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
device_.ForceUnlock();
#endif
}
Expand All @@ -256,15 +256,15 @@ class CombinedAllocator {
void ForEachChunk(ForEachChunkCallback callback, void *arg) {
primary_.ForEachChunk(callback, arg);
secondary_.ForEachChunk(callback, arg);
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
device_.ForEachChunk(callback, arg);
#endif
}

private:
PrimaryAllocator primary_;
SecondaryAllocator secondary_;
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
DeviceAllocator device_;
#endif
AllocatorGlobalStats stats_;
Expand Down
4 changes: 2 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_allocator_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#endif

struct DeviceAllocationInfo;
#if SANITIZER_AMDGPU
#if SANITIZER_AMDHSA
// Device memory allocation usually requires additional information, we can put
// all the additional information into a data structure DeviceAllocationInfo.
// This is only a parent structure since different vendors may require
Expand Down Expand Up @@ -348,4 +348,4 @@ class DeviceAllocatorT {
} stats;
mutable StaticSpinMutex mutex_;
};
#endif // SANITIZER_AMDGPU
#endif // SANITIZER_AMDHSA
Loading
Loading