-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Replace -nostdlib++ flag when building with gcc and add placement new operator to HermeticTestUtils.cpp. #78906
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
Conversation
@llvm/pr-subscribers-libc Author: None (lntue) Changes
Full diff: https://github.com/llvm/llvm-project/pull/78906.diff 2 Files Affected:
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(); }
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work with -nostdlib
on clang? If so it's probably better to be consistent.
Is this still true with |
gcc-13 added support for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change itself looks good to me. Just curious that if COMPILER_RT_BUILD_SCUDO_STANDALONE_WITH_LLVM_LIBC
guarantees the compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall LGTM
@@ -104,6 +104,8 @@ void *__dso_handle = nullptr; | |||
|
|||
} // extern "C" | |||
|
|||
void *operator new(unsigned long size, void *ptr) { return ptr; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this okay or should it call realloc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is variation (9) in the list: https://en.cppreference.com/w/cpp/memory/new/operator_new
and it is said that: "The standard library implementation performs no action and returns ptr
unmodified."
…ent new operator to HermeticTestUtils.cpp.
-nostdlib++
is a clang-only flag. Replacing it with-nostdlib
when building with gcc.