[U-Boot] __weak usage

Jeroen Hofstee jeroen at myspectrum.nl
Sat Jun 28 19:00:52 CEST 2014


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


More information about the U-Boot mailing list