Sun Jul 9 14:30:07 2017 UTC ()
Register support for PKGSRC_USE_STACK_CHECK

This adds -fstack-check to the CFLAGS (with GCC on NetBSD x86). Only
tested on NetBSD/amd64 so far.

Disabled by default.


(khorben)
diff -r1.392 -r1.393 pkgsrc/mk/bsd.prefs.mk
diff -r1.179 -r1.180 pkgsrc/mk/compiler/gcc.mk
diff -r1.277 -r1.278 pkgsrc/mk/defaults/mk.conf
diff -r1.51 -r1.52 pkgsrc/mk/platform/NetBSD.mk

cvs diff -r1.392 -r1.393 pkgsrc/mk/bsd.prefs.mk (expand / switch to unified diff)

--- pkgsrc/mk/bsd.prefs.mk 2017/06/01 02:15:10 1.392
+++ pkgsrc/mk/bsd.prefs.mk 2017/07/09 14:30:07 1.393
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: bsd.prefs.mk,v 1.392 2017/06/01 02:15:10 jlam Exp $ 1# $NetBSD: bsd.prefs.mk,v 1.393 2017/07/09 14:30:07 khorben Exp $
2# 2#
3# This file includes the mk.conf file, which contains the user settings. 3# This file includes the mk.conf file, which contains the user settings.
4# 4#
5# Packages should include this file before any of the .if directives, as 5# Packages should include this file before any of the .if directives, as
6# well as before modifying variables like CFLAGS, LDFLAGS, and so on. 6# well as before modifying variables like CFLAGS, LDFLAGS, and so on.
7# Otherwise the behavior may be unexpected. 7# Otherwise the behavior may be unexpected.
8# 8#
9# When mk.conf is included by this file, the following variables are 9# When mk.conf is included by this file, the following variables are
10# defined: 10# defined:
11# 11#
12# ACCEPTABLE_LICENSES 12# ACCEPTABLE_LICENSES
13# This variable is set to the list of Open Source licenses. See 13# This variable is set to the list of Open Source licenses. See
14# mk/license.mk for details. 14# mk/license.mk for details.
@@ -707,26 +707,32 @@ _PKGSRC_USE_FORTIFY= yes @@ -707,26 +707,32 @@ _PKGSRC_USE_FORTIFY= yes
707 707
708_PKGSRC_USE_RELRO= no 708_PKGSRC_USE_RELRO= no
709.if (${PKGSRC_USE_RELRO:tl} != "no") && \ 709.if (${PKGSRC_USE_RELRO:tl} != "no") && \
710 (${_OPSYS_SUPPORTS_RELRO:Uno} == "yes") 710 (${_OPSYS_SUPPORTS_RELRO:Uno} == "yes")
711_PKGSRC_USE_RELRO= yes 711_PKGSRC_USE_RELRO= yes
712.endif 712.endif
713 713
714_PKGSRC_USE_SSP= no 714_PKGSRC_USE_SSP= no
715.if (${PKGSRC_USE_SSP:tl} != "no") && \ 715.if (${PKGSRC_USE_SSP:tl} != "no") && \
716 (${_OPSYS_SUPPORTS_SSP:Uno} == "yes") 716 (${_OPSYS_SUPPORTS_SSP:Uno} == "yes")
717_PKGSRC_USE_SSP= yes 717_PKGSRC_USE_SSP= yes
718.endif 718.endif
719 719
 720_PKGSRC_USE_STACK_CHECK=no
 721.if (${PKGSRC_USE_STACK_CHECK:tl} != "no") && \
 722 (${_OPSYS_SUPPORTS_STACK_CHECK:Uno} == "yes")
 723_PKGSRC_USE_STACK_CHECK=yes
 724.endif
 725
720# Enable cwrappers if not building the wrappers themselves, and if the user has 726# Enable cwrappers if not building the wrappers themselves, and if the user has
721# explicitly requested them, or if they haven't but the compiler/platform is 727# explicitly requested them, or if they haven't but the compiler/platform is
722# known to support them. 728# known to support them.
723.if empty(PKGPATH:Mpkgtools/cwrappers) && \ 729.if empty(PKGPATH:Mpkgtools/cwrappers) && \
724 (${USE_CWRAPPERS:tl} == "yes" || \ 730 (${USE_CWRAPPERS:tl} == "yes" || \
725 (${USE_CWRAPPERS:tl} == "auto" && \ 731 (${USE_CWRAPPERS:tl} == "auto" && \
726 ${_OPSYS_SUPPORTS_CWRAPPERS:Uno} == "yes")) 732 ${_OPSYS_SUPPORTS_CWRAPPERS:Uno} == "yes"))
727_USE_CWRAPPERS= yes 733_USE_CWRAPPERS= yes
728.else 734.else
729_USE_CWRAPPERS= no 735_USE_CWRAPPERS= no
730.endif 736.endif
731 737
732# Wrapper framework definitions 738# Wrapper framework definitions

