Skip to content

Commit

Permalink
[DeviceRTL] Make defined 'libc' functions weak in OpenMP (llvm#97356)
Browse files Browse the repository at this point in the history
Summary:
These functions provide special-case implementations internal to the
OpenMP device runtime. This can potentially conflict with the symbols
pulled in from the actual GPU `libc`. This patch makes these weak, so in
the case that the GPU libc functions exist they will be overridden. This
should not impact performance in the average case because the old
`-mlink-builtin-bitcode` version does internalization, deleting weak,
and the new LTO path will resolve to the strong reference and then
internalize it.
  • Loading branch information
jhuber6 authored Jul 2, 2024
1 parent 4d88837 commit 3c50cbf
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions offload/DeviceRTL/src/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ using namespace ompx;
extern "C" {
void __assert_assume(bool condition) { __builtin_assume(condition); }

void __assert_fail(const char *expr, const char *file, unsigned line,
const char *function) {
[[gnu::weak]] void __assert_fail(const char *expr, const char *file,
unsigned line, const char *function) {
__assert_fail_internal(expr, nullptr, file, line, function);
}
void __assert_fail_internal(const char *expr, const char *msg, const char *file,
Expand Down
4 changes: 2 additions & 2 deletions offload/DeviceRTL/src/LibC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int32_t omp_vprintf(const char *Format, void *Arguments, uint32_t) {

extern "C" {

int memcmp(const void *lhs, const void *rhs, size_t count) {
[[gnu::weak]] int memcmp(const void *lhs, const void *rhs, size_t count) {
auto *L = reinterpret_cast<const unsigned char *>(lhs);
auto *R = reinterpret_cast<const unsigned char *>(rhs);

Expand All @@ -60,7 +60,7 @@ int memcmp(const void *lhs, const void *rhs, size_t count) {
return 0;
}

void memset(void *dst, int C, size_t count) {
[[gnu::weak]] void memset(void *dst, int C, size_t count) {
auto *dstc = reinterpret_cast<char *>(dst);
for (size_t I = 0; I < count; ++I)
dstc[I] = C;
Expand Down

0 comments on commit 3c50cbf

Please sign in to comment.