[lld] r258430 - ELF: Move code to emit copyrel to one place. NFC.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 25 10:37:49 PST 2016


Thanks!

On 21 January 2016 at 12:59, Rui Ueyama via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Thu Jan 21 14:59:22 2016
> New Revision: 258430
>
> URL: http://llvm.org/viewvc/llvm-project?rev=258430&view=rev
> Log:
> ELF: Move code to emit copyrel to one place. NFC.
>
> In this code, we avoid calling needsCopyRel in writeTo because
> we called that function already in scanRelocs. Making the same
> decision twice is a waste and has a risk of a bug that we get
> inconsistent resuts.
>
> Modified:
>     lld/trunk/ELF/OutputSections.cpp
>
> Modified: lld/trunk/ELF/OutputSections.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=258430&r1=258429&r2=258430&view=diff
> ==============================================================================
> --- lld/trunk/ELF/OutputSections.cpp (original)
> +++ lld/trunk/ELF/OutputSections.cpp Thu Jan 21 14:59:22 2016
> @@ -290,7 +290,16 @@ template <class ELFT> void RelocationSec
>      uint32_t Type = RI.getType(Config->Mips64EL);
>      if (applyTlsDynamicReloc(Body, Type, P, reinterpret_cast<Elf_Rel *>(Buf)))
>        continue;
> -    bool NeedsCopy = Body && Target->needsCopyRel(Type, *Body);
> +
> +    // Emit a copy relocation.
> +    auto *SS = dyn_cast_or_null<SharedSymbol<ELFT>>(Body);
> +    if (SS && SS->NeedsCopy) {
> +      P->setSymbolAndType(Body->DynamicSymbolTableIndex, Target->getCopyReloc(),
> +                          Config->Mips64EL);
> +      P->r_offset = Out<ELFT>::Bss->getVA() + SS->OffsetInBss;
> +      continue;
> +    }
> +
>      bool NeedsGot = Body && Target->relocNeedsGot(Type, *Body);
>      bool CBP = canBePreempted(Body, NeedsGot);
>      bool LazyReloc = Body && Target->supportsLazyRelocations() &&
> @@ -307,8 +316,6 @@ template <class ELFT> void RelocationSec
>        Reloc = Target->getPltReloc();
>      else if (NeedsGot)
>        Reloc = Body->isTls() ? Target->getTlsGotReloc() : Target->getGotReloc();
> -    else if (NeedsCopy)
> -      Reloc = Target->getCopyReloc();
>      else
>        Reloc = Target->getDynReloc(Type);
>      P->setSymbolAndType(Sym, Reloc, Config->Mips64EL);
> @@ -317,9 +324,6 @@ template <class ELFT> void RelocationSec
>        P->r_offset = Out<ELFT>::GotPlt->getEntryAddr(*Body);
>      else if (NeedsGot)
>        P->r_offset = Out<ELFT>::Got->getEntryAddr(*Body);
> -    else if (NeedsCopy)
> -      P->r_offset = Out<ELFT>::Bss->getVA() +
> -                    cast<SharedSymbol<ELFT>>(Body)->OffsetInBss;
>      else
>        P->r_offset = C.getOffset(RI.r_offset) + C.OutSec->getVA();
>
> @@ -328,9 +332,7 @@ template <class ELFT> void RelocationSec
>        OrigAddend = static_cast<const Elf_Rela &>(RI).r_addend;
>
>      uintX_t Addend;
> -    if (NeedsCopy)
> -      Addend = 0;
> -    else if (CBP || IsDynRelative)
> +    if (CBP || IsDynRelative)
>        Addend = OrigAddend;
>      else if (Body)
>        Addend = getSymVA<ELFT>(*Body) + OrigAddend;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list