Skip to content

ARMC6: Add a build profile extension with the link-time optimizer enabled #11874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0780f89
ARMC6: Enable link-time optimizer for release profile
Nov 14, 2019
8fcb00c
ARMC6: Enable link-time optimizer for develop profile
Nov 22, 2019
28b1169
NUVOTON: Fix undefined reference to Reset_Handler_Cascade
fkjagodzinski Nov 26, 2019
8db3b40
STM: change rtc irq handler name
maciejbocianski Nov 27, 2019
783953e
ARMC6 keep __user_setup_stackheap symbol when LTO enabled
maciejbocianski Nov 29, 2019
63d14f3
add dummy SUPER_REALLOC/CALLOC calls to alloc wrappers
maciejbocianski Nov 29, 2019
a761ec5
CC3220SF_LAUNCHXL: keep ulDebugHeader symbol in LTO builds
maciejbocianski Dec 4, 2019
12261ed
EV_COG_AD3029LZ: keep IVT_NAME/blank_checksum symbols in LTO builds
maciejbocianski Dec 4, 2019
cf1e1dd
EV_COG_AD4050LZ: keep IVT_NAME/blank_checksum symbols in LTO builds
maciejbocianski Dec 4, 2019
5fdacc4
MIMXRT1050_EVt: keep hyperflash_config/image_vector_table symbols in …
maciejbocianski Dec 4, 2019
ec839f0
MSP432_LAUNCHPAD: keep interruptVectors symbol in LTO builds
maciejbocianski Dec 4, 2019
9aade4a
NUMAKER_IOT_M263A: keep __vector_handlers symbol in LTO builds
maciejbocianski Dec 4, 2019
f0dc4ab
NUMAKER_M252KG: keep __vector_handlers symbol in LTO builds
maciejbocianski Dec 4, 2019
ddd2cf8
NUMAKER_PFM_M453: keep __vector_handlers symbol in LTO builds
maciejbocianski Dec 4, 2019
ad7f27b
NUMAKER_PFM_NANO130: keep __vector_handlers symbol in LTO builds
maciejbocianski Dec 4, 2019
50c3b10
NUMAKER_PFM_NUC472: keep __vector_handlers symbol in LTO builds
maciejbocianski Dec 4, 2019
6d896f0
NU_PFM_M2351_NPSA: keep __vector_handlers symbol in LTO builds
maciejbocianski Dec 4, 2019
e3b8514
NUMAKER_IOT_M487: keep __vector_handlers symbols in LTO builds
maciejbocianski Dec 4, 2019
57ac6c8
component PSA: keep SVCHandler_main/tfm_pendsv_do_schedule symbol in …
maciejbocianski Dec 4, 2019
083e3e5
armc6: make lto an optional profile
maciejbocianski Jan 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "region_defs.h"
#include "tfm_nspm.h"
#include "tfm_memory_utils.h"
#include "platform/mbed_toolchain.h"

/*
* IPC partitions.
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <stdbool.h>
#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
Expand Down Expand Up @@ -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;
/*
Expand Down
20 changes: 20 additions & 0 deletions platform/source/mbed_alloc_wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm being dense, but why aren't these calls using SUPER_REALLOC and SUPER_CALLOC anyway? Why are they messing around re-implementing them?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see the point - if you did use them, you'd have to reimplement the stuff in your malloc wrapper. Probably a bit bigger overall.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how that fix actually works, mind - so you've inserted a (sort-of) call to the $$Super, but how does that persuade the LTO to retain the $$Sub?

Or maybe that activates a magic heuristic in the compiler - if a function calls any $$Super, assume it's referenced? Hmm. But then why not treat any $$Sub as referenced?

Can you explain how you got to this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesbeyond found that difference between SUB_CALLOC/REALOC and SUB_MALLOC/FREE

And then by the analogy I have added dummy SUPER_CALLOC/REALOC calls inside SUB_CALLOC/REALOC

}
}
#else // #if MBED_HEAP_STATS_ENABLED
new_ptr = SUPER_REALLOC(ptr, size);
#endif // #if MBED_HEAP_STATS_ENABLED
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion platform/source/mbed_retarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") =
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion targets/TARGET_NUVOTON/TARGET_M2351/device/startup_M2351.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion targets/TARGET_NUVOTON/TARGET_M251/device/startup_M251.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion targets/TARGET_NUVOTON/TARGET_M261/device/startup_M261.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions targets/TARGET_NUVOTON/TARGET_M480/device/startup_M480.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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)));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions targets/TARGET_STM/rtc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" = {
Expand Down
6 changes: 6 additions & 0 deletions tools/profiles/extensions/lto.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ARMC6": {
"common": ["-flto"],
"ld": ["--lto", "--lto_level=Oz"]
}
}