Fix segfault with weak external symbols

Eric Botcazou
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
0x75ed9c symtab_alias_ultimate_target(symtab_node*, availability*)
0xb69a59 varpool_variable_node
0xb69a59 tree_could_trap_p(tree_node*)
0xb6a85c stmt_could_throw_1_p
0xb6a85c stmt_could_throw_p(gimple_statement_base*)
0xb6d46f lower_eh_constructs_2
0xb6d46f lower_eh_constructs_1
0xb6f871 lower_eh_constructs
0xb6f871 execute
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <> 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  <>

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

2014-01-08  Eric Botcazou  <>

	* gnat.dg/[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: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: weak2.adb
Type: text/x-adasrc
Size: 124 bytes
Desc: not available
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Type: text/x-adasrc
Size: 151 bytes
Desc: not available
URL: <>

More information about the Gcc-patches mailing list