This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF][AArch64] Set _GLOBAL_OFFSET_TABLE_ at the start of .got
ClosedPublic

Authored by zatrazz on Jan 15 2021, 10:24 AM.

Details

Summary

The commit 18aa0be36ed9 changed the default GotBaseSymInGotPlt to true
for AArch64. This is different than binutils, where
_GLOBAL_OFFSET_TABLE_ points at the start or .got instead of .got.plt.

It seems to not intefere with current relocations used by LLVM. However
as indicated by PR#40357 [1] gcc generates R_AARCH64_LD64_GOTPAGE_LO15
for -pie (in fact it also generated the relocation for -fpic in some
cases).

This change is requires to correctly handle R_AARCH64_LD64_GOTPAGE_LO15
by lld from objects generated by gcc.

[1] https://bugs.llvm.org/show_bug.cgi?id=40357

Diff Detail

Event Timeline

zatrazz created this revision.Jan 15 2021, 10:24 AM
zatrazz requested review of this revision.Jan 15 2021, 10:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 15 2021, 10:24 AM
MaskRay accepted this revision.EditedJan 15 2021, 10:37 AM

Confirmed.

aarch64-linux-gnu-gcc -nostdlib -shared a.c -fpic -o a.so
clang -target aarch64-linux-gnu -fuse-ld=lld -nostdlib -shared a.c -fpic -o a.so

The previous one does use .got for _GLOBAL_OFFSET_TABLE_. Thanks for spotting this issue.

// binutils elfnn-aarch64.c uses .got
  s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
  if (s == NULL
      || !bfd_set_section_alignment (s, bed->s->log_file_align))
    return FALSE;
  htab->sgot = s;
  htab->sgot->size += GOT_ENTRY_SIZE;

  if (bed->want_got_sym)
    {
      /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
         (or .got.plt) section.  We don't do this in the linker script
         because we don't want to define the symbol if we are not creating
         a global offset table.  */
      h = _bfd_elf_define_linkage_sym (abfd, info, s,
                                       "_GLOBAL_OFFSET_TABLE_");
      elf_hash_table (info)->hgot = h;
      if (h == NULL)
        return FALSE;
    }
This revision is now accepted and ready to land.Jan 15 2021, 10:37 AM
zatrazz closed this revision.Jan 18 2021, 10:06 AM