Skip to content

Conversation

@keith-packard
Copy link
Contributor

SDK 1.0 provides -O2 and -Os versions of each library and startup files. These are selected with the compiler optimization flag. The first patch in this series adopts the style of the recent asm optimization flag for linker usage. The second patch delays computation of startup file paths until after the optimization style has been chosen.

The linker may want to know the desired optimization level as when
the multilib configuration includes -Os as a selector.

Adopt the same pattern as the assembler optimization flags by allowing
toolchains to specify linker optimization flags which default to the
compiler optimization flags and the apply those using add_link_options.

Signed-off-by: Keith Packard <[email protected]>
With inclusion of the optimization flag into the multilib selection
process, we cannot compute the compiler library path when the compiler's
target.cmake is processed as LINKER_OPTIMIZATION_FLAG is not computed until
much later.

Instead, add a function (compiler_file_path) which can be used to locate
the appropriate crtbegin.o and crtend.o files.

Delay computation of lib_include_dir and rt_library until after all
compiler flags have been computed by adding compiler_set_linker_properties
and calling that just before toolchain_linker_finalize is invoked.

Place default implementations of both of these functions in a new file,
cmake/compiler/target_template.cmake, where we assume the compiler works
like gcc or clang and handlers the --print-file-name and
--print-libgcc-file-name options. Compilers needing alternate
implementations can override these functions in their target.cmake files.

These implementations require that no generator expressions are necessary
for the compiler to compute the right library paths.

This mechanism is also used to take any additional compiler options by
adding a new (optional) linker function,
toolchain_linker_add_compiler_options, which maps compiler options to
equivalent linker options, discarding any that aren't applicable.

Signed-off-by: Keith Packard <[email protected]>
@sonarqubecloud
Copy link

@cfriedt cfriedt merged commit d77b58a into zephyrproject-rtos:main Aug 14, 2025
31 checks passed
@tagunil
Copy link
Contributor

tagunil commented Aug 15, 2025

Hi @keith-packard, looks like this one just broke our ARC MWDT toolchain as we don't have --print-libgcc-file-name.
Could you please outline which additional CMake functions a toolchain needs to provide to be compliant?

@keith-packard
Copy link
Contributor Author

Hi @keith-packard, looks like this one just broke our ARC MWDT toolchain as we don't have --print-libgcc-file-name. Could you please outline which additional CMake functions a toolchain needs to provide to be compliant?

You'll need to provide compiler_set_linker_properties function which sets lib_include_dir and rt_library linker properties. The template for that is in cmake/compiler/target_template.cmake. It is called just before toolchain_linker_finalize.

@RobinKastberg
Copy link
Contributor

sorry for not responding earlier, this broke us (IAR) as well, but it should be easy and clear to fix, so no problems :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants