[gPXE-devel] [PATCH] [compiler] Mark weak functions noinline
Joshua Oreman
oremanj at rwcr.net
Wed Jul 14 11:53:14 EDT 2010
On Wed, Jul 14, 2010 at 2:13 AM, Stefan Hajnoczi <stefanha at gmail.com> wrote:
> Weak functions whose visibility is hidden may be inlined due to a bug in
> GCC. Explicitly mark weak functions noinline to work around the
> problem.
ACK. Thanks for putting this together.
-- Josh
> This makes the PXE_MENU config option work again, the PXE boot menu was
> never being called because the compiler inlined a weak stub function.
>
> The GCC bug was identified and fixed by Richard Sandiford
> <rdsandiford at googlemail.com> but in the meantime gPXE needs to implement
> a workaround.
>
> Reported-by: Steve Jones <steve at squaregoldfish.co.uk>
> Reported-by: Shao Miller <shao.miller at yrdsb.edu.on.ca>
> Suggested-by: Joshua Oreman <oremanj at rwcr.net>
> Signed-off-by: Stefan Hajnoczi <stefanha at gmail.com>
> ---
> src/include/compiler.h | 10 ++++++++--
> 1 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/src/include/compiler.h b/src/include/compiler.h
> index 8ccc69c..926308b 100644
> --- a/src/include/compiler.h
> +++ b/src/include/compiler.h
> @@ -181,8 +181,14 @@ REQUEST_EXPANDED ( CONFIG_SYMBOL );
>
> #ifndef ASSEMBLY
>
> -/** Declare a function as weak (use *before* the definition) */
> -#define __weak __attribute__ (( weak ))
> +/** Declare a function as weak (use *before* the definition)
> + *
> + * Due to a bug in at least GCC 4.4.4 and earlier, weak symbols may be inlined
> + * if they have hidden visibility (see above for why hidden visibility is
> + * used). This results in the non-weak symbol never being used, so explicitly
> + * mark the function as noinline to prevent inlining.
> + */
> +#define __weak __attribute__ (( weak )) __attribute (( noinline ))
>
> #endif
>
> --
> 1.7.1
>
>
More information about the gPXE-devel
mailing list