Jan Kratochvil 5677fb2
http://sourceware.org/ml/gdb-patches/2013-01/msg00469.html
Jan Kratochvil 5677fb2
Subject: [patch] Fix gdb.fortran/common-block.exp crash in PIE mode
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
Hi Tom,
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
runtest F90_FOR_TARGET="gfortran -fPIE -pie" gdb.fortran/common-block.exp
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
crashes GDB as function relocate_one_symbol
Jan Kratochvil 5677fb2
	if ((SYMBOL_CLASS (sym) == LOC_LABEL
Jan Kratochvil 5677fb2
	     || SYMBOL_CLASS (sym) == LOC_STATIC)
Jan Kratochvil 5677fb2
	    && SYMBOL_SECTION (sym) >= 0)
Jan Kratochvil 5677fb2
	  SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (delta, SYMBOL_SECTION (sym));
Jan Kratochvil 5677fb2
corrupts SYMBOL_VALUE_COMMON_BLOCK
Jan Kratochvil 5677fb2
	struct common_block *common_block;
Jan Kratochvil 5677fb2
as it thinks it can update it like SYMBOL_VALUE_ADDRESS
Jan Kratochvil 5677fb2
	CORE_ADDR address;
Jan Kratochvil 5677fb2
due to its LOC_STATIC.
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
No regressions on {x86_64,x86_64-m32,i686}-fedora18-linux-gnu and in PIE mode.
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
Thanks,
Jan Kratochvil 5677fb2
Jan
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
gdb/
Jan Kratochvil 5677fb2
2013-01-19  Jan Kratochvil  <jan.kratochvil@redhat.com>
Jan Kratochvil 5677fb2
Jan Kratochvil 5677fb2
	Fix gdb.fortran/common-block.exp crash in PIE mode.
Jan Kratochvil 5677fb2
	* dwarf2read.c (new_symbol_full) <DW_TAG_common_block>: Use
Jan Kratochvil 5677fb2
	LOC_COMMON_BLOCK.
Jan Kratochvil 5677fb2
	* f-valprint.c (info_common_command_for_block): Expect
Jan Kratochvil 5677fb2
	LOC_COMMON_BLOCK in gdb_assert.
Jan Kratochvil 5677fb2
	* symtab.h (struct general_symbol_info): Update comment for the
Jan Kratochvil 5677fb2
	common_block member.
Jan Kratochvil 5677fb2
	(domain_enum): Extend comment for the COMMON_BLOCK_DOMAIN member.
Jan Kratochvil 5677fb2
	(enum address_class): New member LOC_COMMON_BLOCK.
Jan Kratochvil 5677fb2
Jan Kratochvil 556378e
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
Jan Kratochvil 556378e
index 7a58c45..364e6af 100644
Jan Kratochvil 556378e
--- a/gdb/dwarf2read.c
Jan Kratochvil 556378e
+++ b/gdb/dwarf2read.c
Jan Kratochvil 556378e
@@ -16071,7 +16071,7 @@ new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
Jan Kratochvil 556378e
 	  list_to_add = &global_symbols;
Jan Kratochvil 556378e
 	  break;
Jan Kratochvil 556378e
 	case DW_TAG_common_block:
Jan Kratochvil 556378e
-	  SYMBOL_CLASS (sym) = LOC_STATIC;
Jan Kratochvil 556378e
+	  SYMBOL_CLASS (sym) = LOC_COMMON_BLOCK;
Jan Kratochvil 556378e
 	  SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN;
Jan Kratochvil 556378e
 	  add_symbol_to_list (sym, cu->list_in_scope);
Jan Kratochvil 556378e
 	  break;
Jan Kratochvil 556378e
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
Jan Kratochvil 556378e
index 22cca83..d01d6ec 100644
Jan Kratochvil 556378e
--- a/gdb/f-valprint.c
Jan Kratochvil 556378e
+++ b/gdb/f-valprint.c
Jan Kratochvil 556378e
@@ -427,7 +427,7 @@ info_common_command_for_block (struct block *block, const char *comname,
Jan Kratochvil 556378e
 	struct common_block *common = SYMBOL_VALUE_COMMON_BLOCK (sym);
Jan Kratochvil 556378e
 	size_t index;
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
-	gdb_assert (SYMBOL_CLASS (sym) == LOC_STATIC);
Jan Kratochvil 556378e
+	gdb_assert (SYMBOL_CLASS (sym) == LOC_COMMON_BLOCK);
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
 	if (comname && (!SYMBOL_LINKAGE_NAME (sym)
Jan Kratochvil 556378e
 	                || strcmp (comname, SYMBOL_LINKAGE_NAME (sym)) != 0))
Jan Kratochvil 556378e
diff --git a/gdb/symtab.h b/gdb/symtab.h
Jan Kratochvil 556378e
index c334a3a..b992266 100644
Jan Kratochvil 556378e
--- a/gdb/symtab.h
Jan Kratochvil 556378e
+++ b/gdb/symtab.h
Jan Kratochvil 556378e
@@ -120,7 +120,7 @@ struct general_symbol_info
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
     CORE_ADDR address;
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
-    /* A common block.  Used with COMMON_BLOCK_DOMAIN.  */
Jan Kratochvil 556378e
+    /* A common block.  Used with LOC_COMMON_BLOCK.  */
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
     struct common_block *common_block;
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
@@ -414,7 +414,8 @@ typedef enum domain_enum_tag
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
   LABEL_DOMAIN,
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
-  /* Fortran common blocks.  Their naming must be separate from VAR_DOMAIN.  */
Jan Kratochvil 556378e
+  /* Fortran common blocks.  Their naming must be separate from VAR_DOMAIN.
Jan Kratochvil 556378e
+     They also always use LOC_COMMON_BLOCK.  */
Jan Kratochvil 556378e
   COMMON_BLOCK_DOMAIN
Jan Kratochvil 556378e
 } domain_enum;
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
@@ -533,6 +534,10 @@ enum address_class
Jan Kratochvil 556378e
   /* The variable's address is computed by a set of location
Jan Kratochvil 556378e
      functions (see "struct symbol_computed_ops" below).  */
Jan Kratochvil 556378e
   LOC_COMPUTED,
Jan Kratochvil 556378e
+
Jan Kratochvil 556378e
+  /* The variable uses general_symbol_info->value->common_block field.
Jan Kratochvil 556378e
+     It also always uses COMMON_BLOCK_DOMAIN.  */
Jan Kratochvil 556378e
+  LOC_COMMON_BLOCK,
Jan Kratochvil 556378e
 };
Jan Kratochvil 556378e
 
Jan Kratochvil 556378e
 /* The methods needed to implement LOC_COMPUTED.  These methods can
Jan Kratochvil 5677fb2