[Openmp-commits] [openmp] 1e5fe67 - [Libomptarget] Make the references to 'malloc' and 'free' weak. (#69356)

via Openmp-commits openmp-commits at lists.llvm.org
Wed Oct 18 09:50:27 PDT 2023


Author: Joseph Huber
Date: 2023-10-18T12:50:23-04:00
New Revision: 1e5fe67e70d4b9612c2f64ad44a836c920894046

URL: https://github.com/llvm/llvm-project/commit/1e5fe67e70d4b9612c2f64ad44a836c920894046
DIFF: https://github.com/llvm/llvm-project/commit/1e5fe67e70d4b9612c2f64ad44a836c920894046.diff

LOG: [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.

Added: 
    

Modified: 
    openmp/libomptarget/DeviceRTL/src/State.cpp
    openmp/libomptarget/DeviceRTL/src/exports

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/DeviceRTL/src/State.cpp b/openmp/libomptarget/DeviceRTL/src/State.cpp
index 721137cb95d658b..422747a94e7943a 100644
--- a/openmp/libomptarget/DeviceRTL/src/State.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/State.cpp
@@ -46,8 +46,8 @@ namespace {
 ///{
 
 extern "C" {
-__attribute__((leaf)) void *malloc(uint64_t Size);
-__attribute__((leaf)) void free(void *Ptr);
+[[gnu::weak, gnu::leaf]] void *malloc(uint64_t Size);
+[[gnu::weak, gnu::leaf]] void free(void *Ptr);
 }
 
 ///}

diff  --git a/openmp/libomptarget/DeviceRTL/src/exports b/openmp/libomptarget/DeviceRTL/src/exports
index fbcda3ce8f555ca..288ddf90b4a9f2d 100644
--- a/openmp/libomptarget/DeviceRTL/src/exports
+++ b/openmp/libomptarget/DeviceRTL/src/exports
@@ -11,6 +11,8 @@ _ZN4ompx*
 
 IsSPMDMode
 
+malloc
+free
 memcmp
 printf
 __assert_fail


        


More information about the Openmp-commits mailing list