cvs diff -r1.179 -r1.180 pkgsrc/mk/compiler/gcc.mk (expand / switch to unified diff)

--- pkgsrc/mk/compiler/gcc.mk 2017/06/25 01:41:15 1.179
+++ pkgsrc/mk/compiler/gcc.mk 2017/07/09 14:30:07 1.180
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: gcc.mk,v 1.179 2017/06/25 01:41:15 joerg Exp $ 1# $NetBSD: gcc.mk,v 1.180 2017/07/09 14:30:07 khorben Exp $
2# 2#
3# This is the compiler definition for the GNU Compiler Collection. 3# This is the compiler definition for the GNU Compiler Collection.
4# 4#
5# User-settable variables: 5# User-settable variables:
6# 6#
7# GCCBASE 7# GCCBASE
8# If using a native GCC and the compiler is not in $PATH then 8# If using a native GCC and the compiler is not in $PATH then
9# this should be set to the base installation directory. 9# this should be set to the base installation directory.
10# 10#
11# USE_NATIVE_GCC 11# USE_NATIVE_GCC
12# When set to "yes", the native gcc is used, no matter which 12# When set to "yes", the native gcc is used, no matter which
13# compiler version a package requires. 13# compiler version a package requires.
14# 14#
@@ -362,26 +362,32 @@ _RELRO_LDFLAGS= -Wl,-z,relro -Wl,-z,now @@ -362,26 +362,32 @@ _RELRO_LDFLAGS= -Wl,-z,relro -Wl,-z,now
362_GCC_LDFLAGS+= ${_RELRO_LDFLAGS} 362_GCC_LDFLAGS+= ${_RELRO_LDFLAGS}
363CWRAPPERS_APPEND.ld+= ${_RELRO_LDFLAGS} 363CWRAPPERS_APPEND.ld+= ${_RELRO_LDFLAGS}
364.endif 364.endif
365  365
366# The user can choose the level of stack smashing protection. 366# The user can choose the level of stack smashing protection.
367.if ${PKGSRC_USE_SSP} == "all" 367.if ${PKGSRC_USE_SSP} == "all"
368_SSP_CFLAGS= -fstack-protector-all 368_SSP_CFLAGS= -fstack-protector-all
369.elif ${PKGSRC_USE_SSP} == "strong" 369.elif ${PKGSRC_USE_SSP} == "strong"
370_SSP_CFLAGS= -fstack-protector-strong 370_SSP_CFLAGS= -fstack-protector-strong
371.else 371.else
372_SSP_CFLAGS= -fstack-protector 372_SSP_CFLAGS= -fstack-protector
373.endif 373.endif
374 374
 375_STACK_CHECK_CFLAGS= -fstack-check
 376
 377.if ${_PKGSRC_USE_STACK_CHECK} == "yes"
 378_GCC_CFLAGS+= ${_STACK_CHECK_CFLAGS}
 379.endif
 380
375# GCC has this annoying behaviour where it advocates in a multi-line 381# GCC has this annoying behaviour where it advocates in a multi-line
376# banner the use of "#include" over "#import" when including headers. 382# banner the use of "#include" over "#import" when including headers.
377# This generates a huge number of warnings when building practically all 383# This generates a huge number of warnings when building practically all
378# Objective-C code where it is convention to use "#import". Suppress 384# Objective-C code where it is convention to use "#import". Suppress
379# the warning if we're building Objective-C code using GCC. 385# the warning if we're building Objective-C code using GCC.
380# 386#
381.if !empty(_LANGUAGES.gcc:Mobjc) 387.if !empty(_LANGUAGES.gcc:Mobjc)
382CFLAGS+= -Wno-import 388CFLAGS+= -Wno-import
383.endif 389.endif
384 390
385CFLAGS+= ${_GCC_CFLAGS} 391CFLAGS+= ${_GCC_CFLAGS}
386 392
387.if !empty(_NEED_GCC2:M[yY][eE][sS]) 393.if !empty(_NEED_GCC2:M[yY][eE][sS])

