Skip to content

Use of ld specic function (ADDR) break non-ld linkers #87200

@tejlmand

Description

@tejlmand

Describe the bug

Non-ld linkers was broken with PR##80768

zephyr_linker_symbol() is only intended with simple math operations, as described by the function:

# EXPR <expr> : Expression that defines the symbol. Due to linker limitations
# all expressions should only contain simple math, such as
# `+, -, *` and similar. The expression will go directly into the
# linker, and all `@<symbol>@` will be replaced with the referred
# symbol.

The changes introduced in #80678 breaks this rule by introducing ADDR() which is a ld specific function not understood by non-ld linkers, such as armlink.

To Reproduce

  1. Setup Arm Conpiler 6, as described: https://docs.zephyrproject.org/latest/develop/toolchains/arm_compiler.html
  2. Build a simple sample, such as hello world:
    west build -p -b qemu_cortex_m3 samples/hello_world/ -- -DCONFIG_CMAKE_LINKER_GENERATOR=y -DCONFIG_ARMCLANG_STD_LIBC=y
  3. See error:
    Error: L6630E: Invalid token start expected number or ( but found A at position 26 on line 498
    Error: L6226E: Missing base address for region __ramfunc_region_start.
    "/projects/github/ncs/zephyr/build/zephyr/linker_zephyr_pre0.cmd", line 498 (column 26): Error: L6292E: Ignoring unknown attribute 'ADDR' specified for region __ramfunc_region_start.
    Error: L6630E: Invalid token start expected number or ( but found . at position 31 on line 498
    Error: L6629E: Unmatched parentheses expecting ) but found . at position 31 on line 498
    "/projects/github/ncs/zephyr/build/zephyr/linker_zephyr_pre0.cmd", line 498 (column 31): Error: L6228E: Expected '{', found '....'.
    "/projects/github/ncs/zephyr/build/zephyr/linker_zephyr_pre0.cmd", line 498 (column 31): Error: L6228E: Expected '}', found 'EOF'.
    

Offending line:

zephyr_linker_symbol(SYMBOL __ramfunc_region_start EXPR "ADDR(.ramfunc)")

Expected behavior
Successful linking:

[2/109] Generating include/generated/zephyr/version.h
-- Zephyr version: 4.0.0-rc2 (/projects/github/ncs/zephyr), build: v4.0.0-rc2-84-g6984237c0638
[109/109] Linking C executable zephyr/zephyr.elf
Generating files from /projects/github/ncs/zephyr/build/zephyr/zephyr.elf for board: qemu_cortex_m3

Impact
Support for Arm Compiler 6 is broken.

Logs and console output
N/A

Environment (please complete the following information):

  • OS: Linux
  • Toolchain: Arm compiler 6
  • Commit SHA or Version used: 6023d6a or never

Additional context
Offending line:

zephyr_linker_symbol(SYMBOL __ramfunc_region_start EXPR "ADDR(.ramfunc)")

Metadata

Metadata

Labels

bugThe issue is a bug, or the PR is fixing a bugpriority: mediumMedium impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions