Skip to content

Commit cc8d6a4

Browse files
committed
[libc] Replace -nostdlib++ flag when building with gcc and add placement new
operator to HermeticTestUtils.cpp.
1 parent 95c1039 commit cc8d6a4

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,10 @@ function(add_integration_test test_name)
564564

565565
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
566566
target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
567-
else()
567+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
568568
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
569+
else()
570+
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib -static)
569571
endif()
570572
target_link_libraries(
571573
${fq_build_target_name}
@@ -741,8 +743,10 @@ function(add_libc_hermetic_test test_name)
741743

742744
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
743745
target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
744-
else()
746+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
745747
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
748+
else()
749+
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib -static)
746750
endif()
747751
target_link_libraries(
748752
${fq_build_target_name}

libc/test/UnitTest/HermeticTestUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ void *__dso_handle = nullptr;
104104

105105
} // extern "C"
106106

107+
void *operator new(unsigned long size, void *ptr) { return ptr; }
108+
107109
void *operator new(size_t size) { return malloc(size); }
108110

109111
void *operator new[](size_t size) { return malloc(size); }
@@ -113,3 +115,5 @@ void operator delete(void *) {
113115
// we just trap here to catch any such accidental usages.
114116
__builtin_trap();
115117
}
118+
119+
void operator delete(void *ptr, size_t size) { __builtin_trap(); }

0 commit comments

Comments
 (0)