On Wed, Feb 4, 2015 at 3:10 PM, H.J. Lu <hjl.to...@gmail.com> wrote: > On Wed, Feb 4, 2015 at 2:47 PM, Bernhard Reutner-Fischer > <rep.dot....@gmail.com> wrote: >> On February 4, 2015 11:37:01 PM GMT+01:00, "H.J. Lu" <hjl.to...@gmail.com> >> wrote: >>>On Wed, Feb 4, 2015 at 1:53 PM, Sriraman Tallam <tmsri...@google.com> >>>wrote: >>>> On Wed, Feb 4, 2015 at 10:57 AM, H.J. Lu <hjl.to...@gmail.com> wrote: >>>>> On Wed, Feb 4, 2015 at 10:51 AM, Sriraman Tallam >>><tmsri...@google.com> wrote: >>>>>> On Wed, Feb 4, 2015 at 10:45 AM, H.J. Lu <hjl.to...@gmail.com> >>>wrote: >>>>>>> On Wed, Feb 4, 2015 at 10:42 AM, Jakub Jelinek <ja...@redhat.com> >>>wrote: >>>>>>>> On Wed, Feb 04, 2015 at 10:38:48AM -0800, H.J. Lu wrote: >>>>>>>>> Common symbol should be resolved locally for PIE. >>>>>>>> >>>>>>>> binds_local_p yes, binds_to_current_def_p no. >>>>>>>> >>>>>>> >>>>>>> Is SYMBOL_REF_LOCAL_P set to binds_local_p or >>>>>>> binds_to_current_def_p? >>>>>> >>>>>> Looks like binds_local_p: >>>>>> >>>>>> varasm.c: >>>>>> void >>>>>> default_encode_section_info (tree decl, rtx rtl, int first >>>ATTRIBUTE_UNUSED) >>>>>> { >>>>>> ... >>>>>> if (targetm.binds_local_p (decl)) >>>>>> flags |= SYMBOL_FLAG_LOCAL; >>>>>> >>>>> >>>>> Why is SYMBOL_REF_LOCAL_P false? >>>> >>>> In varasm.c, default_binds_local_p_1 >>>> >>>> >>>> /* Default visibility weak data can be overridden by a strong symbol >>>> in another module and so are not local. */ >>>> else if (DECL_WEAK (exp) >>>> && !resolved_locally) >>> ^^^^^^^^^^^^^^^^^^^ >>>Why is resolved_locally false? It should be true for common >>>symbol when compiling for PIE. >>> >>>> local_p = false; >>>> >>>> For weak definition, it is set to false here. >> >> Yea and i think this is still wrong and known as >> http://gcc.gnu.org/PR32219 >> >
I am testing this patch. -- H.J.
diff --git a/gcc/varasm.c b/gcc/varasm.c index eb65b1f..36fd393 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -6826,11 +6826,17 @@ default_binds_local_p_1 (const_tree exp, int shlib) && (TREE_STATIC (exp) || DECL_EXTERNAL (exp))) { varpool_node *vnode = varpool_node::get (exp); - if (vnode && (resolution_local_p (vnode->resolution) || vnode->in_other_partition)) - resolved_locally = true; - if (vnode - && resolution_to_local_definition_p (vnode->resolution)) - resolved_to_local_def = true; + /* If not building shared library, common or initialized symbols + are also resolved locally, regardless they are weak or not. */ + if (vnode) + { + if ((!shlib && vnode->definition) + || vnode->in_other_partition + || resolution_local_p (vnode->resolution)) + resolved_locally = true; + if (resolution_to_local_definition_p (vnode->resolution)) + resolved_to_local_def = true; + } } else if (TREE_CODE (exp) == FUNCTION_DECL && TREE_PUBLIC (exp)) { @@ -6880,13 +6886,6 @@ default_binds_local_p_1 (const_tree exp, int shlib) symbols resolved from other modules. */ else if (shlib) local_p = false; - /* Uninitialized COMMON variable may be unified with symbols - resolved from other modules. */ - else if (DECL_COMMON (exp) - && !resolved_locally - && (DECL_INITIAL (exp) == NULL - || (!in_lto_p && DECL_INITIAL (exp) == error_mark_node))) - local_p = false; /* Otherwise we're left with initialized (or non-common) global data which is of necessity defined locally. */ else