tracing: Use address-of operator on section symbols 91/294191/1
authorNathan Chancellor <natechancellor@gmail.com>
Thu, 20 Feb 2020 05:10:12 +0000 (22:10 -0700)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 14 Jun 2023 05:32:50 +0000 (14:32 +0900)
Clang warns:

../kernel/trace/trace.c:9335:33: warning: array comparison always
evaluates to true [-Wtautological-compare]
        if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt)
                                       ^
1 warning generated.

These are not true arrays, they are linker defined symbols, which are
just addresses. Using the address of operator silences the warning and
does not change the runtime result of the check (tested with some print
statements compiled in with clang + ld.lld and gcc + ld.bfd in QEMU).

Link: http://lkml.kernel.org/r/20200220051011.26113-1-natechancellor@gmail.com
Link: https://github.com/ClangBuiltLinux/linux/issues/893
Suggested-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
[sw0312.kim: backport upstream commit bf2cbe044da2 to resolve gcc-13 build issue]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Ie075db5d5b52b4cffdc3540035fe0f2c200b391a

kernel/trace/trace.c

index ab7d21c75dc8e25d2426f9febe4e4734593f8558..16b9435c52edf5052ce6676fa0a24ecb1574d4fa 100644 (file)
@@ -7750,7 +7750,7 @@ __init static int tracer_alloc_buffers(void)
                goto out_free_buffer_mask;
 
        /* Only allocate trace_printk buffers if a trace_printk exists */
-       if (__stop___trace_bprintk_fmt != __start___trace_bprintk_fmt)
+       if (&__stop___trace_bprintk_fmt != &__start___trace_bprintk_fmt)
                /* Must be called before global_trace.buffer is allocated */
                trace_printk_init_buffers();