Re: [PATCH] bug.h: Work around GCC PR82365 in BUG()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 02/07/2018 05:20 PM, Vineet Gupta wrote:

Didn't do ;)

Is Arnd's patch good to merge or do we need a fixup?


From: Arnd Bergmann <arnd@xxxxxxxx>
Subject: bug.h: work around GCC PR82365 in BUG()

Looking at functions with large stack frames across all architectures led
me discovering that BUG() suffers from the same problem as
fortify_panic(), which I've added a workaround for already.  In short,
variables that go out of scope by calling a noreturn function or
__builtin_unreachable() keep using stack space in functions afterwards.

A workaround that was identified is to insert an empty assembler statement
just before calling the function that doesn't return.  I'm adding a macro
"barrier_before_unreachable()" to document this, and insert calls to that
in all instances of BUG() that currently suffer from this problem.

..
..

---

  arch/arc/include/asm/bug.h            |    3 ++-
  arch/cris/include/arch-v10/arch/bug.h |   11 +++++++++--
  arch/ia64/include/asm/bug.h           |    6 +++++-
  arch/m68k/include/asm/bug.h           |    3 +++
  arch/sparc/include/asm/bug.h          |    6 +++++-
  include/asm-generic/bug.h             |    1 +
  include/linux/compiler-gcc.h          |   15 ++++++++++++++-
  include/linux/compiler.h              |    5 +++++
  8 files changed, 44 insertions(+), 6 deletions(-)

diff -puN arch/arc/include/asm/bug.h~bugh-work-around-gcc-pr82365-in-bug arch/arc/include/asm/bug.h
--- a/arch/arc/include/asm/bug.h~bugh-work-around-gcc-pr82365-in-bug
+++ a/arch/arc/include/asm/bug.h
@@ -23,7 +23,8 @@ void die(const char *str, struct pt_regs
    #define BUG()    do {                                \
      pr_warn("BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
-    dump_stack();                                \
+    barrier_before_unreachable();                        \
+    __builtin_trap();                            \
  } while (0)

For ARC, it is double win.

1. Fixes 3 -Wreturn-type warnings

| ../net/core/ethtool.c:311:1: warning: control reaches end of non-void function [-Wreturn-type] | ../kernel/sched/core.c:3246:1: warning: control reaches end of non-void function [-Wreturn-type] | ../include/linux/sunrpc/svc_xprt.h:180:1: warning: control reaches end of non-void function [-Wreturn-type]

2. bloat-o-meter reports code size improvements as gcc elides the generated code for stack return.


Acked-by: Vineet Gupta <vgupta@xxxxxxxxxxxx>   # for arch/arc
Tested-by: Vineet Gupta <vgupta@xxxxxxxxxxxx>   # for arch/arc

Ping ?

--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux&nblp;USB Development]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite Secrets]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux