diff --git a/.gitattributes b/.gitattributes index b3b26584d21ddf63a449b884168582fefc23aa30..84ccc7117c34977a1e1de87cb4534feff2fd11f6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -147,6 +147,7 @@ examples/dumbledore_cmd.c -text examples/integerbug.c -text examples/mul/generate_cprogs.sh -text examples/mul/mul.ctmpl -text +examples/mul/mul.shtmpl -text examples/overflow1.c -text examples/test1.c -text libIRDB/Makefile -text diff --git a/examples/mul/generate_cprogs.sh b/examples/mul/generate_cprogs.sh index 4ee93dfb94072a776a4a11852c163c43a1e59033..185c51e3158e4fbc3f5ed84c51b95167692e847f 100755 --- a/examples/mul/generate_cprogs.sh +++ b/examples/mul/generate_cprogs.sh @@ -1,7 +1,60 @@ #!/bin/bash #types="char short int long unsigned+char unsigned+short unsigned+int unsigned+long"; -types="int char" +types="char short" +sharedlib_gccflags="-O -O2 -fomit-frame-pointer" + +#types="int char" + +# +# The flags passed to the compiler +# +# note use of + to denote multiple parameters together. +# (but you can't use + as an argument to gcc.) +# + +create_test() +{ + my_benchname=$1 + my_benchflag=$2 + my_gccflag=$3 + my_libtype=$4 + + # + # demangle the internal representation of the benchflags and gcc flags + # substitute a + with a space + # + real_benchflag=`echo $my_benchflag | sed "s/+/ /g"` + real_gccflag=`echo $my_gccflag | sed "s/+/ /g"` + + # + # mangle the benchflags and gccflags for filename display. + # + disp_benchflag=$my_benchflag + disp_gccflag=$my_gccflag + + # + # if the name is empty, reset to a nice string for naming. Note: This means you should not use "empty" as a parameter. + # + if [ $my_benchflag"X" = "X" ]; then disp_benchflag="nobenchflag"; fi; + if [ $my_gccflag"X" = "X" ]; then disp_gccflag="nogccflag"; fi; + + scriptname=$my_benchname.$disp_gccflag.$disp_benchflag.test.sh + + # + # demangle the internal representation of the benchflags and gcc flags + # substitute a + with a space + # + real_gccflag=`echo $my_gccflag | sed "s/+/ /g"` + + cat mul.shtmpl | \ + sed "s/@BENCHNAME@/$my_benchname/g" | \ + sed "s/@LIBTYPE@/$my_libtype/g" | \ + sed "s/@COMPFLAGS@/$real_gccflag/g" \ + > $scriptname + + added_files="$scriptname $added_files" +} create_prog() { @@ -29,7 +82,7 @@ create_prog() "unsigned+long") format_specifier="%ul" ;; esac - # create the program. + # create the source .c program. cat mul.ctmpl | \ sed "s/#FUNCTION_NAME#/$function_name/g" | \ sed "s/#FORMAT_SPECIFIER#/$format_specifier/g" | \ @@ -37,9 +90,11 @@ create_prog() sed "s/#TYPE2#/$real_type2/g" \ > $progname.c - gcc -w $progname.c -o $progname.orig.exe - - $PEASOUP_HOME/tools/ps_analyze.sh $progname.orig.exe $progname.protected.exe --step ilr=off --step p1transform=off --step concolic=off + for gccflag in $sharedlib_gccflags + do + create_test $progname_c "" "$gccflag" shared_lib + done + } for type1 in $types @@ -48,6 +103,11 @@ do do progname_c=mul.$type1.$type2 # actually create the .c program - create_prog $progname_c "$type1" "$type2" static_lib + create_prog $progname_c "$type1" "$type2" + done done + +chmod +x *.sh + +echo "would have added: $added_files" diff --git a/examples/mul/mul.shtmpl b/examples/mul/mul.shtmpl new file mode 100755 index 0000000000000000000000000000000000000000..b404df783064ab91b01017c547618360c164a36c --- /dev/null +++ b/examples/mul/mul.shtmpl @@ -0,0 +1,84 @@ +#!/bin/sh + +# Assumptions: +# $1 is the full pathname to output file + + +# For PEASOUP, Required XML fields are +# name - name of the test +# host - name of the host where the test was run +# project - project name +# date_time - date time in specific format date +%FT%R:%S +# key_value pairs, any number +# may include result, user, host platform, build platform + + +# Fixed attributes +# ATTRIBUTE ModDep=strata +# ATTRIBUTE ModDep=diablo_toolchain +# ATTRIBUTE ModDep=binutils-2.19 +# ATTRIBUTE ModDep=stratafier +# ATTRIBUTE ModDep=idapro51 +# ATTRIBUTE ModDep=idapro51_sdk +# ATTRIBUTE TestsWhat=lang_C +# ATTRIBUTE TestsWhat=strata +# ATTRIBUTE TestsWhat=interoverflow +# ATTRIBUTE TestsWhat=@LIBTYPE@ +# ATTRIBUTE OS=linux +# ATTRIBUTE BenchmarkSuite=IntegerOverflow +# ATTRIBUTE Compiler=gcc +# ATTRIBUTE Arch=x86_32 + +# Filled in by test generator +# ATTRIBUTE TestName="@BENCHNAME@.c" +# ATTRIBUTE BenchmarkName=@BENCHNAME@ +# ATTRIBUTE CompilerFlags="@COMPFLAGS@" + +BENCHNAME=@BENCHNAME@ +COMPFLAGS="@COMPFLAGS@" + +outfile=$1 + +cleanup() +{ + exit_code=$1 + shift + msg=$* + + if [ $exit_code -ne 0 ]; then + report_test_failure $outfile "Intermediate step failed, exit code is $exit_code, msg='$msg'" + fi + + basename_orig=`basename $orig .ncexe` + + rm -f $orig strata.$$ tmp1.$$ stratafier.o.exe $orig.annot $orig.{log,SMPobjdump} $basename_orig.{idb,asm} + exit $exit_code +} + +# suck in utils +. ${TEST_HARNESS_HOME}/test_utils.sh || cleanup 1 "Cannot source utils file" + +assert_test_args $* +assert_test_env $outfile STRATAFIER STRATA TOOLCHAIN STRATAFIER_OBJCOPY IDAROOT IDASDK + +# path to source +testloc=`pwd` + +orig=orig$$.exe + +# compile +gcc ${testloc}/$BENCHNAME.c $COMPFLAGS -o $orig || cleanup 2 "gcc failed" + +# sanity check compile +if [ ! -f $orig ]; then cleanup 3 "Failed to create $orig"; fi + +$PEASOUP_HOME/tools/ps_analyze.sh $orig $orig.protected --step ilr=off --step p1transform=off --step concolic=off + +${testloc}/$orig.protected | grep -i "overflow detected" +if [ ! $? -eq 0 ]; then + report_test_failure $outfile "Did not detect overflow" || cleanup 4 "Reporting failed?" +fi + +# cleanup +cleanup 0 "Success!" +