================ @@ -0,0 +1,916 @@ +//===- InstrProfilingPlatformROCm.c - Profile data ROCm platform ---------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "InstrProfiling.h" +#include "InstrProfilingInternal.h" +#include "InstrProfilingPort.h" +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/* -------------------------------------------------------------------------- */ +/* Platform abstraction for dynamic library loading */ +/* -------------------------------------------------------------------------- */ + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +typedef HMODULE DylibHandle; + +static DylibHandle DylibOpen(const char *Name) { return LoadLibraryA(Name); } + +static void *DylibSym(DylibHandle H, const char *Sym) { + return (void *)(uintptr_t)GetProcAddress(H, Sym); +} + +static int DylibAvailable(void) { return 1; } + +#else /* POSIX */ +#include <dlfcn.h> + +/* Use weak references for dl* functions to avoid requiring -ldl at link time. + * + * The profile runtime is a static library, so its dependencies must be + * explicitly linked by the user. Unlike sanitizer runtimes (which are often + * shared libraries with their own dependencies), adding -ldl globally would + * affect all profiling users, including those not using HIP/ROCm. + * + * With weak references: + * - Programs without -ldl link successfully (dl* resolve to NULL) + * - HIP programs get -ldl from the HIP runtime, so dl* work normally + * - OpenMP offload programs without HIP gracefully skip device profiling + */ +#pragma weak dlopen +#pragma weak dlsym +#pragma weak dlerror + +typedef void *DylibHandle; + +static DylibHandle DylibOpen(const char *Name) { + return dlopen(Name, RTLD_LAZY | RTLD_LOCAL); ---------------- jhuber6 wrote:
Does compiler-rt have helpers for all the dynamic libary handling? https://github.com/llvm/llvm-project/pull/177665 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
