Commit c79c4ef9 authored by Torsten Rasmussen's avatar Torsten Rasmussen Committed by Benjamin Cabé
Browse files

linker: move last section id constant to c-code

Move creation of last section id from ld linker script LONG() usage to
C code with last section attribute.

The use of `LONG()` works correctly with ld but lld emits a warning
because .last_section section is not allocated as there are no matching
input sections and discards the `LONG()` call, meaning the last section
identifier will not be present in the flash.
> ld.lld: warning: ignoring memory region assignment for
>                             non-allocatable section '.last_section'

Placing the last section id in `.last_section` in C code makes lld
allocate the memory for the id and thereby create the output section
with the correct output.

Signed-off-by: default avatarTorsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
parent 8f2560cf
Loading
Loading
Loading
Loading
+3 −5
Changes for include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld: 3 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -366,11 +366,9 @@ GROUP_END(OCM)
    /* Must be last in romable region */
    SECTION_PROLOGUE(.last_section,,)
    {
#ifdef CONFIG_LINKER_LAST_SECTION_ID
      /* Fill last section with a word to ensure location counter and actual rom
       * region data usage match. */
      LONG(CONFIG_LINKER_LAST_SECTION_ID_PATTERN)
#endif
      /* .last_section contains a fixed word to ensure location counter and actual
       * rom region data usage match when CONFIG_LINKER_LAST_SECTION_ID=y. */
      KEEP(*(.last_section))
    } GROUP_LINK_IN(ROMABLE_REGION)

    /* To provide the image size as a const expression,
+3 −5
Changes for include/zephyr/arch/arm/cortex_m/scripts/linker.ld: 3 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -412,11 +412,9 @@ GROUP_END(DTCM)
/* Must be last in romable region */
SECTION_PROLOGUE(.last_section,,)
{
#ifdef CONFIG_LINKER_LAST_SECTION_ID
  /* Fill last section with a word to ensure location counter and actual rom
   * region data usage match. */
  LONG(CONFIG_LINKER_LAST_SECTION_ID_PATTERN)
#endif
  /* .last_section contains a fixed word to ensure location counter and actual
   * rom region data usage match when CONFIG_LINKER_LAST_SECTION_ID=y. */
  KEEP(*(.last_section))
} GROUP_LINK_IN(ROMABLE_REGION)

/* To provide the image size as a const expression,
+3 −5
Changes for include/zephyr/arch/arm64/scripts/linker.ld: 3 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -351,11 +351,9 @@ SECTIONS
    /* Must be last in romable region */
    SECTION_PROLOGUE(.last_section,,)
    {
#ifdef CONFIG_LINKER_LAST_SECTION_ID
      /* Fill last section with a word to ensure location counter and actual rom
       * region data usage match. */
      LONG(CONFIG_LINKER_LAST_SECTION_ID_PATTERN)
#endif
      /* .last_section contains a fixed word to ensure location counter and actual
       * rom region data usage match when CONFIG_LINKER_LAST_SECTION_ID=y. */
      KEEP(*(.last_section))
    } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)

    /* To provide the image size as a const expression,
+3 −5
Changes for include/zephyr/arch/riscv/common/linker.ld: 3 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -454,15 +454,13 @@ GROUP_END(DTCM)
/* Must be last in romable region */
SECTION_PROLOGUE(.last_section,,)
{
#ifdef CONFIG_LINKER_LAST_SECTION_ID
  /* Fill last section with a word to ensure location counter and actual rom
   * region data usage match. */
  LONG(CONFIG_LINKER_LAST_SECTION_ID_PATTERN)
  /* .last_section contains a fixed word to ensure location counter and actual
   * rom region data usage match when CONFIG_LINKER_LAST_SECTION_ID=y. */
  KEEP(*(.last_section))
  /* __rom_region_size is used when configuring the PMP entry of the ROM region.
   * Addresses (pmpaddr) in PMP registers need to be aligned to 4. Align
   * __rom_region_size to 4 to meet that requirement. */
  MPU_MIN_SIZE_ALIGN
#endif
} GROUP_LINK_IN(ROMABLE_REGION)

/* To provide the image size as a const expression,
+2 −0
Changes for lib/utils/CMakeLists.txt: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -28,3 +28,5 @@ zephyr_library_include_directories(
  ${ZEPHYR_BASE}/kernel/include
  ${ZEPHYR_BASE}/arch/${ARCH}/include
)

zephyr_sources_ifdef(CONFIG_LINKER_LAST_SECTION_ID last_section_id.c)
Loading