Bug 216090

Summary: GCC12: printk.h:446:44: error: using a dangling pointer to '__str'
Product: Platform Specific/Hardware Reporter: Vitaly Chikunov (vt)
Component: PPC-64Assignee: platform_ppc-64
Status: CLOSED CODE_FIX    
Severity: normal CC: michael
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 5.17.13 Subsystem:
Regression: Yes Bisected commit-id:

Description Vitaly Chikunov 2022-06-07 02:26:24 UTC
There is build error on GCC 12:


  [00:00:26]   CC      arch/powerpc/kernel/trace/ftrace.o
  [00:00:26] In file included from ./include/asm-generic/bug.h:22,
  [00:00:26]                  from ./arch/powerpc/include/asm/bug.h:149,
  [00:00:26]                  from ./include/linux/bug.h:5,
  [00:00:26]                  from ./include/linux/thread_info.h:13,
  [00:00:26]                  from ./include/asm-generic/preempt.h:5,
  [00:00:26]                  from ./arch/powerpc/include/generated/asm/preempt.h:1,
  [00:00:26]                  from ./include/linux/preempt.h:78,
  [00:00:26]                  from ./include/linux/spinlock.h:55,
  [00:00:26]                  from arch/powerpc/kernel/trace/ftrace.c:16:
  [00:00:26] arch/powerpc/kernel/trace/ftrace.c: In function 'ftrace_modify_code':
  [00:00:26] ./include/linux/printk.h:446:44: error: using a dangling pointer to '__str' [-Werror=dangling-pointer=]
  [00:00:26]   446 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
  [00:00:26]       |                                            ^
  [00:00:26] ./include/linux/printk.h:418:17: note: in definition of macro 'printk_index_wrap'
  [00:00:26]   418 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
  [00:00:26]       |                 ^~~~~~~
  [00:00:26] ./include/linux/printk.h:489:9: note: in expansion of macro 'printk'
  [00:00:26]   489 |         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
  [00:00:26]       |         ^~~~~~
  [00:00:26] arch/powerpc/kernel/trace/ftrace.c:76:17: note: in expansion of macro 'pr_err'
  [00:00:26]    76 |                 pr_err("%p: replaced (%s) != old (%s)",
  [00:00:26]       |                 ^~~~~~
  [00:00:26] In file included from ./arch/powerpc/include/asm/code-patching.h:14,
  [00:00:26]                  from arch/powerpc/kernel/trace/ftrace.c:27:
  [00:00:26] ./arch/powerpc/include/asm/inst.h:156:14: note: '__str' declared here
  [00:00:26]   156 |         char __str[PPC_INST_STR_LEN];   \
  [00:00:26]       |              ^~~~~
  [00:00:26] ./include/linux/printk.h:418:33: note: in expansion of macro 'ppc_inst_as_str'
  [00:00:26]   418 |                 _p_func(_fmt, ##__VA_ARGS__);                           \
  [00:00:26]       |                                 ^~~~~~~~~~~
  [00:00:26] ./include/linux/printk.h:446:26: note: in expansion of macro 'printk_index_wrap'
  [00:00:26]   446 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)


This may be related discussion: https://lore.kernel.org/all/20220601162023.GW25951@gate.crashing.org/T/
Comment 1 Artem S. Tashkinov 2022-06-07 08:33:57 UTC
Linux kernel developers are well aware of the regressions related to GCC 12.x. Patches are being worked on.
Comment 2 Michael Ellerman 2022-07-29 06:57:23 UTC
Fixed in 2a83afe72a2b ("powerpc/64: Drop ppc_inst_as_str()").

The warning has also been disabled in 49beadbd47c2 ("gcc-12: disable '-Wdangling-pointer' warning for now").