[PATCH] D45972: [ELF][MIPS] Fix calculation of GP relative relocations in case of relocatable output
Simon Atanasyan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 24 08:44:11 PDT 2018
atanasyan added a comment.
> What bfd/gold do to solve this? I guess the same?
Yes.
================
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;
----------------
grimar wrote:
> Does not seem that test case covers all of these relocations?
Exactly. Moreover the patch contains a bug related to non-tested functionality. I will add more tests in the updated patch.
================
Comment at: ELF/InputSection.cpp:404
+ {R_ABS, Type, Rel.r_offset,
+ Target->getImplicitAddend(BufLoc, Type) + AddendAdjustment, &Sym});
}
----------------
grimar wrote:
> 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;
> ...
> ```
OK
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D45972
More information about the llvm-commits
mailing list