summaryrefslogtreecommitdiffstats
path: root/libc/arch-arm
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@gmail.com>2012-08-21 14:13:50 +0200
committerArd Biesheuvel <ard.biesheuvel@gmail.com>2012-08-28 10:27:02 +0200
commitf3cfcd869ded41d25c1f4f4e48e7c374a64f9583 (patch)
tree8024ef0103694c92f553fae4221fc220e1a12b00 /libc/arch-arm
parent9dfaa63a1c0d1b8e75dd9d7077a8103a19821fa9 (diff)
downloadbionic-f3cfcd869ded41d25c1f4f4e48e7c374a64f9583.zip
bionic-f3cfcd869ded41d25c1f4f4e48e7c374a64f9583.tar.gz
bionic-f3cfcd869ded41d25c1f4f4e48e7c374a64f9583.tar.bz2
ARM: make CRT_LEGACY_WORKAROUND work as intended
To properly support legacy ARM shared libraries, libc.so needs to export the symbols __dso_handle and atexit, even though these are now supplied by the crt startup code. This patch reshuffles the existing CRT_LEGACY_WORKAROUND conditionally compiled code slightly so it works as the original author likely intended. Change-Id: Id6c0e94dc65b7928324a5f0bad7eba6eb2f464b9 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
Diffstat (limited to 'libc/arch-arm')
-rw-r--r--libc/arch-arm/bionic/atexit.h18
-rw-r--r--libc/arch-arm/bionic/atexit_legacy.c46
-rw-r--r--libc/arch-arm/bionic/crtbegin_so.c21
-rw-r--r--libc/arch-arm/bionic/eabi.c16
4 files changed, 64 insertions, 37 deletions
diff --git a/libc/arch-arm/bionic/atexit.h b/libc/arch-arm/bionic/atexit.h
index d567bfc..bc776a8 100644
--- a/libc/arch-arm/bionic/atexit.h
+++ b/libc/arch-arm/bionic/atexit.h
@@ -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
diff --git a/libc/arch-arm/bionic/atexit_legacy.c b/libc/arch-arm/bionic/atexit_legacy.c
new file mode 100644
index 0000000..09da17c
--- /dev/null
+++ b/libc/arch-arm/bionic/atexit_legacy.c
@@ -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));
+}
diff --git a/libc/arch-arm/bionic/crtbegin_so.c b/libc/arch-arm/bionic/crtbegin_so.c
index 57d19bf..36e4b9c 100644
--- a/libc/arch-arm/bionic/crtbegin_so.c
+++ b/libc/arch-arm/bionic/crtbegin_so.c
@@ -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
diff --git a/libc/arch-arm/bionic/eabi.c b/libc/arch-arm/bionic/eabi.c
index 3f26f2b..51a5b97 100644
--- a/libc/arch-arm/bionic/eabi.c
+++ b/libc/arch-arm/bionic/eabi.c
@@ -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.