From df3e4a0f47da12ba70dc0bbeb2fb8d87a1ec0469 Mon Sep 17 00:00:00 2001 From: Lancelot SIX Date: Thu, 21 Nov 2024 14:22:17 +0000 Subject: [PATCH] Use __SANE_USERSPACE_TYPES__ to obtain LL64 Some platforms (such as PowerPC) have "long unsigned int" as linux's __u64. This causses issues when trying to print values produced by KFD's ioctl. Those value (defined in linux/kfd_ioctl.h) are not compatible with "%llx" printf format currently used. This patch proposes to fix that by setting __SANE_USERSPACE_TYPES__ before including linux/types.h, which should provide long long for 64 bits integers. Suggested-by: Laurent Morichetti Bug: https://github.com/ROCm/ROCdbgapi/issues/14 Change-Id: Id682ee82758dfea39a25319670148f44162e98d6 --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index bca34a3..9be8192 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ project(amd-dbgapi VERSION 0.77.0) include(CheckIncludeFile) include(GNUInstallDirs) +include(CheckCXXSourceCompiles) + # Convert the project's name to uppercase and replace '-' with '_'. string(TOUPPER "${PROJECT_NAME}" AMD_DBGAPI_NAME) string(REPLACE "-" "_" AMD_DBGAPI_NAME ${AMD_DBGAPI_NAME}) @@ -132,6 +134,35 @@ set_source_files_properties( COMPILE_DEFINITIONS "PCI_IDS_PATH=\"${PCI_IDS_PATH}\"" ) +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(CMAKE_REQUIRED_FLAGS_BKP "${CMAKE_REQUIRED_FLAGS}") + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++17") + # For some platforms (PPC64), linux/types.h uses L64, but this code assumes + # LL64 (i.e. __u64 should be a long long unsigned, not long unsigned). + check_cxx_source_compiles( + "#include + #include + int main () { static_assert (std::is_same_v); return 0; }" + LINUX_TYPES_HAS_LL64) + + if(NOT LINUX_TYPES_HAS_LL64) + # Check if using __SANE_USERSPACE_TYPES__ gives us LL64 + check_cxx_source_compiles( + "#define __SANE_USERSPACE_TYPES__ + #include + #include + int main () { static_assert (std::is_same_v); return 0; }" + LINUX_TYPES_LL64_NEEDS_SANE_USERSPACE_TYPES) + if(LINUX_TYPES_LL64_NEEDS_SANE_USERSPACE_TYPES) + target_compile_definitions(amd-dbgapi PRIVATE "__SANE_USERSPACE_TYPES__") + else() + message(FATAL_ERROR + "A LL64 configuration is required for the Linux backend") + endif() + endif() + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_BKP}") +endif() + find_package(amd_comgr REQUIRED CONFIG PATHS /opt/rocm/