Module Name: src
Committed By: joerg
Date: Wed Jun 1 21:21:55 UTC 2016
Modified Files:
src/lib/csu/common: crtbegin.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/csu/common/crtbegin.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/csu/common/crtbegin.c
diff -u src/lib/csu/common/crtbegin.c:1.9 src/lib/csu/common/crtbegin.c:1.10
--- src/lib/csu/common/crtbegin.c:1.9 Tue May 6 16:02:10 2014
+++ src/lib/csu/common/crtbegin.c Wed Jun 1 21:21:55 2016
@@ -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 @@ __weakref_visible void Jv_RegisterClasse
__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 @@ __do_global_ctors_aux(void)
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 @@ __do_global_ctors_aux(void)
#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 @@ __do_global_dtors_aux(void)
#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