Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e9compile fixes #76

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions e9compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

if [ -t 1 ]
then
RED="\033[31m"
GREEN="\033[32m"
YELLOW="\033[33m"
BOLD="\033[1m"
OFF="\033[0m"
RED=$'\033[31m'
GREEN=$'\033[32m'
YELLOW=$'\033[33m'
BOLD=$'\033[1m'
OFF=$'\033[0m'
else
RED=
GREEN=
Expand Down Expand Up @@ -51,51 +51,55 @@ case "$1" in
;;
*)
echo >&2
echo "${RED}error${OFF}: file $1 must have a .c/.cpp/.s extension" >&2
echo "${RED}error${OFF}: file ${1@Q} must have a .c/.cpp/.s extension" >&2
echo >&2
exit 1
;;
esac
BASENAME=`basename $1 .$EXTENSION`
DIRNAME=`dirname $1`
SOURCE="$1"
BASENAME="$(basename "$1" .$EXTENSION)"
DIRNAME="$(dirname "$1")"

shift

CFLAGS="-fno-stack-protector -fno-builtin -fno-exceptions \
-fpie -O2 -Wno-unused-function -U_FORTIFY_SOURCE \
-mno-mmx -mno-sse -mno-avx -mno-avx2 -mno-avx512f -msoft-float \
-mstringop-strategy=loop -fno-tree-vectorize -fomit-frame-pointer \
-I examples/"
COMPILE="$CC $CFLAGS -c -Wall $@ \"$DIRNAME/$BASENAME.$EXTENSION\""
CFLAGS=(
-fno-stack-protector -fno-builtin -fno-exceptions
-fpie -O2 -Wno-unused-function -U_FORTIFY_SOURCE
-mno-mmx -mno-sse -mno-avx -mno-avx2 -mno-avx512f -msoft-float
-mstringop-strategy=loop -fno-tree-vectorize -fomit-frame-pointer
)
COMPILE=("$CC" "${CFLAGS[@]}" -c -Wall "$@" "$SOURCE")

echo "$COMPILE" | xargs
if ! eval "$COMPILE"
echo "${COMPILE[@]}"
if ! "${COMPILE[@]}"
then
echo >&2
echo "${RED}error${OFF}: compilation of (${YELLOW}$BASENAME${OFF}) failed" >&2
echo >&2
exit 1
fi

CFLAGS="-pie -nostdlib \
-Wl,-z -Wl,max-page-size=4096 \
-Wl,-z -Wl,norelro \
-Wl,-z -Wl,stack-size=0 \
-Wl,--export-dynamic \
-Wl,--entry=0x0 \
-Wl,--strip-all"
COMPILE="$CC \"$BASENAME.o\" -o \"$BASENAME\" $CFLAGS"
CFLAGS=(
-pie -nostdlib
-Wl,-z -Wl,max-page-size=4096
-Wl,-z -Wl,norelro
-Wl,-z -Wl,stack-size=0
-Wl,--export-dynamic
-Wl,--entry=0x0
-Wl,--strip-all
)
COMPILE=("$CC" "$BASENAME.o" -o "$BASENAME" "${CFLAGS[@]}")

echo "$COMPILE" | xargs
if ! eval "$COMPILE"
echo "${COMPILE[@]}"
if ! "${COMPILE[@]}"
then
echo >&2
echo "${RED}error${OFF}: linking (${YELLOW}$BASENAME${OFF}) failed" >&2
echo >&2
exit 1
fi

RELOCS=`readelf -r "$BASENAME" | head -n 10 | grep 'R_X86_64_'`
RELOCS=$(readelf -r "$BASENAME" | head -n 10 | grep 'R_X86_64_')
if [ ! -z "$RELOCS" ]
then
echo >&2
Expand All @@ -122,7 +126,7 @@ fi

if [ "$NO_SIMD_CHECK" = "" ]
then
SIMD=`objdump -d "$BASENAME" | grep -E '%(x|y|z)mm[0-9]' | head -n 10`
SIMD=$(objdump -d "$BASENAME" | grep -E '%(x|y|z)mm[0-9]' | head -n 10)
if [ ! -z "$SIMD" ]
then
echo >&2
Expand Down