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 via email to