#!/bin/sh
# SPDX-FileCopyrightText: 2021 John Scott <jscott@posteo.net>
# SPDX-License-Identifier: GPL-3.0-or-later

sh-elf-gcc -o "$AUTOPKGTEST_TMP"/stack-smashing-protected debian/tests/stack-smashing.c -fstack-protector-all -Wno-stringop-overflow 2>&1 || exit 1
sh-elf-gcc -o "$AUTOPKGTEST_TMP"/stack-smashing-noprotect debian/tests/stack-smashing.c -fno-stack-protector -Wno-stringop-overflow 2>&1 || exit 1
cd "$AUTOPKGTEST_TMP"
# Check that we get a different exit status when the stack protector is enabled.
sh-elf-run ./stack-smashing-noprotect
oldstat=$?

sh-elf-run ./stack-smashing-protected
if [ $? -eq $oldstat ]
then
	echo Unable to distinguish the stack protector being enabled >&2
	exit 1
fi

