[Bug middle-end/82365] stack locations are consolidated if noreturn function is on the path

arnd at linaro dot org gcc-bugzilla@gcc.gnu.org
Fri Dec 15 13:34:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365

--- Comment #11 from Arnd Bergmann <arnd at linaro dot org> ---
More testing reveals that a handful of files in the kernel are affected by this
bug in the BUG() definition on architectures that do not use an inline assembly
statement to trap during an assertion, around half the supported architectures.
This kernel patch

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 963b755d19b0..23c6a2a6a3d6 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -52,6 +52,7 @@ struct bug_entry {
 #ifndef HAVE_ARCH_BUG
 #define BUG() do { \
        printk("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__);
\
+       barrier(); \
        panic("BUG!"); \
 } while (0)
 #endif

can work around the following set of overly large stack frames:

fs/ext4/inode.c:82:1: warning: the frame size of 1672 bytes is larger than 800
bytes [-Wframe-larger-than=]
fs/ext4/namei.c:434:1: warning: the frame size of 904 bytes is larger than 800
bytes [-Wframe-larger-than=]
fs/ext4/super.c:2279:1: warning: the frame size of 1160 bytes is larger than
800 bytes [-Wframe-larger-than=]
fs/ext4/xattr.c:146:1: warning: the frame size of 1168 bytes is larger than 800
bytes [-Wframe-larger-than=]
fs/f2fs/inode.c:152:1: warning: the frame size of 1424 bytes is larger than 800
bytes [-Wframe-larger-than=]
net/netfilter/ipvs/ip_vs_core.c:1195:1: warning: the frame size of 1068 bytes
is larger than 800 bytes [-Wframe-larger-than=]
net/netfilter/ipvs/ip_vs_core.c:395:1: warning: the frame size of 1084 bytes is
larger than 800 bytes [-Wframe-larger-than=]
net/netfilter/ipvs/ip_vs_ftp.c:298:1: warning: the frame size of 928 bytes is
larger than 800 bytes [-Wframe-larger-than=]
net/netfilter/ipvs/ip_vs_ftp.c:418:1: warning: the frame size of 908 bytes is
larger than 800 bytes [-Wframe-larger-than=]
net/netfilter/ipvs/ip_vs_lblcr.c:718:1: warning: the frame size of 960 bytes is
larger than 800 bytes [-Wframe-larger-than=]
drivers/net/xen-netback/netback.c:1500:1: warning: the frame size of 1088 bytes
is larger than 800 bytes [-Wframe-larger-than=]

and similar patches can be created for architectures not using the generic
implementation. For reference, the above was tested on all architectures that
are supported by mainline versions of both linux and gcc using an
'allmodconfig' build, and the same symptoms were visible on all architectures
using the generic BUG(). I only looked at files that had any functions with
frame sizes over 800 bytes (1000 bytes for 64-bit architectures), 89 files in
total out of 31841 source files that were built, down to 78 with my workaround.

In a single build, around 100 files had functions that get a (mostly minor)
reduction in frame size with my patch, in a few cases the frame sizes appear to
get slightly larger due to different inlining decisions, and in some other
cases including the ones listed above there is a drastic reduction in frame
size of factor two to five.

I have submitted a workaround for the kernel for the original case (involving
strncpy()) and plan to submit another workaround for BUG() now. However, I'd
still like to see this addressed in gcc as well, since that will cover those
instances in other code. I would hope that a simple workaround such as the
patch for PR81715 is possible. This seems to be a related issue with very
similar symptoms.


More information about the Gcc-bugs mailing list