Move libstdc++ into libc.
The Android build system always links against libstdc++.so anyway. Having
operator new and operator delete in a separate library means we can't use
constructors and destructors on heap-allocated objects inside the C library,
which is quite an unfortunate limitation.
This will be cheaper too; on LP64 we can stop linking against the [now empty]
libstdc++.so giving the dynamic linker one less library to worry about for
every process.
There's precedent too --- we already have no libpthread or librt.
For now I'm leaving the include files where they are, and I'm generating a
dummy libstdc++.so and libstdc++.a. We can come back and clean that up later
if all goes well.
Bug: 13367666
Change-Id: I6f3e27ea7c30d03d6394965d0400c9dc87fa83db
diff --git a/libc/bionic/new.cpp b/libc/bionic/new.cpp
new file mode 100644
index 0000000..cb19dfa
--- /dev/null
+++ b/libc/bionic/new.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <new>
+#include <stdlib.h>
+
+const std::nothrow_t std::nothrow = {};
+
+void* operator new(std::size_t size) {
+ void* p = malloc(size);
+ if (p == NULL) {
+ abort();
+ }
+ return p;
+}
+
+void* operator new[](std::size_t size) {
+ void* p = malloc(size);
+ if (p == NULL) {
+ abort();
+ }
+ return p;
+}
+
+void operator delete(void* ptr) {
+ free(ptr);
+}
+
+void operator delete[](void* ptr) {
+ free(ptr);
+}
+
+void* operator new(std::size_t size, const std::nothrow_t&) {
+ return malloc(size);
+}
+
+void* operator new[](std::size_t size, const std::nothrow_t&) {
+ return malloc(size);
+}
+
+void operator delete(void* ptr, const std::nothrow_t&) {
+ free(ptr);
+}
+
+void operator delete[](void* ptr, const std::nothrow_t&) {
+ free(ptr);
+}