am 80cff53e: am 2a602272: Merge "Move libstdc++ into libc."

* commit '80cff53e138cca6c2634e08f5ed1198facc7adb6':
  Move libstdc++ into libc.
This commit is contained in:
Elliott Hughes 2014-05-16 16:42:48 +00:00 committed by Android Git Automerger
commit 505de840a2
10 changed files with 160 additions and 150 deletions

View File

@ -111,6 +111,8 @@ libc_bionic_src_files := \
bionic/clone.cpp \
bionic/cmsg_nxthdr.cpp \
bionic/connect.cpp \
bionic/__cxa_guard.cpp \
bionic/__cxa_pure_virtual.cpp \
bionic/dirent.cpp \
bionic/dup2.cpp \
bionic/epoll_create.cpp \
@ -143,6 +145,7 @@ libc_bionic_src_files := \
bionic/mknod.cpp \
bionic/mntent.cpp \
bionic/NetdClientDispatch.cpp \
bionic/new.cpp \
bionic/open.cpp \
bionic/pause.cpp \
bionic/pipe.cpp \
@ -212,6 +215,7 @@ libc_bionic_src_files := \
bionic/termios.cpp \
bionic/thread_atexit.cpp \
bionic/tmpfile.cpp \
bionic/typeinfo.cpp \
bionic/umount.cpp \
bionic/unlink.cpp \
bionic/utimes.cpp \

View File

@ -1,9 +1,20 @@
/*
* Copyright 2006 The Android Open Source Project
* Copyright (C) 2006 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 <stddef.h>
#include <sys/atomics.h>
#include <endian.h>
#include "private/bionic_atomic_inline.h"
@ -33,41 +44,34 @@
// 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
// The ARM C++ ABI mandates that guard variables are 32-bit aligned, 32-bit
// values. The LSB is tested by the compiler-generated code before calling
// __cxa_guard_acquire.
//
typedef union {
union _guard_t {
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 {
#else
// The Itanium/x86 C++ ABI (used by all other architectures) mandates that
// guard variables are 64-bit aligned, 64-bit values. The LSB is tested by
// the compiler-generated code before calling __cxa_guard_acquire.
union _guard_t {
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)
{
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
@ -81,15 +85,16 @@ retry:
__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
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)
{
extern "C" void __cxa_guard_release(_guard_t* gv) {
// pending -> ready
// waiting -> ready, and wake
@ -102,8 +107,7 @@ extern "C" void __cxa_guard_release(_guard_t* gv)
__futex_wake(&gv->state, 0x7fffffff);
}
extern "C" void __cxa_guard_abort(_guard_t* gv)
{
extern "C" void __cxa_guard_abort(_guard_t* gv) {
ANDROID_MEMBAR_FULL();
gv->state= 0;
__futex_wake(&gv->state, 0x7fffffff);

View File

@ -0,0 +1,21 @@
/*
* 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 <private/libc_logging.h>
extern "C" void __cxa_pure_virtual() {
__libc_fatal("Pure virtual function called. Are you calling virtual methods from a destructor?");
}

60
libc/bionic/new.cpp Normal file
View File

@ -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);
}

43
libc/bionic/typeinfo.cpp Normal file
View File

@ -0,0 +1,43 @@
/*
* 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 <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*/) {
}

View File

@ -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)

View File

@ -0,0 +1 @@
extern "C" void __this_library_is_now_part_of_libc() {}

View File

@ -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);
}

View File

@ -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 */
}

View File

@ -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*/) {
}