zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.82k stars 6.6k forks source link

kernel: CONFIG_SYS_CLOCK_EXISTS can be enabled without system clock implementation #58269

Open MarekPieta opened 1 year ago

MarekPieta commented 1 year ago

Describe the bug We can enable the CONFIG_SYS_CLOCK_EXISTS Kconfig option without actually enabling the implementation of the system clock (e.g. with explicitly disabled CONFIG_NRF_RTC_TIMER on nRF SoC based boards). The build would succeed until the system clock API is used somewhere in the code (using the system clock API would trigger linker failures).

To Reproduce Steps to reproduce the behavior:

  1. Build hello_world sample on nrf52840dk_nrf52840 with CONFIG_NRF_RTC_TIMER=n
  2. See the linker error (zephyr/kernel/timeout.c:64: undefined reference to `sys_clock_elapsed').
  3. Disable also the CONFIG_SYS_CLOCK_EXISTS.
  4. See that build is now successful.

Expected behavior The CONFIG_SYS_CLOCK_EXISTS should depend on the fact that a driver implementation is available to avoid making impression that feature is available when it actually is not. I think we may also need to ensure that only one system clock driver implementation is enabled at a time.

Impact It is quite easy to make improper application configuration and the related linker failures may remain hidden for a long time.

Environment Zephyr version: 49c7aa56fa0c1e61de95577e5fdc1877872b549c (current main). Can be also replicated with other versions.

nordic-krch commented 1 year ago

It looks like the logic in Kconfig is flipped so when CONFIG_SYS_CLOCK_EXISTS is set, only then section with timer driver is enabled: https://github.com/zephyrproject-rtos/zephyr/blob/fe10c0b423cabbee3f2780d1c0e7046e1d2b75f1/drivers/timer/Kconfig#L8

The fix would be to change it so that each system timer driver is selecting CONFIG_SYS_CLOCK_EXISTS. I am not sure if there are any blockers (out of tree drivers?) @teburd @andyross what are your thoughts?

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

github-actions[bot] commented 1 year ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

github-actions[bot] commented 10 months ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

github-actions[bot] commented 6 months ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

github-actions[bot] commented 4 months ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

github-actions[bot] commented 2 months ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

github-actions[bot] commented 1 week ago

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.