clang: objtool: native_machine_emergency_restart() falls through to next function
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
Quoted 25 lines · Matthias Kaehlcke
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 functionmachine_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?
Quoted 6 lines
To repro:
git checkout v4.16
make CC=clang defconfig
echo "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" >> .config
make CC=clangarch/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?
tools/objtool/check.c +1 -0
@@ -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 )
Quoted 43 lines · Josh Poimboeuf
Quoted 25 lines · Matthias Kaehlcke
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 functionmachine_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?Quoted 6 lines
To repro:
git checkout v4.16
make CC=clang defconfig
echo "CONFIG_CC_OPTIMIZE_FOR_SIZE=y" >> .config
make CC=clangarch/x86/kernel/reboot.oHi Matthias,
Objtool can't detect 'noreturn' functions, so unfortunately we have to keep a manual list. Does this fix it?
tools/objtool/check.c +0
-0
tools/objtool/check.c static int __dead_end_function(struct objtool_file *file, struct symbol *func, · line 145
Quoted 7 lines
tools/objtool/check.c +1
-0@@ -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