From b910b2f683329b9e8eb275d5a48f3a2c2b80f71e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mart=C3=ADn?= Date: Wed, 18 Jan 2023 22:40:02 +0100 Subject: [PATCH 1/2] Add csafe and cppsafe executables with sanitizers support --- sql/files/defaultdata/cppsafe/build | 2 ++ sql/files/defaultdata/cppsafe/run | 22 ++++++++++++++++++++++ sql/files/defaultdata/csafe/build | 2 ++ sql/files/defaultdata/csafe/run | 25 +++++++++++++++++++++++++ 4 files changed, 51 insertions(+) create mode 100755 sql/files/defaultdata/cppsafe/build create mode 100755 sql/files/defaultdata/cppsafe/run create mode 100755 sql/files/defaultdata/csafe/build create mode 100755 sql/files/defaultdata/csafe/run diff --git a/sql/files/defaultdata/cppsafe/build b/sql/files/defaultdata/cppsafe/build new file mode 100755 index 0000000000..3ad1806766 --- /dev/null +++ b/sql/files/defaultdata/cppsafe/build @@ -0,0 +1,2 @@ +#!/bin/sh +# nothing to compile diff --git a/sql/files/defaultdata/cppsafe/run b/sql/files/defaultdata/cppsafe/run new file mode 100755 index 0000000000..11a8fd0a52 --- /dev/null +++ b/sql/files/defaultdata/cppsafe/run @@ -0,0 +1,22 @@ +#!/bin/sh + +# C++ compile wrapper-script for 'compile.sh'. +# See that script for syntax and more info. + +DEST="$1" ; shift +MEMLIMIT="$1" ; shift + +# Add -DONLINE_JUDGE or -DDOMJUDGE below if you want it make easier for teams +# to do local debugging. + +# -x c++: Explicitly set compile language to C++ (no object files or +# other languages autodetected by extension) +# -Wall: Report all warnings +# -fsanitize: Enable the specified Sanitizers, see https://github.com/google/sanitizers for the full documentation +# -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls: Make code position independant and disable optimizations that may obfuscate the info provided by the +sanitizers +# -g: Include debugging/symbol information in the executable, improves sanitizers output if an error is detected +# -O2: Level 2 optimizations (default for speed) +# -pipe: Use pipes for communication between stages of compilation +g++ -x c++ -Wall -fsanitize=address,undefined -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -O2 -pipe -o "$DEST" "$@" +exit $? diff --git a/sql/files/defaultdata/csafe/build b/sql/files/defaultdata/csafe/build new file mode 100755 index 0000000000..3ad1806766 --- /dev/null +++ b/sql/files/defaultdata/csafe/build @@ -0,0 +1,2 @@ +#!/bin/sh +# nothing to compile diff --git a/sql/files/defaultdata/csafe/run b/sql/files/defaultdata/csafe/run new file mode 100755 index 0000000000..be8d9d72fe --- /dev/null +++ b/sql/files/defaultdata/csafe/run @@ -0,0 +1,25 @@ +#!/bin/sh + +# C compile wrapper-script for 'compile.sh'. +# See that script for syntax and more info. + +DEST="$1" ; shift +MEMLIMIT="$1" ; shift + +# Add -DONLINE_JUDGE or -DDOMJUDGE below if you want it make easier for teams +# to do local debugging. + +# -x c: Explicitly set compile language to C (no C++ nor object files +# autodetected by extension) +# -Wall: Report all warnings +# -fsanitize: Enable the specified Sanitizers, see https://github.com/google/sanitizers for the full documentation +# -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls: Make code position independant and disable optimizations that may obfuscate the info provided by the +sanitizers +# -g: Include debugging/symbol information in the executable, improves sanitizers output if an error is detected +# -O2: Level 2 optimizations (default for speed) +# -g have file names and line numbers included in warning messages +# -pipe: Use pipes for communication between stages of compilation +# -lm: Link with math-library (has to be last argument!) +export ASAN_OPTIONS=detect_leaks=1 +gcc -x c -Wall -fsanitize=address,undefined -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -O2 -pipe -o "$DEST" "$@" -lm +exit $? From 5858103bf0d3c29d036111ee32bfa80131ca5c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mart=C3=ADn?= Date: Wed, 18 Jan 2023 23:22:51 +0100 Subject: [PATCH 2/2] Fix typo and remove ASAN_OPTIONS as according to docs leak detection is already enabled by default when compiling for x86_64 Linux --- sql/files/defaultdata/cppsafe/run | 2 +- sql/files/defaultdata/csafe/run | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/sql/files/defaultdata/cppsafe/run b/sql/files/defaultdata/cppsafe/run index 11a8fd0a52..cd43a7c45d 100755 --- a/sql/files/defaultdata/cppsafe/run +++ b/sql/files/defaultdata/cppsafe/run @@ -13,7 +13,7 @@ MEMLIMIT="$1" ; shift # other languages autodetected by extension) # -Wall: Report all warnings # -fsanitize: Enable the specified Sanitizers, see https://github.com/google/sanitizers for the full documentation -# -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls: Make code position independant and disable optimizations that may obfuscate the info provided by the +# -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls: Make code position independent and disable optimizations that may obfuscate the info provided by the sanitizers # -g: Include debugging/symbol information in the executable, improves sanitizers output if an error is detected # -O2: Level 2 optimizations (default for speed) diff --git a/sql/files/defaultdata/csafe/run b/sql/files/defaultdata/csafe/run index be8d9d72fe..39e5fed98d 100755 --- a/sql/files/defaultdata/csafe/run +++ b/sql/files/defaultdata/csafe/run @@ -13,13 +13,12 @@ MEMLIMIT="$1" ; shift # autodetected by extension) # -Wall: Report all warnings # -fsanitize: Enable the specified Sanitizers, see https://github.com/google/sanitizers for the full documentation -# -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls: Make code position independant and disable optimizations that may obfuscate the info provided by the +# -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls: make code position independent and disable optimizations that may obfuscate the info provided by the sanitizers # -g: Include debugging/symbol information in the executable, improves sanitizers output if an error is detected # -O2: Level 2 optimizations (default for speed) # -g have file names and line numbers included in warning messages # -pipe: Use pipes for communication between stages of compilation # -lm: Link with math-library (has to be last argument!) -export ASAN_OPTIONS=detect_leaks=1 gcc -x c -Wall -fsanitize=address,undefined -fPIE -pie -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -O2 -pipe -o "$DEST" "$@" -lm exit $?