Use volatile pointers when attempting to trigger SIGSEGVs

Message ID 1593524541-3894-1-git-send-email-gbenson@redhat.com
State New
Headers show
Series
  • Use volatile pointers when attempting to trigger SIGSEGVs
Related show

Commit Message

Shahab Vahedi via Gdb-patches June 30, 2020, 1:42 p.m.
Hi all,

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 patch qualifies the relevant pointers
with 'volatile'.

Checked on Fedora 31 x86_64, GCC and clang.  Ok to commit?

Cheers,
Gary

--
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(-)

-- 
1.8.3.1

Comments

Pedro Alves July 10, 2020, 2:39 p.m. | #1
On 6/30/20 2:42 PM, Gary Benson via Gdb-patches wrote:
> Hi all,

> 

> 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 patch qualifies the relevant pointers

> with 'volatile'.

> 

> Checked on Fedora 31 x86_64, GCC and clang.  Ok to commit?


OK

Thanks,
Pedro Alves
Shahab Vahedi via Gdb-patches July 13, 2020, 1:50 p.m. | #2
Pedro Alves wrote:
> On 6/30/20 2:42 PM, Gary Benson via Gdb-patches wrote:

> > Hi all,

> > 

> > 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 patch qualifies the relevant pointers

> > with 'volatile'.

> > 

> > Checked on Fedora 31 x86_64, GCC and clang.  Ok to commit?

> 

> OK


Thanks, I've pushed it.

Cheers,
Gary

-- 
Gary Benson - he / him / his
Principal Software Engineer, Red Hat

Patch

diff --git a/gdb/testsuite/gdb.base/bigcore.c b/gdb/testsuite/gdb.base/bigcore.c
index 174e0f6..8be1b15 100644
--- a/gdb/testsuite/gdb.base/bigcore.c
+++ b/gdb/testsuite/gdb.base/bigcore.c
@@ -267,5 +267,5 @@  struct list
   /* 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 20cf12c..9ae7cb2 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 73aec40..18169fc 100644
--- a/gdb/testsuite/gdb.base/gcore-tls-pie.c
+++ b/gdb/testsuite/gdb.base/gcore-tls-pie.c
@@ -25,7 +25,7 @@ 
 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 71b076f..aec2a38 100644
--- a/gdb/testsuite/gdb.base/savedregs.c
+++ b/gdb/testsuite/gdb.base/savedregs.c
@@ -46,7 +46,7 @@ 
 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 c260112..b6ab6e8 100644
--- a/gdb/testsuite/gdb.mi/mi-syn-frame.c
+++ b/gdb/testsuite/gdb.mi/mi-syn-frame.c
@@ -27,7 +27,7 @@ 
 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