Debian Codegraph @

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

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