# HG changeset patch # User Tassilo Philipp # Date 1495231379 -7200 # Node ID 7520e22600972ac2c8bd0eda6db91e065ab24108 # Parent 704c28fd94286f189be6e377de03981b9919879a - 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 diff -r 704c28fd9428 -r 7520e2260097 BUGS --- a/BUGS Wed May 17 02:39:41 2017 +0200 +++ b/BUGS Sat May 20 00:02:59 2017 +0200 @@ -1,4 +1,4 @@ -- add support for SELinux; object files need to be tagged with section '.section .note.GNU-stack,"",%progbits' +- add support for SELinux - dyncall sparc v7/v8: -xO3 on SunPro segfaults in tests. - dyncall sparc64 port: works fine on Debian 6, but has issues on OpenBSD and Solaris regarding passing of float and double values. - this BUGS file should be merged with ToDo or vice-versa diff -r 704c28fd9428 -r 7520e2260097 ChangeLog --- a/ChangeLog Wed May 17 02:39:41 2017 +0200 +++ b/ChangeLog Sat May 20 00:02:59 2017 +0200 @@ -28,8 +28,8 @@ return symbol names as they would appear in C code, instead of the raw ones in object files o added new function dlGetLibraryPath, allowing lookups of path to library via handle general: - o marked assembly code as not needing an execstack, for safer/easier integration into other - projects/builds, where needed; this is needed b/c of questionable default behaviours of some + o assembly code now built by explicitily asking for non-execstack, for safer/easier integration + into other projects/builds, where needed; needed b/c of questionable default behaviours of some toolchains (thanks Thorsten Behrens for report and analysis) doc: o working html doc generation from TEX sources diff -r 704c28fd9428 -r 7520e2260097 ToDo --- a/ToDo Wed May 17 02:39:41 2017 +0200 +++ b/ToDo Sat May 20 00:02:59 2017 +0200 @@ -1,5 +1,7 @@ 1.0: ---- +- support platforms without shared libraries so they can be built by just typing `./configure;make` (e.g. minix < 3.2.1) + * also make sure minix with shared library support builds and works in general (>= 3.2.1) as well as ELF on Minix (>= 3.2.0) to begin with (as that's the base, and we only test on 3.1.8 so far) - dyncall supports calls to functions where prototype exists (with and without varargs); however not when no prototype exist (e.g. just calling some pointer), without any declaration... even possible in C, as one has to cast to the function type? need to support? @@ -42,7 +44,7 @@ - callback_plain retval, see above under ARM - callf - support Solaris11 CFLAGS with -D_FILE_OFFSET_BITS=64 -- make sure selinux works (esp. regarding NX bits, asm might need (or similar): .section .note.GNU-stack,"",@progbits) +- make sure selinux works (esp. regarding NX bits) Daniel has a patch for it, if needed, implementing allocwx with two memory blocks, one for w^x, mmaped to one for r|x - support /SAFESEH on cl/win32 - test code functions should be in .so files, optionally, so the suites can directly diff -r 704c28fd9428 -r 7520e2260097 configure --- 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 <= = .. @@ -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 - </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 + diff -r 704c28fd9428 -r 7520e2260097 dyncall/dyncall_call_x64.S --- a/dyncall/dyncall_call_x64.S Wed May 17 02:39:41 2017 +0200 +++ b/dyncall/dyncall_call_x64.S Sat May 20 00:02:59 2017 +0200 @@ -145,6 +145,3 @@ END_ASM - -SECTION_NOTE_NXSTACK /* mark object as not needing execstack */ - diff -r 704c28fd9428 -r 7520e2260097 dyncall/dyncall_call_x86.S --- a/dyncall/dyncall_call_x86.S Wed May 17 02:39:41 2017 +0200 +++ b/dyncall/dyncall_call_x86.S Sat May 20 00:02:59 2017 +0200 @@ -237,6 +237,3 @@ END_ASM - -SECTION_NOTE_NXSTACK /* mark object as not needing execstack */ - diff -r 704c28fd9428 -r 7520e2260097 dyncall/dyncall_call_x86_nasm.asm --- a/dyncall/dyncall_call_x86_nasm.asm Wed May 17 02:39:41 2017 +0200 +++ b/dyncall/dyncall_call_x86_nasm.asm Sat May 20 00:02:59 2017 +0200 @@ -226,9 +226,9 @@ ret -; Stack markings for ELF/GNU to specify no executable stack */ +;; Stack markings for ELF/GNU to specify no executable stack */ +; +;%ifidn __OUTPUT_FORMAT__,elf +;section .note.GNU-stack noalloc noexec nowrite progbits +;%endif -%ifidn __OUTPUT_FORMAT__,elf -section .note.GNU-stack noalloc noexec nowrite progbits -%endif - diff -r 704c28fd9428 -r 7520e2260097 dyncallback/dyncall_callback_x64.S --- a/dyncallback/dyncall_callback_x64.S Wed May 17 02:39:41 2017 +0200 +++ b/dyncallback/dyncall_callback_x64.S Sat May 20 00:02:59 2017 +0200 @@ -178,6 +178,3 @@ END_ASM - -SECTION_NOTE_NXSTACK /* mark object as not needing execstack */ - diff -r 704c28fd9428 -r 7520e2260097 dyncallback/dyncall_callback_x86.S --- a/dyncallback/dyncall_callback_x86.S Wed May 17 02:39:41 2017 +0200 +++ b/dyncallback/dyncall_callback_x86.S Sat May 20 00:02:59 2017 +0200 @@ -110,6 +110,3 @@ END_PROC(dcCallbackThunkEntry) END_ASM - -SECTION_NOTE_NXSTACK /* mark object as not needing execstack */ - diff -r 704c28fd9428 -r 7520e2260097 portasm/portasm-x64.S --- a/portasm/portasm-x64.S Wed May 17 02:39:41 2017 +0200 +++ b/portasm/portasm-x64.S Sat May 20 00:02:59 2017 +0200 @@ -155,11 +155,5 @@ /* not available on some platforms, e.g. old solaris, so use K=V syntax # define SET(K,V) .set K,V */ # define SET(K,V) K = V # define LOCAL(X) .X -# if defined(ABI_ELF) && !defined(CC_SUN)/*syntax error*/ && !defined(OS_OpenBSD)/*does this by default, and better*/ && !defined(OS_DragonFlyBSD)/*does this by default, and better*/ -/* explicitly passing no args to mark stack nx */ -# define SECTION_NOTE_NXSTACK .section .note.GNU-stack,"",@progbits -# else -# define SECTION_NOTE_NXSTACK -# endif #endif diff -r 704c28fd9428 -r 7520e2260097 portasm/portasm-x86.S --- a/portasm/portasm-x86.S Wed May 17 02:39:41 2017 +0200 +++ b/portasm/portasm-x86.S Sat May 20 00:02:59 2017 +0200 @@ -126,11 +126,5 @@ # define FLDL(X) fldl X # define ADD(A,B) add A,B # define LOCAL(X) .X -# if defined(ABI_ELF) && !defined(CC_SUN)/*syntax error*/ && !defined(OS_OpenBSD)/*does this by default, and better*/ && !defined(OS_DragonFlyBSD)/*does this by default, and better*/ -/* explicitly passing no args to mark stack nx */ -# define SECTION_NOTE_NXSTACK .section .note.GNU-stack,"",@progbits -# else -# define SECTION_NOTE_NXSTACK -# endif #endif diff -r 704c28fd9428 -r 7520e2260097 test/resolve_self/Makefile.generic --- a/test/resolve_self/Makefile.generic Wed May 17 02:39:41 2017 +0200 +++ b/test/resolve_self/Makefile.generic Sat May 20 00:02:59 2017 +0200 @@ -3,6 +3,7 @@ SRCTOP = ${VPATH}/../.. BLDTOP = ../.. CFLAGS += -I${SRCTOP}/dynload +LDFLAGS += -rdynamic LDLIBS_D = -L${BLDTOP}/dynload -ldynload_s .PHONY: all clean install all: ${APP}