Skip to content

[libc][NFC] Fix delete operator linkage names after switch to LIBC_NAMESPACE. #67475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

sivachandra
Copy link
Collaborator

The name __llvm_libc was mass-replaced with LIBC_NAMESPACE which ended
up changing the "_llvm_libc" prefix the delete operator linkage names
to "LIBC_NAMESPACE
<...>". This change corrects it by changing the
namespace prefix to to "_llvm_libc".

…MESPACE.

The name __llvm_libc was mass-replaced with LIBC_NAMESPACE which ended
up changing the "__llvm_libc" prefix the delete operator linkage names
to "LIBC_NAMESPACE_<...>". This change corrects it by changing the
namespace prefix to to "__llvm_libc_<version info>".
@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2023

@llvm/pr-subscribers-libc

Changes

The name __llvm_libc was mass-replaced with LIBC_NAMESPACE which ended
up changing the "_llvm_libc" prefix the delete operator linkage names
to "LIBC_NAMESPACE
<...>". This change corrects it by changing the
namespace prefix to to "_llvm_libc<version info>".


Full diff: https://github.com/llvm/llvm-project/pull/67475.diff

2 Files Affected:

  • (modified) libc/src/__support/CPP/new.h (+14-10)
  • (modified) libc/src/__support/common.h (+3)
diff --git a/libc/src/__support/CPP/new.h b/libc/src/__support/CPP/new.h
index 16353d57e3a6cb0..6261dc1ffde6fa9 100644
--- a/libc/src/__support/CPP/new.h
+++ b/libc/src/__support/CPP/new.h
@@ -84,19 +84,23 @@ LIBC_INLINE void *operator new[](size_t size, std::align_val_t align,
 // they will replace operator delete for the entire application. Including this
 // header file in all libc source files where operator delete is called ensures
 // that only libc call sites use these replacement operator delete functions.
-void operator delete(void *) noexcept __asm__("LIBC_NAMESPACE_delete");
+
+#define DELETE_NAME(name)                                                      \
+  __asm__(LIBC_MACRO_TO_STRING(LIBC_NAMESPACE) "_" LIBC_MACRO_TO_STRING(name))
+
+void operator delete(void *) noexcept DELETE_NAME(delete);
 void operator delete(void *, std::align_val_t) noexcept
-    __asm__("LIBC_NAMESPACE_delete_aligned");
-void operator delete(void *, size_t) noexcept
-    __asm__("LIBC_NAMESPACE_delete_sized");
+    DELETE_NAME(delete_aligned);
+void operator delete(void *, size_t) noexcept DELETE_NAME(delete_sized);
 void operator delete(void *, size_t, std::align_val_t) noexcept
-    __asm__("LIBC_NAMESPACE_delete_sized_aligned");
-void operator delete[](void *) noexcept __asm__("LIBC_NAMESPACE_delete_array");
+    DELETE_NAME(delete_sized_aligned);
+void operator delete[](void *) noexcept DELETE_NAME(delete_array);
 void operator delete[](void *, std::align_val_t) noexcept
-    __asm__("LIBC_NAMESPACE_delete_array_aligned");
-void operator delete[](void *, size_t) noexcept
-    __asm__("LIBC_NAMESPACE_delete_array_sized");
+    DELETE_NAME(delete_array_aligned);
+void operator delete[](void *, size_t) noexcept DELETE_NAME(delete_array_sized);
 void operator delete[](void *, size_t, std::align_val_t) noexcept
-    __asm__("LIBC_NAMESPACE_delete_array_sized_aligned");
+    DELETE_NAME(delete_array_sized_aligned);
+
+#undef DELETE_NAME
 
 #endif // LLVM_LIBC_SRC___SUPPORT_CPP_NEW_H
diff --git a/libc/src/__support/common.h b/libc/src/__support/common.h
index fe7b7c8b7624c90..53951dc131c28b6 100644
--- a/libc/src/__support/common.h
+++ b/libc/src/__support/common.h
@@ -46,6 +46,9 @@ LIBC_INLINE constexpr bool same_string(char const *lhs, char const *rhs) {
 } // namespace internal
 } // namespace LIBC_NAMESPACE
 
+#define __LIBC_MACRO_TO_STRING(str) #str
+#define LIBC_MACRO_TO_STRING(str) __LIBC_MACRO_TO_STRING(str)
+
 // LLVM_LIBC_IS_DEFINED checks whether a particular macro is defined.
 // Usage: constexpr bool kUseAvx = LLVM_LIBC_IS_DEFINED(__AVX__);
 //

Copy link
Contributor

@gchatelet gchatelet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for catching this! It slipped through the cracks...
I'm surprised that it didn't make any test fail.

@sivachandra sivachandra merged commit f2c9fe4 into llvm:main Sep 26, 2023
legrosbuffle pushed a commit to legrosbuffle/llvm-project that referenced this pull request Sep 29, 2023
…MESPACE. (llvm#67475)

The name __llvm_libc was mass-replaced with LIBC_NAMESPACE which ended
up changing the "__llvm_libc" prefix of the delete operator linkage names to
"LIBC_NAMESPACE". This change corrects it by changing the namespace prefix
to "__llvm_libc_<version info>".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants