linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* clang: objtool: native_machine_emergency_restart() falls through to next function
@ 2018-06-15 21:14 Matthias Kaehlcke
  2018-06-18 22:17 ` Josh Poimboeuf
  0 siblings, 1 reply; 3+ messages in thread
From: Matthias Kaehlcke @ 2018-06-15 21:14 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: linux-kernel, Manoj Gupta, Nick Desaulniers

Hi Josh,

with your work on objtool and the upcoming implementation of
-fno-delete-null-pointer-checks (https://reviews.llvm.org/D47894,
https://reviews.llvm.org/D47895) in clang most objtool warnings
for clang builds will be fixed.

However even with -fno-delete-null-pointer-checks we currently still
get a warning about native_machine_emergency_restart():

arch/x86/kernel/reboot.o: warning: objtool:
  native_machine_emergency_restart()
  falls through to next function machine_power_off()

This only occurs when building with -Oz.

One of our compiler engineers looked into this, LLVM optimizes the
return statement away since the function has an endless loop, and
actually never returns.

Is there a way to tell objtool that the function is not expected to
return (I tried the attribute __noreturn, but it doesn't make a
difference), or do we have to tell clang to restrain from optimizing
returns out?

To repro:

git checkout v4.16
make CC=clang defconfig
echo "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" >> .config
make CC=clang arch/x86/kernel/reboot.o

Thanks

Matthias

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

* Re: clang: objtool: native_machine_emergency_restart() falls through to next function
  2018-06-15 21:14 clang: objtool: native_machine_emergency_restart() falls through to next function Matthias Kaehlcke
@ 2018-06-18 22:17 ` Josh Poimboeuf
  2018-06-18 22:52   ` Matthias Kaehlcke
  0 siblings, 1 reply; 3+ messages in thread
From: Josh Poimboeuf @ 2018-06-18 22:17 UTC (permalink / raw)
  To: Matthias Kaehlcke; +Cc: linux-kernel, Manoj Gupta, Nick Desaulniers

On Fri, Jun 15, 2018 at 02:14:41PM -0700, Matthias Kaehlcke wrote:
> Hi Josh,
> 
> with your work on objtool and the upcoming implementation of
> -fno-delete-null-pointer-checks (https://reviews.llvm.org/D47894,
> https://reviews.llvm.org/D47895) in clang most objtool warnings
> for clang builds will be fixed.
> 
> However even with -fno-delete-null-pointer-checks we currently still
> get a warning about native_machine_emergency_restart():
> 
> arch/x86/kernel/reboot.o: warning: objtool:
>   native_machine_emergency_restart()
>   falls through to next function machine_power_off()
> 
> This only occurs when building with -Oz.
> 
> One of our compiler engineers looked into this, LLVM optimizes the
> return statement away since the function has an endless loop, and
> actually never returns.
> 
> Is there a way to tell objtool that the function is not expected to
> return (I tried the attribute __noreturn, but it doesn't make a
> difference), or do we have to tell clang to restrain from optimizing
> returns out?
> 
> To repro:
> 
> git checkout v4.16
> make CC=clang defconfig
> echo "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" >> .config
> make CC=clang arch/x86/kernel/reboot.o

Hi Matthias,

Objtool can't detect 'noreturn' functions, so unfortunately we have to
keep a manual list.  Does this fix it?

diff --git a/tools/objtool/check.c b/tools/objtool/check.c
index 5409f6f6c48d..ace3f85701c8 100644
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -139,6 +139,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func,
 		"lbug_with_loc",
 		"fortify_panic",
 		"usercopy_abort",
+		"machine_real_restart",
 	};
 
 	if (func->bind == STB_WEAK)

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

* Re: clang: objtool: native_machine_emergency_restart() falls through to next function
  2018-06-18 22:17 ` Josh Poimboeuf
@ 2018-06-18 22:52   ` Matthias Kaehlcke
  0 siblings, 0 replies; 3+ messages in thread
From: Matthias Kaehlcke @ 2018-06-18 22:52 UTC (permalink / raw)
  To: Josh Poimboeuf; +Cc: linux-kernel, Manoj Gupta, Nick Desaulniers

On Mon, Jun 18, 2018 at 05:17:16PM -0500, Josh Poimboeuf wrote:
> On Fri, Jun 15, 2018 at 02:14:41PM -0700, Matthias Kaehlcke wrote:
> > Hi Josh,
> > 
> > with your work on objtool and the upcoming implementation of
> > -fno-delete-null-pointer-checks (https://reviews.llvm.org/D47894,
> > https://reviews.llvm.org/D47895) in clang most objtool warnings
> > for clang builds will be fixed.
> > 
> > However even with -fno-delete-null-pointer-checks we currently still
> > get a warning about native_machine_emergency_restart():
> > 
> > arch/x86/kernel/reboot.o: warning: objtool:
> >   native_machine_emergency_restart()
> >   falls through to next function machine_power_off()
> > 
> > This only occurs when building with -Oz.
> > 
> > One of our compiler engineers looked into this, LLVM optimizes the
> > return statement away since the function has an endless loop, and
> > actually never returns.
> > 
> > Is there a way to tell objtool that the function is not expected to
> > return (I tried the attribute __noreturn, but it doesn't make a
> > difference), or do we have to tell clang to restrain from optimizing
> > returns out?
> > 
> > To repro:
> > 
> > git checkout v4.16
> > make CC=clang defconfig
> > echo "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" >> .config
> > make CC=clang arch/x86/kernel/reboot.o
> 
> Hi Matthias,
> 
> Objtool can't detect 'noreturn' functions, so unfortunately we have to
> keep a manual list.  Does this fix it?
> 
> diff --git a/tools/objtool/check.c b/tools/objtool/check.c
> index 5409f6f6c48d..ace3f85701c8 100644
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -139,6 +139,7 @@ static int __dead_end_function(struct objtool_file *file, struct symbol *func,
>  		"lbug_with_loc",
>  		"fortify_panic",
>  		"usercopy_abort",
> +		"machine_real_restart",
>  	};
>  
>  	if (func->bind == STB_WEAK)

Yes this helps, thanks for having a look!

Could you send this as an official patch or should I do it (crediting
you)?

Thanks

Matthias

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

end of thread, other threads:[~2018-06-18 22:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-15 21:14 clang: objtool: native_machine_emergency_restart() falls through to next function Matthias Kaehlcke
2018-06-18 22:17 ` Josh Poimboeuf
2018-06-18 22:52   ` Matthias Kaehlcke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).