diff configure @ 256:7520e2260097

- added to configure some detection on how to compile .s/.S with --noexecstack (or similar), as compilers' defaults are often insane - since no-execstack handling is now in build, remove .note.GNU-stack section markers (were of limites use, anyways, b/c unportable or implemented inconsistently across platforms) - some ToDo, etc. updates
author Tassilo Philipp
date Sat, 20 May 2017 00:02:59 +0200
parents 5cfe4322c500
children 8bb4618c18d8
line wrap: on
line diff
--- a/configure	Wed May 17 02:39:41 2017 +0200
+++ b/configure	Sat May 20 00:02:59 2017 +0200
@@ -1,23 +1,6 @@
 #!/bin/sh
-C=Makefile.config
 
-# get full path
-case $0 in
-  /*)
-    FULL=$0
-    ;;
-  *)
-    FULL=$PWD/$0
-    ;;
-esac
-
-printf "# auto-generated by $0\n" >$C
-while [ $# -gt 0 ]; do
-  X=$1
-  shift 1
-# Shell common:
-  case $X in
-    --help|-h|-?)
+usage() {
 cat <<EOF
 usage: $0 --<option>=<value> <var>=<value> ..
 
@@ -32,6 +15,24 @@
 Useful variables CC, CXX, CFLAGS, CXXFLAGS, etc..
 
 EOF
+}
+
+C=Makefile.config
+
+# get full path to this file (portable way), and set where to build
+SRCTOP="`cd \`dirname "$0"\` && pwd`"
+BLDTOP="$PWD"
+
+
+printf "# auto-generated by $0\n" >$C
+
+while [ $# -gt 0 ]; do
+  X=$1
+  shift 1
+  case $X in
+# Shell common:
+    --help|-h|-?)
+      usage
       exit 1
       ;;
 # GNU Compatibility:
@@ -61,7 +62,9 @@
       ;;
   esac
 done
+
 printf "PREFIX=${PREFIX:=/usr/local}\n" >>$C
+
 case ${TARGET:=`uname`} in
   Linux|GNU/kFreeBSD)
     if [ -z "${CFLAGS}" ]; then
@@ -186,9 +189,9 @@
     printf "CXXFLAGS=-I${SDKROOT}/include/\n" >>$C
     # Pulling in dyncall libs below is a hack, for some reason psp-ld is super-picky about order.
     # Use your C lib of choice, from the PSPSDK, or...
-    #printf "LDLIBS=-L${SDKROOT}/lib/ -L`dirname ${FULL}`/dyncall -L`dirname ${FULL}`/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lpsplibc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C
+    #printf "LDLIBS=-L${SDKROOT}/lib/ -L${SRCTOP}/dyncall -L${SRCTOP}/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lpsplibc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C
     # ... newlib.
-    printf "LDLIBS=-L${SDKROOT}/lib/ -L`dirname ${FULL}`/dyncall -L`dirname ${FULL}`/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lc       -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C
+    printf "LDLIBS=-L${SDKROOT}/lib/ -L${SRCTOP}/dyncall -L${SRCTOP}/dyncallback -ldyncall_s -ldyncallback_s -lm -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lstdc++ -lc       -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser \n" >>$C
     ;;
   ?)
     cat $0 | awk '/^esac$/{b=0}/^  [A-Za-z0-9|]+\)/{if(b==1) print substr($1,1,length($1)-1)}BEGIN{b=0}/^case.*TARGET.*uname.*in$/{b=1}' | tr '|' '\n'
@@ -196,8 +199,51 @@
     ;;
 esac
 
-BLDTOP="$PWD"
-SRCTOP=`dirname ${FULL}`
+
+# Assure objects not asking for an execstack (or binary that links dyncall might end
+# up with one, for no reason).
+
+# We run our .s and .S files through $CC. GCC and others (annoyingly) assume without
+# being told explicitly that an executable stack may be required for those.
+# Trying to specify this per source via .section .note.GNU-stack,"",... turned out to
+# be not consistently implemented across our supported platforms and toolchains, and
+# thus not being portable (on some platforms even resulting in the opposite, the mere
+# presence of this section, no matter the flags, creating an rwx stack).
+# So, let's set the needed build flags by running a few tests, if we find any that
+# work.
+
+#determine_asflags() {
+#	AS_PROG=".global main\nmain:\n"
+#	echo "${AS_PROG}"                              | cc -xassembler -o rwxtest.d.out -
+#	echo "${AS_PROG}.section .note.GNU-stack,\"\"" | cc -xassembler -o rwxtest.s.out -
+#	echo "${AS_PROG}"                              | cc -xassembler -o rwxtest.f.out -Wa,--noexecstack -
+
+# @@@ find solution for platforms without objdump
+RWXTESTBIN="$BLDTOP/rwxtest.out" # @@@ put this maybe all in Makefile.generic? out of source builds?
+STACKFLAGS=`make -f - <<MAKEFILE
+include $C
+t:
+	@(echo .global main;echo main:) | \\\${CC} -xassembler -o "$RWXTESTBIN" -Wa,--noexecstack -
+	@(which objdump && objdump -p "$RWXTESTBIN") | grep -A1 STACK | sed '1d;s/^.*flags //' | awk '{print \\\$1}'
+MAKEFILE
+`
+rm "$RWXTESTBIN" 2>/dev/null
+if [ "$STACKFLAGS" = "rw-" ]; then
+  # platforms differe here, so set them all
+  printf "ASFLAGS=-Wa,--noexecstack\n" >>$C # common on GNU
+  printf "ACFLAGS=-Wa,--noexecstack\n" >>$C # specifically for .S.o
+  printf "AFLAGS=--noexecstack\n"      >>$C # for direct assembler invocation
+fi
+
+#if echo ".global main\nmain:\n" | cc -xassembler -o rwxtest.f.out -Wa,--noexecstack -
+#(which objdump && objdump -p rwxtest.f.out  || echo stack flags lookup_err) | grep -i -A1 stack | grep 'flags.*' | sed 's/^.*flags //'
+#}
+
+#printf "ACFLAGS=-Wa,--noexecstack\n" >>$C
+#printf "AFLAGS=--noexecstack\n" >>$C
+
+
+# Generate all makefiles needed
 
 FILES=`( cd $SRCTOP ; find . -name "Makefile.generic" )`
 for FILE in $FILES ; do
@@ -212,3 +258,4 @@
 include \${VPATH}/Makefile.generic
 EOF
 done
+