Blob Blame History Raw
#!/bin/bash

# Copyright (c) 2017-2020 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 abi-test.exe

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

PLUGIN_OPTS="-fplugin-arg-annobin-no-attach"
OPTS="-O2 -D_FORTIFY_SOURCE=2 -fPIE -fstack-protector-strong -D_GLIBCXX_ASSERTIONS -fstack-clash-protection"

$GCC -fplugin=$PLUGIN $PLUGIN_OPTS $OPTS \
     -g -c \
     -fno-stack-protector \
     -fplugin-arg-annobin-stack-threshold=0x10 \
  $srcdir/hello.c 

$GCC -fplugin=$PLUGIN $PLUGIN_OPTS $OPTS \
     -O3 -c \
     -fno-stack-protector \
     -fplugin-arg-annobin-global-file-syms \
   $srcdir/hello2.c 

$GCC -fplugin=$PLUGIN $PLUGIN_OPTS $OPTS \
     -g3 -c \
     -fplugin-arg-annobin-no-stack-size-notes \
     -grecord-gcc-switches \
  $srcdir/hello3.c \

$GCC -fplugin=$PLUGIN $PLUGIN_OPTS $OPTS \
    -shared \
  $srcdir/hello_lib.c \
     -o libhello.so

$GCC \
     -L . -pie \
     -Wl,-z,now,-z,relro \
 hello.o hello2.o hello3.o -lhello -o abi-test.exe

# $OBJCOPY --merge-notes abi-test.exe abi-test-merged.exe

# The --ignore-FORTIFY and --ignore-stack-prot options are here to skip the
# checks that fail because the startup and end files (Scrti.o, crtn.o) are
# built without these safeguards, whereas the test files use them.  Similarly
# the --ignore-ABI option is because these two files are compiled with different
# ABI settings from normal code.
#
# The --ignore-gaps option is there because currently Scrti.o contains some
# annobin notes, but crti.o dies not.  Thus *any* program built with normal
# startup code will contain a gap.
# FIXME: Remove once we have the assembler generating notes.
$srcdir/../scripts/check-abi  --readelf=$READELF --inconsistencies \
				--ignore-FORTIFY --ignore-stack-prot \
				--ignore-gaps --ignore-ABI \
				abi-test.exe