[Bug c/91766] New: -fvisibility=hidden during -fpic still uses GOT indirection on arm64

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug c/91766] New: -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

            Bug ID: 91766
           Summary: -fvisibility=hidden during -fpic still uses GOT
                    indirection on arm64
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blu.dark at gmail dot com
  Target Milestone: ---

Passing -fvisibility=hidden does not stop GOT round-trips for global symbols
during -fpic. Example:

#if DO_HIDE
#define HIDE __attribute__ ((visibility("hidden")))
#else
#define HIDE
#endif

int room[2] HIDE;

int* foo()
{
    int* p = room;
    *p = 0;
    return p;
}

$ gcc-8.2 -Ofast -fvisibility=hidden -fpic

foo:
        adrp    x1, _GLOBAL_OFFSET_TABLE_
        ldr     x1, [x1, #:gotpage_lo15:room]
        mov     x0, x1
        str     wzr, [x1]
        ret

Explicitly hiding it via DO_HIDE works as expected:

$ gcc-8.2 -Ofast -fvisibility=hidden -fpic -DDO_HIDE

foo:
        adrp    x1, room
        add     x0, x1, :lo12:room
        str     wzr, [x1, #:lo12:room]
        ret

Here's the godbolt link: https://godbolt.org/z/HCd2LT
Reply | Threaded
Open this post in threaded view
|

[Bug target/91766] -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Try -fno-common.
Reply | Threaded
Open this post in threaded view
|

[Bug target/91766] -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
In reply to this post by rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Target|                            |aarch64-linux-gnu

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
room is a common symbol which causes issues.
Reply | Threaded
Open this post in threaded view
|

[Bug target/91766] -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
In reply to this post by rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

--- Comment #3 from martin krastev <blu.dark at gmail dot com> ---
So it appears to be a clash between -fcommon and -fvisibility=hidden during
-fpic -- passing either -fno-common or -fno-pic drops the GOT indirection. And
explicitly hiding the symbol obviously solves it. But the crux of the issue,
IMO, is a multi-platform one -- that behavior deviates on gcc-8.2 from platform
to platform. On amd64 it suffices to -fvisibility=hidden to stop GOT detours,
whereas on aarch64 it's -fvisibility=hidden -fno-common. As a result aarch64
performance gets penalized in unsuspecting multi-plats.
Reply | Threaded
Open this post in threaded view
|

[Bug target/91766] -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
In reply to this post by rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

Wilco <wdijkstr at arm dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wdijkstr at arm dot com

--- Comment #4 from Wilco <wdijkstr at arm dot com> ---
(In reply to martin krastev from comment #3)
> So it appears to be a clash between -fcommon and -fvisibility=hidden during
> -fpic -- passing either -fno-common or -fno-pic drops the GOT indirection.
> And explicitly hiding the symbol obviously solves it. But the crux of the
> issue, IMO, is a multi-platform one -- that behavior deviates on gcc-8.2
> from platform to platform. On amd64 it suffices to -fvisibility=hidden to
> stop GOT detours, whereas on aarch64 it's -fvisibility=hidden -fno-common.
> As a result aarch64 performance gets penalized in unsuspecting multi-plats.

-fno-common should really become the default, -fcommon causes way too many
issues.
Reply | Threaded
Open this post in threaded view
|

[Bug target/91766] -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
In reply to this post by rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

--- Comment #5 from martin krastev <blu.dark at gmail dot com> ---
For reference, here what -fvisibility=hidden -fpic -fcommon produces on amd64
(https://godbolt.org/z/0aIyhl):

foo:
        movl    $0, room(%rip)
        leaq    room(%rip), %rax
        ret

Notice the absence of GOT indirection.
Reply | Threaded
Open this post in threaded view
|

[Bug target/91766] -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
In reply to this post by rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |visibility
                 CC|                            |egallager at gcc dot gnu.org
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=85678

--- Comment #6 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Wilco from comment #4)

> (In reply to martin krastev from comment #3)
> > So it appears to be a clash between -fcommon and -fvisibility=hidden during
> > -fpic -- passing either -fno-common or -fno-pic drops the GOT indirection.
> > And explicitly hiding the symbol obviously solves it. But the crux of the
> > issue, IMO, is a multi-platform one -- that behavior deviates on gcc-8.2
> > from platform to platform. On amd64 it suffices to -fvisibility=hidden to
> > stop GOT detours, whereas on aarch64 it's -fvisibility=hidden -fno-common.
> > As a result aarch64 performance gets penalized in unsuspecting multi-plats.
>
> -fno-common should really become the default, -fcommon causes way too many
> issues.

That's bug 85678
Reply | Threaded
Open this post in threaded view
|

[Bug target/91766] -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
In reply to this post by rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

Wilco <wilco at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wilco at gcc dot gnu.org

--- Comment #7 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Eric Gallager from comment #6)

> (In reply to Wilco from comment #4)
> > (In reply to martin krastev from comment #3)
> > > So it appears to be a clash between -fcommon and -fvisibility=hidden during
> > > -fpic -- passing either -fno-common or -fno-pic drops the GOT indirection.
> > > And explicitly hiding the symbol obviously solves it. But the crux of the
> > > issue, IMO, is a multi-platform one -- that behavior deviates on gcc-8.2
> > > from platform to platform. On amd64 it suffices to -fvisibility=hidden to
> > > stop GOT detours, whereas on aarch64 it's -fvisibility=hidden -fno-common.
> > > As a result aarch64 performance gets penalized in unsuspecting multi-plats.
> >
> > -fno-common should really become the default, -fcommon causes way too many
> > issues.
>
> That's bug 85678

Yes, we need to push on that one again since not much happened...
Reply | Threaded
Open this post in threaded view
|

[Bug target/91766] -fvisibility=hidden during -fpic still uses GOT indirection on arm64

rguenth at gcc dot gnu.org
In reply to this post by rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91766

Wilco <wilco at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2019-09-17
     Ever confirmed|0                           |1

--- Comment #8 from Wilco <wilco at gcc dot gnu.org> ---
Confirmed btw - the difference is due to HAVE_LD_PIE_COPYRELOC in i386.c:

/* For i386, common symbol is local only for non-PIE binaries.  For
   x86-64, common symbol is local only for non-PIE binaries or linker
   supports copy reloc in PIE binaries.   */

static bool
ix86_binds_local_p (const_tree exp)
{
  return default_binds_local_p_3 (exp, flag_shlib != 0, true, true,
                                  (!flag_pic
                                   || (TARGET_64BIT
                                       && HAVE_LD_PIE_COPYRELOC != 0)));
}