From c4b4156fcf63665b70094aa948520ad8778af684 Mon Sep 17 00:00:00 2001 From: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com> Date: Wed, 10 Jun 2020 10:03:11 -0700 Subject: [PATCH] Fix out of offset errors when LTO is enabled (#71) When Link Time Optimization (LTO) is enabled, some of the LDR instructions result in out of range access. The reason is that the default generated literal pool is too far and not within the permissible range of 4K. This commit adds LTORG assembly instructions at required places to ensure that access to literals remain in the permissible range of 4K. Signed-off-by: Gaurav Aggarwal --- portable/GCC/ARM_CM3/port.c | 1 + portable/GCC/ARM_CM3_MPU/port.c | 1 + portable/GCC/ARM_CM4F/port.c | 4 +++- portable/GCC/ARM_CM4_MPU/port.c | 4 +++- portable/GCC/ARM_CM7/r0p1/port.c | 4 +++- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/portable/GCC/ARM_CM3/port.c b/portable/GCC/ARM_CM3/port.c index 535926067..d37802a70 100644 --- a/portable/GCC/ARM_CM3/port.c +++ b/portable/GCC/ARM_CM3/port.c @@ -247,6 +247,7 @@ static void prvPortStartFirstTask( void ) " isb \n" " svc 0 \n" /* System call to start first task. */ " nop \n" + " .ltorg \n" ); } /*-----------------------------------------------------------*/ diff --git a/portable/GCC/ARM_CM3_MPU/port.c b/portable/GCC/ARM_CM3_MPU/port.c index 5693a2ff7..a22ce529d 100644 --- a/portable/GCC/ARM_CM3_MPU/port.c +++ b/portable/GCC/ARM_CM3_MPU/port.c @@ -451,6 +451,7 @@ BaseType_t xPortStartScheduler( void ) " isb \n" " svc %0 \n" /* System call to start first task. */ " nop \n" + " .ltorg \n" :: "i" (portSVC_START_SCHEDULER) : "memory" ); /* Should not get here! */ diff --git a/portable/GCC/ARM_CM4F/port.c b/portable/GCC/ARM_CM4F/port.c index 9e1d1a891..2dd152536 100644 --- a/portable/GCC/ARM_CM4F/port.c +++ b/portable/GCC/ARM_CM4F/port.c @@ -277,6 +277,7 @@ static void prvPortStartFirstTask( void ) " isb \n" " svc 0 \n" /* System call to start first task. */ " nop \n" + " .ltorg \n" ); } /*-----------------------------------------------------------*/ @@ -707,7 +708,8 @@ static void vPortEnableVFP( void ) " \n" " orr r1, r1, #( 0xf << 20 ) \n" /* Enable CP10 and CP11 coprocessors, then save back. */ " str r1, [r0] \n" - " bx r14 " + " bx r14 \n" + " .ltorg \n" ); } /*-----------------------------------------------------------*/ diff --git a/portable/GCC/ARM_CM4_MPU/port.c b/portable/GCC/ARM_CM4_MPU/port.c index 5f9697cea..447d39feb 100644 --- a/portable/GCC/ARM_CM4_MPU/port.c +++ b/portable/GCC/ARM_CM4_MPU/port.c @@ -480,6 +480,7 @@ BaseType_t xPortStartScheduler( void ) " isb \n" " svc %0 \n" /* System call to start first task. */ " nop \n" + " .ltorg \n" :: "i" (portSVC_START_SCHEDULER) : "memory" ); /* Should not get here! */ @@ -630,7 +631,8 @@ static void vPortEnableVFP( void ) " \n" " orr r1, r1, #( 0xf << 20 ) \n" /* Enable CP10 and CP11 coprocessors, then save back. */ " str r1, [r0] \n" - " bx r14 " + " bx r14 \n" + " .ltorg \n" ); } /*-----------------------------------------------------------*/ diff --git a/portable/GCC/ARM_CM7/r0p1/port.c b/portable/GCC/ARM_CM7/r0p1/port.c index e13edf94d..1d7df2b75 100644 --- a/portable/GCC/ARM_CM7/r0p1/port.c +++ b/portable/GCC/ARM_CM7/r0p1/port.c @@ -271,6 +271,7 @@ static void prvPortStartFirstTask( void ) " isb \n" " svc 0 \n" /* System call to start first task. */ " nop \n" + " .ltorg \n" ); } /*-----------------------------------------------------------*/ @@ -697,7 +698,8 @@ static void vPortEnableVFP( void ) " \n" " orr r1, r1, #( 0xf << 20 ) \n" /* Enable CP10 and CP11 coprocessors, then save back. */ " str r1, [r0] \n" - " bx r14 " + " bx r14 \n" + " .ltorg \n" ); } /*-----------------------------------------------------------*/