Skip to content

Commit 1e5fe67

Browse files
authored
[Libomptarget] Make the references to 'malloc' and 'free' weak. (#69356)
Summary: We use `malloc` internally in the DeviceRTL to handle data globalization. If this is undefined it will map to the Nvidia implementation of `malloc` for NVPTX and return `nullptr` for AMDGPU. This is somewhat problematic, because when using this as a shared library it causes us to always extract the GPU libc implementation, which uses RPC and thus requires an RPC server. Making this `weak` allows us to implement this internally without worrying about binding to the GPU `libc` implementation.
1 parent 3ef271c commit 1e5fe67

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

openmp/libomptarget/DeviceRTL/src/State.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ namespace {
4646
///{
4747

4848
extern "C" {
49-
__attribute__((leaf)) void *malloc(uint64_t Size);
50-
__attribute__((leaf)) void free(void *Ptr);
49+
[[gnu::weak, gnu::leaf]] void *malloc(uint64_t Size);
50+
[[gnu::weak, gnu::leaf]] void free(void *Ptr);
5151
}
5252

5353
///}

openmp/libomptarget/DeviceRTL/src/exports

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ _ZN4ompx*
1111

1212
IsSPMDMode
1313

14+
malloc
15+
free
1416
memcmp
1517
printf
1618
__assert_fail

0 commit comments

Comments
 (0)