1
0
forked from me/IronOS

Enable -werror & wrap malloc

Preventing accidental use of dynamic memory
This commit is contained in:
Ben V. Brown
2020-05-30 11:39:58 +10:00
parent 341d7b1d5a
commit e422fe28ae
2 changed files with 49 additions and 62 deletions

View File

@@ -66,7 +66,6 @@ LDSCRIPT=LinkerScript.ld
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
COMPILER=gcc COMPILER=gcc
# arm-none is the general ARM compiler, # arm-none is the general ARM compiler,
# arm-atollic is the atollic customised compilers if you have them setup
COMPILER_PREFIX=arm-none COMPILER_PREFIX=arm-none
# programs --------------------------------------------------------------------- # programs ---------------------------------------------------------------------
CC=$(COMPILER_PREFIX)-eabi-gcc CC=$(COMPILER_PREFIX)-eabi-gcc
@@ -84,6 +83,8 @@ SREC_INFO=srec_info
# linker flags ----------------------------------------------------------------- # linker flags -----------------------------------------------------------------
LINKER_FLAGS=-Wl,--gc-sections \ LINKER_FLAGS=-Wl,--gc-sections \
-Wl,--wrap=malloc \
-Wl,--wrap=free \
-o$(OUT_HEXFILE).elf \ -o$(OUT_HEXFILE).elf \
-Wl,-Map=$(OUT_HEXFILE).map \ -Wl,-Map=$(OUT_HEXFILE).map \
-mcpu=cortex-m3 \ -mcpu=cortex-m3 \
@@ -128,7 +129,8 @@ CHECKOPTIONS= -Wall \
-Winline \ -Winline \
-Wshadow \ -Wshadow \
-Wno-unused-parameter \ -Wno-unused-parameter \
-Wdouble-promotion -Wdouble-promotion \
-Werror
CHECKOPTIONS_C= -Wbad-function-cast CHECKOPTIONS_C= -Wbad-function-cast

View File

