comparison configure @ 262:edbada931b3f

configure: - don't accidentally override set vars when checking for nonexecstack build flags - comment cleanup
author Tassilo Philipp
date Tue, 23 May 2017 00:08:26 +0200
parents 943c182692e2
children a8c9e3654062
comparison
equal deleted inserted replaced
261:b625f2e11911 262:edbada931b3f
201 201
202 202
203 # Assure objects not asking for an execstack (or binary that links dyncall might end 203 # Assure objects not asking for an execstack (or binary that links dyncall might end
204 # up with one, for no reason). 204 # up with one, for no reason).
205 205
206 # We run our .s and .S files through $CC. GCC and others might (annoyingly) assume that 206 # .s.o/.S.o rules often use ${CC} which then invokes the tools needed. GCC and
207 # an executable stack may be required for those, if not told explicitly that it isn't. 207 # others might (annoyingly) assume that an executable stack may be required for
208 # Trying to specify this per source via .section .note.GNU-stack,"",... turned out to 208 # those sources, if not told explicitly that it isn't.
209 # be not consistently implemented across our supported platforms and toolchains, and 209 # Neither specifying this per source (e.g. via .section .note.GNU-stack,"",...), nor
210 # thus not being portable (on some platforms even resulting in the opposite, the mere 210 # per toolchain flags (e.g. as' --noexecstack) turned out to be portable across our
211 # presence of this section, no matter the flags, creating an rwx stack). 211 # supported platforms, toolchains, and different versions of the latter (some even
212 # So, let's set the needed build flags by running a few tests, if we find any that 212 # producing the opposite result).
213 # work (as those also don't always have the intended effect). 213 # Find needed build flags by running a few tests; use default if none result in "rw-".
214 214
215 RWXTESTPREFIX="rwxtest" # @@@ put this maybe all in Makefile.generic? out of source builds? 215 RWXTESTPREFIX="rwxtest" # @@@ put this maybe all in Makefile.generic? out of source builds?
216 for s in S s ; do ( 216 for s in S s ; do (
217 cd "$BLDTOP" 217 cd "$BLDTOP"
218 # asm test file, with main and _main for portability. 218 # asm test file, with main and _main for portability.
219 (echo '.text';(echo '.globl main';echo 'main:') | sed 'p;s/m/_m/') > $RWXTESTPREFIX.$s 219 (echo '.text';(echo '.globl main';echo 'main:') | sed 'p;s/m/_m/') > $RWXTESTPREFIX.$s
220 220
221 # Check var to be used, which depends on inference rules of this platform. E.g. ASFLAGS is only common 221 # Check var to be used, which depends on inference rules of this platform. E.g. ASFLAGS is only common on GNU, and
222 # on GNU, and on some other platforms only CFLAGS is used, ... 222 # on some other platforms only CFLAGS is used, ... Check makes use of the config written so far, so use '+='.
223 for f in "ASFLAGS=-Wa,--noexecstack" "ACFLAGS=-Wa,--noexecstack" "AFLAGS=--noexecstack" "CFLAGS+=-Wa,--noexecstack"; do 223 for f in "ASFLAGS+=-Wa,--noexecstack" "ACFLAGS+=-Wa,--noexecstack" "AFLAGS+=--noexecstack" "CFLAGS+=-Wa,--noexecstack"; do
224 # Build a dummy makefile that triggers inference rules that dyncall's build also uses 224 # dummy makefile triggering inference rules, reflecting dyncall's build
225 make -f - <<MAKEFILE 225 make -f - <<MAKEFILE
226 include $C 226 include $C
227 $f 227 $f
228 # Force dependency via .o, to avoid .[sS].out rules that might be set - also set command as not all platforms set .o.out 228 # Force dependency via .o, to avoid .[sS].out rules that might be set - also set command as not all platforms set .o.out
229 $RWXTESTPREFIX.out: $RWXTESTPREFIX.o 229 $RWXTESTPREFIX.out: $RWXTESTPREFIX.o
230 \${CC} \${CFLAGS} \${LDFLAGS} \$< \${LDLIBS} -o \$@ 230 \${CC} \${CFLAGS} \${LDFLAGS} \$< \${LDLIBS} -o \$@
231 MAKEFILE 231 MAKEFILE
232 232
233 # Check what stack of a built test binary would result in. 233 # Check what stack of a built test binary would result in.
234 # @@@ add xxd hexdump based versions for when objdump is not available; also check for those if we deal with ELF files 234 # @@@ add xxd hexdump based versions for when objdump is not available; also check for those if we deal with ELF files
235 # @@@ maybe also limit to ELF files
235 STACKFLAGS=`(which objdump && objdump -p $RWXTESTPREFIX.out) | sed -e '/STACK/bx' -e 'd' -e ':x' -e 'N' -e 's/^.*flags[ \t]\([^ \t]*\).*/\1/'` 236 STACKFLAGS=`(which objdump && objdump -p $RWXTESTPREFIX.out) | sed -e '/STACK/bx' -e 'd' -e ':x' -e 'N' -e 's/^.*flags[ \t]\([^ \t]*\).*/\1/'`
236 rm $RWXTESTPREFIX.out $RWXTESTPREFIX.o 237 rm $RWXTESTPREFIX.out $RWXTESTPREFIX.o
237 if [ "$STACKFLAGS" = "rw-" ]; then 238 if [ "$STACKFLAGS" = "rw-" ]; then
238 printf "$f\n" 239 printf "$f\n"
239 break 240 break