[review] Make struct symbol inherit from general_symbol_info

Message ID gerrit.1572895167000.I05b1628455bcce3efaa101e65ef051708d17eb07@gnutoolchain-gerrit.osci.io
State New, archived
Headers

Commit Message

Simon Marchi (Code Review) Nov. 4, 2019, 7:19 p.m. UTC
  Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/510
......................................................................

Make struct symbol inherit from general_symbol_info

Since this is now no longer a POD, also give it a constructor that
initializes all fields. (I have considered overloading operator new
to zero-initialize the memory instead; let me know if you prefer that)

gdb/ChangeLog:

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

	* ada-exp.y: Update.
	* buildsym.c (add_symbol_to_list): Update.
	* dwarf2read.c (read_variable): Update.
	(new_symbol): Update.
	* jit.c (finalize_symtab): Update.
	* language.c (language_alloc_type_symbol): Update.
	* symtab.c (fixup_symbol_section): Update.
	(initialize_objfile_symbol_1): Move code to...
	(initialize_objfile_symbol): ...here. Remove now-unnecessary memset.
	(allocate_symbol): Update.
	(allocate_template_symbol): Update.
	(get_symbol_address): Update.
	* symtab.h (struct symbol): Inherit from general_symbol_info instead
	of having as a field, and add a constructor.
	(SYMBOL_VALUE): Update.
	(SYMBOL_VALUE_ADDRESS): Update.
	(SET_SYMBOL_VALUE_ADDRESS): Update.
	(SYMBOL_VALUE_BYTES): Update.
	(SYMBOL_VALUE_COMMON_BLOCK): Update.
	(SYMBOL_BLOCK_VALUE): Update.
	(SYMBOL_VALUE_CHAIN): Update.
	(SYMBOL_LANGUAGE): Update.
	(SYMBOL_SECTION): Update.
	(SYMBOL_OBJ_SECTION): Update.
	(SYMBOL_SET_LANGUAGE): Update.
	(SYMBOL_SET_LINKAGE_NAME): Update.
	(SYMBOL_SET_NAMES): Update.
	(SYMBOL_NATURAL_NAME): Update.
	(SYMBOL_LINKAGE_NAME): Update.
	(SYMBOL_DEMANGLED_NAME): Update.
	(SYMBOL_SEARCH_NAME): Update.
	(SYMBOL_MATCHES_SEARCH_NAME): Update.
	(struct symbol): Update.
	(struct template_symbol): Update.
	(struct rust_vtable_symbol): Update.
	* xcoffread.c (SYMBOL_DUP): Update.

Change-Id: I05b1628455bcce3efaa101e65ef051708d17eb07
---
M gdb/ada-exp.y
M gdb/buildsym.c
M gdb/dwarf2read.c
M gdb/jit.c
M gdb/language.c
M gdb/symtab.c
M gdb/symtab.h
M gdb/xcoffread.c
8 files changed, 69 insertions(+), 73 deletions(-)
  

Comments

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

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


Patch Set 1: Code-Review+1

(2 comments)

