Skip to content

Runtime linker symbol address resolved as 0x1 #829

Description

@flotter-cs

Summary
I am getting strange address values for linker symbols, unless the target variable is of volatile type.

0801a064 <intFlashHal_init>:
801a064: b5f0 push {r4, r5, r6, r7, lr}
801a066: b08d sub sp, #0x34
801a068: f643 70f4 movw r0, #0x3ff4
801a06c: f2c2 0000 movt r0, #0x2000
801a070: 2101 movs r1, #0x1 <----------------------------------- Linker symbol address = 0x1
801a072: 7001 strb r1, [r0]
801a074: f643 70f8 movw r0, #0x3ff8
801a078: f647 6144 movw r1, #0x7e44
801a07c: f2c2 0000 movt r0, #0x2000
801a080: f6c0 0102 movt r1, #0x802
801a084: 6001 str r1, [r0]

To Reproduce

intFlashHal.c:

static uint32_t maxFlashPages;

#define RUNTIMESYMBOL static volatile

RUNTIMESYMBOL U32 flashImageEndAddress;

ErrorCode intFlashHal_init(void)
{
ErrorCode result = ERROR_OK;

maxFlashPages           = SYMBOL_VALUE(definesLnk_flashPagesPerBank);   <--- working (destination has volatile)

flashImageEndAddress    = SYMBOL_VALUE(flashRTLnk_imageEndAddress);     <--- not working

:

linker.h:

#define SYMBOL extern uint32_t

SYMBOL definesLnk_flashOrigin; // The origin of the flash bank
SYMBOL definesLnk_flashSize; // The size of the Flash memory
SYMBOL definesLnk_flashPageSize; // The size of a flash page
SYMBOL definesLnk_flashBankSize; // The size of the bank in flash
SYMBOL definesLnk_flashDualBank; // 1 if dual bank is supposed to be active
SYMBOL definesLnk_flashPagesPerBank; // number of flash pages on device

(sofia) flotter@flotter-laptop:~/sofia/DEBUG/mcb-control-mcb-e1$ starm-nm firmware-mcb-control-mcb-e1.elf | grep flash
00000100 A _flash_page_count
00000800 A _flash_page_size
00000100 A _flash_pages
00080000 A _flash_size
00080000 A definesLnk_flashBankSize
00000000 A definesLnk_flashDualBank
08000000 A definesLnk_flashOrigin
00000800 A definesLnk_flashPageSize
00000100 A definesLnk_flashPagesPerBank
00080000 A definesLnk_flashSize
08027e44 D flashRTLnk_imageEndAddress

[CC] [build]/mcb-control-mcb-e1/hal/stm32l4xx-v1.18.2/intFlashHal/intFlashHal.o
/home/flotter/sofia/tools-installed/st-arm-clang-v21.1.1/bin/starm-clang -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Wall -Wextra -Werror -fdata-sections -ffunction-sections -ftls-model=local-exec -fstack-usage -g3 -Og -DDEBUG -DOS_freertos -DUSE_HAL_DRIVER -DUSER_VECT_TAB_ADDRESS -DSTM32L452xx -DMAKE_GEN3 -DBUILD_BOARD_SOC= -DBUILD_NODE_TYPE=mcb -DBUILD_NODE_FIRMWARE=control -DBUILD_NODE_VERSION_MAJOR=5 -DBUILD_NODE_VERSION_MINOR=0 -DBUILD_NODE_VERSION_PATCH=9 -DBUILD_SYSTEM_VERSION_MAJOR=5 -DBUILD_SYSTEM_VERSION_MINOR=0 -DBUILD_SYSTEM_VERSION_PATCH=9 -DBUILD_CONFIG_VERSION=1 -DBUILD_COMPILER_NAME= -DBUILD_COMPILER_VERSION= -DBUILD_GIT_HASH=0x5465a69c -DBUILD_GIT_BRANCH=mcb-rover -DBUILD_DATETIME=1776067468U -DBUILD_SHORT_HASH=0x2a27b4a8 -DPICOLIBC -std=gnu11
:
-c /home/flotter/sofia/common/hal/stm32l4xx-v1.18.2/intFlashHal/intFlashHal.c -o DEBUG/mcb-control-mcb-e1/hal/stm32l4xx-v1.18.2/intFlashHal/intFlashHal.o

[LD] [build]/mcb-control-mcb-e1/firmware-mcb-control-mcb-e1.elf
/home/flotter/sofia/tools-installed/st-arm-clang-v21.1.1/bin/starm-clang -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Wall -Wextra -Werror -fdata-sections -ffunction-sections -ftls-model=local-exec -fstack-usage -g3 -Og -DDEBUG -DOS_freertos -DUSE_HAL_DRIVER -DUSER_VECT_TAB_ADDRESS -DSTM32L452xx -DMAKE_GEN3 -DBUILD_BOARD_SOC= -DBUILD_NODE_TYPE=mcb -DBUILD_NODE_FIRMWARE=control -DBUILD_NODE_VERSION_MAJOR=5 -DBUILD_NODE_VERSION_MINOR=0 -DBUILD_NODE_VERSION_PATCH=9 -DBUILD_SYSTEM_VERSION_MAJOR=5 -DBUILD_SYSTEM_VERSION_MINOR=0 -DBUILD_SYSTEM_VERSION_PATCH=9 -DBUILD_CONFIG_VERSION=1 -DBUILD_COMPILER_NAME= -DBUILD_COMPILER_VERSION= -DBUILD_GIT_HASH=0x5465a69c -DBUILD_GIT_BRANCH=mcb-rover -DBUILD_DATETIME=1776067468U -DBUILD_SHORT_HASH=0x2a27b4a8 -DPICOLIBC -lcrt0-hosted -z norelro -L /home/flotter/sofia/common/linker -L /home/flotter/sofia/common/linker/stm32l452xx -L /home/flotter/sofia/boards/mcb/e1.x -T /home/flotter/sofia/nodes/mcb/control/node.ld -Wl,-Map=DEBUG/mcb-control-mcb-e1/firmware-mcb-control-mcb-e1.map -Wl,--gc-sections -z noexecstack -Wl,--print-memory-usage
:
-o DEBUG/mcb-control-mcb-e1/firmware-mcb-control-mcb-e1.elf > DEBUG/mcb-control-mcb-e1/firmware-mcb-control-mcb-e1.mem 2>&1

Expected behavior
Should match the address as per the symbol table

Actual behavior
Codegeneration with value stored as 0x1

Environment
STMicroelectronics Arm Clang Toolchain -- clang version 21.1.1 [rel1.20260121-1116]
Target: arm-st-none-eabi
Thread model: posix

[Additional context]
I am using the ST released version based on this. I am asking the question here as I strongly suspect the issue to be unrelated to ST tweaks. Likely something I am not understanding and doing wrong. I do not understand why the variable has to be volatile, and it bugs my doing something that I do not understand. Any help will be hugely appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions