From 0780f89011c8306d02d36af0b0bc3bdd81d7abfe Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Thu, 14 Nov 2019 14:40:59 +0100 Subject: [PATCH 01/20] ARMC6: Enable link-time optimizer for release profile --- tools/profiles/release.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/profiles/release.json b/tools/profiles/release.json index 5ab3a58d73..59576a23d1 100644 --- a/tools/profiles/release.json +++ b/tools/profiles/release.json @@ -15,7 +15,7 @@ "-Wl,-n"] }, "ARMC6": { - "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz", + "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz", "-flto", "-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions", "-Wno-reserved-user-defined-literal", "-Wno-deprecated-register", "-DMULADDC_CANNOT_USE_R7", "-fdata-sections", @@ -25,7 +25,7 @@ "c": ["-D__ASSERT_MSG", "-std=gnu11"], "cxx": ["-fno-rtti", "-std=gnu++14"], "ld": ["--show_full_path", "--legacyalign", "--any_contingency", - "--keep=os_cb_sections"] + "--keep=os_cb_sections", "--lto", "--lto_level=Oz"] }, "ARM": { "common": ["-c", "--gnu", "-Ospace", "--split_sections", From 8fcb00cccd2476dc7852e4a5e07e1f89bd15474b Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Fri, 22 Nov 2019 13:00:08 +0100 Subject: [PATCH 02/20] ARMC6: Enable link-time optimizer for develop profile --- tools/profiles/develop.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/profiles/develop.json b/tools/profiles/develop.json index f8626d86f9..cd05490bcb 100644 --- a/tools/profiles/develop.json +++ b/tools/profiles/develop.json @@ -15,7 +15,7 @@ "-Wl,-n"] }, "ARMC6": { - "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Os", + "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Os", "-flto", "-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions", "-Wno-reserved-user-defined-literal", "-Wno-deprecated-register", "-DMULADDC_CANNOT_USE_R7", "-fdata-sections", @@ -25,7 +25,7 @@ "c": ["-D__ASSERT_MSG", "-std=gnu11"], "cxx": ["-fno-rtti", "-std=gnu++14"], "ld": ["--show_full_path", "--legacyalign", "--any_contingency", - "--keep=os_cb_sections"] + "--keep=os_cb_sections", "--lto", "--lto_level=Os"] }, "ARM": { "common": ["-c", "--gnu", "-Ospace", "--split_sections", From 28b1169b7ed6a32e668f458084c05869955708b2 Mon Sep 17 00:00:00 2001 From: Filip Jagodzinski Date: Tue, 26 Nov 2019 14:34:32 +0100 Subject: [PATCH 03/20] NUVOTON: Fix undefined reference to Reset_Handler_Cascade Add a "used" attribute to Reset_Handler_Cascade to fix GCC build with the "-flto" flag. This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. --- targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c b/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c index 792d0eeb31..0a6032a559 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c @@ -24,11 +24,13 @@ #if defined(__CC_ARM) #define WEAK __attribute__ ((weak)) #define ALIAS(f) __attribute__ ((weak, alias(#f))) +#define USED __attribute__ ((used)) #define WEAK_ALIAS_FUNC(FUN, FUN_ALIAS) \ void FUN(void) __attribute__ ((weak, alias(#FUN_ALIAS))); #elif defined(__ICCARM__) +#define USED __root //#define STRINGIFY(x) #x //#define _STRINGIFY(x) STRINGIFY(x) #define WEAK_ALIAS_FUNC(FUN, FUN_ALIAS) \ @@ -42,6 +44,7 @@ _Pragma(_STRINGIFY(_WEAK_ALIAS_FUNC(FUN, FUN_ALIAS))) #elif defined(__GNUC__) #define WEAK __attribute__ ((weak)) #define ALIAS(f) __attribute__ ((weak, alias(#f))) +#define USED __attribute__ ((used)) #define WEAK_ALIAS_FUNC(FUN, FUN_ALIAS) \ void FUN(void) __attribute__ ((weak, alias(#FUN_ALIAS))); @@ -77,7 +80,7 @@ void Default_Handler(void); void Reset_Handler(void); void Reset_Handler_1(void); void Reset_Handler_2(void); -void Reset_Handler_Cascade(void *sp, void *pc); +USED void Reset_Handler_Cascade(void *sp, void *pc); /* Cortex-M4 core handlers */ WEAK_ALIAS_FUNC(NMI_Handler, Default_Handler) From 8db3b40a7bf60828f24949eee55361fc6d8cc6dc Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 27 Nov 2019 08:40:56 +0100 Subject: [PATCH 04/20] STM: change rtc irq handler name Fix for the error caused by lto on armc6 compiler: L6137E: Symbol RTC_IRQHandler was not preserved by the LTO codegen but is needed by the image. lto optimization cause that local symbol RTC_IRQHandler(from rtc_api.c) somehow interferes with global symbol RTC_IRQHandler (from startup_stm32f070xb.S) Changing local RTC_IRQHandler to _RTC_IRQHandler fixes problem --- targets/TARGET_STM/rtc_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/targets/TARGET_STM/rtc_api.c b/targets/TARGET_STM/rtc_api.c index bd03002f7b..52b236bc5f 100644 --- a/targets/TARGET_STM/rtc_api.c +++ b/targets/TARGET_STM/rtc_api.c @@ -289,12 +289,12 @@ int rtc_isenabled(void) #if DEVICE_LPTICKER && !MBED_CONF_TARGET_LPTICKER_LPTIM -static void RTC_IRQHandler(void); +static void _RTC_IRQHandler(void); static void (*irq_handler)(void); volatile uint8_t lp_Fired = 0; -static void RTC_IRQHandler(void) +static void _RTC_IRQHandler(void) { /* Update HAL state */ RtcHandle.Instance = RTC; @@ -428,7 +428,7 @@ void rtc_set_wake_up_timer(timestamp_t timestamp) } #endif /* RTC_WUTR_WUTOCLR */ - NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_IRQHandler); + NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)_RTC_IRQHandler); irq_handler = (void (*)(void))lp_ticker_irq_handler; NVIC_EnableIRQ(RTC_WKUP_IRQn); core_util_critical_section_exit(); @@ -437,7 +437,7 @@ void rtc_set_wake_up_timer(timestamp_t timestamp) void rtc_fire_interrupt(void) { lp_Fired = 1; - NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_IRQHandler); + NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)_RTC_IRQHandler); irq_handler = (void (*)(void))lp_ticker_irq_handler; NVIC_SetPendingIRQ(RTC_WKUP_IRQn); NVIC_EnableIRQ(RTC_WKUP_IRQn); From 783953e5dc827f681923fee21eaf4b1e6a2f363f Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Fri, 29 Nov 2019 09:52:07 +0100 Subject: [PATCH 05/20] ARMC6 keep __user_setup_stackheap symbol when LTO enabled Fix for the error L6915E: Library reports error: Heap was used, but no heap region was defined --- platform/source/mbed_retarget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/source/mbed_retarget.cpp b/platform/source/mbed_retarget.cpp index a234a51764..9eab48fff0 100644 --- a/platform/source/mbed_retarget.cpp +++ b/platform/source/mbed_retarget.cpp @@ -1141,7 +1141,7 @@ extern "C" __value_in_regs struct __argc_argv $Sub$$__rt_lib_init(unsigned heapb } #endif -extern "C" __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) +MBED_USED extern "C" __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) { return _mbed_user_setup_stackheap(R0, R1, R2, R3); } From 63d14f3af4ffa4d4d6416cea3b25c6420fbed6f3 Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Fri, 29 Nov 2019 10:24:01 +0100 Subject: [PATCH 06/20] add dummy SUPER_REALLOC/CALLOC calls to alloc wrappers This code prevents the ARMC6 compiler/linker from removing SUB_REALLOC/CALLOC symbols from image when LTO is enabled Fixes below error: L6137E: Symbol $Sub$$calloc was not preserved by the LTO codegen but is needed by the image. --- platform/source/mbed_alloc_wrappers.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/platform/source/mbed_alloc_wrappers.cpp b/platform/source/mbed_alloc_wrappers.cpp index 91c412561b..a3c2844c85 100644 --- a/platform/source/mbed_alloc_wrappers.cpp +++ b/platform/source/mbed_alloc_wrappers.cpp @@ -347,6 +347,16 @@ extern "C" void *SUB_REALLOC(void *ptr, size_t size) memcpy(new_ptr, (void *)ptr, copy_size); free(ptr); } + + { + volatile uint8_t dummy = 0; + if (dummy != 0) { // always false + // this code will never be executed + // it's just to tell the compiler/linker to preserve SUB_REALLOC symbol + // when LTO enabled + SUPER_REALLOC(NULL, 0); + } + } #else // #if MBED_HEAP_STATS_ENABLED new_ptr = SUPER_REALLOC(ptr, size); #endif // #if MBED_HEAP_STATS_ENABLED @@ -369,6 +379,16 @@ extern "C" void *SUB_CALLOC(size_t nmemb, size_t size) if (ptr != NULL) { memset(ptr, 0, nmemb * size); } + + { + volatile uint8_t dummy = 0; + if (dummy != 0) { // always false + // this code will never be executed + // it's just to tell the compiler/linker to preserve SUB_CALLOC symbol + // when LTO enabled + SUPER_CALLOC(NULL, 0); + } + } #else // #if MBED_HEAP_STATS_ENABLED ptr = SUPER_CALLOC(nmemb, size); #endif // #if MBED_HEAP_STATS_ENABLED From a761ec57fd19d425dc8f12a7f99e43525d8f355b Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 09:08:53 +0100 Subject: [PATCH 07/20] CC3220SF_LAUNCHXL: keep ulDebugHeader symbol in LTO builds Add a "used" attribute to ulDebugHeader (placed in signature_section section) to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST. ) This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. --- .../TARGET_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/TARGET_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/TARGET_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c index 6500d968eb..77f80daeb7 100755 --- a/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/TARGET_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c +++ b/targets/TARGET_TI/TARGET_CC32XX/TARGET_CC3220SF/TARGET_CC3220SF_LAUNCHXL/CC3220SF_LAUNCHXL.c @@ -336,7 +336,7 @@ void CC3220SF_LAUNCHXL_initGeneral(void) } #if defined TOOLCHAIN_ARM -__attribute__((section("signature_section"))) +__attribute__((section("signature_section"), used)) #elif defined TOOLCHAIN_IAR #pragma default_variable_attributes = @ ".dbghdr" #elif defined TOOLCHAIN_GCC_ARM From 12261edd2b46eaa43c9a5a14602676da639347de Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 09:17:59 +0100 Subject: [PATCH 08/20] EV_COG_AD3029LZ: keep IVT_NAME/blank_checksum symbols in LTO builds Add a "used" attribute to IVT_NAME/blank_checksum to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST. ) This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. --- .../TARGET_EV_COG_AD3029LZ/device/startup_ADuCM3029.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/TARGET_EV_COG_AD3029LZ/device/startup_ADuCM3029.c b/targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/TARGET_EV_COG_AD3029LZ/device/startup_ADuCM3029.c index 8bc0ae8289..5ed935626a 100755 --- a/targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/TARGET_EV_COG_AD3029LZ/device/startup_ADuCM3029.c +++ b/targets/TARGET_Analog_Devices/TARGET_ADUCM302X/TARGET_ADUCM3029/TARGET_EV_COG_AD3029LZ/device/startup_ADuCM3029.c @@ -62,7 +62,9 @@ extern void SramInit(void); #if defined( __ICCARM__) __root -#endif /* __ICCARM__ */ +#else +__attribute__((used)) +#endif const uint32_t SECTION_PLACE(blank_checksum[],".checksum") = { BLANKX60,BLANKX600 @@ -139,6 +141,11 @@ WEAK_FUNCTION( DMA_SIP7_Int_Handler ) /*---------------------------------------------------------------------------- Exception / Interrupt Vector table *----------------------------------------------------------------------------*/ +#if defined( __ICCARM__) +__root +#else +__attribute__((used)) +#endif const pFunc SECTION_PLACE(IVT_NAME[104],VECTOR_SECTION) = { (pFunc) INITIAL_SP, /* Initial Stack Pointer */ From cf1e1ddd4b85ff410ee37e20b8cf3f2a4a563fbc Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 09:21:19 +0100 Subject: [PATCH 09/20] EV_COG_AD4050LZ: keep IVT_NAME/blank_checksum symbols in LTO builds Add a "used" attribute to IVT_NAME/blank_checksum to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST. ) This attribute, attached to a function, means that code must be emitted for the function even if it appears that the function is not referenced. --- .../TARGET_EV_COG_AD4050LZ/device/startup_ADuCM4050.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/TARGET_EV_COG_AD4050LZ/device/startup_ADuCM4050.c b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/TARGET_EV_COG_AD4050LZ/device/startup_ADuCM4050.c index c9ff9816e0..96cbd39135 100755 --- a/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/TARGET_EV_COG_AD4050LZ/device/startup_ADuCM4050.c +++ b/targets/TARGET_Analog_Devices/TARGET_ADUCM4X50/TARGET_ADUCM4050/TARGET_EV_COG_AD4050LZ/device/startup_ADuCM4050.c @@ -60,8 +60,10 @@ extern void SramInit(void); Checksum options *----------------------------------------------------------------------------*/ -#if defined(__ICCARM__) +#if defined( __ICCARM__) __root +#else +__attribute__((used)) #endif const uint32_t SECTION_PLACE(blank_checksum[],".checksum") = { @@ -144,6 +146,11 @@ WEAK_FUNCTION( Root_Clk_Err_Handler ) /*---------------------------------------------------------------------------- Exception / Interrupt Vector table *----------------------------------------------------------------------------*/ +#if defined( __ICCARM__) +__root +#else +__attribute__((used)) +#endif const pFunc SECTION_PLACE(IVT_NAME[104],VECTOR_SECTION) = { (pFunc) INITIAL_SP, /* Initial Stack Pointer */ ADUCM4050_VECTORS From 5fdacc4fb3a42413a38ec1a158f180784feef7ae Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 09:35:14 +0100 Subject: [PATCH 10/20] MIMXRT1050_EVt: keep hyperflash_config/image_vector_table symbols in LTO builds Add a "used" attribute to hyperflash_config/image_vector_table to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST. ) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- .../TARGET_EVK/xip/evkbimxrt1050_flexspi_nor_config.c | 2 +- .../TARGET_MIMXRT1050/drivers/fsl_flexspi_nor_boot.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/TARGET_EVK/xip/evkbimxrt1050_flexspi_nor_config.c b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/TARGET_EVK/xip/evkbimxrt1050_flexspi_nor_config.c index 3486c84963..1193ad7f37 100644 --- a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/TARGET_EVK/xip/evkbimxrt1050_flexspi_nor_config.c +++ b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/TARGET_EVK/xip/evkbimxrt1050_flexspi_nor_config.c @@ -17,7 +17,7 @@ ******************************************************************************/ #if defined(XIP_BOOT_HEADER_ENABLE) && (XIP_BOOT_HEADER_ENABLE == 1) #if defined(__CC_ARM) || defined(__ARMCC_VERSION) || defined(__GNUC__) -__attribute__((section(".boot_hdr.conf"))) +__attribute__((section(".boot_hdr.conf"), used)) #elif defined(__ICCARM__) #pragma location = ".boot_hdr.conf" #endif diff --git a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/drivers/fsl_flexspi_nor_boot.c b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/drivers/fsl_flexspi_nor_boot.c index 41b273f70b..09a59ed7c7 100644 --- a/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/drivers/fsl_flexspi_nor_boot.c +++ b/targets/TARGET_NXP/TARGET_MCUXpresso_MCUS/TARGET_MIMXRT1050/drivers/fsl_flexspi_nor_boot.c @@ -14,7 +14,7 @@ #if defined(XIP_BOOT_HEADER_ENABLE) && (XIP_BOOT_HEADER_ENABLE == 1) #if defined(__CC_ARM) || defined(__ARMCC_VERSION) || defined(__GNUC__) - __attribute__((section(".boot_hdr.ivt"))) + __attribute__((section(".boot_hdr.ivt"), used)) #elif defined(__ICCARM__) #pragma location=".boot_hdr.ivt" #endif From ec839f0931a69bb22566188f9477cfc3f6adb97e Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 09:38:58 +0100 Subject: [PATCH 11/20] MSP432_LAUNCHPAD: keep interruptVectors symbol in LTO builds Add a "used" attribute to interruptVectors to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST. ) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- .../TARGET_MSP432P401R/device/startup_msp432p401r.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_TI/TARGET_MSP432/TARGET_MSP432P401R/device/startup_msp432p401r.c b/targets/TARGET_TI/TARGET_MSP432/TARGET_MSP432P401R/device/startup_msp432p401r.c index 1afa191a34..1ae6f4a667 100644 --- a/targets/TARGET_TI/TARGET_MSP432/TARGET_MSP432P401R/device/startup_msp432p401r.c +++ b/targets/TARGET_TI/TARGET_MSP432/TARGET_MSP432P401R/device/startup_msp432p401r.c @@ -156,7 +156,7 @@ WEAK_ALIAS_FUNC(EUSCIB3_SPI_IRQHandler, Default_Handler) // to ensure that it ends up at physical address 0x0000.0000 or at the start of the // program if located at a start address other than 0. #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) -void (* const interruptVectors[])(void) __attribute__((section("RESET"))) = { +void (* const interruptVectors[])(void) __attribute__((section("RESET"), used)) = { (pFunc) &Image$$ARM_LIB_STACK$$ZI$$Limit, // The initial stack pointer #elif defined(__ICCARM__) void (* const __vector_table[])(void) @ ".intvec" = { From 9aade4a816455b758d6211bc7ce2dd931c1598d8 Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 09:42:44 +0100 Subject: [PATCH 12/20] NUMAKER_IOT_M263A: keep __vector_handlers symbol in LTO builds Add a "used" attribute to __vector_handlers to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST. ) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- targets/TARGET_NUVOTON/TARGET_M261/device/startup_M261.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M261/device/startup_M261.c b/targets/TARGET_NUVOTON/TARGET_M261/device/startup_M261.c index 9af13c61ac..58a328e60d 100644 --- a/targets/TARGET_NUVOTON/TARGET_M261/device/startup_M261.c +++ b/targets/TARGET_NUVOTON/TARGET_M261/device/startup_M261.c @@ -193,7 +193,7 @@ WEAK_ALIAS_FUNC(TRNG_IRQHandler, Default_Handler) // 101: /* Vector table */ #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) -__attribute__ ((section("RESET"))) +__attribute__ ((section("RESET"), used)) const uint32_t __vector_handlers[] = { #elif defined(__ICCARM__) extern uint32_t CSTACK$$Limit; From f0dc4abb3ff09ee678acf0174759c98175922012 Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 09:58:40 +0100 Subject: [PATCH 13/20] NUMAKER_M252KG: keep __vector_handlers symbol in LTO builds Add a "used" attribute to __vector_handlers to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST. ) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- targets/TARGET_NUVOTON/TARGET_M251/device/startup_M251.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M251/device/startup_M251.c b/targets/TARGET_NUVOTON/TARGET_M251/device/startup_M251.c index a4e0c39ab0..662c23931d 100644 --- a/targets/TARGET_NUVOTON/TARGET_M251/device/startup_M251.c +++ b/targets/TARGET_NUVOTON/TARGET_M251/device/startup_M251.c @@ -155,7 +155,7 @@ WEAK_ALIAS_FUNC(OPA_IRQHandler, Default_Handler) // 62: OPA Interrupt /* Vector table */ #if defined(__ARMCC_VERSION) -__attribute__ ((section("RESET"))) +__attribute__ ((section("RESET"), used)) const uint32_t __vector_handlers[] = { #elif defined(__ICCARM__) extern uint32_t CSTACK$$Limit; From ddd2cf8920cf3dabe1c2745af9e01845d874036b Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 10:07:37 +0100 Subject: [PATCH 14/20] NUMAKER_PFM_M453: keep __vector_handlers symbol in LTO builds Add a "used" attribute to __vector_handlers to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST.) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- targets/TARGET_NUVOTON/TARGET_M451/device/startup_M451Series.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M451/device/startup_M451Series.c b/targets/TARGET_NUVOTON/TARGET_M451/device/startup_M451Series.c index 2c4752992e..67b0bd98c2 100644 --- a/targets/TARGET_NUVOTON/TARGET_M451/device/startup_M451Series.c +++ b/targets/TARGET_NUVOTON/TARGET_M451/device/startup_M451Series.c @@ -152,7 +152,7 @@ WEAK_ALIAS_FUNC(TK_IRQHandler, Default_Handler) // 63: /* Vector table */ #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) -__attribute__ ((section("RESET"))) +__attribute__ ((section("RESET"), used)) const uint32_t __vector_handlers[] = { #elif defined(__ICCARM__) extern uint32_t CSTACK$$Limit; From ad7f27bf7793e2f4a09a3d9271039757b7e7a632 Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 10:14:26 +0100 Subject: [PATCH 15/20] NUMAKER_PFM_NANO130: keep __vector_handlers symbol in LTO builds Add a "used" attribute to __vector_handlers to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST.) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- .../TARGET_NANO100/device/startup_Nano100Series.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_NUVOTON/TARGET_NANO100/device/startup_Nano100Series.c b/targets/TARGET_NUVOTON/TARGET_NANO100/device/startup_Nano100Series.c index da4379dd34..57f1f81e87 100644 --- a/targets/TARGET_NUVOTON/TARGET_NANO100/device/startup_Nano100Series.c +++ b/targets/TARGET_NUVOTON/TARGET_NANO100/device/startup_Nano100Series.c @@ -114,7 +114,7 @@ WEAK_ALIAS_FUNC(RTC_IRQHandler, Default_Handler) // Real time clock i /* Vector table */ #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) -__attribute__ ((section("RESET"))) +__attribute__ ((section("RESET"), used)) const uint32_t __vector_handlers[] = { #elif defined(__ICCARM__) extern uint32_t CSTACK$$Limit; From 50c3b100a8e71504422b335985686f24f2bfa038 Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 10:17:05 +0100 Subject: [PATCH 16/20] NUMAKER_PFM_NUC472: keep __vector_handlers symbol in LTO builds Add a "used" attribute to __vector_handlers to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST.) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- .../TARGET_NUVOTON/TARGET_NUC472/device/startup_NUC472_442.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_NUVOTON/TARGET_NUC472/device/startup_NUC472_442.c b/targets/TARGET_NUVOTON/TARGET_NUC472/device/startup_NUC472_442.c index bde25dc172..883d2500ea 100644 --- a/targets/TARGET_NUVOTON/TARGET_NUC472/device/startup_NUC472_442.c +++ b/targets/TARGET_NUVOTON/TARGET_NUC472/device/startup_NUC472_442.c @@ -232,7 +232,7 @@ WEAK_ALIAS_FUNC(CRC_IRQHandler, Default_Handler) // 141: CRC /* Vector table */ #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) -__attribute__ ((section("RESET"))) +__attribute__ ((section("RESET"), used)) const uint32_t __vector_handlers[] = { #elif defined(__ICCARM__) extern uint32_t CSTACK$$Limit; From 6d896f032f65b856da0ad581cf9974eaece0a892 Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 10:19:23 +0100 Subject: [PATCH 17/20] NU_PFM_M2351_NPSA: keep __vector_handlers symbol in LTO builds Add a "used" attribute to __vector_handlers to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST.) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c b/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c index 5045697770..fdac4da8d2 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c @@ -192,7 +192,7 @@ WEAK_ALIAS_FUNC(TRNG_IRQHandler, Default_Handler) // 101: /* Vector table */ #if defined(__ARMCC_VERSION) -__attribute__ ((section("RESET"))) +__attribute__ ((section("RESET"), used)) const uint32_t __vector_handlers[] = { #elif defined(__ICCARM__) #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) && (TFM_LVL > 0) From e3b8514a915a2d4e008ded743d2449f1a0e56ebe Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 09:55:40 +0100 Subject: [PATCH 18/20] NUMAKER_IOT_M487: keep __vector_handlers symbols in LTO builds Add a "used" attribute to __vector_handlers to fix ARMC6 build with the "-flto" flag. (Error: L6236E: No section matches selector - no section to be FIRST/LAST. ) This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c b/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c index 0a6032a559..a851c655ed 100644 --- a/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c +++ b/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c @@ -193,7 +193,7 @@ WEAK_ALIAS_FUNC(ETMC_IRQHandler, Default_Handler) // 95: /* Vector table */ #if defined(__CC_ARM) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) -__attribute__ ((section("RESET"))) +__attribute__ ((section("RESET"), used)) const uint32_t __vector_handlers[] = { #elif defined(__ICCARM__) extern uint32_t CSTACK$$Limit; From 57ac6c83d68e3dbbca7415e06b8df8743196e51d Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Wed, 4 Dec 2019 14:04:30 +0100 Subject: [PATCH 19/20] component PSA: keep SVCHandler_main/tfm_pendsv_do_schedule symbol in LTO builds Add a "used" attribute to SVCHandler_main/tfm_pendsv_do_schedule to fix ARMC6 build with the "-flto" flag. This attribute, attached to a function/variable, means that code must be emitted for the function even if it appears that the function is not referenced. --- .../TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c | 3 ++- .../TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_handler.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c index 30210d940b..5ee30a614e 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/ipc/tfm_spm.c @@ -27,6 +27,7 @@ #include "region_defs.h" #include "tfm_nspm.h" #include "tfm_memory_utils.h" +#include "platform/mbed_toolchain.h" /* * IPC partitions. @@ -580,7 +581,7 @@ void tfm_spm_init(void) tfm_thrd_start_scheduler(&this_thrd); } -void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb) +MBED_USED void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb) { #if TFM_LVL == 2 struct spm_partition_desc_t *p_next_partition; diff --git a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_handler.c b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_handler.c index 10a91a56dd..79caca211c 100644 --- a/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_handler.c +++ b/components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/core/tfm_handler.c @@ -19,6 +19,7 @@ #include #include "tfm_svcalls.h" #endif +#include "platform/mbed_toolchain.h" /* This SVC handler is called when a secure partition requests access to a * buffer area @@ -135,7 +136,7 @@ __attribute__((naked)) void SVC_Handler(void) #error "Unsupported ARM Architecture." #endif -uint32_t SVCHandler_main(uint32_t *svc_args, uint32_t lr) +MBED_USED uint32_t SVCHandler_main(uint32_t *svc_args, uint32_t lr) { uint8_t svc_number; /* From 083e3e569dde2f804c86953f1ef72a981731956c Mon Sep 17 00:00:00 2001 From: Maciej Bocianski Date: Tue, 28 Jan 2020 14:41:44 +0100 Subject: [PATCH 20/20] armc6: make lto an optional profile --- tools/profiles/develop.json | 4 ++-- tools/profiles/extensions/lto.json | 6 ++++++ tools/profiles/release.json | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 tools/profiles/extensions/lto.json diff --git a/tools/profiles/develop.json b/tools/profiles/develop.json index cd05490bcb..f8626d86f9 100644 --- a/tools/profiles/develop.json +++ b/tools/profiles/develop.json @@ -15,7 +15,7 @@ "-Wl,-n"] }, "ARMC6": { - "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Os", "-flto", + "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Os", "-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions", "-Wno-reserved-user-defined-literal", "-Wno-deprecated-register", "-DMULADDC_CANNOT_USE_R7", "-fdata-sections", @@ -25,7 +25,7 @@ "c": ["-D__ASSERT_MSG", "-std=gnu11"], "cxx": ["-fno-rtti", "-std=gnu++14"], "ld": ["--show_full_path", "--legacyalign", "--any_contingency", - "--keep=os_cb_sections", "--lto", "--lto_level=Os"] + "--keep=os_cb_sections"] }, "ARM": { "common": ["-c", "--gnu", "-Ospace", "--split_sections", diff --git a/tools/profiles/extensions/lto.json b/tools/profiles/extensions/lto.json new file mode 100644 index 0000000000..59366afb32 --- /dev/null +++ b/tools/profiles/extensions/lto.json @@ -0,0 +1,6 @@ +{ + "ARMC6": { + "common": ["-flto"], + "ld": ["--lto", "--lto_level=Oz"] + } +} diff --git a/tools/profiles/release.json b/tools/profiles/release.json index 59576a23d1..5ab3a58d73 100644 --- a/tools/profiles/release.json +++ b/tools/profiles/release.json @@ -15,7 +15,7 @@ "-Wl,-n"] }, "ARMC6": { - "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz", "-flto", + "common": ["-c", "--target=arm-arm-none-eabi", "-mthumb", "-Oz", "-Wno-armcc-pragma-push-pop", "-Wno-armcc-pragma-anon-unions", "-Wno-reserved-user-defined-literal", "-Wno-deprecated-register", "-DMULADDC_CANNOT_USE_R7", "-fdata-sections", @@ -25,7 +25,7 @@ "c": ["-D__ASSERT_MSG", "-std=gnu11"], "cxx": ["-fno-rtti", "-std=gnu++14"], "ld": ["--show_full_path", "--legacyalign", "--any_contingency", - "--keep=os_cb_sections", "--lto", "--lto_level=Oz"] + "--keep=os_cb_sections"] }, "ARM": { "common": ["-c", "--gnu", "-Ospace", "--split_sections",