You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cmake: linker: Use the same linker for cmake checks and final build
Currently, the linker that is used when performing various cmake checks
(check_c_compiler_flag, for example) may be different than the linker that
will be used during the actual build. This happens as we currently specify
'-fuse-ld' to force the appropriate linker a) after many such checks have
already happened and b) in a way which is not automatically propagated to
check_c_compiler_flag (and friends). As a result, the toolchain's default
linker will generally be used for such checks regardless of which linker
was selected in Zephyr.
This can lead to a number of surprises when building Zephyr, particularly
when building with clang. For example:
- If the linker is misconfigured, where the build will fail can vary
depending on whether the linker is the toolchain's default. When the
configured linker happens to be the toolchain's default, the build
(helpfully) fails quickly on the checks for a basic working toochain.
When the configured linker isn't the default, the build won't fail until
the final link steps.
- The build can fail due to issues with a linker other than the one
configured by the user in Zephyr. For example, LLVM toolchains without
lld will generally fail to build Zephyr (the checks for a basic
working toochain will fail) for targets where lld is the default in LLVM
even if GNU ld is configured in Zephyr and would otherwise be used in the
final build.
- Flags which are only added if check_c_compiler_flag (or similar) succeeds
may be unexpectedly omitted during the final build if the flag is
supported in the configured linker but is unsupported in the toolchain's
default linker (as check_c_compiler_flag will test using the default
one).
Note that this isn't limited to clang--even when we are building with
Zephyr's SDK and force ld.bfd, we seem to use the 'ld' variant during the
cmake checks (though this generally seems fairly harmless compared to
mixing ld/lld or other proprietary linkers).
To fix this, ensure the appropriate 'fuse-ld' is set early enough and in
such a way that the same linker will be used throughout the entire build.
Signed-off-by: Jonathon Penix <[email protected]>
Signed-off-by: Torsten Rasmussen <[email protected]>
0 commit comments