[review] Don't use class-initialization for the owner union

Message ID gerrit.1574039773000.I94f48afeae5d29cf81a280295e2d02e2d7e1c1f1@gnutoolchain-gerrit.osci.io
State New, archived
Headers

Commit Message

Simon Marchi (Code Review) Nov. 18, 2019, 1:16 a.m. UTC
  Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/684
......................................................................

Don't use class-initialization for the owner union

As reported by PhilippeW, valgrind reports that symtab is uninitialized
when compiling with GCC 4.8.5, which is the default compiler on CentOS 7.

This is apparently a compiler bug fixed in later versions, but to keep
CentOS 7 working, this patch initializes the union explicitly instead of
using a class initializer.

gdb/ChangeLog:

2019-11-17  Christian Biesinger  <cbiesinger@google.com>

	* symtab.h (struct symbol) <owner>: Initialize explicitly in the
	constructor instead of using a class initializer.

Change-Id: I94f48afeae5d29cf81a280295e2d02e2d7e1c1f1
---
M gdb/symtab.h
1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Simon Marchi (Code Review) Nov. 18, 2019, 4:56 p.m. UTC | #1
Tom Tromey has posted comments on this change.

Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/684
......................................................................


Patch Set 1: Code-Review+2

Thank you.  This is ok.
  

Patch

diff --git a/gdb/symtab.h b/gdb/symtab.h
index a6bd3c4..1e82182 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1113,6 +1113,9 @@ 
       language = language_unknown;
       ada_mangled = 0;
       section = 0;
+      /* GCC 4.8.5 (on CentOS 7) does not correctly compile class-
+         initialization of unions, so we initialize it manually here.  */
+      owner.symtab = nullptr;
     }
 
   /* Data type of value */
@@ -1127,7 +1130,7 @@ 
     /* The symbol table containing this symbol.  This is the file associated
        with LINE.  It can be NULL during symbols read-in but it is never NULL
        during normal operation.  */
-    struct symtab *symtab = nullptr;
+    struct symtab *symtab;
 
     /* For types defined by the architecture.  */
     struct gdbarch *arch;