Created
September 27, 2023 14:37
-
-
Save ljmccarthy/eca3aa556c410f9941e82da70b468937 to your computer and use it in GitHub Desktop.
Run C programs for fun!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Run C programs for fun! | |
# | |
# Disables all optimizations, enables warnings, debug info and some hardening options. | |
# | |
if [ $# -lt 1 ]; then | |
echo "usage: $0 FILE.c" | |
exit 1 | |
fi | |
if [ -z "$CC" ]; then | |
CC=gcc | |
fi | |
SRC="$1" | |
DST="$(mktemp "$TMPDIR/${SRC%.*}-XXXXXXXX")" | |
shift | |
GCC_O0_OPTS_DISABLED=$("$CC" -Q -O0 --help=optimizers | awk -v ORS=" " '($1 ~ /^-f/) && ($2 ~ /enabled/) {print "-fno-" substr($1,3)}') | |
"$CC" -pipe -O0 -ggdb -std=c17 -Wall -Wextra -Wpedantic \ | |
-D_FORTIFY_SOURCE=3 -fPIE -pie -fstack-protector-strong -fstack-clash-protection $GCC_O0_OPTS_DISABLED \ | |
-o "$DST" "$SRC" && "$DST" "$@" | |
retval=$? | |
rm -f "$DST" | |
exit $retval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment