[Bug target/65780] [5 Regression] Uninitialized common handling in executables

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Apr 16 07:33:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65780

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to H.J. Lu from comment #9)
> Created attachment 35327 [details]
> A different patch
> 
> On x86, this issue only shows up with PIE. Here is a different
> patch to treat common symbol defined locally only if the backend
> passes true common_maybe_local.  For x86-64, it is true only if
> HAVE_LD_PIE_COPYRELOC is 1.  For i386, it is always false.  If
> we aren't building PIE, common_maybe_local is true or false
> doesn't make a difference for x86 since the common symbol is
> always referenced normally with copy reloc.  For PIE on x86-64,
> common symbol is local only if HAVE_LD_PIE_COPYRELOC is 1.

+
+  /* For common symbol, it is defined locally only if common_maybe_local
+     is true.  */
+  bool defined_locally = (!DECL_EXTERNAL (exp)
+              && (!DECL_COMMON (exp) || common_maybe_local));

I think better would be:
  bool uninited_common = (DECL_COMMON (exp)
                          && (DECL_INITIAL (exp) == NULL
                              || (!in_lto_p && DECL_INITIAL (exp) ==
error_mark_node)));
  /* For common symbol, it is defined locally only if common_maybe_local
     is true.  */
  bool defined_locally = (!DECL_EXTERNAL (exp) && (!uninited_common ||
common_maybe_local));
...
and then use
  /* Uninitialized COMMON variable may be unified with symbols
     resolved from other modules.  */
  if (uninited_common && !resolved_locally)
    return false;



More information about the Gcc-bugs mailing list