[lld] r286937 - Avoid creating reference from nullptr.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 15 06:00:29 PST 2016


This was found by an existing test with ubsan or should we add
something to lld/test/ELF?

Thanks,
Rafael


On 15 November 2016 at 02:32, Vitaly Buka via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: vitalybuka
> Date: Tue Nov 15 01:32:51 2016
> New Revision: 286937
>
> URL: http://llvm.org/viewvc/llvm-project?rev=286937&view=rev
> Log:
> Avoid creating reference from nullptr.
>
> Summary:
> getFile() can return nullptr. This usually happens when Rels is empty so
> the reference is never used. Still UBSAN complains.
>
> Reviewers: rafael
>
> Subscribers: llvm-commits
>
> Differential Revision: https://reviews.llvm.org/D26662
>
> Modified:
>     lld/trunk/ELF/Relocations.cpp
>
> Modified: lld/trunk/ELF/Relocations.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=286937&r1=286936&r2=286937&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Relocations.cpp (original)
> +++ lld/trunk/ELF/Relocations.cpp Tue Nov 15 01:32:51 2016
> @@ -615,7 +615,7 @@ static void scanRelocs(InputSectionBase<
>      Out<ELFT>::RelaDyn->addReloc(Reloc);
>    };
>
> -  const elf::ObjectFile<ELFT> &File = *C.getFile();
> +  const elf::ObjectFile<ELFT> *File = C.getFile();
>    ArrayRef<uint8_t> SectionData = C.Data;
>    const uint8_t *Buf = SectionData.begin();
>
> @@ -628,7 +628,7 @@ static void scanRelocs(InputSectionBase<
>
>    for (auto I = Rels.begin(), E = Rels.end(); I != E; ++I) {
>      const RelTy &RI = *I;
> -    SymbolBody &Body = File.getRelocTargetSym(RI);
> +    SymbolBody &Body = File->getRelocTargetSym(RI);
>      uint32_t Type = RI.getType(Config->Mips64EL);
>
>      if (Config->MipsN32Abi) {
> @@ -645,7 +645,7 @@ static void scanRelocs(InputSectionBase<
>
>      RelExpr Expr = Target->getRelExpr(Type, Body);
>      bool Preemptible = isPreemptible(Body, Type);
> -    Expr = adjustExpr(File, Body, IsWrite, Expr, Type, Buf + RI.r_offset);
> +    Expr = adjustExpr(*File, Body, IsWrite, Expr, Type, Buf + RI.r_offset);
>      if (HasError)
>        continue;
>
> @@ -673,7 +673,7 @@ static void scanRelocs(InputSectionBase<
>          Expr == R_GOTREL || Expr == R_GOTREL_FROM_END || Expr == R_PPC_TOC)
>        In<ELFT>::Got->HasGotOffRel = true;
>
> -    uintX_t Addend = computeAddend(File, Buf, E, RI, Expr, Body);
> +    uintX_t Addend = computeAddend(*File, Buf, E, RI, Expr, Body);
>
>      if (unsigned Processed =
>              handleTlsRelocation<ELFT>(Type, Body, C, Offset, Addend, Expr)) {
> @@ -796,14 +796,14 @@ template <class ELFT> void scanRelocatio
>
>  template <class ELFT, class RelTy>
>  static void createThunks(InputSectionBase<ELFT> &C, ArrayRef<RelTy> Rels) {
> -  const elf::ObjectFile<ELFT> &File = *C.getFile();
> +  const elf::ObjectFile<ELFT> *File = C.getFile();
>    for (const RelTy &Rel : Rels) {
> -    SymbolBody &Body = File.getRelocTargetSym(Rel);
> +    SymbolBody &Body = File->getRelocTargetSym(Rel);
>      uint32_t Type = Rel.getType(Config->Mips64EL);
>      RelExpr Expr = Target->getRelExpr(Type, Body);
>      if (!isPreemptible(Body, Type) && needsPlt(Expr))
>        Expr = fromPlt(Expr);
> -    Expr = Target->getThunkExpr(Expr, Type, File, Body);
> +    Expr = Target->getThunkExpr(Expr, Type, *File, Body);
>      // Some targets might require creation of thunks for relocations.
>      // Now we support only MIPS which requires LA25 thunk to call PIC
>      // code from non-PIC one, and ARM which requires interworking.
>
>
> _______________________________________________
> 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