Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series of linker infrastructure cleanups and alignments #77887

Merged

Conversation

tejlmand
Copy link
Collaborator

@tejlmand tejlmand commented Sep 2, 2024

This PR contains a series of cleanup commit and commits which aligns linker flag handling with the compiler infrastructure introduced in PR #24851 .

This work cleanup and alignment is done to prepare for upcoming work related to improved linker handling, especially related to runtime library linking.

This will be needed for improved LLVM integration with Zephyr.

No functional change expected.

Commit 282f77e removed the only place
defining LIBC_INCLUDE_DIR. Remove the corresponding use of
LIBC_INCLUDE_DIR from newlib/CMakeLists.txt as this setting is no longer
being defined anywhere.

Signed-off-by: Torsten Rasmussen <[email protected]>
The macro `toolchain_cc_nostdinc` were made obsolete with PR#24851 and
are no longer invoked.

Remove the macro implementations.

Signed-off-by: Torsten Rasmussen <[email protected]>
The support of PROPERTY_LINKER_SCRIPT_DEFINES has been broken since
the transition to CMake in 12f8f76.

The intention was probably to allow users / projects to adjust
PROPERTY_LINKER_SCRIPT_DEFINES by setting a CMake cache variable.

The implementation tests for the CMake variable (local scope or cache)
PROPERTY_LINKER_SCRIPT_DEFINES, but it never uses such CMake variable.

Instead it uses a CMake global property named
PROPERTY_LINKER_SCRIPT_DEFINES. CMake variables and CMake global
properties are two very different things, and therefore the current
implementation has never worked. The fact that no one has never noticed
this flaw, means that the feature has never been used as intended.

Simplify the code by removing the use of the global CMake property and
instead set the value of the property on the linker script
pre-processing invocation.

Signed-off-by: Torsten Rasmussen <[email protected]>
The selection of the runtime library when using LLVM has already been
done in llvm/target.cmake and passed to the toolchain_ld_base() function
through the global TOOLCHAIN_LD_FLAGS setting.

The only reason this haven't been noticed is because of CMake's built-in
symbol de-duplication feature.

Remove the redundant runtime library handling.

Signed-off-by: Torsten Rasmussen <[email protected]>
Fix check_set_linker_property() to correctly handle multiple linker
flags passed on function call.

Signed-off-by: Torsten Rasmussen <[email protected]>
To ease the use of linker flag properties and to simplify the use of
generator expression then an optional PROPERTY argument has been added
to the zephyr_link_libraries() function.

This means a call such as:
zephyr_link_libraries($<TARGET_PROPERTY:linker,<property-name>)
can instead be simplified to:
zephyr_link_libraries(PROPERTY <property-name>)

Thus making intention clearer and keeping the complexity and minimizes
the risk of typos when writing generator expressions.

Signed-off-by: Torsten Rasmussen <[email protected]>
Transition the linker flag for the toolchain_ld_base and
toolchain_ld_cpp macros to linker flag properties.
This work follows the toolchain abstraction started in PR#24851.

toolchain_ld_base() was intended for base linker flags, but has slowly
become a 'set-any-linker-flag-here' and thus having several
`if(<check>)` or `<func>_ifdef(<check> ...)`.

Move the check to the top-level Zephyr CMakeLists.txt file, so that it
becomes cleaner which part is responsible for setting a value, and then
move the actual value (the linker flag) definition to the linker flag
property location.

It also helps adding support for new linkers, as it becomes clearer
which linker flags Zephyr always expects, for example `base` and
`cpp_base`, as well as those settings which are targeting for a given
purpose, such as linker sort alignment.

It also makes it clearer when those are used, for example in top-level
CMakeLists.txt with CONFIG_LINKER_SORT_BY_ALIGNMENT compared to this
information being buried in a linker support macro.

Signed-off-by: Torsten Rasmussen <[email protected]>
nordicjm
nordicjm previously approved these changes Sep 3, 2024
CMakeLists.txt Outdated Show resolved Hide resolved
Move linker flag setting from toolchain_ld_baremetal() to linker flag
properties as to follow the principle used in previos commits and from
PR#24851.

