[PATCH] D94612: [LLD][ELF][AArch64] Add support for R_AARCH64_LD64_GOTPAGE_LO15 relocation

Adhemerval Zanella via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 15 10:27:00 PST 2021


zatrazz added a comment.

I will update the patch, since it is incomplete and requires https://reviews.llvm.org/D94809 .



================
Comment at: lld/ELF/InputSection.cpp:708
     return getAArch64Page(sym.getGotVA() + a) - getAArch64Page(p);
+  case R_AARCH64_GOT_PAGE:
+    return sym.getGotVA() - getAArch64Page(p);
----------------
psmith wrote:
> I think that this should be
> ```
> return getAArch64Page(sym.getGotVA() + a) - getAArch64Page(in.got->getVA());
> ```
> From https://github.com/ARM-software/abi-aa/blob/master/aaelf64/aaelf64.rst the expression is: G(GDAT(S+A))-Page(GOT)
> Where GOT is "GOT is the address of the Global Offset Table"
> Page(p) will be the same as Page(GOT) for many entries close to the start of the GOT.
> 
> IIUC the intent is to get an offset from the base of the GOT so that the same register can hold the base of the GOT for the whole function.
> ```
> adrp x0, _GLOBAL_OFFSET_TABLE_
> ldr x1, [x0, #:gotpage_lo15:foo]
> ldr x2, [x0, #:gotpage_lo15:bar]
> ``` 
> 
> 
Indeed it misses the addend in the account. I am not sure if G() should be page aligned as well, the AArch64 ABI is only explict about Page() operation, gold at least does not seem to align it.  I think the correct formula is in fact:


```
return sym.getGotVA() + a - getAArch64Page(in.got->getVA());
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94612/new/

https://reviews.llvm.org/D94612



More information about the llvm-commits mailing list