summaryrefslogtreecommitdiffstats
path: root/libstdc++
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2014-05-14 18:18:55 -0700
committerElliott Hughes <enh@google.com>2014-05-14 18:18:55 -0700
commit15b641a26731a7e42455c3ed22e1e9bdf31ea79c (patch)
treec06577c257be144af1d59f9f23e1f1117b22c3aa /libstdc++
parentbc7f8a791b4a510914fd5cac713415acb80fb806 (diff)
downloadbionic-15b641a26731a7e42455c3ed22e1e9bdf31ea79c.zip
bionic-15b641a26731a7e42455c3ed22e1e9bdf31ea79c.tar.gz
bionic-15b641a26731a7e42455c3ed22e1e9bdf31ea79c.tar.bz2
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
Diffstat (limited to 'libstdc++')
-rw-r--r--libstdc++/Android.mk35
-rw-r--r--libstdc++/src/libstdc++.cpp1
-rw-r--r--libstdc++/src/new.cpp57
-rw-r--r--libstdc++/src/one_time_construction.cpp110
-rw-r--r--libstdc++/src/pure_virtual.cpp8
-rw-r--r--libstdc++/src/typeinfo.cpp27
6 files changed, 3 insertions, 235 deletions
diff --git a/libstdc++/Android.mk b/libstdc++/Android.mk
index c7ed1f5..ff9609a 100644
--- a/libstdc++/Android.mk
+++ b/libstdc++/Android.mk
@@ -1,46 +1,15 @@
LOCAL_PATH:= $(call my-dir)
-# Common C++ flags to build this library.
-# Note that we need to access private Bionic headers
-# and define ANDROID_SMP accordingly.
-libstdc++_cflags := -Ibionic/libc/
-ifeq ($(TARGET_CPU_SMP),true)
- libstdc++_cflags += -DANDROID_SMP=1
-else
- libstdc++_cflags += -DANDROID_SMP=0
-endif
-libstdc++_cflags += -Wall -Wextra -Werror
-
include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- src/one_time_construction.cpp \
- src/new.cpp \
- src/pure_virtual.cpp \
- src/typeinfo.cpp
-
+LOCAL_SRC_FILES := src/libstdc++.cpp
LOCAL_MODULE:= libstdc++
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
-LOCAL_CFLAGS := $(libstdc++_cflags)
-
LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= \
- src/one_time_construction.cpp \
- src/new.cpp \
- src/pure_virtual.cpp \
- src/typeinfo.cpp
-
-LOCAL_CFLAGS := $(libstdc++_cflags)
-
+LOCAL_SRC_FILES:= src/libstdc++.cpp
LOCAL_MODULE:= libstdc++
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
-
LOCAL_SYSTEM_SHARED_LIBRARIES := libc
-
include $(BUILD_STATIC_LIBRARY)
diff --git a/libstdc++/src/libstdc++.cpp b/libstdc++/src/libstdc++.cpp
new file mode 100644
index 0000000..3676aa1
--- /dev/null
+++ b/libstdc++/src/libstdc++.cpp
@@ -0,0 +1 @@
+extern "C" void __this_library_is_now_part_of_libc() {}
diff --git a/libstdc++/src/new.cpp b/libstdc++/src/new.cpp
deleted file mode 100644
index ddd3dba..0000000
--- a/libstdc++/src/new.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#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);
-}
-
-
-
-
-
diff --git a/libstdc++/src/one_time_construction.cpp b/libstdc++/src/one_time_construction.cpp
deleted file mode 100644
index 5574311..0000000
--- a/libstdc++/src/one_time_construction.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2006 The Android Open Source Project
- */
-
-#include <stddef.h>
-#include <sys/atomics.h>
-#include <endian.h>
-
-#include "private/bionic_atomic_inline.h"
-#include "private/bionic_futex.h"
-
-// This file contains C++ ABI support functions for one time
-// constructors as defined in the "Run-time ABI for the ARM Architecture"
-// section 4.4.2
-//
-// ARM C++ ABI and Itanium/x86 C++ ABI has different definition for
-// one time construction:
-//
-// ARM C++ ABI defines the LSB of guard variable should be tested
-// by compiler-generated code before calling __cxa_guard_acquire et al.
-//
-// The Itanium/x86 C++ ABI defines the low-order _byte_ should be
-// tested instead.
-//
-// Meanwhile, guard variable are 32bit aligned for ARM, and 64bit
-// aligned for x86.
-//
-// Reference documentation:
-//
-// section 3.2.3 of ARM IHI 0041C (for ARM)
-// section 3.3.2 of the Itanium C++ ABI specification v1.83 (for x86).
-//
-// There is no C++ ABI available for other ARCH. But the gcc source
-// shows all other ARCH follow the definition of Itanium/x86 C++ ABI.
-
-
-#if defined(__arm__)
-// The ARM C++ ABI mandates that guard variable are
-// 32-bit aligned, 32-bit values. And only its LSB is tested by
-// the compiler-generated code before calling
-// __cxa_guard_acquire.
-//
-typedef union {
- int volatile state;
- int32_t aligner;
-} _guard_t;
-
-const static int ready = 0x1;
-const static int pending = 0x2;
-const static int waiting = 0x6;
-
-#else // GCC sources indicates all none-arm follow the same ABI
-// The Itanium/x86 C++ ABI mandates that guard variables
-// are 64-bit aligned, 64-bit values. Also, the least-significant
-// byte is tested by the compiler-generated code before, we calling
-// __cxa_guard_acquire. We can access it through the first
-// 32-bit word in the union below.
-//
-typedef union {
- int volatile state;
- int64_t aligner;
-} _guard_t;
-
-const static int ready = letoh32(0x1);
-const static int pending = letoh32(0x100);
-const static int waiting = letoh32(0x10000);
-#endif
-
-extern "C" int __cxa_guard_acquire(_guard_t* gv)
-{
- // 0 -> pending, return 1
- // pending -> waiting, wait and return 0
- // waiting: untouched, wait and return 0
- // ready: untouched, return 0
-
-retry:
- if (__bionic_cmpxchg(0, pending, &gv->state) == 0) {
- ANDROID_MEMBAR_FULL();
- return 1;
- }
- __bionic_cmpxchg(pending, waiting, &gv->state); // Indicate there is a waiter
- __futex_wait(&gv->state, waiting, NULL);
-
- if (gv->state != ready) // __cxa_guard_abort was called, let every thread try since there is no return code for this condition
- goto retry;
-
- ANDROID_MEMBAR_FULL();
- return 0;
-}
-
-extern "C" void __cxa_guard_release(_guard_t* gv)
-{
- // pending -> ready
- // waiting -> ready, and wake
-
- ANDROID_MEMBAR_FULL();
- if (__bionic_cmpxchg(pending, ready, &gv->state) == 0) {
- return;
- }
-
- gv->state = ready;
- __futex_wake(&gv->state, 0x7fffffff);
-}
-
-extern "C" void __cxa_guard_abort(_guard_t* gv)
-{
- ANDROID_MEMBAR_FULL();
- gv->state= 0;
- __futex_wake(&gv->state, 0x7fffffff);
-}
diff --git a/libstdc++/src/pure_virtual.cpp b/libstdc++/src/pure_virtual.cpp
deleted file mode 100644
index 6b5e328..0000000
--- a/libstdc++/src/pure_virtual.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#undef NDEBUG
-#include <assert.h>
-
-extern "C" void __cxa_pure_virtual() {
- // We can't call __libc_format_log from libstdc++ because it's hidden and in libc, so cheat.
- assert(!"Pure virtual function called. Are you calling virtual methods from a destructor?");
- /* NOTREACHED */
-}
diff --git a/libstdc++/src/typeinfo.cpp b/libstdc++/src/typeinfo.cpp
deleted file mode 100644
index 928d2ea..0000000
--- a/libstdc++/src/typeinfo.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "typeinfo"
-#include <stdlib.h>
-
-type_info::type_info() {
-}
-
-type_info::~type_info() {
-}
-
-char const* type_info::name() const {
- return "N/A";
-}
-
-bool type_info::operator==(type_info const& /*rhs*/) const {
- return false;
-}
-
-bool type_info::operator!=(type_info const& /*rhs*/) const {
- return false;
-}
-
-bool type_info::before(type_info const& /*rhs*/) const {
- return false;
-}
-
-type_info::type_info(type_info const& /*rhs*/) {
-}