Blob Blame History Raw
#!/bin/bash

# Copyright (c) 2018-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.


# Test building an assembler source file without creating a gap in the notes.

rm -f hello.o hello2.o hello3.o
rm -f gap1.o assembler-gap-test1.exe assembler-gas-test1.out
rm -f gap2.o assembler-gap-test2.exe assembler-gas-test2.out

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

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

# Assemble the file, and include debug information which will
# identify the producer as being AS.

$GAS --gdwarf-2 $srcdir/gap.S -o gap1.o

# Compile a C source file as well, so that we end up with a binary
# that was partially built by GCC, and partially not.  Note - we
# are not using all of the hardening options as we want to be sure
# that annocheck will notice.

$GCC -fplugin=$PLUGIN $PLUGIN_OPTS -c -O2 -fPIC $srcdir/hello.c 
$GCC -fplugin=$PLUGIN $PLUGIN_OPTS -c -O2 -fPIC $srcdir/hello2.c 
$GCC -fplugin=$PLUGIN $PLUGIN_OPTS -c -O2 -fPIC $srcdir/hello3.c 

# Put our assemblt file between C files, so that the gap will be noticed.
$GCC -nostartfiles -e 0 hello.o hello2.o gap1.o hello3.o -o assembler-gap-test1.exe \
     -Wl,--defsym,extern_func3=0 \
     -Wl,-z,now -pie

$ANNOCHECK -v -v --enable-builtby --all assembler-gap-test1.exe > assembler-gap-test1.out

# FAIL if a gap is NOT reported
grep --silent -e "Gaps were detected" assembler-gap-test1.out
if [ $? != 0 ];
then
    echo "assembler-gap-test: FAIL: GAP *not* found in notes:"
    cat assembler-gap-test1.out
    exit 1
fi

# Repeat the test, but this time, instead of generating debug inofrmation
# generate a note.

$GAS --generate-missing-build-notes=yes $srcdir/gap.S -o gap2.o
if [ $? != 0 ];
then
    echo "Assembler does not support generating build notes.  Skipping test."
    exit 0
fi

$GCC -nostartfiles -e 0 hello.o hello2.o gap2.o hello3.o -o assembler-gap-test2.exe \
     -Wl,--defsym,extern_func3=0 \
     -Wl,-z,now -pie

$ANNOCHECK -v assembler-gap-test2.exe > assembler-gap-test2.out

# FAIL if a gap is NOT reported
grep --silent -e "No gaps found" assembler-gap-test2.out
if [ $? != 0 ];
then
    echo "assembler-gap-test: FAIL: GAP found in notes:"
    cat assembler-gap-test2.out
    exit 1
fi