Thanks for the patch.  I think this is good, but I found a couple of nits,
so I'm marking it +1 for now.

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/510/1/gdb/symtab.h 
File gdb/symtab.h:

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/510/1/gdb/symtab.h@1102 
PS1, Line 1102: 
1097 |   SYMBOL_RUST_VTABLE
1098 | };
1099 | 
1100 | /* This structure is space critical.  See space comments at the top.  */
1101 | 
1102 > struct symbol : public general_symbol_info
1103 | {
1104 |   symbol ()
1105 |     {
1106 |       name = nullptr;
1107 |       value.ivalue = 0;

Should this also derive from `allocate_on_obstack`?


https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/510/1/gdb/symtab.h@1106 
PS1, Line 1106: 
1101 | 
1102 | struct symbol : public general_symbol_info
1103 | {
1104 |   symbol ()
1105 |     {
1106 >       name = nullptr;
1107 >       value.ivalue = 0;
1108 >       language_specific.obstack = nullptr;
1109 >       language = language_unknown;
1110 >       ada_mangled = 0;
1111 >       section = 0;
1112 >       /* Class-initialization of bitfields is only allowed in C++20.  */
1113 >       domain = UNDEF_DOMAIN;
1114 >       aclass_index = 0;
1115 >       is_objfile_owned = 0;
1116 >       is_argument = 0;
1117 >       is_inlined = 0;
1118 >       maybe_copied = 0;
1119 >       subclass = SYMBOL_NONE;
1120 |     }
1121 | 
1122 |   /* Data type of value */
1123 | 
1124 |   struct type *type = nullptr;

The usual approach here in gdb is to use member initialization,
like symbol () : name (nullptr), ...
(at least when possible)
  
Simon Marchi (Code Review) Nov. 6, 2019, 9:56 p.m. UTC | #2
Christian Biesinger has posted comments on this change.

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


Uploaded patch set 2.

(2 comments)

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/510/1/gdb/symtab.h 
File gdb/symtab.h:

https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/510/1/gdb/symtab.h@1102 
PS1, Line 1102: 
1097 |   SYMBOL_RUST_VTABLE
1098 | };
1099 | 
1100 | /* This structure is space critical.  See space comments at the top.  */
1101 | 
1102 > struct symbol : public general_symbol_info
1103 | {
1104 |   symbol ()
1105 |     {
1106 |       name = nullptr;
1107 |       value.ivalue = 0;

> Should this also derive from `allocate_on_obstack`?

Ah thanks, done. (And changed other code to use the overloaded operator new instead of obstack_new)


https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/510/1/gdb/symtab.h@1106 
PS1, Line 1106: 
1101 | 
1102 | struct symbol : public general_symbol_info
1103 | {
1104 |   symbol ()
1105 |     {
1106 >       name = nullptr;
1107 >       value.ivalue = 0;
1108 >       language_specific.obstack = nullptr;
1109 >       language = language_unknown;
1110 >       ada_mangled = 0;
1111 >       section = 0;
1112 >       /* Class-initialization of bitfields is only allowed in C++20.  */
1113 >       domain = UNDEF_DOMAIN;
1114 >       aclass_index = 0;
1115 >       is_objfile_owned = 0;
1116 >       is_argument = 0;
1117 >       is_inlined = 0;
1118 >       maybe_copied = 0;
1119 >       subclass = SYMBOL_NONE;
1120 |     }
1121 | 
1122 |   /* Data type of value */
1123 | 
1124 |   struct type *type = nullptr;

> The usual approach here in gdb is to use member initialization, […]

It's not possible for the first half because they are in the base class (and I can't add a constructor to the base class, I think, because it needs to stay a POD type for psymbols)

I could do it for the second part but I thought it would be weird to only do it for those members. WDYT?
  
Simon Marchi (Code Review) Nov. 11, 2019, 2:11 p.m. UTC | #3
Tom Tromey has posted comments on this change.

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


Patch Set 2: Code-Review+2

(1 comment)

Thanks again.  One more note about the initialization nit.
It is ok with this change, no need for another review IMO.

| --- gdb/symtab.h
| +++ gdb/symtab.h
| @@ -1109,12 +1102,26 @@ struct symbol
| -{
| -
| -  /* The general symbol info required for all types of symbols.  */
| -
| -  struct general_symbol_info ginfo;
| +struct symbol : public general_symbol_info
| +{
| +  symbol ()
| +    {
| +      name = nullptr;
| +      value.ivalue = 0;
| +      language_specific.obstack = nullptr;
| +      language = language_unknown;
| +      ada_mangled = 0;
| +      section = 0;
| +      /* Class-initialization of bitfields is only allowed in C++20.  */
| +      domain = UNDEF_DOMAIN;
| +      aclass_index = 0;
| +      is_objfile_owned = 0;
| +      is_argument = 0;
| +      is_inlined = 0;
| +      maybe_copied = 0;
| +      subclass = SYMBOL_NONE;

PS1, Line 1119:

> It's not possible for the first half because they are in the base class (and I can't add a constructor to the base class, I think, because it needs to stay a POD type for psymbols)
> 
> I could do it for the second part but I thought it would be weird to only do it for those members. WDYT?

I think in other spots we do initialize "local" bit-fields using
initializer syntax.  So, I think it would be preferable to do so
here as well; and maybe also add a comment explaining that we
have to explicitly initialize the other members in the constructor
body because the base class is POD.

| +    }
|  
|    /* Data type of value */
|  
| -  struct type *type;
| +  struct type *type = nullptr;
|  
|    /* The owner of this symbol.
|       Which one to use is defined by symbol.is_objfile_owned.  */
  
Simon Marchi (Code Review) Nov. 12, 2019, 9:20 p.m. UTC | #4
Christian Biesinger has posted comments on this change.

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


Patch Set 2:

(1 comment)

| --- gdb/symtab.h
| +++ gdb/symtab.h
| @@ -1109,12 +1102,26 @@ struct symbol
| -{
| -
| -  /* The general symbol info required for all types of symbols.  */
| -
| -  struct general_symbol_info ginfo;
| +struct symbol : public general_symbol_info
| +{
| +  symbol ()
| +    {
| +      name = nullptr;
| +      value.ivalue = 0;
| +      language_specific.obstack = nullptr;
| +      language = language_unknown;
| +      ada_mangled = 0;
| +      section = 0;
| +      /* Class-initialization of bitfields is only allowed in C++20.  */
| +      domain = UNDEF_DOMAIN;
| +      aclass_index = 0;
| +      is_objfile_owned = 0;
| +      is_argument = 0;
| +      is_inlined = 0;
| +      maybe_copied = 0;
| +      subclass = SYMBOL_NONE;

PS1, Line 1119:

OK, I made that change and am pushing this now.

| +    }
|  
|    /* Data type of value */
|  
| -  struct type *type;
| +  struct type *type = nullptr;
|  
|    /* The owner of this symbol.
|       Which one to use is defined by symbol.is_objfile_owned.  */
  

Patch

diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y
index 160e64b..22a7b9a 100644
--- a/gdb/ada-exp.y
+++ b/gdb/ada-exp.y
@@ -1102,9 +1102,8 @@ 
 write_ambiguous_var (struct parser_state *par_state,
 		     const struct block *block, char *name, int len)
 {
-  struct symbol *sym = XOBNEW (&temp_parse_space, struct symbol);
+  struct symbol *sym = obstack_new<struct symbol> (&temp_parse_space);
 
-  memset (sym, 0, sizeof (struct symbol));
   SYMBOL_DOMAIN (sym) = UNDEF_DOMAIN;
   SYMBOL_LINKAGE_NAME (sym) = obstack_strndup (&temp_parse_space, name, len);
   SYMBOL_LANGUAGE (sym) = language_ada;
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 954a610..24d1e0f 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -135,7 +135,7 @@ 
   struct pending *link;
 
   /* If this is an alias for another symbol, don't add it.  */
-  if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
+  if (symbol->name && symbol->name[0] == '#')
     return;
 
   /* We keep PENDINGSIZE symbols in each link of the list.  If we
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 0a7a033..8815481 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -14320,8 +14320,8 @@ 
 	{
 	  struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
 
-	  storage = OBSTACK_ZALLOC (&objfile->objfile_obstack,
-				    struct rust_vtable_symbol);
+	  storage = obstack_new <struct rust_vtable_symbol>
+	    (&objfile->objfile_obstack);
 	  initialize_objfile_symbol (storage);
 	  storage->concrete_type = containing_type;
 	  storage->subclass = SYMBOL_RUST_VTABLE;
@@ -21636,8 +21636,8 @@ 
       /* Fortran does not have mangling standard and the mangling does differ
 	 between gfortran, iFort etc.  */
       if (cu->language == language_fortran
-          && symbol_get_demangled_name (&(sym->ginfo)) == NULL)
-	symbol_set_demangled_name (&(sym->ginfo),
+          && symbol_get_demangled_name (sym) == NULL)
+	symbol_set_demangled_name (sym,
 				   dwarf2_full_name (name, die, cu),
 	                           NULL);
 
diff --git a/gdb/jit.c b/gdb/jit.c
index 08fd862..85a01ef 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -700,8 +700,8 @@ 
       SYMBOL_TYPE (block_name) = lookup_function_type (block_type);
       SYMBOL_BLOCK_VALUE (block_name) = new_block;
 
-      block_name->ginfo.name = obstack_strdup (&objfile->objfile_obstack,
-					       gdb_block_iter->name);
+      block_name->name = obstack_strdup (&objfile->objfile_obstack,
+					 gdb_block_iter->name);
 
       BLOCK_FUNCTION (new_block) = block_name;
 
diff --git a/gdb/language.c b/gdb/language.c
index 02c448f..b7fba4f 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1058,10 +1058,10 @@ 
   gdb_assert (!TYPE_OBJFILE_OWNED (type));
 
   gdbarch = TYPE_OWNER (type).gdbarch;
-  symbol = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct symbol);
+  symbol = obstack_new <struct symbol> (gdbarch_obstack (gdbarch));
 
-  symbol->ginfo.name = TYPE_NAME (type);
-  symbol->ginfo.language = lang;
+  symbol->name = TYPE_NAME (type);
+  symbol->language = lang;
   symbol->owner.arch = gdbarch;
   SYMBOL_OBJFILE_OWNED (symbol) = 0;
   SYMBOL_TYPE (symbol) = type;
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 2c934b9..3f8e3e0 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -1759,7 +1759,7 @@ 
       return sym;
     }
 
-  fixup_section (&sym->ginfo, addr, objfile);
+  fixup_section (sym, addr, objfile);
 
   return sym;
 }
@@ -6208,23 +6208,13 @@ 
 
 
 
-/* Helper function to initialize the fields of an objfile-owned symbol.
-   It assumed that *SYM is already all zeroes.  */
-
-static void
-initialize_objfile_symbol_1 (struct symbol *sym)
-{
-  SYMBOL_OBJFILE_OWNED (sym) = 1;
-  SYMBOL_SECTION (sym) = -1;
-}
-
 /* Initialize the symbol SYM, and mark it as being owned by an objfile.  */
 
 void
 initialize_objfile_symbol (struct symbol *sym)
 {
-  memset (sym, 0, sizeof (*sym));
-  initialize_objfile_symbol_1 (sym);
+  SYMBOL_OBJFILE_OWNED (sym) = 1;
+  SYMBOL_SECTION (sym) = -1;
 }
 
 /* Allocate and initialize a new 'struct symbol' on OBJFILE's
@@ -6233,10 +6223,10 @@ 
 struct symbol *
 allocate_symbol (struct objfile *objfile)
 {
-  struct symbol *result;
+  struct symbol *result = obstack_new <struct symbol>
+    (&objfile->objfile_obstack);
 
-  result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol);
-  initialize_objfile_symbol_1 (result);
+  initialize_objfile_symbol (result);
 
   return result;
 }
@@ -6249,8 +6239,8 @@ 
 {
   struct template_symbol *result;
 
-  result = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct template_symbol);
-  initialize_objfile_symbol_1 (result);
+  result = obstack_new <struct template_symbol> (&objfile->objfile_obstack);
+  initialize_objfile_symbol (result);
 
   return result;
 }
@@ -6309,7 +6299,7 @@ 
       if (minsym.minsym != nullptr)
 	return BMSYMBOL_VALUE_ADDRESS (minsym);
     }
-  return sym->ginfo.value.address;
+  return sym->value.address;
 }
 
 /* See symtab.h.  */
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 83b75d1..928aaab 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -470,35 +470,29 @@ 
 
 extern CORE_ADDR get_symbol_address (const struct symbol *sym);
 
-/* Note that all the following SYMBOL_* macros are used with the
-   SYMBOL argument being either a partial symbol or
-   a full symbol.  Both types have a ginfo field.  In particular
-   the SYMBOL_SET_LANGUAGE, SYMBOL_DEMANGLED_NAME, etc.
-   macros cannot be entirely substituted by
-   functions, unless the callers are changed to pass in the ginfo
-   field only, instead of the SYMBOL parameter.  */
+/* Note that these macros only work with symbol, not partial_symbol.  */
 
-#define SYMBOL_VALUE(symbol)		(symbol)->ginfo.value.ivalue
+#define SYMBOL_VALUE(symbol)		(symbol)->value.ivalue
 #define SYMBOL_VALUE_ADDRESS(symbol)			      \
   (((symbol)->maybe_copied) ? get_symbol_address (symbol)     \
-   : ((symbol)->ginfo.value.address))
+   : ((symbol)->value.address))
 #define SET_SYMBOL_VALUE_ADDRESS(symbol, new_value)	\
-  ((symbol)->ginfo.value.address = (new_value))
-#define SYMBOL_VALUE_BYTES(symbol)	(symbol)->ginfo.value.bytes
-#define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->ginfo.value.common_block
-#define SYMBOL_BLOCK_VALUE(symbol)	(symbol)->ginfo.value.block
-#define SYMBOL_VALUE_CHAIN(symbol)	(symbol)->ginfo.value.chain
-#define SYMBOL_LANGUAGE(symbol)		(symbol)->ginfo.language
-#define SYMBOL_SECTION(symbol)		(symbol)->ginfo.section
+  ((symbol)->value.address = (new_value))
+#define SYMBOL_VALUE_BYTES(symbol)	(symbol)->value.bytes
+#define SYMBOL_VALUE_COMMON_BLOCK(symbol) (symbol)->value.common_block
+#define SYMBOL_BLOCK_VALUE(symbol)	(symbol)->value.block
+#define SYMBOL_VALUE_CHAIN(symbol)	(symbol)->value.chain
+#define SYMBOL_LANGUAGE(symbol)		(symbol)->language
+#define SYMBOL_SECTION(symbol)		(symbol)->section
 #define SYMBOL_OBJ_SECTION(objfile, symbol)			\
-  (((symbol)->ginfo.section >= 0)				\
-   ? (&(((objfile)->sections)[(symbol)->ginfo.section]))	\
+  (((symbol)->section >= 0)				\
+   ? (&(((objfile)->sections)[(symbol)->section]))	\
    : NULL)
 
 /* Initializes the language dependent portion of a symbol
    depending upon the language for the symbol.  */
 #define SYMBOL_SET_LANGUAGE(symbol,language,obstack)	\
-  (symbol_set_language (&(symbol)->ginfo, (language), (obstack)))
+  (symbol_set_language ((symbol), (language), (obstack)))
 extern void symbol_set_language (struct general_symbol_info *symbol,
                                  enum language language,
 				 struct obstack *obstack);
@@ -509,13 +503,13 @@ 
    be terminated and either already on the objfile's obstack or
    permanently allocated.  */
 #define SYMBOL_SET_LINKAGE_NAME(symbol,linkage_name) \
-  (symbol)->ginfo.name = (linkage_name)
+  (symbol)->name = (linkage_name)
 
 /* Set the linkage and natural names of a symbol, by demangling
    the linkage name.  If linkage_name may not be nullterminated,
    copy_name must be set to true.  */
 #define SYMBOL_SET_NAMES(symbol,linkage_name,copy_name,objfile)	\
-  symbol_set_names (&(symbol)->ginfo, linkage_name, copy_name, \
+  symbol_set_names ((symbol), linkage_name, copy_name, \
 		    (objfile)->per_bfd)
 extern void symbol_set_names (struct general_symbol_info *symbol,
 			      gdb::string_view linkage_name, bool copy_name,
@@ -535,7 +529,7 @@ 
    demangled name.  */
 
 #define SYMBOL_NATURAL_NAME(symbol) \
-  (symbol_natural_name (&(symbol)->ginfo))
+  (symbol_natural_name ((symbol)))
 extern const char *symbol_natural_name
   (const struct general_symbol_info *symbol);
 
@@ -544,12 +538,12 @@ 
    manipulation by the linker, this is the mangled name; otherwise,
    it's the same as SYMBOL_NATURAL_NAME.  */
 
-#define SYMBOL_LINKAGE_NAME(symbol)	(symbol)->ginfo.name
+#define SYMBOL_LINKAGE_NAME(symbol)	(symbol)->name
 
 /* Return the demangled name for a symbol based on the language for
    that symbol.  If no demangled name exists, return NULL.  */
 #define SYMBOL_DEMANGLED_NAME(symbol) \
-  (symbol_demangled_name (&(symbol)->ginfo))
+  (symbol_demangled_name ((symbol)))
 extern const char *symbol_demangled_name
   (const struct general_symbol_info *symbol);
 
@@ -560,7 +554,7 @@ 
    The result should never be NULL.  Don't use this for internal
    purposes (e.g. storing in a hashtable): it's only suitable for output.
 
-   N.B. symbol may be anything with a ginfo member,
+   N.B. symbol may be anything inheriting from general_symbol_info,
    e.g., struct symbol or struct minimal_symbol.  */
 
 #define SYMBOL_PRINT_NAME(symbol)					\
@@ -573,13 +567,13 @@ 
    name.  If there is no distinct demangled name, then SYMBOL_SEARCH_NAME
    returns the same value (same pointer) as SYMBOL_LINKAGE_NAME.  */
 #define SYMBOL_SEARCH_NAME(symbol)					 \
-   (symbol_search_name (&(symbol)->ginfo))
+   (symbol_search_name (symbol))
 extern const char *symbol_search_name (const struct general_symbol_info *ginfo);
 
 /* Return true if NAME matches the "search" name of SYMBOL, according
    to the symbol's language.  */
 #define SYMBOL_MATCHES_SEARCH_NAME(symbol, name)                       \
-  symbol_matches_search_name (&(symbol)->ginfo, (name))
+  symbol_matches_search_name ((symbol), (name))
 
 /* Helper for SYMBOL_MATCHES_SEARCH_NAME that works with both symbols
    and psymbols.  */
@@ -1105,16 +1099,29 @@ 
 
 /* This structure is space critical.  See space comments at the top.  */
 
-struct symbol
+struct symbol : public general_symbol_info
 {
-
-  /* The general symbol info required for all types of symbols.  */
-
-  struct general_symbol_info ginfo;
+  symbol ()
+    {
+      name = nullptr;
+      value.ivalue = 0;
+      language_specific.obstack = nullptr;
+      language = language_unknown;
+      ada_mangled = 0;
+      section = 0;
+      /* Class-initialization of bitfields is only allowed in C++20.  */
+      domain = UNDEF_DOMAIN;
+      aclass_index = 0;
+      is_objfile_owned = 0;
+      is_argument = 0;
+      is_inlined = 0;
+      maybe_copied = 0;
+      subclass = SYMBOL_NONE;
+    }
 
   /* Data type of value */
 
-  struct type *type;
+  struct type *type = nullptr;
 
   /* The owner of this symbol.
      Which one to use is defined by symbol.is_objfile_owned.  */
@@ -1124,7 +1131,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;
+    struct symtab *symtab = nullptr;
 
     /* For types defined by the architecture.  */
     struct gdbarch *arch;
@@ -1141,7 +1148,7 @@ 
   unsigned int aclass_index : SYMBOL_ACLASS_BITS;
 
   /* If non-zero then symbol is objfile-owned, use owner.symtab.
-     Otherwise symbol is arch-owned, use owner.arch.  */
+       Otherwise symbol is arch-owned, use owner.arch.  */
 
   unsigned int is_objfile_owned : 1;
 
@@ -1175,7 +1182,7 @@ 
      to debug files longer than 64K lines?  What about machine
      generated programs?  */
 
-  unsigned short line;
+  unsigned short line = 0;
 
   /* An arbitrary data pointer, allowing symbol readers to record
      additional information on a per-symbol basis.  Note that this data
@@ -1189,9 +1196,9 @@ 
      to add a magic symbol to the block containing this information,
      or to have a generic debug info annotation slot for symbols.  */
 
-  void *aux_value;
+  void *aux_value = nullptr;
 
-  struct symbol *hash_next;
+  struct symbol *hash_next = nullptr;
 };
 
 /* This struct is size-critical (see comment at the top), so this assert
@@ -1272,11 +1279,11 @@ 
 struct template_symbol : public symbol
 {
   /* The number of template arguments.  */
-  int n_template_arguments;
+  int n_template_arguments = 0;
 
   /* The template arguments.  This is an array with
      N_TEMPLATE_ARGUMENTS elements.  */
-  struct symbol **template_arguments;
+  struct symbol **template_arguments = nullptr;
 };
 
 /* A symbol that represents a Rust virtual table object.  */
@@ -1285,7 +1292,7 @@ 
 {
   /* The concrete type for which this vtable was created; that is, in
      "impl Trait for Type", this is "Type".  */
-  struct type *concrete_type;
+  struct type *concrete_type = nullptr;
 };
 
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 20a2187..df1569e 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -1522,7 +1522,7 @@ 
 }
 
 #define	SYMBOL_DUP(SYMBOL1, SYMBOL2)	\
-  (SYMBOL2) = XOBNEW (&objfile->objfile_obstack, struct symbol); \
+  (SYMBOL2) = obstack_new <struct symbol> (&objfile->objfile_obstack); \
   *(SYMBOL2) = *(SYMBOL1);