This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH x86_64] Optimize access to globals in "-fpie -pie" builds with copy relocations
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Bernhard Reutner-Fischer <rep dot dot dot nop at gmail dot com>
- Cc: Sriraman Tallam <tmsriram at google dot com>, Jakub Jelinek <jakub at redhat dot com>, Uros Bizjak <ubizjak at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, David Li <davidxl at google dot com>, Cary Coutant <ccoutant at google dot com>
- Date: Wed, 4 Feb 2015 15:10:26 -0800
- Subject: Re: [PATCH x86_64] Optimize access to globals in "-fpie -pie" builds with copy relocations
- Authentication-results: sourceware.org; auth=none
- References: <20150203193615 dot GZ1746 at tucnak dot redhat dot com> <CAMe9rOrLwHdtsH2z_7dBpVKiJRtfT7iHaHO7wQ23o25TL7cTMw at mail dot gmail dot com> <CAAs8Hmw=Z9VeLz+MAY0X-POfkwXLFEsRFy8wEPDdyzVPV8ee=g at mail dot gmail dot com> <CAMe9rOouVu9Ndgf231iOt=ry0jWiw573H+y1KxycWkqSw=unOA at mail dot gmail dot com> <20150203221935 dot GA1746 at tucnak dot redhat dot com> <CAMe9rOq-A3YebgJ_xRnQDekYuvRw6C9GD9DYbhUizvr3OPad_Q at mail dot gmail dot com> <CAAs8Hmxdx1n+hgJ0oTAufPauz=S67oM2F_NAmyTzzUSh-ic=4Q at mail dot gmail dot com> <20150204183127 dot GU1746 at tucnak dot redhat dot com> <CAMe9rOpWUnex45v3hM9=tDNfnC6ipJ-hMEkiY1714Km15bL=bg at mail dot gmail dot com> <20150204184205 dot GW1746 at tucnak dot redhat dot com> <CAMe9rOoWkw==PQZt1hR1xjKaVxwkFh39vNbFb1WFbaxgxofJMA at mail dot gmail dot com> <CAAs8HmzByYULg8y0F2DnVo0YBnh__Jx2xSrvAoMYuWPJJb2q6A at mail dot gmail dot com> <CAMe9rOpFiaRuauCqFwUxYPEo46jPiQf8=W9+7Cf8q=1QCm0sEA at mail dot gmail dot com> <CAAs8HmwHY-vNEBdULByHYU__xKcKOarMqr-+69VRxo_kBkzwxw at mail dot gmail dot com> <CAMe9rOoGdDBpn12LFyTqdbfhdOxXgw4i9Xmk34fj=K+KzhSoAw at mail dot gmail dot com> <50365BC5-5D7C-423A-803B-F8F6F040C865 at gmail dot com>
On Wed, Feb 4, 2015 at 2:47 PM, Bernhard Reutner-Fischer
<rep.dot.nop@gmail.com> wrote:
> On February 4, 2015 11:37:01 PM GMT+01:00, "H.J. Lu" <hjl.tools@gmail.com> wrote:
>>On Wed, Feb 4, 2015 at 1:53 PM, Sriraman Tallam <tmsriram@google.com>
>>wrote:
>>> On Wed, Feb 4, 2015 at 10:57 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Wed, Feb 4, 2015 at 10:51 AM, Sriraman Tallam
>><tmsriram@google.com> wrote:
>>>>> On Wed, Feb 4, 2015 at 10:45 AM, H.J. Lu <hjl.tools@gmail.com>
>>wrote:
>>>>>> On Wed, Feb 4, 2015 at 10:42 AM, Jakub Jelinek <jakub@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
>
Try this.
--
H.J.
diff --git a/gcc/varasm.c b/gcc/varasm.c
index eb65b1f..c95eebd 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -6826,7 +6826,15 @@ 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))
+ /* If not building shared library, common or initialized symbols
+ are also resolved locally, regardless they are weak or not. */
+ if ((!shlib
+ && (DECL_COMMON (exp)
+ || (DECL_INITIAL (exp) != NULL
+ && (in_lto_p
+ || DECL_INITIAL (exp) != error_mark_node))))
+ || (vnode && (resolution_local_p (vnode->resolution)
+ || vnode->in_other_partition)))
resolved_locally = true;
if (vnode
&& resolution_to_local_definition_p (vnode->resolution))