Skip to content

Commit

Permalink
added configLTO_HELPER setting to prevent the GNU Link Time Optimizer…
Browse files Browse the repository at this point in the history
… to remove variables used by FreeRTOS Thread Awareness (e.g. from SEGGER).
  • Loading branch information
Erich Styger committed Aug 1, 2017
1 parent c3bc03e commit 6a4af83
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 15 deletions.
20 changes: 19 additions & 1 deletion Beans/FreeRTOS/FreeRTOS.bean
Expand Up @@ -4,7 +4,7 @@
<Name>FreeRTOS</Name>
<Description>FreeRTOS McuOnEclipse Port with FreeRTOS+Trace</Description>
<Author>Erich Styger</Author>
<Version>01.546</Version>
<Version>01.548</Version>
<Icon>FreeRTOS</Icon>
<TypesFiles>PE,FreeRTOS\FreeRTOS</TypesFiles>
<FileVersion>6</FileVersion>
Expand Down Expand Up @@ -460,6 +460,24 @@ This is defined to be the most efficient, natural, type for the architecture. Fo
<Popup>false</Popup>
</TBoolItem>
</GrupItem>
<GrupItem>
<TBoolItem>
<Name>Enable LinkTimeOptimizer Helper</Name>
<Symbol>EnableLTODebugHelper</Symbol>
<TypeSpec>typeYesNo</TypeSpec>
<Hint>This setting configures the configLTO_HELPER macro. With -LTO (GNU Link Time Optimizer), certain symbols might be optimized which affect kernel aware debugging. This setting disables optimization so debugging is still possible.</Hint>
<ItemLevel>BASIC</ItemLevel>
<EditLine>false</EditLine>
<TypeSpecNameChangeAble>false</TypeSpecNameChangeAble>
<DefaultIndex>1</DefaultIndex>
<TextValueIndex>false</TextValueIndex>
<RuntimeProperty>false</RuntimeProperty>
<CanDelete>false</CanDelete>
<IconPopup>false</IconPopup>
<DefaultValue>false</DefaultValue>
<Popup>false</Popup>
</TBoolItem>
</GrupItem>
<GrupItem>
<TBoolItem>
<Name>uxTopUsedPriority</Name>
Expand Down
2 changes: 1 addition & 1 deletion Beans/FreeRTOS/FreeRTOS.uis
@@ -1,6 +1,6 @@

[USED_FACES]
BeanVersion=01.546
BeanVersion=01.548

InterfacesCount=10

