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: Richard Henderson <rth at redhat dot com>
- Cc: Bernhard Reutner-Fischer <rep dot dot dot nop at gmail dot com>, 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: Thu, 5 Feb 2015 11:01:24 -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> <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> <CAMe9rOpAnkfsJMXMM=MGNfqsCsLeBdNwmyCqLk6FbbrULbKigQ at mail dot gmail dot com> <54D3BC5B dot 3080300 at redhat dot com>
On Thu, Feb 5, 2015 at 10:54 AM, Richard Henderson <rth@redhat.com> wrote:
> On 02/04/2015 03:29 PM, H.J. Lu wrote:
>> +++ 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;
>> + }
>
> This is only true if the target uses COPY relocations, which is not universally
> true for all ELF targets.
>
Can you elaborate why it depends on COPY relocation? There
is no COPY relocation on x86-64.
--
H.J.
---
[hjl@gnu-6 copyreloc-3]$ cat x.c
__attribute__((weak))
int foo;
extern void bar (void);
int main()
{
if (foo != 0)
__builtin_abort();
bar ();
if (foo != 30)
__builtin_abort();
return 0;
}
[hjl@gnu-6 copyreloc-3]$ cat bar.c
int foo = -1;
void
bar ()
{
foo = 30;
}
[hjl@gnu-6 copyreloc-3]$ make x
gcc -pie -fpie -O3 -g -fuse-ld=gold -fpie -c -o x.o x.c
gcc -pie -fpie -O3 -g -fuse-ld=gold -fpic -c -o bar.o bar.c
gcc -pie -fpie -shared -o libbar.so bar.o
gcc -pie -fpie -O3 -g -fuse-ld=gold -o x x.o libbar.so -Wl,-R,.
[hjl@gnu-6 copyreloc-3]$ ./x
[hjl@gnu-6 copyreloc-3]$ readelf -rW x.o | grep foo
0000000000000004 0000001100000009 R_X86_64_GOTPCREL
0000000000000000 foo - 4
0000000000000079 0000001100000001 R_X86_64_64
0000000000000000 foo + 0
[hjl@gnu-6 copyreloc-3]$ readelf -rW x | grep foo
[hjl@gnu-6 copyreloc-3]$ readelf -rW libbar.so | grep foo
00000000002008c8 0000000900000006 R_X86_64_GLOB_DAT
0000000000200900 foo + 0
[hjl@gnu-6 copyreloc-3]$