[PATCH] D45972: [ELF][MIPS] Fix calculation of GP relative relocations in case of relocatable output

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 24 02:30:47 PDT 2018


grimar added a comment.

What bfd/gold do to solve this? I guess the same?



================
Comment at: ELF/InputSection.cpp:393
+        if (Type == R_MIPS_GPREL32 || Type == R_MIPS_GPREL16 ||
+            R_MICROMIPS_GPREL16 || R_MICROMIPS_GPREL7_S2)
+          AddendAdjustment = Sec->getFile<ELFT>()->MipsGp0;
----------------
Does not seem that test case covers all of these relocations?


================
Comment at: ELF/InputSection.cpp:404
+            {R_ABS, Type, Rel.r_offset,
+             Target->getImplicitAddend(BufLoc, Type) + AddendAdjustment, &Sym});
       }
----------------
I would probably make addend calculation a bit more explicit
to avoid additional variable, something like:

```
  int64_t Addend = getAddend<ELFT>(Rel);
  if (!RelTy::IsRela) {
    const uint8_t *BufLoc = Sec->Data.begin() + Rel.r_offset;
    Addend += Target->getImplicitAddend(BufLoc, Type);
  }

  if (Config->EMachine == EM_MIPS && ...)
    Addend += Sec->getFile<ELFT>()->MipsGp0;
...
```


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D45972





More information about the llvm-commits mailing list