[lld] r198788 - [Mips] Factor out the code determines type of GOT entry (local/global)

Rui Ueyama ruiu at google.com
Wed Jan 8 14:39:16 PST 2014


On Wed, Jan 8, 2014 at 12:42 PM, Simon Atanasyan <simon at atanasyan.com>wrote:

> Author: atanasyan
> Date: Wed Jan  8 14:42:45 2014
> New Revision: 198788
>
> URL: http://llvm.org/viewvc/llvm-project?rev=198788&view=rev
> Log:
> [Mips] Factor out the code determines type of GOT entry (local/global)
> into the separate function.
>
> Modified:
>     lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
>     lld/trunk/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp?rev=198788&r1=198787&r2=198788&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Wed Jan  8
> 14:42:45 2014
> @@ -122,30 +122,47 @@ private:
>      const_cast<Reference &>(ref).setTarget(getGOTEntry(ref.target()));
>    }
>
> +  bool requireLocalGOT(const Atom *a) {
> +    Atom::Scope scope;
> +    if (isa<DefinedAtom>(a))
> +      scope = dyn_cast<DefinedAtom>(a)->scope();
> +    else if (isa<AbsoluteAtom>(a))
> +      scope = dyn_cast<AbsoluteAtom>(a)->scope();
> +    else
> +      return false;
>

dyn_cast calls isa, so isa is called twice in each expression. Probably

 if (auto *def = dyn_cast<DefinedAtom>(a))
   scope = def->scope();
 else if (auto *abs = dyn_cast<AbsoluteAtom>(a))
   ...

would be a bit better?

+
> +    // Local and hidden symbols must be local.
> +    if (scope == Atom::scopeTranslationUnit ||
> +        scope == Atom::scopeLinkageUnit)
> +      return true;
> +
> +    return false;
> +  }
> +
>    const GOTAtom *getGOTEntry(const Atom *a) {
>      auto got = _gotMap.find(a);
>      if (got != _gotMap.end())
>        return got->second;
>
> -    const DefinedAtom *da = dyn_cast<DefinedAtom>(a);
> -    bool isLocal = (da && da->scope() == Atom::scopeTranslationUnit);
> -
>      auto ga = new (_file._alloc) GOT0Atom(_file);
>      _gotMap[a] = ga;
> -    if (isLocal)
> +
> +    bool localGOT = requireLocalGOT(a);
> +
> +    if (localGOT)
>        _localGotVector.push_back(ga);
>      else {
> -      if (da)
> -        ga->addReferenceELF_Mips(R_MIPS_32, 0, a, 0);
> -      else
> -        ga->addReferenceELF_Mips(LLD_R_MIPS_GLOBAL_GOT, 0, a, 0);
>        _globalGotVector.push_back(ga);
> +      ga->addReferenceELF_Mips(LLD_R_MIPS_GLOBAL_GOT, 0, a, 0);
>      }
>
> +    if (const DefinedAtom *da = dyn_cast<DefinedAtom>(a))
> +      ga->addReferenceELF_Mips(R_MIPS_32, 0, da, 0);
> +
>      DEBUG_WITH_TYPE("MipsGOT", {
>        ga->_name = "__got_";
>        ga->_name += a->name();
> -      llvm::dbgs() << "[ GOT ] Create " << (isLocal ? "L " : "G ") <<
> a->name()
> +      llvm::dbgs() << "[ GOT ] Create " << (localGOT ? "L " : "G ") <<
> a->name()
>                     << "\n";
>      });
>
>
> Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h?rev=198788&r1=198787&r2=198788&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h (original)
> +++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsSectionChunks.h Wed Jan  8
> 14:42:45 2014
> @@ -54,8 +54,7 @@ public:
>        if (r->kindNamespace() != lld::Reference::KindNamespace::ELF)
>          continue;
>        assert(r->kindArch() == Reference::KindArch::Mips);
> -      if (r->kindValue() == llvm::ELF::R_MIPS_32 ||
> -          r->kindValue() == LLD_R_MIPS_GLOBAL_GOT) {
> +      if (r->kindValue() == LLD_R_MIPS_GLOBAL_GOT) {
>          ta = r->target();
>          break;
>        }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140108/8f13c71e/attachment.html>


More information about the llvm-commits mailing list