Skip to content

Commit 3c50cbf

Browse files
authored
[DeviceRTL] Make defined 'libc' functions weak in OpenMP (#97356)
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.
1 parent 4d88837 commit 3c50cbf

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

offload/DeviceRTL/src/Debug.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ using namespace ompx;
2626
extern "C" {
2727
void __assert_assume(bool condition) { __builtin_assume(condition); }
2828

29-
void __assert_fail(const char *expr, const char *file, unsigned line,
30-
const char *function) {
29+
[[gnu::weak]] void __assert_fail(const char *expr, const char *file,
30+
unsigned line, const char *function) {
3131
__assert_fail_internal(expr, nullptr, file, line, function);
3232
}
3333
void __assert_fail_internal(const char *expr, const char *msg, const char *file,

offload/DeviceRTL/src/LibC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int32_t omp_vprintf(const char *Format, void *Arguments, uint32_t) {
4949

5050
extern "C" {
5151

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

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

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

0 commit comments

Comments
 (0)