From 760647dd199c0a2a016bfc2320e45f3d6cde73d9 Mon Sep 17 00:00:00 2001 From: "Sv. Lockal" Date: Sat, 9 Mar 2024 13:46:32 +0000 Subject: [PATCH] Fix compilation on musl-based systems This allows to build ROCT-Thunk-Interface for Alpine Linux, Gentoo with musl profile and so on. List of changes: * Fix redefinition of PAGE_SIZE from limits.h * Use NAME_MAX from limits.h Closes #65 Change-Id: Ibdb0ef5668a07b7b403fcc4a44cd2658e00a584a Signed-off-by: Sv. Lockal Signed-off-by: Kent Russell [ROCm/ROCR-Runtime commit: 9a89997b5f4047dbf3a288ac9a94860d6e8a8cdf] --- projects/rocr-runtime/src/globals.c | 4 ++++ projects/rocr-runtime/src/libhsakmt.h | 4 ++++ projects/rocr-runtime/src/openclose.c | 2 ++ projects/rocr-runtime/src/topology.c | 5 +++++ 4 files changed, 15 insertions(+) diff --git a/projects/rocr-runtime/src/globals.c b/projects/rocr-runtime/src/globals.c index 771eb6758b..2afd09011a 100644 --- a/projects/rocr-runtime/src/globals.c +++ b/projects/rocr-runtime/src/globals.c @@ -32,7 +32,11 @@ unsigned long kfd_open_count; unsigned long system_properties_count; pthread_mutex_t hsakmt_mutex = PTHREAD_MUTEX_INITIALIZER; bool is_dgpu; + +#ifndef PAGE_SIZE int PAGE_SIZE; +#endif + int PAGE_SHIFT; /* whether to check all dGPUs in the topology support SVM API */ diff --git a/projects/rocr-runtime/src/libhsakmt.h b/projects/rocr-runtime/src/libhsakmt.h index 0f1943445b..fd298e2832 100644 --- a/projects/rocr-runtime/src/libhsakmt.h +++ b/projects/rocr-runtime/src/libhsakmt.h @@ -64,7 +64,11 @@ extern HsaVersionInfo kfd_version_info; do { if ((minor) > kfd_version_info.KernelInterfaceMinorVersion)\ return HSAKMT_STATUS_NOT_SUPPORTED; } while (0) +/* Might be defined in limits.h on platforms where it is constant (used by musl) */ +/* See also: https://pubs.opengroup.org/onlinepubs/7908799/xsh/limits.h.html */ +#ifndef PAGE_SIZE extern int PAGE_SIZE; +#endif extern int PAGE_SHIFT; /* VI HW bug requires this virtual address alignment */ diff --git a/projects/rocr-runtime/src/openclose.c b/projects/rocr-runtime/src/openclose.c index 0e5c10c065..6d66bdfde9 100644 --- a/projects/rocr-runtime/src/openclose.c +++ b/projects/rocr-runtime/src/openclose.c @@ -114,7 +114,9 @@ static void clear_after_fork(void) static inline void init_page_size(void) { +#ifndef PAGE_SIZE PAGE_SIZE = sysconf(_SC_PAGESIZE); +#endif PAGE_SHIFT = ffs(PAGE_SIZE) - 1; } diff --git a/projects/rocr-runtime/src/topology.c b/projects/rocr-runtime/src/topology.c index 7e655e362e..4738499fce 100644 --- a/projects/rocr-runtime/src/topology.c +++ b/projects/rocr-runtime/src/topology.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -1372,6 +1373,10 @@ static int topology_create_temp_cpu_cache_list(int node, * which can be present twice in the string above. 29 is for the prefix * and the +6 is for the cache suffix */ +#ifndef MAXNAMLEN +/* MAXNAMLEN is the BSD name for NAME_MAX. glibc aliases this as NAME_MAX, but not musl */ +#define MAXNAMLEN NAME_MAX +#endif const uint32_t MAXPATHSIZE = 29 + MAXNAMLEN + (MAXNAMLEN + 6); cpu_cacheinfo_t *p_temp_cpu_ci_list; /* a list of cpu_ci */ char path[MAXPATHSIZE], node_dir[MAXPATHSIZE];