[PATCH] D47098: [ELF] Make R_GOTONLY_PC_FROM_END R_GOTREL_FROM_END relative to _GLOBAL_OFFSET_TABLE_ instead of end of .got

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 29 09:52:07 PDT 2018


grimar added a comment.

In https://reviews.llvm.org/D47098#1114819, @peter.smith wrote:

> > If llvm-mc would emit R_X86_64_GOTPC32 too that we probably could do nothing here and continue resolving such relocations relative to the .got end.
> >  I am not sure about the other targets, but if they also have special relocations for _GLOBAL_OFFSET_TABLE_, that could help to resolve this.
> > 
> > Or probably we could special case relocating _GLOBAL_OFFSET_TABLE_ symbol for now.
>
> I think if we change anything we should probably make it Target specific or risk breaking something. I know that when I made the mistake of moving _GLOBAL_OFFSET_TABLE_ to be the base of .got.plt on Arm I broke Chrome https://bugs.llvm.org/show_bug.cgi?id=36555#c16 . This would have worked if llvm-mc had used R_ARM_BASE_PREL rather than R_ARM_REL32  but sadly it doesn't so it needs _GLOBAL_OFFSET_TABLE_ to be the base of the .got output section.


Ok, so seems safe fix, for now, would be to make llvm-mc to emit R_X86_64_GOTPC32 for _GLOBAL_OFFSET_TABLE_ , as it does now for R_X86_64_GOTPC64.
That way we:

1. Make llvm-mc output consistent with gas and sample from ABI.
2. Isolate change to x86_64 target.
3. Do not need to change anything significant in LLD, it will handle relocations to _GLOBAL_OFFSET_TABLE_ just like it already do (via R_GOTONLY_PC_FROM_END and R_GOTREL_FROM_END).

It will not work correctly with objects built with current llvm-mc which use R_X86_64_PC32 for _GLOBAL_OFFSET_TABLE_,
but since LLD does not support R_X86_64_GOTPC32/R_X86_64_GOTPC64 at all yet, and nobody yet complained,
it hopefully should not be a huge problem. Also, such objects currently do not seem to be fully ABI compatible anyways.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D47098





More information about the llvm-commits mailing list