-
Notifications
You must be signed in to change notification settings - Fork 8.2k
cmake: toolchain: cache property GNULD_LINKER_IS_BFD #56547
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
cmake: toolchain: cache property GNULD_LINKER_IS_BFD #56547
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm a (small variation of) this fixes #56501. Thanks for the very prompt fix!
I would still like some clarification about https://docs.zephyrproject.org/latest/develop/west/build-flash-debug.html#one-time-cmake-arguments : is it "safe" or not? I mean as long as the same CMake arguments are used every time. Just slower sometimes?
Nit: instead of duplicating them exactly, I would make the doc strings slightly different and unique so they can be used as "breadcrumbs".
tejlmand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor adjustments requested, but generally looks good.
cmake/modules/FindGnuLd.cmake
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lookup at those locations has already set the cache variable:
https://github.com/zephyrproject-rtos/zephyr/blob/bbc4f11fb3a35d84568c53340a6a934777f71461/cmake/modules/FindGnuLd.cmake#L46
https://github.com/zephyrproject-rtos/zephyr/blob/bbc4f11fb3a35d84568c53340a6a934777f71461/cmake/modules/FindGnuLd.cmake#L49
so only chance that GNULD_LINKER_IS_BFD has already been set, but the corresponding GNULD_LINKER_IS_BFD is undefined is when a user has specifically pointed to a ld through the use of: -DGNULD_LINKER_IS_BFD=<forced-linker-to-use>.
In such a case we cannot really know if linker is bfd compatible or not, as we have no proper detection mechanism.
So in the scenario described we must rely on user to provide us the correct setting, so I propose issue a warning in such case.
Something like:
if(EXISTS "${GNULD_LINKER}")
if(NOT DEFINED GNULD_LINKER_IS_BFD)
message(WARNING "GNULD_LINKER specified directly in cache, but GNULD_LINKER_IS_BFD is not defined."
"Assuming GNULD_LINKER_IS_BFD as OFF, please set GNULD_LINKER_IS_BFD to correct value in cache to silence this warning"
)
set(GNULD_LINKER_IS_BFD OFF)
endif()
endif()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the warning and also to return early if variable is already set.
cmake/modules/FindGnuLd.cmake
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add FORCE.
If this code ever executes a second time, then it means that someone purposely has cleared the GNULD_LINKER setting, and therefor we should ensure to update the corresponding GNULD_LINKER_IS_BFD to the new lookup we perform.
| set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Is linker ld.bfd compatible") | |
| set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Is linker ld.bfd compatible" FORCE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the code to return early if GNULD_LINKER_IS_BFD is already set. So no need to FORCE a change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My rule of thumb for FORCE is to add it first and then think later
https://stackoverflow.com/questions/39588836/why-do-i-need-force-to-override-a-cmake-option
cmake/modules/FindGnuLd.cmake
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| set(GNULD_LINKER_IS_BFD OFF CACHE BOOL "Is linker ld.bfd compatible") | |
| set(GNULD_LINKER_IS_BFD OFF CACHE BOOL "Is linker ld.bfd compatible" FORCE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the code to return early if GNULD_LINKER_IS_BFD is already set. So no need to FORCE a change.
|
Thanks again @tejlmand for your time and critical/"bus factor" expertise. Since you have a very good understanding of these CMake issues and while you're here, could you please answer this earlier, more generic and related question of mine:
@mbolivar-nordic I think you mentioned once some past discussions on this topic, were they on Github, Slack or Discord? As usual I'm volunteering for a minor doc fix if needed but I need to know what it should be :-) I'm among the few people who know the secrets to make the doc build usable (#55708) |
bbc4f11 to
8f5d46b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested again and fixes the issue again.
Nit: instead of duplicating them exactly, I would make the doc strings slightly different and unique so they can be used as "breadcrumbs".
Ping? Even more relevant now that the logic is becoming more complex.
8f5d46b to
d2d9a2f
Compare
Forgot to change those while juggling other changes. |
ca84c55 to
e444f68
Compare
With @mbolivar-nordic's help, partly answered myself in the bug for this: Small doc improvement submitted in |
tejlmand
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the return should also cover the case where the GNULD_LINKER_IS_BFD as there seems to be no reason to start detecting / manipulating GNULD_LINKER` setting when already set.
And while at it, please align the CMakeCache description text.
cmake/modules/FindGnuLd.cmake
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you would want to move the return down, so that if ever GNULD_LINKER is defined then the look-up of ld linker is aborted.
Other comment will be made to follow up this comment.
cmake/modules/FindGnuLd.cmake
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the early return should happen here.
If for any reason GNULD_LINKER has been pointed out manually by a user, then we should not try to detect GNULD_LINKER_IS_BFD based on current compiler, hence I believe we should move the return here:
| endif() | |
| endif() | |
| return() |
cmake/modules/FindGnuLd.cmake
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe try to make the CMake cache comment more aligned. (see also following comments)
Proposal:
| set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Compiler says linker is ld.bfd compatible" FORCE) | |
| set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Linker BFD compatibility (compiler reported)" FORCE) |
cmake/modules/FindGnuLd.cmake
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Found ld.bfd compatible linker" FORCE) | |
| set(GNULD_LINKER_IS_BFD ON CACHE BOOL "Linker BFD compatibility (inferred from binary)" FORCE) |
cmake/modules/FindGnuLd.cmake
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| set(GNULD_LINKER_IS_BFD OFF CACHE BOOL "ld.bfd compatible linker not found" FORCE) | |
| set(GNULD_LINKER_IS_BFD OFF CACHE BOOL "Linker BFD compatibility (inferred from binary)" FORCE) |
been out for Easter 🐰 , but happy to give an answer. When it comes to Some settings can be passed multiple times only if the value is identical to the existing value in the cache, for example when the passed board is identical to existing value. But changing the board is prohibited, so if you try to do: the old value will be used. That is not a CMake limitation, but a Zephyr limitation because some settings are so fundamental that we cannot allow them to be changed without a pristine build. |
Cache the property GNULD_LINKER_IS_BFD between cmake invocations. It is observed that, in repeated builds (2nd time and later), this property becomes true even for non-bfd compatible linker. So cache it to avoid any surprises. Fixes zephyrproject-rtos#56501 Signed-off-by: Daniel Leung <[email protected]>
e444f68 to
0521d54
Compare
|
Updated according to comments. |
|
@dcpleung thanks for the patience 👍 |

Cache the property GNULD_LINKER_IS_BFD between cmake invocations. It is observed that, in repeated builds (2nd time and later), this property becomes true even for non-bfd compatible linker. So cache it to avoid any surprises.
Fixes #56501