[PATCH] D48095: [ELF][X86_64] Use R_GOTREL_FROM_END instead of R_GOTREL for R_X86_64_GOTOFF64

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 13 16:45:48 PDT 2018


MaskRay added a comment.

Yes, the emitted `R_X86_64_RELATIVE` in .text is text relocation and in conjunction with `R_X86_64_IRELATIVE` (ifunc calls, which can even be left in statically linked executables), glibc ld.so will segfault when resolving the relocations.

https://sourceware.org/git/?p=glibc.git;a=blob_plain;f=elf/dl-reloc.c

  /* DT_TEXTREL is now in level 2 and might phase out at some time.
     But we rewrite the DT_FLAGS entry to a DT_TEXTREL entry to make
     testing easier and therefore it will be available at all time.  */
  if (__builtin_expect (l->l_info[DT_TEXTREL] != NULL, 0))
  {
    ...
      /////////// the program text segment is remapped as read+write but not executable ///////
      if (__mprotect (newp->start, newp->len, PROT_READ|PROT_WRITE) < 0)
      ...
  
    ////// IFUNC (R_X86_64_IRELATIVE) is resolved in this call ///////
    ELF_DYNAMIC_RELOCATE (l, lazy, consider_profiling, skip_ifunc);
  
  ...
  
  /////// recover //////////
  /* Undo the segment protection changes.  */
  while (__builtin_expect (textrels != NULL, 0))
  {
    if (__mprotect (textrels->start, textrels->len, textrels->prot) < 0)


Repository:
  rL LLVM

https://reviews.llvm.org/D48095





More information about the llvm-commits mailing list