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; /* 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 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); } 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 */ 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 diff --git a/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c b/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c index ad89beaa76..502ba4d259 100644 --- a/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c +++ b/targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c @@ -207,7 +207,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__) const uint32_t __vector_table[] @ ".intvec" = { 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; 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; 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; diff --git a/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c b/targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c index 792d0eeb31..a851c655ed 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) @@ -190,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; 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; 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; 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 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); 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 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" = { 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"] + } +}