am 340ff83f: am ac3e35cd: am a76f2eca: am 26f2e4a1: Merge "ARM: make CRT_LEGACY_WORKAROUND work as intended"

* commit '340ff83f9878a478cfa4b5aaaf4260f96304c416':
  ARM: make CRT_LEGACY_WORKAROUND work as intended
This commit is contained in:
Elliott Hughes 2012-09-05 10:06:25 -07:00 committed by Android Git Automerger
commit ec0d2a86b7
7 changed files with 76 additions and 56 deletions

View file

@ -585,10 +585,6 @@ libc_crt_target_cflags += \
-I$(LOCAL_PATH)/include \
-DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
ifeq ($(TARGET_ARCH),arm)
libc_crt_target_cflags += -DCRT_LEGACY_WORKAROUND
endif
# Define some common includes
# ========================================================
libc_common_c_includes := \
@ -763,9 +759,6 @@ include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(libc_common_src_files)
LOCAL_CFLAGS := $(libc_common_cflags)
ifeq ($(TARGET_ARCH),arm)
LOCAL_CFLAGS += -DCRT_LEGACY_WORKAROUND
endif
LOCAL_C_INCLUDES := $(libc_common_c_includes)
LOCAL_MODULE := libc_common
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
@ -852,6 +845,17 @@ LOCAL_SRC_FILES := \
bionic/pthread_debug.c \
bionic/libc_init_dynamic.c
ifeq ($(TARGET_ARCH),arm)
LOCAL_NO_CRT := true
LOCAL_CFLAGS += -DCRT_LEGACY_WORKAROUND
LOCAL_SRC_FILES := \
arch-arm/bionic/crtbegin_so.c \
arch-arm/bionic/atexit_legacy.c \
$(LOCAL_SRC_FILES) \
arch-arm/bionic/crtend_so.S
endif
LOCAL_MODULE:= libc
LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk

View file

@ -26,23 +26,6 @@
* SUCH DAMAGE.
*/
/* CRT_LEGACY_WORKAROUND should only be defined when building
* this file as part of the platform's C library.
*
* The C library already defines a function named 'atexit()'
* for backwards compatibility with older NDK-generated binaries.
*
* For newer ones, 'atexit' is actually embedded in the C
* runtime objects that are linked into the final ELF
* binary (shared library or executable), and will call
* __cxa_atexit() in order to un-register any atexit()
* handler when a library is unloaded.
*
* This function must be global *and* hidden. Only the
* code inside the same ELF binary should be able to access it.
*/
#ifndef CRT_LEGACY_WORKAROUND
extern void *__dso_handle;
__attribute__ ((visibility ("hidden")))
@ -50,4 +33,3 @@ int atexit(void (*func)(void))
{
return (__cxa_atexit((void (*)(void *))func, (void *)0, &__dso_handle));
}
#endif

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2012 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
/*
* This source file should only be included by libc.so, its purpose is
* to support legacy ARM binaries by exporting a publicly visible
* implementation of atexit().
*/
extern int __cxa_atexit(void (*func)(void *), void *arg, void *dso);
/*
* Register a function to be performed at exit.
*/
int
atexit(void (*func)(void))
{
return (__cxa_atexit((void (*)(void *))func, NULL, NULL));
}

View file

@ -34,10 +34,25 @@ void __on_dlclose() {
__cxa_finalize(&__dso_handle);
}
/* CRT_LEGACY_WORKAROUND should only be defined when building
* this file as part of the platform's C library.
*
* The C library already defines a function named 'atexit()'
* for backwards compatibility with older NDK-generated binaries.
*
* For newer ones, 'atexit' is actually embedded in the C
* runtime objects that are linked into the final ELF
* binary (shared library or executable), and will call
* __cxa_atexit() in order to un-register any atexit()
* handler when a library is unloaded.
*
* This function must be global *and* hidden. Only the
* code inside the same ELF binary should be able to access it.
*/
#ifdef CRT_LEGACY_WORKAROUND
#include "__dso_handle.h"
#else
#include "__dso_handle_so.h"
#endif
#include "__dso_handle_so.c"
#include "atexit.h"
#endif

View file

@ -30,22 +30,6 @@
extern int __cxa_atexit(void (*)(void*), void*, void* );
/* Temporary hack: this variable should not be part of the C library
* itself, but placed in the .bss section of each executable or
* shared library instead.
*
* We keep it here temporarily until the build system has been
* modified properly to use crtbegin_so.S and crtend_so.S when
* generating shared libraries.
*
* It must be a 'weak' symbol to avoid conflicts with the definitions
* that have been moved to crtbegin_static.S and crtbegin_dynamic.S
*
* For the record, it is used for static C++ object construction
* and destruction. See http://www.codesourcery.com/public/cxx-abi/abi.html#dso-dtor
*/
void* __attribute__((weak)) __dso_handle;
/* The "C++ ABI for ARM" document states that static C++ constructors,
* which are called from the .init_array, should manually call
* __aeabi_atexit() to register static destructors explicitely.

View file

@ -29,4 +29,4 @@
__attribute__ ((visibility ("hidden")))
__attribute__ ((section (".data")))
void *__dso_handle;
void *__dso_handle = &__dso_handle;

View file

@ -104,17 +104,6 @@ unlock:
return (ret);
}
#ifdef CRT_LEGACY_WORKAROUND
/*
* Register a function to be performed at exit.
*/
int
atexit(void (*func)(void))
{
return (__cxa_atexit((void (*)(void *))func, NULL, NULL));
}
#endif
/*
* Call all handlers registered with __cxa_atexit() for the shared
* object owning 'dso'.