]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
kselftest/coredump: use __builtin_trap() instead of null pointer
authorClint George <clintbgeorge@gmail.com>
Mon, 15 Dec 2025 08:47:37 +0000 (14:17 +0530)
committerShuah Khan <skhan@linuxfoundation.org>
Wed, 31 Dec 2025 17:49:57 +0000 (10:49 -0700)
Use __builtin_trap() to truly crash the program instead of dereferencing
null pointer which may be optimized by the compiler preventing the crash
from occurring

[] Testing:
The diff between before and after of running the kselftest test of the
module shows no regression on system with x86 architecture

[] Error log:
~/Desktop/kernel-dev/linux-v1/tools/testing/selftests/coredump$ make LLVM=1 W=1
  CC       stackdump_test
coredump_test_helpers.c:59:6: warning: indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference]
   59 |         i = *(int *)NULL;
      |             ^~~~~~~~~~~~
coredump_test_helpers.c:59:6: note: consider using __builtin_trap() or qualifying pointer with 'volatile'
1 warning generated.
  CC       coredump_socket_test
coredump_test_helpers.c:59:6: warning: indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference]
   59 |         i = *(int *)NULL;
      |             ^~~~~~~~~~~~
coredump_test_helpers.c:59:6: note: consider using __builtin_trap() or qualifying pointer with 'volatile'
1 warning generated.
  CC       coredump_socket_protocol_test
coredump_test_helpers.c:59:6: warning: indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference]
   59 |         i = *(int *)NULL;
      |             ^~~~~~~~~~~~
coredump_test_helpers.c:59:6: note: consider using __builtin_trap() or qualifying pointer with 'volatile'
1 warning generated.

Link: https://lore.kernel.org/r/20251215084737.7504-1-clintbgeorge@gmail.com
Signed-off-by: Clint George <clintbgeorge@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/coredump/coredump_test_helpers.c

index a6f6d5f2ae07a7cf71c098086db1f96dc4bf6bbd..5c8adee63641490f7b949d291728b18d2befb220 100644 (file)
@@ -56,7 +56,7 @@ void crashing_child(void)
                pthread_create(&thread, NULL, do_nothing, NULL);
 
        /* crash on purpose */
-       i = *(int *)NULL;
+       __builtin_trap();
 }
 
 int create_detached_tmpfs(void)