Debian Codegraph @

vmtest/patches/5.10-gcc-12-disable-Wdangling-pointer-warning-for-now.patch

raw
1 From 1d8693376aaa10f12bbd67cfecb72a26a83058c5 Mon Sep 17 00:00:00 2001
2 Message-ID: <1d8693376aaa10f12bbd67cfecb72a26a83058c5.1744698211.git.osandov@fb.com>
3 From: Linus Torvalds <[email protected]>
4 Date: Thu, 9 Jun 2022 09:41:42 -0700
5 Subject: [PATCH] gcc-12: disable '-Wdangling-pointer' warning for now
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 commit f7d63b50898172b9eb061b9e2daad61b428792d0 upstream.
11
12 [ Upstream commit 49beadbd47c270a00754c107a837b4f29df4c822 ]
13
14 While the concept of checking for dangling pointers to local variables
15 at function exit is really interesting, the gcc-12 implementation is not
16 compatible with reality, and results in false positives.
17
18 For example, gcc sees us putting things on a local list head allocated
19 on the stack, which involves exactly those kinds of pointers to the
20 local stack entry:
21
22 In function ‘__list_add’,
23 inlined from ‘list_add_tail’ at include/linux/list.h:102:2,
24 inlined from ‘rebuild_snap_realms’ at fs/ceph/snap.c:434:2:
25 include/linux/list.h:74:19: warning: storing the address of local variable ‘realm_queue’ in ‘*&realm_27(D)->rebuild_item.prev’ [-Wdangling-pointer=]
26 74 | new->prev = prev;
27 | ~~~~~~~~~~^~~~~~
28
29 But then gcc - understandably - doesn't really understand the big
30 picture how the doubly linked list works, so doesn't see how we then end
31 up emptying said list head in a loop and the pointer we added has been
32 removed.
33
34 Gcc also complains about us (intentionally) using this as a way to store
35 a kind of fake stack trace, eg
36
37 drivers/acpi/acpica/utdebug.c:40:38: warning: storing the address of local variable ‘current_sp’ in ‘acpi_gbl_entry_stack_pointer’ [-Wdangling-pointer=]
38 40 | acpi_gbl_entry_stack_pointer = &current_sp;
39 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
40
41 which is entirely reasonable from a compiler standpoint, and we may want
42 to change those kinds of patterns, but not not.
43
44 So this is one of those "it would be lovely if the compiler were to
45 complain about us leaving dangling pointers to the stack", but not this
46 way.
47
48 Signed-off-by: Linus Torvalds <[email protected]>
49 Signed-off-by: Sasha Levin <[email protected]>
50 Signed-off-by: Greg Kroah-Hartman <[email protected]>
51 ---
52 Makefile | 4 ++++
53 1 file changed, 4 insertions(+)
54
55 diff --git a/Makefile b/Makefile
56 index 2f0efde21902..209d5ae9ddb5 100644
57 --- a/Makefile
58 +++ b/Makefile
59 @@ -808,6 +808,10 @@ endif
60 KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
61
62 KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
63 +
64 +# These result in bogus false positives
65 +KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
66 +
67 ifdef CONFIG_FRAME_POINTER
68 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
69 else
70 --
71 2.49.0
72