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: Sriraman Tallam <tmsriram at google dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: 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 10:27:34 -0800
- Subject: Re: [PATCH x86_64] Optimize access to globals in "-fpie -pie" builds with copy relocations
- Authentication-results: sourceware.org; auth=none
- References: <CAMe9rOr6BsvSgOtM2K+JfTgLktnTa19YFrfRUdRQpRPjDjOdmg at mail dot gmail dot com> <CAMe9rOpXupztWPgTWAxGx7yP7aynAjYoJbh-5L+wJ3S=qk8CvQ at mail dot gmail dot com> <CAFULd4aTkv0wjuqZMGCmYPiGJ50tLqWtf+-V0e3U5bFUj2Gfng at mail dot gmail dot com> <CAMe9rOpkZZmuhL_rqYrAE6wx6u7QYWe-DjuKp11u5wPh1dGztA at mail dot gmail dot com> <CAAs8Hmw0-+jN9BKwPB2BkGhTZwrc9V3zsAW2QTCuKnZKz7NVAQ at mail dot gmail dot com> <20150203193615 dot GZ1746 at tucnak dot redhat dot com> <CAAs8HmwAx0GWcEsDYQhO-dNtage5=j=z47anoFPTz324WTvZPw at mail dot gmail 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>
On Tue, Feb 3, 2015 at 5:16 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Tue, Feb 3, 2015 at 2:19 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>> On Tue, Feb 03, 2015 at 02:03:14PM -0800, H.J. Lu wrote:
>>> So we aren't SYMBOL_REF_EXTERNAL_P nor
>>> SYMBOL_REF_LOCAL_P. What do we reference?
>>
>> That is reasonable. There is no guarantee the extern weak symbol is local,
>> it could very well be non-local. All that you know about the symbols is
>> that its address is non-NULL in that case.
>>
>
> This may be true for shared library. But it isn't true for PIE:
Also, gcc and g++ are inconsistent about something even more simple:
$ cat x.c
int a;
int main() {
printf("%d\n", a);
}
With gcc -fPIE x.c
SYMBOL_REF_LOCAL_P(op0) = false
With g++ -fPIE x.c
SYMBOL_REF_LOCAL_P(op0) = true
Sri
>
> [hjl@gnu-6 copyreloc-3]$ cat x.c
> __attribute__((weak))
> int a;
>
> extern void bar (void);
>
> int main()
> {
> if (a != 0)
> __builtin_abort();
> bar ();
> if (a != 30)
> __builtin_abort();
> return 0;
> }
> [hjl@gnu-6 copyreloc-3]$ cat bar.c
> int a = -1;
>
> void
> bar ()
> {
> a = 30;
> }
> [hjl@gnu-6 copyreloc-3]$ make
> gcc -pie -O3 -g -fuse-ld=gold -fpie -c x.i
> gcc -pie -O3 -g -fuse-ld=gold -fpic -c -o bar.o bar.c
> gcc -pie -shared -o libbar.so bar.o
> gcc -pie -O3 -g -fuse-ld=gold -o x x.o libbar.so -Wl,-R,.
> ./x
> [hjl@gnu-6 copyreloc-3]$
>
> Even if a common symbol, a, is weak, all references to
> a within PIE is local.
>
> --
> H.J.