#4953 reopened defect

Use of symbol addresses for arbitrary values may not work for some code models

Reported by: Sebastian Huber Owned by: Sebastian Huber
Priority: normal Milestone: 6.1
Component: score Version: 6
Severity: normal Keywords: qualification
Cc: Blocked By:
Blocking:

Description

The _ISR_Stack_size is defined by the application configuration like this:

/**
 * @ingroup RTEMSAPIBaseDefs
 *
 * @brief Defines a global symbol with the name and value.
 *
 * @param _name is the user defined name of the symbol.  The name shall be a
 *   valid designator.  On the name a macro expansion is performed and
 *   afterwards it is stringified.
 *
 * @param _value is the value of the symbol.  On the value a macro expansion is
 *   performed and afterwards it is stringified.  It shall expand to an integer
 *   expression understood by the assembler.
 *
 * This macro shall be placed at file scope.
 */
#if defined(__USER_LABEL_PREFIX__)
  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value ) \
    __asm__( \
      "\t.globl " RTEMS_XSTRING( RTEMS_SYMBOL_NAME( _name ) ) \
      "\n\t.set " RTEMS_XSTRING( RTEMS_SYMBOL_NAME( _name ) ) \
      ", " RTEMS_STRING( _value ) "\n" \
    )
#else
  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value )
#endif

RTEMS_DEFINE_GLOBAL_SYMBOL(
  _ISR_Stack_size,
  CONFIGURE_INTERRUPT_STACK_SIZE
);

Firstly, the RTEMS_DEFINE_GLOBAL_SYMBOL() is broken. It should depend on GNUC and not USER_LABEL_PREFIX.

Secondly, setting a symbol to an arbitrary absolute address may not work with all code models, see:

https://sourceware.org/pipermail/binutils/2023-September/129448.html

The _ISR_Stack_size should be changed to point to the end of the ISR stack of processor 0:

RTEMS_DEFINE_GLOBAL_SYMBOL(
  _ISR_Stack_0_end,
  RTEMS_SYMBOL_NAME( _ISR_Stack_area_begin )
    + CONFIGURE_INTERRUPT_STACK_SIZE
);

The tests for RTEMS_DEFINE_GLOBAL_SYMBOL() should be changed to use values relative to another symbol.

Change History (9)

comment:1 Changed on 09/13/23 at 05:28:52 by Sebastian Huber <sebastian.huber@…>

In 0add2d2/rtems:

score: Fix RTEMS_DEFINE_GLOBAL_SYMBOL()

The availability of a proper RTEMS_DEFINE_GLOBAL_SYMBOL() implementation
depends on asm() and thus GNUC.

Clarify documentation.

Update #4953.

comment:2 Changed on 09/13/23 at 05:28:54 by Sebastian Huber <sebastian.huber@…>

In d7a6e80/rtems:

tests: Improve RTEMS_DEFINE_GLOBAL_SYMBOL() tests

Use a symbol value relative to an existing symbol address to make the
test work on more code models.

Update #4953.

comment:3 Changed on 09/13/23 at 05:44:16 by Sebastian Huber

Resolution: fixed
Status: assignedclosed

Since the start files are written in assembly, they can use the right instructions to load an arbitrary absolute address. A review of the uses of _ISR_Stack_size showed that there is actually no issue right now. Adjusting the tests for RTEMS_DEFINE_GLOBAL_SYMBOL() should be enough.

comment:4 Changed on 09/13/23 at 08:52:29 by Sebastian Huber

Resolution: fixed
Status: closedreopened

The spconfig01 test fails on aarch64 with:

testsuites/sptests/spconfig01/init.c: 89 rtems_configuration_get_interrupt_stack_size() == CPU_STACK_MINIMUM_SIZE

The rtems_configuration_get_interrupt_stack_size() needs to be fixed.

comment:5 Changed on 09/13/23 at 08:57:43 by Sebastian Huber

Summary: Definition of _ISR_Stack_size may not work for some code modelsUse of symbol addresses for arbitrary values may not work for some code models

The use of _TLS_BSS_size and _TLS_Data_begin may also not work on some code models. I really wonder why the TLS related tests pass on aarch64.

comment:6 Changed on 09/13/23 at 09:02:33 by Sebastian Huber

There are also issues with _TLS_Size and _TLS_Alignment.

comment:7 Changed on 09/14/23 at 12:01:15 by Sebastian Huber <sebastian.huber@…>

In 5f8415b/rtems:

validation: Add RTEMS_DEFINE_GLOBAL_SYMBOL() test

Update #4953.

comment:8 Changed on 09/18/23 at 05:24:10 by Sebastian Huber <sebastian.huber@…>

In 206bbeb/rtems:

score: Fix TLS support for some code models

Store symbols with an arbitrary absolute address such as _TLS_Size,
_TLS_Alignment, _TLS_Data_size, and _TLS_BSS_size in an object to avoid issues
with some code models.

Update #4953.

comment:9 Changed on 09/18/23 at 05:24:12 by Sebastian Huber <sebastian.huber@…>

In 2111497/rtems:

rtems: rtems_configuration_get_interrupt_stack_size()

Fix rtems_configuration_get_interrupt_stack_size() for some code models.

The _ISR_Stack_size symbol has an arbitrary absolute address and may not
be representable in the code model used by the compiler.

Update #4953.

Note: See TracTickets for help on using tickets.