diff --git a/core/embed/bootloader/main.c b/core/embed/bootloader/main.c index 6b39d669a..f9522893c 100644 --- a/core/embed/bootloader/main.c +++ b/core/embed/bootloader/main.c @@ -21,6 +21,7 @@ #include #include "common.h" +#include "compiler_traits.h" #include "display.h" #include "flash.h" #include "image.h" @@ -36,20 +37,6 @@ #include "messages.h" // #include "mpu.h" -/* - * Avoid accidental build with gcc versions having broken stack protector 9.2.1 - 10.2 - */ -#if defined(__GNUC__) && !defined(__llvm__) - -#define GCC_VERSION (__GNUC__ * 10000 \ - + __GNUC_MINOR__ * 100 \ - + __GNUC_PATCHLEVEL__) - -#if GCC_VERSION >= 90201 && GCC_VERSION <= 100200 -#error "ARM GCC versions 9.2.1 - 10.2 have broken stack smash protector, preventing build" -#endif -#endif - const uint8_t BOOTLOADER_KEY_M = 2; const uint8_t BOOTLOADER_KEY_N = 3; static const uint8_t * const BOOTLOADER_KEYS[] = { diff --git a/core/embed/firmware/main.c b/core/embed/firmware/main.c index 4e0909fdf..6f3f2030c 100644 --- a/core/embed/firmware/main.c +++ b/core/embed/firmware/main.c @@ -38,6 +38,7 @@ #include "bl_check.h" #include "button.h" #include "common.h" +#include "compiler_traits.h" #include "display.h" #include "flash.h" #include "mpu.h" @@ -53,20 +54,6 @@ // from util.s extern void shutdown_privileged(void); -/* - * Avoid accidental build with gcc versions having broken stack protector 9.2.1 - 10.2 - */ -#if defined(__GNUC__) && !defined(__llvm__) - -#define GCC_VERSION (__GNUC__ * 10000 \ - + __GNUC_MINOR__ * 100 \ - + __GNUC_PATCHLEVEL__) - -#if GCC_VERSION >= 90201 && GCC_VERSION <= 100200 -#error "ARM GCC versions 9.2.1 - 10.2 have broken stack smash protector, preventing build" -#endif -#endif - int main(void) { random_delays_init(); diff --git a/core/embed/trezorhal/compiler_traits.h b/core/embed/trezorhal/compiler_traits.h new file mode 100644 index 000000000..c5b46345d --- /dev/null +++ b/core/embed/trezorhal/compiler_traits.h @@ -0,0 +1,38 @@ +/* + * This file is part of the Trezor project, https://trezor.io/ + * + * Copyright (c) SatoshiLabs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __COMPILER_TRAITS_H__ +#define __COMPILER_TRAITS_H__ + +/* + * Avoid accidental build with gcc versions having broken stack protector 9.2.1 - 10.2 + */ +#if defined(__GNUC__) && !defined(__llvm__) + +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if GCC_VERSION >= 90201 && GCC_VERSION <= 100200 +#pragma message "Only remove this GCC check if you are sure your compiler is patched or not used for production." +#error "ARM GCC versions 9.2.1 - 10.2 have broken stack smash protector, aborting build." +#endif +#endif + +#endif diff --git a/legacy/bootloader/bootloader.c b/legacy/bootloader/bootloader.c index 005e999b6..c6eaaa91d 100644 --- a/legacy/bootloader/bootloader.c +++ b/legacy/bootloader/bootloader.c @@ -25,6 +25,7 @@ #include "bootloader.h" #include "buttons.h" +#include "compiler_traits.h" #include "layout.h" #include "memory.h" #include "oled.h" diff --git a/legacy/compiler_traits.h b/legacy/compiler_traits.h new file mode 100644 index 000000000..8fb6908df --- /dev/null +++ b/legacy/compiler_traits.h @@ -0,0 +1,39 @@ +/* + * This file is part of the Trezor project, https://trezor.io/ + * + * Copyright (c) SatoshiLabs + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef __COMPILER_TRAITS_H__ +#define __COMPILER_TRAITS_H__ + +/* + * Avoid accidental build with gcc versions having broken stack protector 9.2.1 - 10.2 + */ +#if defined(__GNUC__) && !defined(__llvm__) + +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if GCC_VERSION >= 90201 && GCC_VERSION <= 100200 +#pragma message "Only remove this GCC check if you are sure your compiler is patched or not used for production." +#error "ARM GCC versions 9.2.1 - 10.2 have broken stack smash protector, aborting build." +#endif +#endif + +#endif + diff --git a/legacy/firmware/trezor.c b/legacy/firmware/trezor.c index 831cf1edd..c21902cf6 100644 --- a/legacy/firmware/trezor.c +++ b/legacy/firmware/trezor.c @@ -22,6 +22,7 @@ #include "bl_check.h" #include "buttons.h" #include "common.h" +#include "compiler_traits.h" #include "config.h" #include "gettext.h" #include "layout.h" @@ -38,20 +39,6 @@ #include "otp.h" #endif -/* - * Avoid accidental build with gcc versions having broken stack protector 9.2.1 - 10.2 - */ -#if defined(__GNUC__) && !defined(__llvm__) - -#define GCC_VERSION (__GNUC__ * 10000 \ - + __GNUC_MINOR__ * 100 \ - + __GNUC_PATCHLEVEL__) - -#if GCC_VERSION >= 90201 && GCC_VERSION <= 100200 -#error "ARM GCC versions 9.2.1 - 10.2 have broken stack smash protector, preventing build" -#endif -#endif - /* Screen timeout */ uint32_t system_millis_lock_start = 0;