Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. (cherry picked from commit 9fe6c5e) Original-Signed-off-by: Jonathon Penix <jpenix@quicinc.com> Original-Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no> GitOrigin-RevId: 9fe6c5e Cr-Build-Id: 8734742957433546641 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8734742957433546641 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: Ibbfbd56f0e2edb93f4402b69be3c0d210c6c08b6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5908563 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com> Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
- Loading branch information