cvs diff -r1.277 -r1.278 pkgsrc/mk/defaults/mk.conf (expand / switch to unified diff)

--- pkgsrc/mk/defaults/mk.conf 2017/07/05 15:58:30 1.277
+++ pkgsrc/mk/defaults/mk.conf 2017/07/09 14:30:07 1.278
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: mk.conf,v 1.277 2017/07/05 15:58:30 khorben Exp $ 1# $NetBSD: mk.conf,v 1.278 2017/07/09 14:30:07 khorben Exp $
2# 2#
3 3
4# This file provides default values for variables that may be overridden 4# This file provides default values for variables that may be overridden
5# in the MAKECONF file, which is /etc/mk.conf by default. 5# in the MAKECONF file, which is /etc/mk.conf by default.
6# 6#
7# Note: This file is included after the MAKECONF file, so you cannot query 7# Note: This file is included after the MAKECONF file, so you cannot query
8# these default values in the MAKECONF using the ".if" and ".for" 8# these default values in the MAKECONF using the ".if" and ".for"
9# preprocessing directives. 9# preprocessing directives.
10 10
11# ************************************************************************ 11# ************************************************************************
12# NOTE TO PEOPLE EDITING THIS FILE - USE LEADING SPACES, NOT LEADING TABS. 12# NOTE TO PEOPLE EDITING THIS FILE - USE LEADING SPACES, NOT LEADING TABS.
13# ************************************************************************ 13# ************************************************************************
14 14
@@ -248,26 +248,33 @@ PKGSRC_USE_RELRO?= no @@ -248,26 +248,33 @@ PKGSRC_USE_RELRO?= no
248# no: Do not pass any flags for RELRO 248# no: Do not pass any flags for RELRO
249# partial: Pass -Wl,-z,relro 249# partial: Pass -Wl,-z,relro
250# full: Pass -Wl,-z,relro -Wl,-z,now 250# full: Pass -Wl,-z,relro -Wl,-z,now
251 251
252PKGSRC_USE_SSP?= yes 252PKGSRC_USE_SSP?= yes
253# Configure this to enable stack smashing protection (on supported platforms). 253# Configure this to enable stack smashing protection (on supported platforms).
254# Possible values: 254# Possible values:
255# no: Do not pass any stack protection flags 255# no: Do not pass any stack protection flags
256# yes: Pass -fstack-protector 256# yes: Pass -fstack-protector
257# strong: Pass -fstack-protector-strong 257# strong: Pass -fstack-protector-strong
258# all: Pass -fstack-protector-all 258# all: Pass -fstack-protector-all
259# Default: yes 259# Default: yes
260 260
 261PKGSRC_USE_STACK_CHECK?= no
 262# Configure this to enable stack boundary verification (on supported platforms).
 263# Possible values:
 264# no: Do not pass any stack protection flags
 265# yes: Pass -fstack-check
 266# Default: no
 267
261# The default PREFER_PKGSRC should be empty, but due to historical reasons we have the list below. 268# The default PREFER_PKGSRC should be empty, but due to historical reasons we have the list below.
262# Please add your platform here once you have confirmed it is correct 269# Please add your platform here once you have confirmed it is correct
263.if ${OPSYS} == "OpenBSD" || ${OPSYS} == "Bitrig" 270.if ${OPSYS} == "OpenBSD" || ${OPSYS} == "Bitrig"
264PREFER_PKGSRC?= 271PREFER_PKGSRC?=
265.elif (!empty(MACHINE_PLATFORM:MNetBSD-*-*) && \ 272.elif (!empty(MACHINE_PLATFORM:MNetBSD-*-*) && \
266 exists(/usr/X11R7/lib/libX11.so)) 273 exists(/usr/X11R7/lib/libX11.so))
267PREFER_PKGSRC?= 274PREFER_PKGSRC?=
268.elif (!empty(MACHINE_PLATFORM:MNetBSD-*-*) && \ 275.elif (!empty(MACHINE_PLATFORM:MNetBSD-*-*) && \
269 exists(/usr/lib/libexpat.so)) 276 exists(/usr/lib/libexpat.so))
270PREFER_PKGSRC?= MesaLib Xft2 Xrandr Xrender fontconfig \ 277PREFER_PKGSRC?= MesaLib Xft2 Xrandr Xrender fontconfig \
271 freetype2 glu randrproto renderproto xcursor 278 freetype2 glu randrproto renderproto xcursor
272.elif !empty(MACHINE_PLATFORM:MLinux-*-*) && \ 279.elif !empty(MACHINE_PLATFORM:MLinux-*-*) && \
273 (!defined(X11_TYPE) || ${X11_TYPE} == "native") 280 (!defined(X11_TYPE) || ${X11_TYPE} == "native")

