NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: toolchain/51121: sparc64 can't build perl
The following reply was made to PR toolchain/51121; it has been noted by GNATS.
From: Martin Husemann <martin%duskware.de@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc:
Subject: Re: toolchain/51121: sparc64 can't build perl
Date: Wed, 11 May 2016 11:06:03 +0200
Suggested by Andrew Pinski in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71051
I reworked the crt source slightly and it now works even if compiled wiht -O2
for me.
Suggestions for a better name for the macro hiding the asm() ?
Should we put that somewhere else, in case we need to reuse it elsewhere?
(Linksets?)
Joerg, how does this interact with Clang?
Martin
Index: common/Makefile.inc
===================================================================
RCS file: /cvsroot/src/lib/csu/common/Makefile.inc,v
retrieving revision 1.31
diff -u -p -r1.31 Makefile.inc
--- common/Makefile.inc 10 May 2016 10:23:09 -0000 1.31
+++ common/Makefile.inc 11 May 2016 08:43:43 -0000
@@ -17,14 +17,6 @@ OBJS+= sysident.o
.if ${MKPIC} == "yes"
OBJS+= crtbeginS.o
CFLAGS.crtbegin.c+= -fPIE
-# XXXGCC5 - GCC 5 miscompiles crtbeginS.c on many platforms. on SPARC it
-# XXXGCC5 emits "clr %g1; call %g1", which is effectively jumping to zero.
-. if defined(HAVE_GCC) && ${HAVE_GCC} == 53 && \
- !exists(${ARCHDIR}/crtbegin.S)
-CFLAGS.crt0-common.c+= -O1
-CFLAGS.crtbeginS.c+= -O1
-CFLAGS.crtbegin.c+= -O1
-. endif
.endif
.if ${MACHINE_ARCH} == "alpha"
Index: common/crt0-common.c
===================================================================
RCS file: /cvsroot/src/lib/csu/common/crt0-common.c,v
retrieving revision 1.13
diff -u -p -r1.13 crt0-common.c
--- common/crt0-common.c 31 Jan 2013 22:24:25 -0000 1.13
+++ common/crt0-common.c 11 May 2016 08:43:43 -0000
@@ -89,6 +89,13 @@ do { \
#ifdef HAVE_INITFINI_ARRAY
/*
+ * Make sure the compiler does not know about start/end pointing
+ * to different arrays (so pointer comparison is undefined
+ * behaviour).
+ */
+#define UNALIAS_PTR(PTR) asm("":"+r"(PTR))
+
+/*
* If we are using INIT_ARRAY/FINI_ARRAY and we are linked statically,
* we have to process these instead of relying on RTLD to do it for us.
*
@@ -111,7 +118,12 @@ __weakref_visible const fptr_t fini_arra
static inline void
_preinit(void)
{
- for (const fptr_t *f = preinit_array_start; f < preinit_array_end; f++) {
+ const fptr_t *start = preinit_array_start;
+ const fptr_t *end = preinit_array_end;
+ UNALIAS_PTR(start);
+ UNALIAS_PTR(end);
+
+ for (const fptr_t *f = start; f < end; f++) {
(*f)();
}
}
@@ -119,7 +131,12 @@ _preinit(void)
static inline void
_init(void)
{
- for (const fptr_t *f = init_array_start; f < init_array_end; f++) {
+ const fptr_t *start = init_array_start;
+ const fptr_t *end = init_array_end;
+ UNALIAS_PTR(start);
+ UNALIAS_PTR(end);
+
+ for (const fptr_t *f = start; f < end; f++) {
(*f)();
}
}
@@ -127,7 +144,12 @@ _init(void)
static void
_fini(void)
{
- for (const fptr_t *f = fini_array_start; f < fini_array_end; f++) {
+ const fptr_t *start = fini_array_start;
+ const fptr_t *end = fini_array_end;
+ UNALIAS_PTR(start);
+ UNALIAS_PTR(end);
+
+ for (const fptr_t *f = start; f < end; f++) {
(*f)();
}
}
Index: common/crtbegin.c
===================================================================
RCS file: /cvsroot/src/lib/csu/common/crtbegin.c,v
retrieving revision 1.9
diff -u -p -r1.9 crtbegin.c
--- common/crtbegin.c 6 May 2014 16:02:10 -0000 1.9
+++ common/crtbegin.c 11 May 2016 08:43:43 -0000
@@ -90,7 +90,20 @@ __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; ) {
+
+/*
+ * Make sure the compiler does not know about start/end pointing
+ * to different arrays (so pointer comparison is undefined
+ * behaviour).
+ */
+#define UNALIAS_PTR(PTR) asm("":"+r"(PTR))
+
+ const fptr_t *start = __CTOR_LIST__;
+ const fptr_t *end = __CTOR_LIST_END__;
+ UNALIAS_PTR(start);
+ UNALIAS_PTR(end);
+
+ for (const fptr_t *p = end; p > start + 1; ) {
(*(*--p))();
}
#endif
@@ -122,7 +135,12 @@ __do_global_dtors_aux(void)
#endif
#if !defined(HAVE_INITFINI_ARRAY)
- for (const fptr_t *p = __DTOR_LIST__ + 1; p < __DTOR_LIST_END__; ) {
+ const fptr_t *start = __DTOR_LIST__;
+ const fptr_t *end = __DTOR_LIST_END__;
+ UNALIAS_PTR(start);
+ UNALIAS_PTR(end);
+
+ for (const fptr_t *p = start + 1; p < end; ) {
(*(*p++))();
}
#endif
Home |
Main Index |
Thread Index |
Old Index