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.
This commit is contained in:
mrg 2016-03-27 00:03:06 +00:00
parent 0b2c20760e
commit 09a7b9833f

View File

@ -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 @@ OBJS+= crtbegin.o crtend.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 && \
${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH} != "amd64"
CFLAGS.crtbeginS.c+= -O1
. endif
.endif
.if ${MACHINE_ARCH} == "alpha"
OBJS+= crtfm.o
.endif
@ -55,7 +62,7 @@ crtbeginS.o: crtbegin.S
.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