[PATCH] kselftest/coredump: Fix test failure due to __builtin_trap()

From: Nam Cao

Date: Fri Mar 06 2026 - 03:24:13 EST


Commit 673a55cc49da ("kselftest/coredump: use __builtin_trap() instead of
null pointer") changed the plain NULL pointer deference to __builtin_trap()
because LLVM optimizes the NULL pointer deference away.

However, this makes the test fail on RISC-V, because __builtin_trap()
raises a SIGTRAP instead of SIGSEGV as expected by the test:

# RUN coredump.socket_coredump_signal_sigsegv ...
Set core_pattern to '@@/tmp/coredump.socket' | 22 == 22
get_peer_pidfd: successfully retrieved pidfd 13
get_pidfd_info: mask=0x57, coredump_mask=0x5, coredump_signal=5
socket_coredump_signal_sigsegv: coredump_signal=5, expected SIGSEGV=11
# coredump_socket_protocol_test.c:1125:socket_coredump_signal_sigsegv:Expected WTERMSIG(status) (5) == SIGSEGV (11)
# socket_coredump_signal_sigsegv: Test terminated by assertion
# FAIL coredump.socket_coredump_signal_sigsegv
not ok 8 coredump.socket_coredump_signal_sigsegv

Instead of __builtin_trap(), implement the other suggestion from LLVM
(volatile) to make the test pass.

Signed-off-by: Nam Cao <namcao@xxxxxxxxxxxxx>
---
tools/testing/selftests/coredump/coredump_test_helpers.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/coredump/coredump_test_helpers.c b/tools/testing/selftests/coredump/coredump_test_helpers.c
index 5c8adee63641..2c850e0b1b57 100644
--- a/tools/testing/selftests/coredump/coredump_test_helpers.c
+++ b/tools/testing/selftests/coredump/coredump_test_helpers.c
@@ -56,7 +56,7 @@ void crashing_child(void)
pthread_create(&thread, NULL, do_nothing, NULL);

/* crash on purpose */
- __builtin_trap();
+ i = *(volatile int *)NULL;
}

int create_detached_tmpfs(void)
--
2.47.3