Skip to content

TOOLCHAIN_LD_FLAGS setting of -mabi/-march aren't propagated to linker invocation on RISC-V #91045

@Fymyte

Description

@Fymyte

Describe the bug

I am facing the exact same issue as in #28456.

However, the cause is different.

TL;DR:
TOOLCHAIN_LD_FLAGS contains -fuse-ld=bfd in addition to -march and -mabi, which makes zephyr_check_compiler_flag fail, and in turn fails to add any flags in target_ld_options

Details:
Using TOOLCHAIN_LD_FLAGS for other things than -mabi and -march while adding the NO_SPLIT flag will break this check and make any flags specified in TOOLCHAIN_LD_FLAGS to not be present in the final link command.

In the best case, it will error out because the -mabi or -march is not compatible with the default toolchain build option. In the worst case, it will silently ignore any flags in the TOOLCHAIN_LD_FLAGS variable.

There are multiple solutions:

  • Find a way to localize the effect of NO_SPLIT, so it only affects the expected arguments
  • Use different variable names for toolchains' target specific options (-mabi and -march) and global options (-fuse-ld for example)

I would argue the first one is probably the most user-friendly, because it would remove the hidden merge of every ld flags without the user of TOOLCHAIN_LD_FLAGS knowing it. But I don't see any straightforward way to do it.
The second is easy enough: use a new variable, for example TOOLCHAIN_TARGET_LD_FLAGS, to store the target specific flags, and add this with a separate call to zephyr_ld_options.

Regression

  • This is a regression.

Steps to reproduce

Use another linker than the toolchain default. bfd for example.

Try to build any application with a riscv board.

Check the content of build/zephyr/CMakeFiles/zephyr_pre0.dir/link.txt for the presence of the requested flags (-fuse-ld and -mabi/-march)

Relevant log output

Impact

Major – Severely degrades functionality; workaround is difficult or unavailable.

Environment

  • OS: Linux (debian 12)
  • Toolchain: custom riscv toolchain (gcc 12.2 with additional target support)
  • Zephyr version: 4.1

Additional Context

No response

Metadata

Metadata

Assignees

Labels

area: RISCVRISCV Architecture (32-bit & 64-bit)area: ToolchainsToolchainsbugThe 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