Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/csu/common PR toolchain/51121:



details:   https://anonhg.NetBSD.org/src/rev/4543741d8bce
branches:  trunk
changeset: 345612:4543741d8bce
user:      joerg <joerg%NetBSD.org@localhost>
date:      Wed Jun 01 21:21:55 2016 +0000

description:
PR toolchain/51121:
__CTOR_LIST__ and __CTOR_LIST_END__ are logically the same object, but
due to the start marker, the former has to be declared as array of fixed
size. Newer GCC versions take the liberty of exploiting the UB of
accessing global objects past the end to unconditionally load zero
values in that case. Two fixes are possible:
(1) Pruning via inline assembler as done by GCC's own CRT copy.
(2) Pruning via weak references as done for linker sets.
Since the second part is known and required to work anyway, prefer this
approach. In theory, the labels could be replaced completely, except
that GNU as doesn't provide start/end symbols for sections containing
dots.

diffstat:

 lib/csu/common/crtbegin.c |  16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diffs (54 lines):

diff -r b2a6d2a2e759 -r 4543741d8bce lib/csu/common/crtbegin.c
--- a/lib/csu/common/crtbegin.c Wed Jun 01 17:10:04 2016 +0000
+++ b/lib/csu/common/crtbegin.c Wed Jun 01 21:21:55 2016 +0000
@@ -27,7 +27,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: crtbegin.c,v 1.9 2014/05/06 16:02:10 joerg Exp $");
+__RCSID("$NetBSD: crtbegin.c,v 1.10 2016/06/01 21:21:55 joerg Exp $");
 
 #include "crtbegin.h"
 
@@ -39,6 +39,11 @@
        __weak_reference(_Jv_RegisterClasses);
 
 #if !defined(HAVE_INITFINI_ARRAY)
+__weakref_visible const fptr_t __CTOR_LIST__start[]
+    __weak_reference(__CTOR_LIST__);
+__weakref_visible const fptr_t __CTOR_LIST__end[]
+    __weak_reference(__CTOR_LIST_END__);
+
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __CTOR_LIST__[] __section(".ctors") = {
        (fptr_t) -1,
 };
@@ -90,7 +95,7 @@
                Jv_RegisterClasses(__JCR_LIST__);
 
 #if !defined(HAVE_INITFINI_ARRAY)
-       for (const fptr_t *p = __CTOR_LIST_END__; p > __CTOR_LIST__ + 1; ) {
+       for (const fptr_t *p = __CTOR_LIST__end; p > __CTOR_LIST__start + 1; ) {
                (*(*--p))();
        }
 #endif
@@ -98,6 +103,11 @@
 
 #if !defined(__ARM_EABI__) || defined(SHARED) || defined(__ARM_DWARF_EH__)
 #if !defined(HAVE_INITFINI_ARRAY)
+__weakref_visible const fptr_t __DTOR_LIST__start[]
+    __weak_reference(__DTOR_LIST__);
+__weakref_visible const fptr_t __DTOR_LIST__end[]
+    __weak_reference(__DTOR_LIST_END__);
+
 __dso_hidden const fptr_t __aligned(sizeof(void *)) __DTOR_LIST__[] __section(".dtors") = {
        (fptr_t) -1,
 };
@@ -122,7 +132,7 @@
 #endif
 
 #if !defined(HAVE_INITFINI_ARRAY)
-       for (const fptr_t *p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__; ) {
+       for (const fptr_t *p = __DTOR_LIST__start + 1; p < __DTOR_LIST__end; ) {
                (*(*p++))();
        }
 #endif



Home | Main Index | Thread Index | Old Index