[lld] r249061 - Don't include shared libraries multiple times.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 12:59:13 PDT 2015


I'm wondering if this is really an expected behavior. Does linkers have to
look at DT_SONAME field in DSOs to dedup them? Is this what other linkers
do?

On Thu, Oct 1, 2015 at 12:52 PM, Rafael Espindola via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: rafael
> Date: Thu Oct  1 14:52:48 2015
> New Revision: 249061
>
> URL: http://llvm.org/viewvc/llvm-project?rev=249061&view=rev
> Log:
> Don't include shared libraries multiple times.
>
> Modified:
>     lld/trunk/ELF/InputFiles.cpp
>     lld/trunk/ELF/InputFiles.h
>     lld/trunk/ELF/SymbolTable.cpp
>     lld/trunk/ELF/SymbolTable.h
>     lld/trunk/test/elf2/soname.s
>
> Modified: lld/trunk/ELF/InputFiles.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=249061&r1=249060&r2=249061&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/InputFiles.cpp (original)
> +++ lld/trunk/ELF/InputFiles.cpp Thu Oct  1 14:52:48 2015
> @@ -77,13 +77,14 @@ ELFData<ELFT>::getSymbolsHelper(bool Loc
>    return make_range(Syms.begin() + 1, Syms.begin() + FirstNonLocal);
>  }
>
> -template <class ELFT>
> -typename ELFData<ELFT>::Elf_Sym_Range ELFData<ELFT>::getNonLocalSymbols()
> {
> -  if (!Symtab)
> -    return Elf_Sym_Range(nullptr, nullptr);
> +template <class ELFT> void ELFData<ELFT>::initStringTable() {
>    ErrorOr<StringRef> StringTableOrErr =
> ELFObj.getStringTableForSymtab(*Symtab);
>    error(StringTableOrErr.getError());
>    StringTable = *StringTableOrErr;
> +}
> +
> +template <class ELFT>
> +typename ELFData<ELFT>::Elf_Sym_Range ELFData<ELFT>::getNonLocalSymbols()
> {
>    return getSymbolsHelper(false);
>  }
>
> @@ -141,6 +142,7 @@ template <class ELFT> void elf2::ObjectF
>  }
>
>  template <class ELFT> void elf2::ObjectFile<ELFT>::initializeSymbols() {
> +  this->initStringTable();
>    Elf_Sym_Range Syms = this->getNonLocalSymbols();
>    uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());
>    SymbolBodies.reserve(NumSymbols);
> @@ -233,7 +235,7 @@ template <class ELFT>
>  SharedFile<ELFT>::SharedFile(MemoryBufferRef M)
>      : SharedFileBase(getStaticELFKind<ELFT>(), M), ELFData<ELFT>(M) {}
>
> -template <class ELFT> void SharedFile<ELFT>::parse() {
> +template <class ELFT> void SharedFile<ELFT>::parseSoName() {
>    typedef typename ELFFile<ELFT>::Elf_Dyn Elf_Dyn;
>    typedef typename ELFFile<ELFT>::uintX_t uintX_t;
>    const Elf_Shdr *DynamicSec = nullptr;
> @@ -247,8 +249,7 @@ template <class ELFT> void SharedFile<EL
>        DynamicSec = &Sec;
>    }
>
> -  // Also sets StringTable
> -  Elf_Sym_Range Syms = this->getNonLocalSymbols();
> +  this->initStringTable();
>    SoName = getName();
>
>    if (DynamicSec) {
> @@ -266,7 +267,10 @@ template <class ELFT> void SharedFile<EL
>        }
>      }
>    }
> +}
>
> +template <class ELFT> void SharedFile<ELFT>::parse() {
> +  Elf_Sym_Range Syms = this->getNonLocalSymbols();
>    uint32_t NumSymbols = std::distance(Syms.begin(), Syms.end());
>    SymbolBodies.reserve(NumSymbols);
>    for (const Elf_Sym &Sym : Syms) {
>
> Modified: lld/trunk/ELF/InputFiles.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=249061&r1=249060&r2=249061&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/InputFiles.h (original)
> +++ lld/trunk/ELF/InputFiles.h Thu Oct  1 14:52:48 2015
> @@ -116,6 +116,7 @@ protected:
>    llvm::object::ELFFile<ELFT> ELFObj;
>    const Elf_Shdr *Symtab = nullptr;
>    StringRef StringTable;
> +  void initStringTable();
>    Elf_Sym_Range getNonLocalSymbols();
>    Elf_Sym_Range getSymbolsHelper(bool);
>  };
> @@ -194,6 +195,7 @@ public:
>        : ELFFileBase(SharedKind, EKind, M) {}
>    static bool classof(const InputFile *F) { return F->kind() ==
> SharedKind; }
>    StringRef getSoName() const { return SoName; }
> +  virtual void parseSoName() = 0;
>  };
>
>  template <class ELFT>
> @@ -217,6 +219,7 @@ public:
>
>    explicit SharedFile(MemoryBufferRef M);
>
> +  void parseSoName() override;
>    void parse() override;
>  };
>
>
> Modified: lld/trunk/ELF/SymbolTable.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=249061&r1=249060&r2=249061&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.cpp (original)
> +++ lld/trunk/ELF/SymbolTable.cpp Thu Oct  1 14:52:48 2015
> @@ -41,6 +41,11 @@ void SymbolTable::addFile(std::unique_pt
>        addLazy(&Sym);
>      return;
>    }
> +  if (auto *S = dyn_cast<SharedFileBase>(File.get())) {
> +    S->parseSoName();
> +    if (!IncludedSoNames.insert(S->getSoName()).second)
> +      return;
> +  }
>    File->parse();
>    addELFFile(cast<ELFFileBase>(File.release()));
>  }
>
> Modified: lld/trunk/ELF/SymbolTable.h
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=249061&r1=249060&r2=249061&view=diff
>
> ==============================================================================
> --- lld/trunk/ELF/SymbolTable.h (original)
> +++ lld/trunk/ELF/SymbolTable.h Thu Oct  1 14:52:48 2015
> @@ -93,6 +93,7 @@ private:
>    std::vector<std::unique_ptr<ObjectFileBase>> ObjectFiles;
>
>    std::vector<std::unique_ptr<SharedFileBase>> SharedFiles;
> +  llvm::DenseSet<StringRef> IncludedSoNames;
>
>    SymbolBody *EntrySym = nullptr;
>  };
>
> Modified: lld/trunk/test/elf2/soname.s
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/soname.s?rev=249061&r1=249060&r2=249061&view=diff
>
> ==============================================================================
> --- lld/trunk/test/elf2/soname.s (original)
> +++ lld/trunk/test/elf2/soname.s Thu Oct  1 14:52:48 2015
> @@ -1,9 +1,10 @@
>  // RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
>  // RUN: lld -flavor gnu2 %t.o -shared -soname=bar -o %t.so
> -// RUN: lld -flavor gnu2 %t.o %t.so -o %t
> +// RUN: lld -flavor gnu2 %t.o %t.so %t.so -o %t
>  // RUN: llvm-readobj --dynamic-table %t | FileCheck %s
>
>  // CHECK:  0x0000000000000001 NEEDED               SharedLibrary (bar)
> +// CHECK-NOT: NEEDED
>
>  .global _start
>  _start:
>
>
> _______________________________________________
> 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/20151001/14887785/attachment.html>


More information about the llvm-commits mailing list