Signed-off-by: Torsten Rasmussen <[email protected]>
Remove the toolchain_ld_<base|baremetal|cpp> macro as all the macro
handling is now done through the use of linker properties.

Keep support for calling the old macros for out of tree toolchains
which have not been updated to the new property approach.

Signed-off-by: Torsten Rasmussen <[email protected]>
Copy link
Collaborator

@keith-packard keith-packard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good cleanup, happy to see this get done.

cmake/modules/extensions.cmake Show resolved Hide resolved
cmake/linker/lld/linker_flags.cmake Show resolved Hide resolved
@carlescufi
Copy link
Member

@keith-packard would you mind approving if you are happy with @tejlmand's replies?

@carlescufi carlescufi merged commit 5db1f1a into zephyrproject-rtos:main Sep 4, 2024
23 checks passed
set_property(TARGET linker PROPERTY partial_linking "-r")

check_set_linker_property(TARGET linker PROPERTY no_relax ${LINKERFLAGPREFIX},--no-relax)
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit 9a9e252 broke the build with every xt-clang toolchain we have. Any idea?

14:01:36 CMake Error at /srv/home/jenkins/workspace/sof_generic_build/zephyr/cmake/linker/xt-ld/linker_flags.cmake:32:
14:01:36   Parse error.  Expected a command name, got right paren with text ")".
14:01:36 Call Stack (most recent call first):
14:01:36   /srv/home/jenkins/workspace/sof_generic_build/zephyr/cmake/target_toolchain_flags.cmake:42 (include)
14:01:36   /srv/home/jenkins/workspace/sof_generic_build/zephyr/cmake/modules/kernel.cmake:148 (include)
14:01:36   /srv/home/jenkins/workspace/sof_generic_build/zephyr/cmake/modules/zephyr_default.cmake:142 (include)
14:01:36   /srv/home/jenkins/workspace/sof_generic_build/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
14:01:36   /srv/home/jenkins/workspace/sof_generic_build/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:97 (include_boilerplate)
14:01:36   CMakeLists.txt:5 (find_package)

Copy link
Collaborator

@marc-hb marc-hb Sep 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tejlmand added a commit to tejlmand/zephyr that referenced this pull request Sep 12, 2024
Follow-up: zephyrproject-rtos#77887

The macros:
- toolchain_ld_base
- toolchain_ld_baremetal
- toolchain_ld_cpp

was deprecated in 5db1f1a but no check
was added to FindDeprecated.cmake, meaning toolchains still providing
those macros was not getting a proper deprecation warning.

Signed-off-by: Torsten Rasmussen <[email protected]>
tejlmand added a commit to tejlmand/zephyr that referenced this pull request Sep 12, 2024
Follow-up: zephyrproject-rtos#77887

The macros:
- toolchain_ld_base
- toolchain_ld_baremetal
- toolchain_ld_cpp

was deprecated in 5db1f1a but no check
was added to FindDeprecated.cmake, meaning toolchains still providing
those macros was not getting a proper deprecation warning.

Signed-off-by: Torsten Rasmussen <[email protected]>
tejlmand added a commit to tejlmand/zephyr that referenced this pull request Sep 12, 2024
Follow-up: zephyrproject-rtos#77887

The macros:
- toolchain_ld_base
- toolchain_ld_baremetal
- toolchain_ld_cpp

was deprecated in 5db1f1a but no check
was added to FindDeprecated.cmake, meaning toolchains still providing
those macros was not getting a proper deprecation warning.

Signed-off-by: Torsten Rasmussen <[email protected]>
carlescufi pushed a commit that referenced this pull request Sep 16, 2024
Follow-up: #77887

The macros:
- toolchain_ld_base
- toolchain_ld_baremetal
- toolchain_ld_cpp

was deprecated in 5db1f1a but no check
was added to FindDeprecated.cmake, meaning toolchains still providing
those macros was not getting a proper deprecation warning.

Signed-off-by: Torsten Rasmussen <[email protected]>
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.

9 participants