[lld] r319378 - Use Symbol::File directly.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 14:58:25 PST 2017


Nice.

On Wed, Nov 29, 2017 at 2:47 PM, Rafael Espindola via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: rafael
> Date: Wed Nov 29 14:47:35 2017
> New Revision: 319378
>
> URL: http://llvm.org/viewvc/llvm-project?rev=319378&view=rev
> Log:
> Use Symbol::File directly.
>
> We are already paying the cost of storing a InputFile in every
> Symbol, so use it uniformly.
>
> Modified:
>     lld/trunk/ELF/InputFiles.cpp
>     lld/trunk/ELF/LTO.cpp
>     lld/trunk/ELF/MapFile.cpp
>     lld/trunk/ELF/Relocations.cpp
>     lld/trunk/ELF/SymbolTable.cpp
>     lld/trunk/ELF/Symbols.cpp
>     lld/trunk/ELF/Symbols.h
>     lld/trunk/ELF/SyntheticSections.cpp
>     lld/trunk/ELF/Writer.cpp
>
> Modified: lld/trunk/ELF/InputFiles.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> InputFiles.cpp?rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/InputFiles.cpp (original)
> +++ lld/trunk/ELF/InputFiles.cpp Wed Nov 29 14:47:35 2017
> @@ -635,9 +635,9 @@ template <class ELFT> Symbol *ObjFile<EL
>
>      StringRefZ Name = this->StringTable.data() + Sym->st_name;
>      if (Sym->st_shndx == SHN_UNDEF)
> -      return make<Undefined>(Name, Binding, StOther, Type);
> +      return make<Undefined>(this, Name, Binding, StOther, Type);
>
> -    return make<Defined>(Name, Binding, StOther, Type, Value, Size, Sec);
> +    return make<Defined>(this, Name, Binding, StOther, Type, Value, Size,
> Sec);
>    }
>
>    StringRef Name = check(Sym->getName(this->StringTable),
> toString(this));
>
> Modified: lld/trunk/ELF/LTO.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?
> rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/LTO.cpp (original)
> +++ lld/trunk/ELF/LTO.cpp Wed Nov 29 14:47:35 2017
> @@ -145,7 +145,7 @@ void BitcodeCompiler::add(BitcodeFile &F
>      // flags an undefined in IR with a definition in ASM as prevailing.
>      // Once IRObjectFile is fixed to report only one symbol this hack can
>      // be removed.
> -    R.Prevailing = !ObjSym.isUndefined() && Sym->getFile() == &F;
> +    R.Prevailing = !ObjSym.isUndefined() && Sym->File == &F;
>
>      // We ask LTO to preserve following global symbols:
>      // 1) All symbols when doing relocatable link, so that them can be
> used
>
> Modified: lld/trunk/ELF/MapFile.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/MapFile.
> cpp?rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/MapFile.cpp (original)
> +++ lld/trunk/ELF/MapFile.cpp Wed Nov 29 14:47:35 2017
> @@ -52,7 +52,7 @@ static std::vector<Defined *> getSymbols
>    for (InputFile *File : ObjectFiles)
>      for (Symbol *B : File->getSymbols())
>        if (auto *DR = dyn_cast<Defined>(B))
> -        if (DR->getFile() == File && !DR->isSection() && DR->Section &&
> +        if (DR->File == File && !DR->isSection() && DR->Section &&
>              DR->Section->Live)
>            V.push_back(DR);
>    return V;
>
> Modified: lld/trunk/ELF/Relocations.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> Relocations.cpp?rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/Relocations.cpp (original)
> +++ lld/trunk/ELF/Relocations.cpp Wed Nov 29 14:47:35 2017
> @@ -73,7 +73,7 @@ template <class ELFT>
>  static std::string getLocation(InputSectionBase &S, const Symbol &Sym,
>                                 uint64_t Off) {
>    std::string Msg =
> -      "\n>>> defined in " + toString(Sym.getFile()) + "\n>>> referenced
> by ";
> +      "\n>>> defined in " + toString(Sym.File) + "\n>>> referenced by ";
>    std::string Src = S.getSrcMsg<ELFT>(Sym, Off);
>    if (!Src.empty())
>      Msg += Src + "\n>>>               ";
> @@ -641,7 +641,7 @@ static RelExpr adjustExpr(Symbol &Sym, R
>    }
>
>    errorOrWarn("symbol '" + toString(Sym) + "' defined in " +
> -              toString(Sym.getFile()) + " has no type");
> +              toString(Sym.File) + " has no type");
>    return Expr;
>  }
>
>
> Modified: lld/trunk/ELF/SymbolTable.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> SymbolTable.cpp?rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/SymbolTable.cpp (original)
> +++ lld/trunk/ELF/SymbolTable.cpp Wed Nov 29 14:47:35 2017
> @@ -421,8 +421,7 @@ static void warnOrError(const Twine &Msg
>
>  static void reportDuplicate(Symbol *Sym, InputFile *NewFile) {
>    warnOrError("duplicate symbol: " + toString(*Sym) + "\n>>> defined in "
> +
> -              toString(Sym->getFile()) + "\n>>> defined in " +
> -              toString(NewFile));
> +              toString(Sym->File) + "\n>>> defined in " +
> toString(NewFile));
>  }
>
>  template <class ELFT>
>
> Modified: lld/trunk/ELF/Symbols.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.
> cpp?rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/Symbols.cpp (original)
> +++ lld/trunk/ELF/Symbols.cpp Wed Nov 29 14:47:35 2017
> @@ -93,7 +93,7 @@ static uint64_t getSymVA(const Symbol &S
>
>      if (D.isTls() && !Config->Relocatable) {
>        if (!Out::TlsPhdr)
> -        fatal(toString(D.getFile()) +
> +        fatal(toString(D.File) +
>                " has an STT_TLS symbol but doesn't have an SHF_TLS
> section");
>        return VA - Out::TlsPhdr->p_vaddr;
>      }
> @@ -123,17 +123,6 @@ bool Symbol::isUndefWeak() const {
>    return !isLocal() && isWeak() && (isUndefined() || isLazy());
>  }
>
> -InputFile *Symbol::getFile() const {
> -  if (isLocal()) {
> -    const SectionBase *Sec = cast<Defined>(this)->Section;
> -    // Local absolute symbols actually have a file, but that is not
> currently
> -    // used. We could support that by having a mostly redundant InputFile
> in
> -    // Symbol, or having a special absolute section if needed.
> -    return Sec ? cast<InputSectionBase>(Sec)->File : nullptr;
> -  }
> -  return File;
> -}
> -
>  uint64_t Symbol::getVA(int64_t Addend) const {
>    uint64_t OutVA = getSymVA(*this, Addend);
>    return OutVA + Addend;
> @@ -226,7 +215,7 @@ void Symbol::parseSymbolVersion() {
>    // but we may still want to override a versioned symbol from DSO,
>    // so we do not report error in this case.
>    if (Config->Shared)
> -    error(toString(getFile()) + ": symbol " + S + " has undefined version
> " +
> +    error(toString(File) + ": symbol " + S + " has undefined version " +
>            Verstr);
>  }
>
> @@ -236,9 +225,7 @@ InputFile *Lazy::fetch() {
>    return cast<LazyObject>(this)->fetch();
>  }
>
> -ArchiveFile *LazyArchive::getFile() {
> -  return cast<ArchiveFile>(Symbol::getFile());
> -}
> +ArchiveFile *LazyArchive::getFile() { return cast<ArchiveFile>(File); }
>
>  InputFile *LazyArchive::fetch() {
>    std::pair<MemoryBufferRef, uint64_t> MBInfo =
> getFile()->getMember(&Sym);
> @@ -250,9 +237,7 @@ InputFile *LazyArchive::fetch() {
>    return createObjectFile(MBInfo.first, getFile()->getName(),
> MBInfo.second);
>  }
>
> -LazyObjFile *LazyObject::getFile() {
> -  return cast<LazyObjFile>(Symbol::getFile());
> -}
> +LazyObjFile *LazyObject::getFile() { return cast<LazyObjFile>(File); }
>
>  InputFile *LazyObject::fetch() { return getFile()->fetch(); }
>
>
> Modified: lld/trunk/ELF/Symbols.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.
> h?rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/Symbols.h (original)
> +++ lld/trunk/ELF/Symbols.h Wed Nov 29 14:47:35 2017
> @@ -85,7 +85,7 @@ public:
>    unsigned InVersionScript : 1;
>
>    // The file from which this symbol was created.
> -  InputFile *File = nullptr;
> +  InputFile *File;
>
>    bool includeInDynsym() const;
>    uint8_t computeBinding() const;
> @@ -104,7 +104,6 @@ public:
>    // all input files have been added.
>    bool isUndefWeak() const;
>
> -  InputFile *getFile() const;
>    StringRef getName() const { return Name; }
>    uint8_t getVisibility() const { return StOther & 0x3; }
>    void parseSymbolVersion();
> @@ -129,9 +128,9 @@ public:
>    uint32_t GlobalDynIndex = -1;
>
>  protected:
> -  Symbol(Kind K, StringRefZ Name, uint8_t Binding, uint8_t StOther,
> -         uint8_t Type)
> -      : Binding(Binding), SymbolKind(K), NeedsPltAddr(false),
> +  Symbol(Kind K, InputFile *File, StringRefZ Name, uint8_t Binding,
> +         uint8_t StOther, uint8_t Type)
> +      : Binding(Binding), File(File), SymbolKind(K), NeedsPltAddr(false),
>          IsInGlobalMipsGot(false), Is32BitMipsGot(false), IsInIplt(false),
>          IsInIgot(false), IsPreemptible(false), Used(!Config->GcSections),
>          Type(Type), StOther(StOther), Name(Name) {}
> @@ -184,9 +183,9 @@ protected:
>  // Represents a symbol that is defined in the current output file.
>  class Defined : public Symbol {
>  public:
> -  Defined(StringRefZ Name, uint8_t Binding, uint8_t StOther, uint8_t Type,
> -          uint64_t Value, uint64_t Size, SectionBase *Section)
> -      : Symbol(DefinedKind, Name, Binding, StOther, Type), Value(Value),
> +  Defined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t
> StOther,
> +          uint8_t Type, uint64_t Value, uint64_t Size, SectionBase
> *Section)
> +      : Symbol(DefinedKind, File, Name, Binding, StOther, Type),
> Value(Value),
>          Size(Size), Section(Section) {}
>
>    static bool classof(const Symbol *S) { return S->isDefined(); }
> @@ -198,8 +197,9 @@ public:
>
>  class Undefined : public Symbol {
>  public:
> -  Undefined(StringRefZ Name, uint8_t Binding, uint8_t StOther, uint8_t
> Type)
> -      : Symbol(UndefinedKind, Name, Binding, StOther, Type) {}
> +  Undefined(InputFile *File, StringRefZ Name, uint8_t Binding, uint8_t
> StOther,
> +            uint8_t Type)
> +      : Symbol(UndefinedKind, File, Name, Binding, StOther, Type) {}
>
>    static bool classof(const Symbol *S) { return S->kind() ==
> UndefinedKind; }
>  };
> @@ -208,10 +208,10 @@ class SharedSymbol : public Symbol {
>  public:
>    static bool classof(const Symbol *S) { return S->kind() == SharedKind; }
>
> -  SharedSymbol(StringRef Name, uint8_t Binding, uint8_t StOther, uint8_t
> Type,
> -               uint64_t Value, uint64_t Size, uint32_t Alignment,
> -               const void *Verdef)
> -      : Symbol(SharedKind, Name, Binding, StOther, Type), Verdef(Verdef),
> +  SharedSymbol(InputFile *File, StringRef Name, uint8_t Binding,
> +               uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t
> Size,
> +               uint32_t Alignment, const void *Verdef)
> +      : Symbol(SharedKind, File, Name, Binding, StOther, Type),
> Verdef(Verdef),
>          Value(Value), Size(Size), Alignment(Alignment) {
>      // GNU ifunc is a mechanism to allow user-supplied functions to
>      // resolve PLT slot values at load-time. This is contrary to the
> @@ -234,7 +234,7 @@ public:
>    }
>
>    template <class ELFT> SharedFile<ELFT> *getFile() const {
> -    return cast<SharedFile<ELFT>>(Symbol::getFile());
> +    return cast<SharedFile<ELFT>>(File);
>    }
>
>    // This field is a pointer to the symbol's version definition.
> @@ -266,8 +266,9 @@ public:
>    InputFile *fetch();
>
>  protected:
> -  Lazy(Kind K, StringRef Name, uint8_t Type)
> -      : Symbol(K, Name, llvm::ELF::STB_GLOBAL, llvm::ELF::STV_DEFAULT,
> Type) {}
> +  Lazy(Kind K, InputFile *File, StringRef Name, uint8_t Type)
> +      : Symbol(K, File, Name, llvm::ELF::STB_GLOBAL,
> llvm::ELF::STV_DEFAULT,
> +               Type) {}
>  };
>
>  // This class represents a symbol defined in an archive file. It is
> @@ -276,8 +277,9 @@ protected:
>  // symbol.
>  class LazyArchive : public Lazy {
>  public:
> -  LazyArchive(const llvm::object::Archive::Symbol S, uint8_t Type)
> -      : Lazy(LazyArchiveKind, S.getName(), Type), Sym(S) {}
> +  LazyArchive(InputFile *File, const llvm::object::Archive::Symbol S,
> +              uint8_t Type)
> +      : Lazy(LazyArchiveKind, File, S.getName(), Type), Sym(S) {}
>
>    static bool classof(const Symbol *S) { return S->kind() ==
> LazyArchiveKind; }
>
> @@ -292,7 +294,8 @@ private:
>  // --start-lib and --end-lib options.
>  class LazyObject : public Lazy {
>  public:
> -  LazyObject(StringRef Name, uint8_t Type) : Lazy(LazyObjectKind, Name,
> Type) {}
> +  LazyObject(InputFile *File, StringRef Name, uint8_t Type)
> +      : Lazy(LazyObjectKind, File, Name, Type) {}
>
>    static bool classof(const Symbol *S) { return S->kind() ==
> LazyObjectKind; }
>
> @@ -343,7 +346,7 @@ union SymbolUnion {
>  void printTraceSymbol(Symbol *Sym);
>
>  template <typename T, typename... ArgT>
> -void replaceSymbol(Symbol *S, InputFile *File, ArgT &&... Arg) {
> +void replaceSymbol(Symbol *S, ArgT &&... Arg) {
>    static_assert(sizeof(T) <= sizeof(SymbolUnion), "SymbolUnion too
> small");
>    static_assert(alignof(T) <= alignof(SymbolUnion),
>                  "SymbolUnion not aligned enough");
> @@ -353,7 +356,6 @@ void replaceSymbol(Symbol *S, InputFile
>    Symbol Sym = *S;
>
>    new (S) T(std::forward<ArgT>(Arg)...);
> -  S->File = File;
>
>    S->VersionId = Sym.VersionId;
>    S->Visibility = Sym.Visibility;
>
> Modified: lld/trunk/ELF/SyntheticSections.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/
> SyntheticSections.cpp?rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/SyntheticSections.cpp (original)
> +++ lld/trunk/ELF/SyntheticSections.cpp Wed Nov 29 14:47:35 2017
> @@ -275,8 +275,8 @@ InputSection *elf::createInterpSection()
>
>  Symbol *elf::addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t
> Value,
>                                 uint64_t Size, InputSectionBase *Section) {
> -  auto *S =
> -      make<Defined>(Name, STB_LOCAL, STV_DEFAULT, Type, Value, Size,
> Section);
> +  auto *S = make<Defined>(Section->File, Name, STB_LOCAL, STV_DEFAULT,
> Type,
> +                          Value, Size, Section);
>    if (InX::SymTab)
>      InX::SymTab->addSymbol(S);
>    return S;
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.
> cpp?rev=319378&r1=319377&r2=319378&view=diff
> ============================================================
> ==================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Wed Nov 29 14:47:35 2017
> @@ -508,8 +508,9 @@ template <class ELFT> void Writer<ELFT>:
>      if (isa<SyntheticSection>(IS) && !(IS->Flags & SHF_MERGE))
>        continue;
>
> -    auto *Sym = make<Defined>("", STB_LOCAL, /*StOther=*/0, STT_SECTION,
> -                              /*Value=*/0, /*Size=*/0, IS);
> +    auto *Sym =
> +        make<Defined>(IS->File, "", STB_LOCAL, /*StOther=*/0, STT_SECTION,
> +                      /*Value=*/0, /*Size=*/0, IS);
>      InX::SymTab->addSymbol(Sym);
>    }
>  }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171129/543e2a77/attachment-0001.html>


More information about the llvm-commits mailing list