diff options
author | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
---|---|---|
committer | Ben Cheng <bccheng@google.com> | 2014-03-25 22:37:19 -0700 |
commit | 1bc5aee63eb72b341f506ad058502cd0361f0d10 (patch) | |
tree | c607e8252f3405424ff15bc2d00aa38dadbb2518 /gcc-4.9/libvtv/scripts | |
parent | 283a0bf58fcf333c58a2a92c3ebbc41fb9eb1fdb (diff) | |
download | toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.gz toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.tar.bz2 toolchain_gcc-1bc5aee63eb72b341f506ad058502cd0361f0d10.zip |
Initial checkin of GCC 4.9.0 from trunk (r208799).
Change-Id: I48a3c08bb98542aa215912a75f03c0890e497dba
Diffstat (limited to 'gcc-4.9/libvtv/scripts')
-rw-r--r-- | gcc-4.9/libvtv/scripts/run-testsuite.sh | 226 | ||||
-rw-r--r-- | gcc-4.9/libvtv/scripts/sum-vtv-counts.c | 150 |
2 files changed, 376 insertions, 0 deletions
diff --git a/gcc-4.9/libvtv/scripts/run-testsuite.sh b/gcc-4.9/libvtv/scripts/run-testsuite.sh new file mode 100644 index 000000000..a02ce1562 --- /dev/null +++ b/gcc-4.9/libvtv/scripts/run-testsuite.sh @@ -0,0 +1,226 @@ +#!/usr/bin/env bash + +# Script to do testing. + +# Invocation +# run-testsuite SRC_DIR BUILD_DIR + +# Pass in build/src directory as parameters. +SRC_DIR=$1 +BUILD_DIR=$2 + +# Now that we've successfully translated the numerical option into +# a symbolic one, we can safely ignore it. +shift + +# Use build compiler/library flags from libstdc++ +flags_script=$BUILD_DIR/../libstdc++-v3/scripts/testsuite_flags +INCLUDES=`$flags_script --build-includes` +COMPILER=`$flags_script --build-cxx` +CXX="$COMPILER $INCLUDES -L$BUILD_DIR/.libs -Wl,--rpath -Wl,$BUILD_DIR/.libs" + +echo "compiler config is:" +echo $CXX +echo "" + +# Other constants. +LOPT_LEVELS=${OPT_LEVELS:-"-O0 -O2"} +#LDATA_MODELS=${DATA_MODELS:-"32 64"} +LDATA_MODELS=${DATA_MODELS:-"64"} + +# Check if value of LGCC_LIB_PATH/$1 exists. If it does, save this path. +# If it doesn't, use LGCC_LIB_PATH as the library path. +# This allows us to check for paths that are of the form <x>/lib32 or <x>/lib64. +get_lib_path() +{ + if [[ -e $LGCC_LIB_PATH$1 ]]; then + LLGCC_LIB_PATH=$LGCC_LIB_PATH$1 + else + LLGCC_LIB_PATH=$LGCC_LIB_PATH + fi + return +} + +LGCC_SRC=$SRC_DIR/testsuite + +TESTS="const_vtable.cc dataentry.cc dup_name.cc environment.cc template-list.cc template-list2.cc template-list-iostream.cc povray-derived.cc thunk.cc thunk_vtable_map_attack.cc virtual_inheritance.cc " + +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for T in $TESTS; do + TSRC=${LGCC_SRC}/${T} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fvtable-verify=std -fpic -rdynamic -Wl,-z,relro ${TSRC} ${OL}" + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 ) && echo "PASS $T $OL") || echo "FAIL $T $OL" + done + done +done + +TESTS_COMPOUND_parts="${LGCC_SRC}/parts-test-main.cc ${LGCC_SRC}/parts-test-extra-parts.cc ${LGCC_SRC}/parts-test-extra-parts-views.cc" +TESTS_COMPOUND_events="${LGCC_SRC}/event-main.cc ${LGCC_SRC}/event-definitions.cc ${LGCC_SRC}/event-private.cc" + +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fvtable-verify=std -fpic -rdynamic -Wl,-z,relro ${TESTS_COMPOUND_parts} ${OL}" + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 ) && echo "PASS $T $OL") || echo "FAIL $T $OL" + done +done + +for M in $LDATA_MODELS; do + for (( TN = 0 ; TN < 100 ; TN++ )); do + SO_NAME=so$TN.so + if [ -f ./lib${M}/$SO_NAME ]; then + /bin/rm ./lib${M}/$SO_NAME + fi + CMD="${CXX} -m${M} -fvtable-verify=std -O0 -g -shared -fpic -rdynamic -Wl,-z,relro -DTPID=$TN -I${SRC_DIR} ${LGCC_SRC}/so.cc -o ./lib${M}/$SO_NAME" + echo ${CMD} + ${CMD} || exit 8 + done +done + +DLOPEN_TESTS="dlopen.cc dlopen_mt.cc" + +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for T in $DLOPEN_TESTS; do + TSRC=${LGCC_SRC}/${T} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fvtable-verify=std -fpic -rdynamic -Wl,-z,relro -Wl,-R,./lib${M} -I${SRC_DIR} ${TSRC} ${OL} -ldl -lpthread" + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 ) && echo "PASS $T $OL") || echo "FAIL $T $OL" + done + done +done + +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for T in $TESTS; do + TSRC=${LGCC_SRC}/${T} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fvtable-verify=preinit -fpic -rdynamic -Wl,-z,relro ${TSRC} ${OL}" + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 ) && echo "PASS $T $OL") || echo "FAIL $T $OL" + done + done +done + +for M in $LDATA_MODELS; do + if [ -f ./lib${M}/vtv_malloc.o ]; then + /bin/rm ./lib${M}/vtv_malloc.o; + fi + CMD="${CXX} -m${M} -O2 -g -c -fpic ${SRC_DIR}/vtv_malloc.cc -o ./lib${M}/vtv_malloc.o" + echo ${CMD} + ${CMD} || exit 3 + + if [ -f ./lib${M}/vtv_utils.o ]; then + /bin/rm ./lib${M}/vtv_utils.o; + fi + CMD="${CXX} -m${M} -O2 -g -c -fpic ${SRC_DIR}/vtv_utils.cc -o ./lib${M}/vtv_utils.o" + echo ${CMD} + ${CMD} || exit 4 +done + +MEMPOOL_TESTS="mempool_positive.c mempool_negative.c" + +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for T in $MEMPOOL_TESTS; do + TSRC=${LGCC_SRC}/${T} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fpic -rdynamic -I${SRC_DIR} ${TSRC} ${OL} ./lib${M}/vtv_malloc.o ./lib${M}/vtv_utils.o" + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 ) && echo "PASS $T $OL") || echo "FAIL $T $OL" + done + done +done + +# bkoz not working ATM signature mismatch +#MT_TESTS="register_pair_mt.cc register_pair_inserts_mt.cc" +MT_TESTS= +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for T in $MT_TESTS; do + TSRC=${LGCC_SRC}/${T} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fpic -rdynamic -I${SRC_DIR} ${TSRC} ${OL} -lpthread" + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 ) && echo "PASS $T $OL") || echo "FAIL $T $OL" + done + done +done + +# These test cases were written for performance measurements, not for +# correctness but lets run them here so that we dont loose track of +# them +# bkoz not working ATM signature mismatch +#PERF_TESTS="register_pair.cc register_pair_inserts.cc" +PERF_TESTS= +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for T in $PERF_TESTS; do + TSRC=${LGCC_SRC}/${T} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fpic -rdynamic -I${SRC_DIR} ${TSRC} ${OL} " + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 ) && echo "PASS $T $OL") || echo "FAIL $T $OL" + done + done +done + + +PASS_FAIL_TESTS="field-test.cc temp_deriv.cc temp_deriv2.cc temp_deriv3.cc" + +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for T in $PASS_FAIL_TESTS; do + TSRC=${LGCC_SRC}/${T} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fvtable-verify=std -fpic -rdynamic ${TSRC} ${OL} -Wl,-z,relro -DTPID" + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 )) || (( grep "Pass first attack" $T.$OL.out ) && echo "PASS $T $OL - correctly passed then failed.") || echo "FAIL $T $OL" + done + done +done + +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for T in $PERF_TESTS; do + TSRC=${LGCC_SRC}/${T} + for OL in $LOPT_LEVELS; do + CMD="${CXX} -m${M} -fpic -rdynamic -I${SRC_DIR} ${TSRC} ${OL} " + echo $CMD + ($CMD && ( ./a.out > $T.$OL.out 2>&1 ) && echo "PASS $T $OL") || echo "FAIL $T $OL" + done + done +done + +for M in $LDATA_MODELS; do + get_lib_path lib${M} + for OL in $LOPT_LEVELS; do + + CMD="as --${M} -o environment-fail-${M}.o ${LGCC_SRC}/environment-fail-${M}.s" + echo $CMD + ${CMD} || exit 5 + + CMD="${CXX} -m${M} environment-fail-${M}.o -O0 -Wl,-z,relro -o environment-fail-${M}" + echo ${CMD} + # ${CMD} || exit 6 + # (./environment-fail-${M}) || echo "PASS environment-fail-${M} (correctly failed), ${OL}" + + CMD="${CXX} -fvtable-verify=std -m${M} environment-fail-${M}.o -O0 -Wl,-z,relro -o environment-fail-${M}" + echo ${CMD} + ($CMD && ( ./environment-fail-${M} > environment-fail-${M}-stubs.out 2>&1 ) && echo "PASS environment-fail-${M} with libvtv_stubs ${OL}" ) || echo "FAIL environment-fail-${M} with libvtv_stubs ${OL}" + + CMD="${CXX} -m${M} ${LGCC_SRC}/replace-fail.cc -O0 -c -o replace-fail-${M}.o" + echo ${CMD} + ${CMD} || exit 7 + + CMD="${CXX} -fvtable-verify=std -m${M} environment-fail-${M}.o replace-fail-${M}.o -O0 -Wl,-z,relro -o environment-fail-${M}" + echo ${CMD} + ($CMD && ( ./environment-fail-${M} > environment-fail-${M}-stubs.out 2>&1 ) && echo "PASS environment-fail-${M} with replace-fail ${OL}" ) || echo "FAIL environment-fail-${M} with replace-fail ${OL}" + done +done + diff --git a/gcc-4.9/libvtv/scripts/sum-vtv-counts.c b/gcc-4.9/libvtv/scripts/sum-vtv-counts.c new file mode 100644 index 000000000..fc99498e7 --- /dev/null +++ b/gcc-4.9/libvtv/scripts/sum-vtv-counts.c @@ -0,0 +1,150 @@ +/* +This script sums up the counters for seeing how many virtual calls are +actually being verified. The flag for generating the count data is +"-fvtv-counts". This flag will generate two files in /tmp, +"vtv_count_data.log" and "vtv_class_set_sizes.log". The first file is +the one that contains the info I mentioned; the second one is one I +generated because I was curious about how big the average set size was +for the vtable verification work. + +After compiling the attached program, run it on the vtv_count_data.log +file: + +$ sum-counters /tmp/vtv_count_data.log + +One can optionally pass a "--verbose" flag. This file generates an +output file whose name is the same as the input file, with ".summary" +appended to it, e.g. /tmp/vtv_count_data.log.summary . Without the +verbose flag, it will just contain something like this: + +Total # virtual calls: 349123 +Total # verified calls: 348236 +Percent verified: 99 % + +Total calls to __VLTRegisterSet: 42236 +Total calls to __VLTRegisterPair: 84371 +Total # unused vtable map vars: 1536333 + +With the --verbose flag it will also output one line for each +compilation unit for which it verified less than 90% of the virtual +calls (and there were more than 20 virtual calls in the file), +something like this: + +Verified 1 out of 25 (4.00%) : foo.cc +Verified 27 out of 43 (62.00%) : bar.cc +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void +usage (const char *error_text) +{ + fprintf (stderr, "%s", error_text); + fprintf (stderr, "Usage: \n"); + fprintf (stderr, "sum-counters <input-file> [--verbose]\n"); +} + +int +main (int argc, char **argv) +{ + FILE *fp_in = NULL; + FILE *fp_out = NULL; + int sum_vcalls = 0; + int sum_verified = 0; + int sum_regset = 0; + int sum_regpair = 0; + int sum_unused = 0; + char fname_in[1024]; + char fname_out[1024]; + int total; + int verified; + int regset; + int regpair; + int unused; + float pct; + char buffer[1024]; + int verbose = 0; + + if (argc < 2) + { + usage ("Error: Need an input file.\n"); + return 1; + } + + fp_in = fopen (argv[1], "r"); + if (!fp_in) + { + snprintf (buffer, 1024, "Error: Unable to open input file '%s'.\n", + argv[1]); + usage (buffer); + return 1; + } + + if (argc == 3) + { + if (strcmp (argv[2], "--verbose") == 0) + verbose = 1; + else + { + snprintf (buffer, 1024, "Error: Unrecognized option '%s'.\n", + argv[2]); + usage (buffer); + return 1; + } + } + + snprintf (fname_out, 1024, "%s.summary", argv[1]); + + fp_out = fopen (fname_out, "w"); + if (!fp_out) + { + fprintf (stderr, "Error: Unable to open output file '%s'\n", + fname_out); + return 1; + } + + while (fscanf (fp_in, "%s %d %d %d %d %d\n", fname_in, &total, + &verified, ®set, ®pair, &unused) != EOF) + { + sum_vcalls += total; + sum_verified += verified; + sum_regset += regset; + sum_regpair += regpair; + sum_unused += unused; + + float tmp_pct = 0.0; + + if (total > 0) + tmp_pct = (verified * 100) / total; + + if (verbose && tmp_pct < 90 && total >= 20) + { + fprintf (fp_out, "Verified %d out of %d (%.2f%%) : %s\n", + verified, total, tmp_pct, fname_in); + } + + } + + fclose (fp_in); + + fprintf (fp_out, "\n\n"); + fprintf (fp_out, "Total # virtual calls: %d\n", sum_vcalls); + fprintf (fp_out, "Total # verified calls: %d\n", sum_verified); + if (sum_vcalls > 0) + fprintf (fp_out, "Percent verified: %d %%\n", + sum_verified * 100 / sum_vcalls); + else + fprintf (fp_out, "Percent verified: NA %%\n"); + + fprintf (fp_out, "\nTotal calls to __VLTRegisterSet: %d\n", + sum_regset); + fprintf (fp_out, "Total calls to __VLTRegisterPair: %d\n", + sum_regpair); + fprintf (fp_out, "Total # unused vtable map vars: %d\n", sum_unused); + + fclose (fp_out); + + return 0; +} |