Source-Changes-HG archive

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

[src/trunk]: src/lib/csu/common add a hack for GCC 5 and non-x86 platforms:



details:   https://anonhg.NetBSD.org/src/rev/16ec922f3abd
branches:  trunk
changeset: 344405:16ec922f3abd
user:      mrg <mrg%NetBSD.org@localhost>
date:      Sun Mar 27 00:03:06 2016 +0000

description:
add a hack for GCC 5 and non-x86 platforms:

build crtbeginS.o with -O1 as GCC tries to be very smart with the
__DTOR_LIST__ as it believes it knows the size of the array at
compile time (which is not true until link time).  on SPARC and
MIPS, the result was emitting a call to 0.

technically, i believe that GCC isn't "wrong" to make this choice,
as the array is declared with a well-known initialiser size in the
crtbegin.c compilation unit, and we have noticed that the libgcc
version of this code has some hacks added, most likely to avoid
being bitten by this optimisation.


this makes sshd work for me on earm and sparc with GCC 5.

diffstat:

 lib/csu/common/Makefile.inc |  11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diffs (33 lines):

diff -r 2b8863ffb691 -r 16ec922f3abd lib/csu/common/Makefile.inc
--- a/lib/csu/common/Makefile.inc       Sat Mar 26 17:40:02 2016 +0000
+++ b/lib/csu/common/Makefile.inc       Sun Mar 27 00:03:06 2016 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.25 2014/03/04 17:57:56 joerg Exp $
+#      $NetBSD: Makefile.inc,v 1.26 2016/03/27 00:03:06 mrg Exp $
 
 .include <bsd.own.mk>
 
@@ -16,7 +16,14 @@
 .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 && \
+     ${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH} != "amd64"
+CFLAGS.crtbeginS.c+=   -O1
+. endif
 .endif
+
 .if ${MACHINE_ARCH} == "alpha"
 OBJS+=         crtfm.o
 .endif
@@ -55,7 +62,7 @@
 .else
 crtbeginS.o: crtbegin.c crtbegin.h
        ${_MKTARGET_COMPILE}
-       ${COMPILE.c} ${PICFLAGS} -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
+       ${COMPILE.c} ${CFLAGS.crtbeginS.c} ${PICFLAGS} -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
 .endif
        ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET} 
        rm -f ${.TARGET}.o



Home | Main Index | Thread Index | Old Index