From: Jeroen Hofstee <jeroen@myspectrum.nl>
To: u-boot@lists.denx.de
Subject: [U-Boot] __weak usage
Date: Sat, 28 Jun 2014 19:00:52 +0200 [thread overview]
Message-ID: <53AEF4C4.1040108@myspectrum.nl> (raw)
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
next reply other threads:[~2014-06-28 17:00 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-28 17:00 Jeroen Hofstee [this message]
2014-06-28 18:34 ` [U-Boot] __weak usage Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53AEF4C4.1040108@myspectrum.nl \
--to=jeroen@myspectrum.nl \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.