[libc-commits] [libc] [libc] Replace -nostdlib++ flag when building with gcc and add placement new operator to HermeticTestUtils.cpp. (PR #78906)

via libc-commits libc-commits at lists.llvm.org
Sun Jan 21 10:56:26 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (lntue)

<details>
<summary>Changes</summary>

`-nostdlib++` is a clang-only flag.  Replacing it with `-nostdlib` when building with gcc.

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


2 Files Affected:

- (modified) libc/cmake/modules/LLVMLibCTestRules.cmake (+6-2) 
- (modified) libc/test/UnitTest/HermeticTestUtils.cpp (+4) 


``````````diff
diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 24f543f6e4c132..211188da801524 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -564,8 +564,10 @@ function(add_integration_test test_name)
 
   if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
     target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
-  else()
+  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
     target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
+  else()
+    target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib -static)
   endif()
   target_link_libraries(
     ${fq_build_target_name}
@@ -741,8 +743,10 @@ function(add_libc_hermetic_test test_name)
 
   if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
     target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
-  else()
+  elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
     target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
+  else()
+    target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib -static)
   endif()
   target_link_libraries(
     ${fq_build_target_name}
diff --git a/libc/test/UnitTest/HermeticTestUtils.cpp b/libc/test/UnitTest/HermeticTestUtils.cpp
index 68e31f478d79ab..349c182ff2379f 100644
--- a/libc/test/UnitTest/HermeticTestUtils.cpp
+++ b/libc/test/UnitTest/HermeticTestUtils.cpp
@@ -104,6 +104,8 @@ void *__dso_handle = nullptr;
 
 } // extern "C"
 
+void *operator new(unsigned long size, void *ptr) { return ptr; }
+
 void *operator new(size_t size) { return malloc(size); }
 
 void *operator new[](size_t size) { return malloc(size); }
@@ -113,3 +115,5 @@ void operator delete(void *) {
   // we just trap here to catch any such accidental usages.
   __builtin_trap();
 }
+
+void operator delete(void *ptr, size_t size) { __builtin_trap(); }

``````````

</details>


https://github.com/llvm/llvm-project/pull/78906


More information about the libc-commits mailing list