* [U-Boot] __weak usage
@ 2014-06-28 17:00 Jeroen Hofstee
2014-06-28 18:34 ` Tom Rini
0 siblings, 1 reply; 2+ messages in thread
From: Jeroen Hofstee @ 2014-06-28 17:00 UTC (permalink / raw)
To: u-boot
Hi,
Perhaps this is trivial for you all, but it is something I had
not realized before looking into the warnings u-boot generates
with W=1 / clang. The below "program" will compile fine with
MAKEALL (even with pedantic warnings). Since the compiler
never sees the different definition and the linker does not care,
there is no warning at all.
If a weak prototype ever changes, running MAKEALL gives no
guarantee boards don't crash at runtime. Hence I would propose
that when adding a new __weak, both the weak and non weak
definition actually see the common prototype. And please use
__weak to reduce the noise when compiling with W=1.
Regards,
Jeroen
::::::::::::::
a.c
::::::::::::::
#define __weak __attribute__((weak))
__weak void some_function(void)
{
}
void go(void)
{
some_function();
}
::::::::::::::
b.c
::::::::::::::
#include <stdio.h>
extern void go(void);
void some_function(int *arg)
{
printf("lets crash %d", *arg);
}
int main()
{
go();
return 0;
}
jeroen at yellow:~/weak$ gcc -Wall -Wpedantic a.c b.c
jeroen at yellow:~/weak$ ./a.out
Segmentation fault
^ permalink raw reply [flat|nested] 2+ messages in thread
* [U-Boot] __weak usage
2014-06-28 17:00 [U-Boot] __weak usage Jeroen Hofstee
@ 2014-06-28 18:34 ` Tom Rini
0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2014-06-28 18:34 UTC (permalink / raw)
To: u-boot
On Sat, Jun 28, 2014 at 07:00:52PM +0200, Jeroen Hofstee wrote:
> Hi,
>
> Perhaps this is trivial for you all, but it is something I had
> not realized before looking into the warnings u-boot generates
> with W=1 / clang. The below "program" will compile fine with
> MAKEALL (even with pedantic warnings). Since the compiler
> never sees the different definition and the linker does not care,
> there is no warning at all.
>
> If a weak prototype ever changes, running MAKEALL gives no
> guarantee boards don't crash at runtime. Hence I would propose
> that when adding a new __weak, both the weak and non weak
> definition actually see the common prototype. And please use
> __weak to reduce the noise when compiling with W=1.
Indeed, __weak functions should still be listed in header files, cases
that don't are a bug.
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140628/b309a70d/attachment.pgp>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-06-28 18:34 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-28 17:00 [U-Boot] __weak usage Jeroen Hofstee
2014-06-28 18:34 ` 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.