From 355713c3c9b5db773cc2ee84f89bf69ca677ade0 Mon Sep 17 00:00:00 2001 From: cancel Date: Fri, 30 Nov 2018 20:29:31 +0900 Subject: [PATCH] Add PIE/ASLR flag option for build tool --- tool | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tool b/tool index 15864fe..07e1dea 100755 --- a/tool +++ b/tool @@ -21,6 +21,7 @@ Options: -d Enable compiler safeguards like -fstack-protector. You should probably do this if you plan to give the compiled binary to other people. + -p Enable PIE (ASLR) -s Print statistics about compile time and binary size. -h or --help Print this message and exit. EOF @@ -40,8 +41,9 @@ cc_exe="${CC:-cc}" verbose=0 protections_enabled=0 stats_enabled=0 +pie_enabled=0 -while getopts c:dhsv-: opt_val; do +while getopts c:dhpsv-: opt_val; do case "$opt_val" in -) case "$OPTARG" in @@ -54,8 +56,9 @@ while getopts c:dhsv-: opt_val; do esac ;; c) cc_exe="$OPTARG";; - h) print_usage; exit 0;; d) protections_enabled=1;; + h) print_usage; exit 0;; + p) pie_enabled=1;; s) stats_enabled=1;; v) verbose=1;; \?) print_usage >&2; exit 1;; @@ -161,7 +164,10 @@ build_target() { add cc_flags -fuse-ld=lld fi if [[ $protections_enabled = 1 ]]; then - add cc_flags -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fpie + add cc_flags -D_FORTIFY_SOURCE=2 -fstack-protector-strong + fi + if [[ $pie_enabled = 1 ]]; then + add cc_flags -fpie if [[ $lld_detected = 1 ]]; then # LLD seems to need this or it fails at linking. If we also pass -Wl,-pie # then the built binary will crash before reaching main().