@@ -9,9 +9,8 @@ BUILD_LANGUAGES=()
AVAILABLE_MODELS=("TS100" "TS80") AVAILABLE_MODELS=("TS100" "TS80")
BUILD_MODELS=() BUILD_MODELS=()
usage () usage() {
{ echo "Usage : $(basename "$0") [-l <LANG_CODE>] [-m <TS100|TS80>] [-h]
echo "Usage : $(basename "$0") [-l <LANG_CODE>] [-m <TS100|TS80>] [-h]
Parameters : Parameters :
-l LANG_CODE : Force a specific language (E.g. : EN, FR, NL_BE, ...) -l LANG_CODE : Force a specific language (E.g. : EN, FR, NL_BE, ...)
@@ -19,59 +18,53 @@ Parameters :
-h : Show this help message -h : Show this help message
INFO : By default, without parameters, the build is for all platforms and all languages" 1>&2 INFO : By default, without parameters, the build is for all platforms and all languages" 1>&2
exit 1 exit 1
} }
checkLastCommand () checkLastCommand() {
{ if [ $? -eq 0 ]; then
if [ $? -eq 0 ]
then
echo " [Success]" echo " [Success]"
echo "*********************************************" echo "*********************************************"
else else
forceExit forceExit
fi fi
} }
forceExit () forceExit() {
{
echo " [Error]" echo " [Error]"
echo "*********************************************" echo "*********************************************"
echo " -- Stop on error --" echo " -- Stop on error --"
exit 1 exit 1
} }
isInArray () isInArray() {
{
local value="$1" # Save first argument in a variable local value="$1" # Save first argument in a variable
shift # Shift all arguments to the left (original $1 gets lost) shift # Shift all arguments to the left (original $1 gets lost)
local array=("$@") # Rebuild the array with rest of arguments local array=("$@") # Rebuild the array with rest of arguments
for item in "${array[@]}" for item in "${array[@]}"; do
do
[[ $value == "$item" ]] && return 0 [[ $value == "$item" ]] && return 0
done done
return 1 return 1
} }
while getopts h:l:m: option while getopts h:l:m: option; do
do
case "${option}" in case "${option}" in
h) h)
usage usage
;; ;;
l) l)
LANGUAGEREQ=${OPTARG} LANGUAGEREQ=${OPTARG}
;; ;;
m) m)
MODEL=${OPTARG} MODEL=${OPTARG}
;; ;;
*) *)
usage usage
;; ;;
esac esac
done done
shift $((OPTIND-1)) shift $((OPTIND - 1))
echo "*********************************************" echo "*********************************************"
echo " Builder for the" echo " Builder for the"
@@ -82,27 +75,24 @@ echo " "
echo "*********************************************" echo "*********************************************"
# Calculate available languages # Calculate available languages
for f in "$TRANSLATION_DIR"/translation_*.json for f in "$TRANSLATION_DIR"/translation_*.json; do
do AVAILABLE_LANGUAGES+=($(echo $f | tr "[:lower:]" "[:upper:]" | sed "s/[^_]*_//" | sed "s/\.JSON//g"))
AVAILABLE_LANGUAGES+=(`echo $f | tr "[:lower:]" "[:upper:]" | sed "s/[^_]*_//" | sed "s/\.JSON//g"`) done
done
# Checking requested language # Checking requested language
echo "Available languages :" echo "Available languages :"
echo " ${AVAILABLE_LANGUAGES[*]}" echo " ${AVAILABLE_LANGUAGES[*]}"
echo "Requested languages :" echo "Requested languages :"
if [ -n "$LANGUAGEREQ" ] if [ -n "$LANGUAGEREQ" ]; then
then if isInArray "$LANGUAGEREQ" "${AVAILABLE_LANGUAGES[@]}"; then
if isInArray "$LANGUAGEREQ" "${AVAILABLE_LANGUAGES[@]}" echo " $LANGUAGEREQ"
then
echo " $LANGUAGEREQ"
BUILD_LANGUAGES+=("$LANGUAGEREQ") BUILD_LANGUAGES+=("$LANGUAGEREQ")
else else
echo " $LANGUAGEREQ doesn't exist" echo " $LANGUAGEREQ doesn't exist"
forceExit forceExit
fi fi
else else
echo " [ALL LANGUAGES]" echo " [ALL LANGUAGES]"
BUILD_LANGUAGES+=("${AVAILABLE_LANGUAGES[@]}") BUILD_LANGUAGES+=("${AVAILABLE_LANGUAGES[@]}")
fi fi
echo "*********************************************" echo "*********************************************"
@@ -111,26 +101,23 @@ echo "*********************************************"
echo "Available models :" echo "Available models :"
echo " ${AVAILABLE_MODELS[*]}" echo " ${AVAILABLE_MODELS[*]}"
echo "Requested models :" echo "Requested models :"
if [ -n "$MODEL" ] if [ -n "$MODEL" ]; then
then if isInArray "$MODEL" "${AVAILABLE_MODELS[@]}"; then
if isInArray "$MODEL" "${AVAILABLE_MODELS[@]}" echo " $MODEL"
then
echo " $MODEL"
BUILD_MODELS+=("$MODEL") BUILD_MODELS+=("$MODEL")
else else
echo " $MODEL doesn't exist" echo " $MODEL doesn't exist"
forceExit forceExit
fi fi
else else
echo " [ALL MODELS]" echo " [ALL MODELS]"
BUILD_MODELS+=("${AVAILABLE_MODELS[@]}") BUILD_MODELS+=("${AVAILABLE_MODELS[@]}")
fi fi
echo "*********************************************" echo "*********************************************"
if [ ${#BUILD_LANGUAGES[@]} -gt 0 ] && [ ${#BUILD_MODELS[@]} -gt 0 ] if [ ${#BUILD_LANGUAGES[@]} -gt 0 ] && [ ${#BUILD_MODELS[@]} -gt 0 ]; then
then
echo "Generating Translation.cpp" echo "Generating Translation.cpp"
python3 "$TRANSLATION_DIR/$TRANSLATION_SCRIPT" "$TRANSLATION_DIR" python3 "$TRANSLATION_DIR/$TRANSLATION_SCRIPT" "$TRANSLATION_DIR"
checkLastCommand checkLastCommand
echo "Cleaning previous builds" echo "Cleaning previous builds"
@@ -139,20 +126,18 @@ then
make clean >/dev/null make clean >/dev/null
checkLastCommand checkLastCommand
for model in "${BUILD_MODELS[@]}" for model in "${BUILD_MODELS[@]}"; do
do for lang in "${BUILD_LANGUAGES[@]}"; do
for lang in "${BUILD_LANGUAGES[@]}"
do
echo "Building firmware for $model in $lang" echo "Building firmware for $model in $lang"
make -j lang="$lang" model="$model" >/dev/null make -j lang="$lang" model="$model" >/dev/null
checkLastCommand
echo "Cleanup Temp files 1 for $model in $lang"
rm -rf Objects/Core >/dev/null
checkLastCommand checkLastCommand
echo "Cleanup Temp files 2 for $model in $lang" echo "Cleanup Temp files for $model in $lang"
rm -rf Objects/Src >/dev/null rm -rf Objects/Core/ >/dev/null
checkLastCommand checkLastCommand
done done
echo "Cleanup model change"
rm -rf Objects/ >/dev/null
checkLastCommand
done done
else else
echo "Nothing to build. (no model or language specified)" echo "Nothing to build. (no model or language specified)"