Expand Down
4 changes: 4 additions & 0 deletions Beans/FreeRTOS/FreeRTOSProperties.html
Expand Up @@ -371,6 +371,10 @@
<b>Enable GDB Debug Helper</b></a> - If enabled, a debug helper for GDB is enabled to do thread stack debugging with a special vPortPendSVHandler(). This setting configures the configGDB_HELPER macro.
</li>
<li>
<a name="EnableLTODebugHelper">
<b>Enable LinkTimeOptimizer Helper</b></a> - This setting configures the configLTO_HELPER macro. With -LTO (GNU Link Time Optimizer), certain symbols might be optimized which affect kernel aware debugging. This setting disables optimization so debugging is still possible.
</li>
<li>
<a name="uxTopUsedPriority">
<b>uxTopUsedPriority</b></a> - Configures configUSE_TOP_USED_PRIORITY. OpenOCD Thread Aware debugging needs the variable uxTopUsedPriority present.
</li>
Expand Down
6 changes: 3 additions & 3 deletions Drivers/freeRTOS/Source/portable/GCC/ARM_CM4F/port.c
Expand Up @@ -1215,7 +1215,7 @@ void vPortStopTickTimer(void) {
#if configCPU_FAMILY_IS_ARM_FPU(configCPU_FAMILY) /* has floating point unit */
#if (configCOMPILER==configCOMPILER_ARM_GCC)
/* added noinline attribute to prevent the GNU linker to optimize the following function. That symbol is required for the FreeRTOS GDB thread awareness by Segger */
void __attribute__ ((noinline)) vPortEnableVFP(void) {
void __attribute__ ((noinline, used)) vPortEnableVFP(void) {
/* The FPU enable bits are in the CPACR. */
__asm volatile (
" ldr.w r0, =0xE000ED88 \n" /* CAPCR, 0xE000ED88 */
Expand Down Expand Up @@ -1849,8 +1849,8 @@ __asm void vPortStartFirstTask(void) {
/* Need the 'noinline', as latest gcc with -O3 tries to inline it, and gives error message: "Error: symbol `pxCurrentTCBConst2' is already defined" */
__attribute__((noinline))
void vPortStartFirstTask(void) {
#if configUSE_TOP_USED_PRIORITY
/* only needed for openOCD thread awareness. It needs the symbol uxTopUsedPriority present after linking */
#if configUSE_TOP_USED_PRIORITY || configLTO_HELPER
/* only needed for openOCD or Segger FreeRTOS thread awareness. It needs the symbol uxTopUsedPriority present after linking */
{
extern volatile const int uxTopUsedPriority;
__attribute__((__unused__)) volatile uint8_t dummy_value_for_openocd;
Expand Down
59 changes: 49 additions & 10 deletions Drivers/freeRTOS/Source/tasks.c
Expand Up @@ -404,12 +404,26 @@ which static variables must be declared volatile. */
PRIVILEGED_DATA TCB_t * volatile pxCurrentTCB = NULL;

/* Lists for ready and blocked tasks. --------------------*/
PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */
PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */
PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */
PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */
PRIVILEGED_DATA static List_t * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */
#if configLTO_HELPER /* << EST */
/* If using -lto (Link Time Optimization), the linker might replace/remove the names of the following variables.
* If using a FreeRTOS Kernel aware debugger (e.g. Segger FreeRTOS task aware plugin), then the debugger won't be able to see the symbols and will fail.
* Therefore (more as of a hack) the symbols are defined with external linkage, even if not used from other modules.
* See https://mcuoneclipse.com/2017/07/27/troubleshooting-tips-for-freertos-thread-aware-debugging-in-eclipse/
*/
PRIVILEGED_DATA /*static*/ List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */
PRIVILEGED_DATA /*static*/ List_t xDelayedTaskList1; /*< Delayed tasks. */
PRIVILEGED_DATA /*static*/ List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */
PRIVILEGED_DATA /*static*/ List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */
PRIVILEGED_DATA /*static*/ List_t * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
PRIVILEGED_DATA /*static*/ List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */
#else
PRIVILEGED_DATA static List_t pxReadyTasksLists[ configMAX_PRIORITIES ];/*< Prioritised ready tasks. */
PRIVILEGED_DATA static List_t xDelayedTaskList1; /*< Delayed tasks. */
PRIVILEGED_DATA static List_t xDelayedTaskList2; /*< Delayed tasks (two lists are used - one for delays that have overflowed the current tick count. */
PRIVILEGED_DATA static List_t * volatile pxDelayedTaskList; /*< Points to the delayed task list currently being used. */
PRIVILEGED_DATA static List_t * volatile pxOverflowDelayedTaskList; /*< Points to the delayed task list currently being used to hold tasks that have overflowed the current tick count. */
PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tasks that have been readied while the scheduler was suspended. They will be moved to the ready list when the scheduler is resumed. */
#endif

#if( INCLUDE_vTaskDelete == 1 )

Expand All @@ -419,15 +433,40 @@ PRIVILEGED_DATA static List_t xPendingReadyList; /*< Tasks that have been r
#endif

#if ( INCLUDE_vTaskSuspend == 1 )

#if configLTO_HELPER /* << EST */
/* If using -lto (Link Time Optimization), the linker might replace/remove the names of the following variables.
* If using a FreeRTOS Kernel aware debugger (e.g. Segger FreeRTOS task aware plugin), then the debugger won't be able to see the symbols and will fail.
* Therefore (more as of a hack) the symbols are defined with external linkage, even if not used from other modules.
* See https://mcuoneclipse.com/2017/07/27/troubleshooting-tips-for-freertos-thread-aware-debugging-in-eclipse/
*/
PRIVILEGED_DATA /*static*/ List_t xSuspendedTaskList; /*< Tasks that are currently suspended. */
#else
PRIVILEGED_DATA static List_t xSuspendedTaskList; /*< Tasks that are currently suspended. */

#endif
#endif

/* Other file private variables. --------------------------------*/
PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
#if configLTO_HELPER /* << EST */
/* If using -lto (Link Time Optimization), the linker might replace/remove the names of the following variables.
* If using a FreeRTOS Kernel aware debugger (e.g. Segger FreeRTOS task aware plugin), then the debugger won't be able to see the symbols and will fail.
* Therefore (more as of a hack) the symbols are defined with external linkage, even if not used from other modules.
* See https://mcuoneclipse.com/2017/07/27/troubleshooting-tips-for-freertos-thread-aware-debugging-in-eclipse/
*/
PRIVILEGED_DATA /*static*/ volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
#else
PRIVILEGED_DATA static volatile UBaseType_t uxCurrentNumberOfTasks = ( UBaseType_t ) 0U;
#endif
PRIVILEGED_DATA static volatile TickType_t xTickCount = ( TickType_t ) 0U;
PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;
#if configLTO_HELPER /* << EST */
/* If using -lto (Link Time Optimization), the linker might replace/remove the names of the following variables.
* If using a FreeRTOS Kernel aware debugger (e.g. Segger FreeRTOS task aware plugin), then the debugger won't be able to see the symbols and will fail.
* Therefore (more as of a hack) the symbols are defined with external linkage, even if not used from other modules.
* See https://mcuoneclipse.com/2017/07/27/troubleshooting-tips-for-freertos-thread-aware-debugging-in-eclipse/
*/
PRIVILEGED_DATA /*static*/ volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;
#else
PRIVILEGED_DATA static volatile UBaseType_t uxTopReadyPriority = tskIDLE_PRIORITY;
#endif
PRIVILEGED_DATA static volatile BaseType_t xSchedulerRunning = pdFALSE;
PRIVILEGED_DATA static volatile UBaseType_t uxPendedTicks = ( UBaseType_t ) 0U;
PRIVILEGED_DATA static volatile BaseType_t xYieldPending = pdFALSE;
Expand Down
9 changes: 9 additions & 0 deletions Drivers/sw/FreeRTOS.drv
Expand Up @@ -4763,6 +4763,15 @@ void %vOnPreSleepProcessing(portTickType expectedIdleTicks)
/*!< 1: enable special GDB stack backtrace debug helper; 0: disabled */
#endif

#ifndef configLTO_HELPER
%if defined(EnableLTODebugHelper) & %EnableLTODebugHelper='yes'
#define configLTO_HELPER %>50 (1 && configCPU_FAMILY_IS_ARM(configCPU_FAMILY) && (configCOMPILER==configCOMPILER_ARM_GCC))
%else
#define configLTO_HELPER %>50 (0 && configCPU_FAMILY_IS_ARM(configCPU_FAMILY) && (configCOMPILER==configCOMPILER_ARM_GCC))
%endif
/*!< 1: enable special GNU Link Time Optimizer (-lto) debug helper code; 0: disabled */
#endif

#ifndef configHEAP_SCHEME_IDENTIFICATION
%if defined(freeRTOSMemorySchemeConstant) & %freeRTOSMemorySchemeConstant='yes'
#define configHEAP_SCHEME_IDENTIFICATION %>50 (1 && configCPU_FAMILY_IS_ARM(configCPU_FAMILY))
Expand Down

0 comments on commit 6a4af83

Please sign in to comment.