All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Revert "time: add weak annotation to timer_read_counter declaration"
@ 2023-01-05  0:08 Harald Seiler
  2023-01-11 20:49 ` Rob Herring
  2023-01-13  0:16 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Harald Seiler @ 2023-01-05  0:08 UTC (permalink / raw)
  To: u-boot; +Cc: Rob Herring, Simon Glass, Harald Seiler, Serge Bazanski

This reverts commit 65ba7add0d609bbd035b8d42fafdaf428ac24751.

A weak extern is a nasty sight to behold: If the symbol is never
defined, on ARM, the linker will replace the function call with a NOP.
This behavior isn't well documented but there are at least some hints
to it [1].

When timer_read_counter() is not defined, this obviously does the wrong
thing here and it does so silently.  The consequence is that a board
without timer_read_counter() will sleep for random amounts and generally
have erratic get_ticks() values.

Drop the __weak annotation of the extern so a linker error is raised
when timer_read_counter() is not defined.  This is okay, the original
reason for the reverted change - breaking the sandbox build - no longer
applies.

Final sidenote:  This was the only weak extern in the entire tree at
this time as far as I can tell.  I guess we should avoid introduction of
them again as they are obviously a very big footgun.

[1]: https://stackoverflow.com/questions/31203402/gcc-behavior-for-unresolved-weak-functions

Fixes: 65ba7add0d60 ("time: add weak annotation to timer_read_counter declaration")
Reported-by: Serge Bazanski <q3k@q3k.org>
Signed-off-by: Harald Seiler <hws@denx.de>
---
 lib/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/time.c b/lib/time.c
index f3aaf472d1..1e24b1b03c 100644
--- a/lib/time.c
+++ b/lib/time.c
@@ -63,7 +63,7 @@ ulong timer_get_boot_us(void)
 }
 
 #else
-extern unsigned long __weak timer_read_counter(void);
+extern unsigned long timer_read_counter(void);
 #endif
 
 #if CONFIG_IS_ENABLED(TIMER)
-- 
2.39.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Revert "time: add weak annotation to timer_read_counter declaration"
  2023-01-05  0:08 [PATCH] Revert "time: add weak annotation to timer_read_counter declaration" Harald Seiler
@ 2023-01-11 20:49 ` Rob Herring
  2023-01-13  0:16 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Rob Herring @ 2023-01-11 20:49 UTC (permalink / raw)
  To: Harald Seiler; +Cc: u-boot, Simon Glass, Serge Bazanski

On Wed, Jan 4, 2023 at 6:09 PM Harald Seiler <hws@denx.de> wrote:
>
> This reverts commit 65ba7add0d609bbd035b8d42fafdaf428ac24751.
>
> A weak extern is a nasty sight to behold: If the symbol is never
> defined, on ARM, the linker will replace the function call with a NOP.
> This behavior isn't well documented but there are at least some hints
> to it [1].
>
> When timer_read_counter() is not defined, this obviously does the wrong
> thing here and it does so silently.  The consequence is that a board
> without timer_read_counter() will sleep for random amounts and generally
> have erratic get_ticks() values.
>
> Drop the __weak annotation of the extern so a linker error is raised
> when timer_read_counter() is not defined.  This is okay, the original
> reason for the reverted change - breaking the sandbox build - no longer
> applies.
>
> Final sidenote:  This was the only weak extern in the entire tree at
> this time as far as I can tell.  I guess we should avoid introduction of
> them again as they are obviously a very big footgun.
>
> [1]: https://stackoverflow.com/questions/31203402/gcc-behavior-for-unresolved-weak-functions
>
> Fixes: 65ba7add0d60 ("time: add weak annotation to timer_read_counter declaration")

I don't agree that this is a fix to the above commit. Applying it at
any point after commit 65ba7add0d60 would not work in all cases. It
may not be needed any more, but that is probably due to the addition
of the timer class 2 years later, not that the commit was wrong/broken
at the time.

Rob

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Revert "time: add weak annotation to timer_read_counter declaration"
  2023-01-05  0:08 [PATCH] Revert "time: add weak annotation to timer_read_counter declaration" Harald Seiler
  2023-01-11 20:49 ` Rob Herring
@ 2023-01-13  0:16 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2023-01-13  0:16 UTC (permalink / raw)
  To: Harald Seiler; +Cc: u-boot, Rob Herring, Simon Glass, Serge Bazanski

[-- Attachment #1: Type: text/plain, Size: 1402 bytes --]

On Thu, Jan 05, 2023 at 01:08:47AM +0100, Harald Seiler wrote:

> This reverts commit 65ba7add0d609bbd035b8d42fafdaf428ac24751.
> 
> A weak extern is a nasty sight to behold: If the symbol is never
> defined, on ARM, the linker will replace the function call with a NOP.
> This behavior isn't well documented but there are at least some hints
> to it [1].
> 
> When timer_read_counter() is not defined, this obviously does the wrong
> thing here and it does so silently.  The consequence is that a board
> without timer_read_counter() will sleep for random amounts and generally
> have erratic get_ticks() values.
> 
> Drop the __weak annotation of the extern so a linker error is raised
> when timer_read_counter() is not defined.  This is okay, the original
> reason for the reverted change - breaking the sandbox build - no longer
> applies.
> 
> Final sidenote:  This was the only weak extern in the entire tree at
> this time as far as I can tell.  I guess we should avoid introduction of
> them again as they are obviously a very big footgun.
> 
> [1]: https://stackoverflow.com/questions/31203402/gcc-behavior-for-unresolved-weak-functions
> 
> Fixes: 65ba7add0d60 ("time: add weak annotation to timer_read_counter declaration")
> Reported-by: Serge Bazanski <q3k@q3k.org>
> Signed-off-by: Harald Seiler <hws@denx.de>

Applied to u-boot/master, thanks!

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-13  0:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-05  0:08 [PATCH] Revert "time: add weak annotation to timer_read_counter declaration" Harald Seiler
2023-01-11 20:49 ` Rob Herring
2023-01-13  0:16 ` Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.