From 2a122642b4e4a7ec0f414b30d6ed7c48bc5c2eeb Mon Sep 17 00:00:00 2001 From: Gary Benson Date: Mon, 13 Jul 2020 14:47:44 +0100 Subject: [PATCH] Use volatile pointers when attempting to trigger SIGSEGVs Clang fails to compile a number of files with the following warning: indirection of non-volatile null pointer will be deleted, not trap [-Wnull-dereference]. This commit qualifies the relevant pointers with 'volatile'. gdb/testsuite/ChangeLog: * gdb.base/bigcore.c (main): Use a volatile pointer when attempting to trigger a SIGSEGV. * gdb.base/gcore-relro-pie.c (break_here): Likewise. * gdb.base/gcore-tls-pie.c (break_here): Likewise. * gdb.base/savedregs.c (thrower): Likewise. * gdb.mi/mi-syn-frame.c (bar): Likewise. --- gdb/testsuite/ChangeLog | 9 +++++++++ gdb/testsuite/gdb.base/bigcore.c | 2 +- gdb/testsuite/gdb.base/gcore-relro-pie.c | 2 +- gdb/testsuite/gdb.base/gcore-tls-pie.c | 2 +- gdb/testsuite/gdb.base/savedregs.c | 2 +- gdb/testsuite/gdb.mi/mi-syn-frame.c | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 1798f92705b..fc9dcac563a 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2020-07-13 Gary Benson + + * gdb.base/bigcore.c (main): Use a volatile pointer when + attempting to trigger a SIGSEGV. + * gdb.base/gcore-relro-pie.c (break_here): Likewise. + * gdb.base/gcore-tls-pie.c (break_here): Likewise. + * gdb.base/savedregs.c (thrower): Likewise. + * gdb.mi/mi-syn-frame.c (bar): Likewise. + 2020-07-13 Gary Benson * gdb.base/vla-datatypes.c (vla_factory): Factor out sections diff --git a/gdb/testsuite/gdb.base/bigcore.c b/gdb/testsuite/gdb.base/bigcore.c index 174e0f67f00..8be1b154b39 100644 --- a/gdb/testsuite/gdb.base/bigcore.c +++ b/gdb/testsuite/gdb.base/bigcore.c @@ -267,5 +267,5 @@ main () /* Push everything out to disk. */ print_string ("Dump core ....\n"); - *(char*)0 = 0; + *(volatile char*)0 = 0; } diff --git a/gdb/testsuite/gdb.base/gcore-relro-pie.c b/gdb/testsuite/gdb.base/gcore-relro-pie.c index 20cf12c5632..9ae7cb2cb9b 100644 --- a/gdb/testsuite/gdb.base/gcore-relro-pie.c +++ b/gdb/testsuite/gdb.base/gcore-relro-pie.c @@ -18,7 +18,7 @@ void break_here (void) { - *(int *) 0 = 0; + *(volatile int *) 0 = 0; } void diff --git a/gdb/testsuite/gdb.base/gcore-tls-pie.c b/gdb/testsuite/gdb.base/gcore-tls-pie.c index 73aec409f1e..18169fcd627 100644 --- a/gdb/testsuite/gdb.base/gcore-tls-pie.c +++ b/gdb/testsuite/gdb.base/gcore-tls-pie.c @@ -25,7 +25,7 @@ __thread char i; void break_here (void) { - *(int *) 0 = 0; + *(volatile int *) 0 = 0; } void diff --git a/gdb/testsuite/gdb.base/savedregs.c b/gdb/testsuite/gdb.base/savedregs.c index d3bcbf7826d..05fba506156 100644 --- a/gdb/testsuite/gdb.base/savedregs.c +++ b/gdb/testsuite/gdb.base/savedregs.c @@ -46,7 +46,7 @@ static void thrower (void) { /* Trigger a SIGSEGV. */ - *(char *)0 = 0; + *(volatile char *)0 = 0; /* On MMU-less system, previous memory access to address zero doesn't trigger a SIGSEGV. Trigger a SIGILL. Each arch should define its diff --git a/gdb/testsuite/gdb.mi/mi-syn-frame.c b/gdb/testsuite/gdb.mi/mi-syn-frame.c index c260112b3fd..b6ab6e8d88a 100644 --- a/gdb/testsuite/gdb.mi/mi-syn-frame.c +++ b/gdb/testsuite/gdb.mi/mi-syn-frame.c @@ -27,7 +27,7 @@ foo (void) void bar (void) { - *(char *)0 = 0; /* try to cause a segfault */ + *(volatile char *)0 = 0; /* try to cause a segfault */ /* On MMU-less system, previous memory access to address zero doesn't trigger a SIGSEGV. Trigger a SIGILL. Each arch should define its -- 2.30.2