Mercurial > pub > dyncall > dyncall
comparison configure @ 258:943c182692e2
- configure: noexecstack flag check/search now reflecting what dyncall build needs/does
author | Tassilo Philipp |
---|---|
date | Sun, 21 May 2017 22:21:47 +0200 |
parents | 8bb4618c18d8 |
children | edbada931b3f |
comparison
equal
deleted
inserted
replaced
257:8bb4618c18d8 | 258:943c182692e2 |
---|---|
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 (annoyingly) assume without | 206 # We run our .s and .S files through $CC. GCC and others might (annoyingly) assume that |
207 # being told explicitly that an executable stack may be required for those. | 207 # an executable stack may be required for those, if not told explicitly that it isn't. |
208 # Trying to specify this per source via .section .note.GNU-stack,"",... turned out to | 208 # Trying to specify this per source via .section .note.GNU-stack,"",... turned out to |
209 # be not consistently implemented across our supported platforms and toolchains, and | 209 # be not consistently implemented across our supported platforms and toolchains, and |
210 # thus not being portable (on some platforms even resulting in the opposite, the mere | 210 # thus not being portable (on some platforms even resulting in the opposite, the mere |
211 # presence of this section, no matter the flags, creating an rwx stack). | 211 # presence of this section, no matter the flags, creating an rwx stack). |
212 # So, let's set the needed build flags by running a few tests, if we find any that | 212 # So, let's set the needed build flags by running a few tests, if we find any that |
213 # work. | 213 # work (as those also don't always have the intended effect). |
214 | 214 |
215 #determine_asflags() { | 215 RWXTESTPREFIX="rwxtest" # @@@ put this maybe all in Makefile.generic? out of source builds? |
216 # AS_PROG=".global main\nmain:\n" | 216 for s in S s ; do ( |
217 # echo "${AS_PROG}" | cc -xassembler -o rwxtest.d.out - | 217 cd "$BLDTOP" |
218 # echo "${AS_PROG}.section .note.GNU-stack,\"\"" | cc -xassembler -o rwxtest.s.out - | 218 # asm test file, with main and _main for portability. |
219 # echo "${AS_PROG}" | cc -xassembler -o rwxtest.f.out -Wa,--noexecstack - | 219 (echo '.text';(echo '.globl main';echo 'main:') | sed 'p;s/m/_m/') > $RWXTESTPREFIX.$s |
220 | 220 |
221 # @@@ find solution for platforms without objdump | 221 # Check var to be used, which depends on inference rules of this platform. E.g. ASFLAGS is only common |
222 RWXTESTBIN="$BLDTOP/rwxtest.out" # @@@ put this maybe all in Makefile.generic? out of source builds? | 222 # on GNU, and on some other platforms only CFLAGS is used, ... |
223 STACKFLAGS=`make -f - <<MAKEFILE | 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 | |
225 make -f - <<MAKEFILE | |
224 include $C | 226 include $C |
225 t: | 227 $f |
226 @(echo .text;echo .globl main;echo main:) | sed '/m/p;s/m/_m/' | \\\${CC} -xassembler -o "$RWXTESTBIN" -Wa,--noexecstack - | 228 # Force dependency via .o, to avoid .[sS].out rules that might be set - also set command as not all platforms set .o.out |
227 @(which objdump && objdump -p "$RWXTESTBIN") | grep -A1 STACK | sed '1d;s/^.*flags[ \\t]\\(rw[x-]\\)[ \\t]*/\\1/' | 229 $RWXTESTPREFIX.out: $RWXTESTPREFIX.o |
230 \${CC} \${CFLAGS} \${LDFLAGS} \$< \${LDLIBS} -o \$@ | |
228 MAKEFILE | 231 MAKEFILE |
229 ` | 232 |
230 rm "$RWXTESTBIN" 2>/dev/null | 233 # Check what stack of a built test binary would result in. |
231 if [ "$STACKFLAGS" = "rw-" ]; then | 234 # @@@ add xxd hexdump based versions for when objdump is not available; also check for those if we deal with ELF files |
232 # platforms differe here, so set them all | 235 STACKFLAGS=`(which objdump && objdump -p $RWXTESTPREFIX.out) | sed -e '/STACK/bx' -e 'd' -e ':x' -e 'N' -e 's/^.*flags[ \t]\([^ \t]*\).*/\1/'` |
233 printf "ASFLAGS=-Wa,--noexecstack\n" >>$C # common on GNU | 236 rm $RWXTESTPREFIX.out $RWXTESTPREFIX.o |
234 printf "ACFLAGS=-Wa,--noexecstack\n" >>$C # specifically for .S.o | 237 if [ "$STACKFLAGS" = "rw-" ]; then |
235 printf "AFLAGS=--noexecstack\n" >>$C # for direct assembler invocation | 238 printf "$f\n" |
236 fi | 239 break |
237 | 240 fi |
238 #if echo ".global main\nmain:\n" | cc -xassembler -o rwxtest.f.out -Wa,--noexecstack - | 241 |
239 #(which objdump && objdump -p rwxtest.f.out || echo stack flags lookup_err) | grep -i -A1 stack | grep 'flags.*' | sed 's/^.*flags //' | 242 done |
240 #} | 243 |
241 | 244 rm $RWXTESTPREFIX.$s |
242 #printf "ACFLAGS=-Wa,--noexecstack\n" >>$C | 245 |
243 #printf "AFLAGS=--noexecstack\n" >>$C | 246 ) done 2>&1 | grep '^[ASC]\+FLAGS.*noexecstack$' | uniq >>$C |
247 | |
244 | 248 |
245 | 249 |
246 # Generate all makefiles needed | 250 # Generate all makefiles needed |
247 | 251 |
248 FILES=`( cd $SRCTOP ; find . -name "Makefile.generic" )` | 252 FILES=`( cd $SRCTOP ; find . -name "Makefile.generic" )` |
257 include $BLDTOP/Makefile.config | 261 include $BLDTOP/Makefile.config |
258 include \${VPATH}/Makefile.generic | 262 include \${VPATH}/Makefile.generic |
259 EOF | 263 EOF |
260 done | 264 done |
261 | 265 |
266 echo "Configuration written do $C" | |
267 |