Fix segfault with weak external symbols

Eric Botcazou ebotcazou@adacore.com
Wed Jan 8 22:39:00 GMT 2014


This is a regression present on the mainline for weak external symbols and 
languages with non-call exceptions:

0xb222df crash_signal
        /home/eric/svn/gcc/gcc/toplev.c:337
0x75ed9c symtab_alias_ultimate_target(symtab_node*, availability*)
        /home/eric/svn/gcc/gcc/symtab.c:989
0xb69a59 varpool_variable_node
        /home/eric/svn/gcc/gcc/cgraph.h:1430
0xb69a59 tree_could_trap_p(tree_node*)
        /home/eric/svn/gcc/gcc/tree-eh.c:2691
0xb6a85c stmt_could_throw_1_p
        /home/eric/svn/gcc/gcc/tree-eh.c:2751
0xb6a85c stmt_could_throw_p(gimple_statement_base*)
        /home/eric/svn/gcc/gcc/tree-eh.c:2780
0xb6d46f lower_eh_constructs_2
        /home/eric/svn/gcc/gcc/tree-eh.c:2028
0xb6d46f lower_eh_constructs_1
        /home/eric/svn/gcc/gcc/tree-eh.c:2123
0xb6f871 lower_eh_constructs
        /home/eric/svn/gcc/gcc/tree-eh.c:2141
0xb6f871 execute
        /home/eric/svn/gcc/gcc/tree-eh.c:2193
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.

In tree_could_trap_p:

    case VAR_DECL:
      /* Assume that accesses to weak vars may trap, unless we know
	 they are certainly defined in current TU or in some other
	 LTO partition.  */
      if (DECL_WEAK (expr))
	{
	  struct varpool_node *node;
	  if (!DECL_EXTERNAL (expr))
	    return false;
	  node = varpool_variable_node (varpool_get_node (expr), NULL);
	  if (node && node->symbol.in_other_partition)
	    return false;
	  return true;
	}
      return false;

The problem is that varpool_get_node returns NULL and varpool_variable_node
(and its callee symtab_alias_ultimate_target) chokes on the NULL.  This is
a regression from the 4.8.x series, where the same NULL goes through the
function without a hitch.

Tested on x86_64-suse-linux, applied on the mainline as obvious.


2014-01-08  Eric Botcazou  <ebotcazou@adacore.com>

	* cgraph.h (varpool_variable_node): Do not choke on null node.


2014-01-08  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/weak2.ad[sb]: New test.


-- 
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 550 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140108/db2ccc94/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: weak2.adb
Type: text/x-adasrc
Size: 124 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140108/db2ccc94/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: weak2.ads
Type: text/x-adasrc
Size: 151 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20140108/db2ccc94/attachment-0002.bin>


More information about the Gcc-patches mailing list