Blob Blame History Raw
#!/bin/bash

# Copyright (c) 2017-2019 Red Hat.
#
# This is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 3, or (at your
# option) any later version.
#
# It is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

rm -f hello.o hello2.o hello3.o libhello.so hardening-fail-test.exe

GCC=${GCC:-gcc}
READELF=${READELF:-readelf}
OBJCOPY=${OBJCOPY:-objcopy}
ANNOCHECK=${ANNOCHECK:-../annocheck/annocheck}
PLUGIN=${PLUGIN:-../gcc-plugin/.libs/annobin.so}

PLUGIN_OPTS="-fplugin-arg-annobin-no-attach"

OPTS="-c -O2 -D_FORTIFY_SOURCE=2 -fpie -Wall -fstack-protector-strong -D_GLIBCXX_ASSERTIONS -fstack-clash-protection"

$GCC -fplugin=$PLUGIN $PLUGIN_OPTS -c $OPTS $srcdir/hello.c -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
$GCC -fplugin=$PLUGIN $PLUGIN_OPTS -c $OPTS $srcdir/hello2.c -U_GLIBCXX_ASSERTIONS
$GCC -fplugin=$PLUGIN $PLUGIN_OPTS -c $OPTS $srcdir/hello3.c -fno-stack-protector -fshort-enums
$GCC -fplugin=$PLUGIN $PLUGIN_OPTS -c $OPTS $srcdir/hello_lib.c -O1

$GCC hello.o hello2.o hello3.o hello_lib.o -o hardening-fail-test.exe -Wl,-z,norelro

$ANNOCHECK hardening-fail-test.exe

# FIXME: Add regexps to check for the expected failure messages