Sun Mar 27 00:03:06 2016 UTC ()
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.


(mrg)
diff -r1.25 -r1.26 src/lib/csu/common/Makefile.inc

cvs diff -r1.25 -r1.26 src/lib/csu/common/Makefile.inc (expand / switch to unified diff)

--- src/lib/csu/common/Makefile.inc 2014/03/04 17:57:56 1.25
+++ src/lib/csu/common/Makefile.inc 2016/03/27 00:03:06 1.26
@@ -1,32 +1,39 @@ @@ -1,32 +1,39 @@
1# $NetBSD: Makefile.inc,v 1.25 2014/03/04 17:57:56 joerg Exp $ 1# $NetBSD: Makefile.inc,v 1.26 2016/03/27 00:03:06 mrg Exp $
2 2
3.include <bsd.own.mk> 3.include <bsd.own.mk>
4 4
5# XXX: FIXME: This is defined in bsd.lib.mk 5# XXX: FIXME: This is defined in bsd.lib.mk
6PICFLAGS ?= -fPIC 6PICFLAGS ?= -fPIC
7 7
8COMMON_DIR:= ${.CURDIR}/common 8COMMON_DIR:= ${.CURDIR}/common
9.PATH: ${COMMON_DIR} 9.PATH: ${COMMON_DIR}
10 10
11CPPFLAGS+= -I${NETBSDSRCDIR}/libexec/ld.elf_so -I${COMMON_DIR} -I. 11CPPFLAGS+= -I${NETBSDSRCDIR}/libexec/ld.elf_so -I${COMMON_DIR} -I.
12 12
13OBJS+= crt0.o gcrt0.o crti.o crtn.o 13OBJS+= crt0.o gcrt0.o crti.o crtn.o
14OBJS+= crtbegin.o crtend.o 14OBJS+= crtbegin.o crtend.o
15 15
16.if ${MKPIC} == "yes" 16.if ${MKPIC} == "yes"
17OBJS+= crtbeginS.o 17OBJS+= crtbeginS.o
18CFLAGS.crtbegin.c+= -fPIE 18CFLAGS.crtbegin.c+= -fPIE
 19# XXXGCC5 - GCC 5 miscompiles crtbeginS.c on many platforms. on SPARC it
 20# XXXGCC5 emits "clr %g1; call %g1", which is effectively jumping to zero.
 21. if defined(HAVE_GCC) && ${HAVE_GCC} == 53 && \
 22 ${MACHINE_ARCH} != "i386" && ${MACHINE_ARCH} != "amd64"
 23CFLAGS.crtbeginS.c+= -O1
 24. endif
19.endif 25.endif
 26
20.if ${MACHINE_ARCH} == "alpha" 27.if ${MACHINE_ARCH} == "alpha"
21OBJS+= crtfm.o 28OBJS+= crtfm.o
22.endif 29.endif
23 30
24.if ${CSU_MACHINE_ARCH} == "sparc64" 31.if ${CSU_MACHINE_ARCH} == "sparc64"
25# create helper objects for the compiler to mark compiler memory models 32# create helper objects for the compiler to mark compiler memory models
26.for m in medlow medmid medany 33.for m in medlow medmid medany
27sparc_mc${m}.o: compident.S sysident_assym.h 34sparc_mc${m}.o: compident.S sysident_assym.h
28 ${CC} ${ASFLAGS} -I. -DCONTENT=\"${m}\\0\\0\" -DCONTENTLENGTH=8 -c \ 35 ${CC} ${ASFLAGS} -I. -DCONTENT=\"${m}\\0\\0\" -DCONTENTLENGTH=8 -c \
29 -o $@ ${COMMON_DIR}/compident.S 36 -o $@ ${COMMON_DIR}/compident.S
30.endfor 37.endfor
31OBJS += sparc_mcmedlow.o sparc_mcmedmid.o sparc_mcmedany.o 38OBJS += sparc_mcmedlow.o sparc_mcmedmid.o sparc_mcmedany.o
32.endif 39.endif
@@ -45,27 +52,27 @@ crtbegin.o: crtbegin.c crtbegin.h @@ -45,27 +52,27 @@ crtbegin.o: crtbegin.c crtbegin.h
45 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET}  52 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET}
46 rm -f ${.TARGET}.o 53 rm -f ${.TARGET}.o
47.if ${MKSTRIPIDENT} != "no" 54.if ${MKSTRIPIDENT} != "no"
48 ${OBJCOPY} -R .ident ${.TARGET} 55 ${OBJCOPY} -R .ident ${.TARGET}
49.endif 56.endif
50 57
51.if exists(${ARCHDIR}/crtbegin.S) 58.if exists(${ARCHDIR}/crtbegin.S)
52crtbeginS.o: crtbegin.S 59crtbeginS.o: crtbegin.S
53 ${_MKTARGET_COMPILE} 60 ${_MKTARGET_COMPILE}
54 ${COMPILE.S} ${PICFLAGS} -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o 61 ${COMPILE.S} ${PICFLAGS} -DSHARED ${ARCHDIR}/crtbegin.S -o ${.TARGET}.o
55.else 62.else
56crtbeginS.o: crtbegin.c crtbegin.h 63crtbeginS.o: crtbegin.c crtbegin.h
57 ${_MKTARGET_COMPILE} 64 ${_MKTARGET_COMPILE}
58 ${COMPILE.c} ${PICFLAGS} -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o 65 ${COMPILE.c} ${CFLAGS.crtbeginS.c} ${PICFLAGS} -DSHARED ${COMMON_DIR}/crtbegin.c -o ${.TARGET}.o
59.endif 66.endif
60 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET}  67 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET}
61 rm -f ${.TARGET}.o 68 rm -f ${.TARGET}.o
62.if ${MKSTRIPIDENT} != "no" 69.if ${MKSTRIPIDENT} != "no"
63 ${OBJCOPY} -R .ident ${.TARGET} 70 ${OBJCOPY} -R .ident ${.TARGET}
64.endif 71.endif
65 72
66crtend.o: crtend.S 73crtend.o: crtend.S
67 ${_MKTARGET_COMPILE} 74 ${_MKTARGET_COMPILE}
68 ${COMPILE.S} ${ARCHDIR}/crtend.S -o ${.TARGET}.o 75 ${COMPILE.S} ${ARCHDIR}/crtend.S -o ${.TARGET}.o
69 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET}  76 ${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}.o ${.TARGET}
70 rm -f ${.TARGET}.o 77 rm -f ${.TARGET}.o
71.if ${MKSTRIPIDENT} != "no" 78.if ${MKSTRIPIDENT} != "no"