cvs diff -r1.51 -r1.52 pkgsrc/mk/platform/NetBSD.mk (expand / switch to unified diff)

--- pkgsrc/mk/platform/NetBSD.mk 2017/07/04 18:29:24 1.51
+++ pkgsrc/mk/platform/NetBSD.mk 2017/07/09 14:30:07 1.52
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: NetBSD.mk,v 1.51 2017/07/04 18:29:24 khorben Exp $ 1# $NetBSD: NetBSD.mk,v 1.52 2017/07/09 14:30:07 khorben Exp $
2# 2#
3# Variable definitions for the NetBSD operating system. 3# Variable definitions for the NetBSD operating system.
4 4
5# Needed for 1.6.1 and earlier due to rpcgen bugs and paths 5# Needed for 1.6.1 and earlier due to rpcgen bugs and paths
6.if defined(CPP) && ${CPP} == "cpp" 6.if defined(CPP) && ${CPP} == "cpp"
7CPP= /usr/bin/cpp 7CPP= /usr/bin/cpp
8.endif 8.endif
9ECHO_N?= ${ECHO} -n 9ECHO_N?= ${ECHO} -n
10IMAKE_MAKE?= ${MAKE} # program which gets invoked by imake 10IMAKE_MAKE?= ${MAKE} # program which gets invoked by imake
11PKGLOCALEDIR?= share 11PKGLOCALEDIR?= share
12PS?= /bin/ps 12PS?= /bin/ps
13SU?= /usr/bin/su 13SU?= /usr/bin/su
14TYPE?= type # Shell builtin 14TYPE?= type # Shell builtin
@@ -144,22 +144,28 @@ _OPSYS_SUPPORTS_MKPIE= yes @@ -144,22 +144,28 @@ _OPSYS_SUPPORTS_MKPIE= yes
144.if (${MACHINE_ARCH} == "i386") || \ 144.if (${MACHINE_ARCH} == "i386") || \
145 (${MACHINE_ARCH} == "x86_64") 145 (${MACHINE_ARCH} == "x86_64")
146_OPSYS_SUPPORTS_RELRO= yes 146_OPSYS_SUPPORTS_RELRO= yes
147.endif 147.endif
148 148
149# Register support for SSP on most architectures (with GCC) 149# Register support for SSP on most architectures (with GCC)
150.if (${MACHINE_ARCH} != "alpha") && \ 150.if (${MACHINE_ARCH} != "alpha") && \
151 (${MACHINE_ARCH} != "hppa") && \ 151 (${MACHINE_ARCH} != "hppa") && \
152 (${MACHINE_ARCH} != "ia64") && \ 152 (${MACHINE_ARCH} != "ia64") && \
153 (${MACHINE_ARCH} != "mips") 153 (${MACHINE_ARCH} != "mips")
154_OPSYS_SUPPORTS_SSP= yes 154_OPSYS_SUPPORTS_SSP= yes
155.endif 155.endif
156 156
 157# Register support for stack check on supported architectures (with GCC)
 158.if (${MACHINE_ARCH} == "i386") || \
 159 (${MACHINE_ARCH} == "x86_64")
 160_OPSYS_SUPPORTS_STACK_CHECK= yes
 161.endif
 162
157_OPSYS_SUPPORTS_CWRAPPERS= yes 163_OPSYS_SUPPORTS_CWRAPPERS= yes
158 164
159# use readelf in check/bsd.check-vars.mk 165# use readelf in check/bsd.check-vars.mk
160_OPSYS_CAN_CHECK_RELRO= yes 166_OPSYS_CAN_CHECK_RELRO= yes
161_OPSYS_CAN_CHECK_SHLIBS= yes 167_OPSYS_CAN_CHECK_SHLIBS= yes
162 168
163# check for maximum command line length and set it in configure's environment, 169# check for maximum command line length and set it in configure's environment,
164# to avoid a test required by the libtool script that takes forever. 170# to avoid a test required by the libtool script that takes forever.
165_OPSYS_MAX_CMDLEN_CMD= /sbin/sysctl -n kern.argmax 171_OPSYS_MAX_CMDLEN_CMD= /sbin/sysctl -n kern.argmax