[lld] r312796 - Currently lld creates a single section to collect all commons. There is no way

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 14:41:44 PDT 2017


On Tue, Sep 12, 2017 at 2:31 PM, Shoaib Meenai <smeenai at fb.com> wrote:

> It's written in C, and it has 325 common symbols.
>

It seems 325 common symbols are few to explain the regression you have
experienced from  ~4.5 seconds to ~5.3 seconds. This patch creates one
virtual section for each common symbol, so the linker would create just 325
section objects which should be pretty fast. I cannot imagine that it takes
almost one second. I wonder if there's a factor other than that.

I only read up on common symbols today, so please correct me if my
> understanding is off. From what I've read, you'll end up with a common
> symbol
> in your object file if you have an uninitialized non-static global
> variable,
> e.g. (in the global scope):
>
> int x;
>
> If you mark the variable static, or if you explicitly zero-initialize it,
> it'll end up in bss instead of COMMON. You can also use -fno-common to
> force
> the use of bss, and C++ does so by default.
>
> I understand that COMMON symbols were originally devised to deal with
> people
> writing `int x` instead of `extern int x` in headers. My library doesn't
> have
> that problem; the `int x` form is used only in source files, and the
> intent is
> to define a variable and have it be automatically zero-initialized. I was
> hoping that if a variable was preceded by an extern declaration, e.g.
>
> extern int x;
> ...
> int x;
>
> the compiler would place it in bss instead of COMMON, but that doesn't
> appear
> to be the case.
>
> I'll try compiling my sources with -fno-common. This definitely seems like
> something a lot of libraries could run into though, since it looks like all
> you need to trigger it is an uninitialized global variable.
>
> On 9/12/17, 1:25 PM, "Rafael Avila de Espindola" <
> rafael.espindola at gmail.com> wrote:
>
>     How many common symbols do you see in your library? What language is it
>     written in?
>
>     Cheers,
>     Rafael
>
>     Shoaib Meenai <smeenai at fb.com> writes:
>
>     > I'm seeing an 18% regression in link times for a large library from
> this
>     > change (it increases from ~4.5 seconds to ~5.3 seconds). I'm looking
> into why
>     > the library I'm linking has so many common symbols, since from the
> discussion
>     > on the patch it sounds like common symbols should be relatively
> rare, but
>     > there are probably other binaries out there which are similarly
> regressed.
>     >
>     > On 9/8/17, 9:24 AM, "llvm-commits on behalf of Dmitry Mikulin via
> llvm-commits" <llvm-commits-bounces at lists.llvm.org on behalf of
> llvm-commits at lists.llvm.org> wrote:
>     >
>     >     Author: dmikulin
>     >     Date: Fri Sep  8 09:22:43 2017
>     >     New Revision: 312796
>     >
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject-3Frev-3D312796-26view-3Drev&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=F0escWBl3X6bxsDuK92_UGN64Bcg7zhj2C7t3I1SJqQ&e=
>     >     Log:
>     >     Currently lld creates a single section to collect all commons.
> There is no way
>     >     to separate commons based on file name patterns. The following
> linker script
>     >     construct does not work because commons are allocated before
> section placement
>     >     is done and the only synthesized BssSection that holds all
> commons has no file
>     >     associated with it:
>     >     SECTIONS { .common_0 : { *file0.o(COMMON) }}
>     >
>     >     This patch changes the allocation of commons to create a section
> per common
>     >     symbol and let the section logic do the layout.
>     >
>     >     Differential revision: https://urldefense.proofpoint.
> com/v2/url?u=https-3A__reviews.llvm.org_D37489&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=hohyhSx7Or16JdZrgLzWWM6xJR5MYfzYxT7efGbRmfM&e=
>     >
>     >     Added:
>     >         lld/trunk/test/ELF/linkerscript/Inputs/common-filespec1.s
>     >         lld/trunk/test/ELF/linkerscript/Inputs/common-filespec2.s
>     >         lld/trunk/test/ELF/linkerscript/common-exclude.s
>     >         lld/trunk/test/ELF/linkerscript/common-filespec.s
>     >     Modified:
>     >         lld/trunk/ELF/LinkerScript.cpp
>     >         lld/trunk/ELF/MapFile.cpp
>     >         lld/trunk/ELF/Symbols.cpp
>     >         lld/trunk/ELF/Symbols.h
>     >         lld/trunk/ELF/SyntheticSections.cpp
>     >         lld/trunk/ELF/SyntheticSections.h
>     >         lld/trunk/ELF/Writer.cpp
>     >         lld/trunk/test/ELF/common.s
>     >         lld/trunk/test/ELF/linkerscript/common.s
>     >         lld/trunk/test/ELF/linkerscript/discard-section-err.s
>     >         lld/trunk/test/ELF/map-file.s
>     >
>     >     Modified: lld/trunk/ELF/LinkerScript.cpp
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_ELF_LinkerScript.cpp-
> 3Frev-3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=aoZ7kwk46HKH2ETf1dfWh2-cXemDYt9vf9VnTnLdcuk&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/ELF/LinkerScript.cpp (original)
>     >     +++ lld/trunk/ELF/LinkerScript.cpp Fri Sep  8 09:22:43 2017
>     >     @@ -174,17 +174,17 @@ bool BytesDataCommand::classof(const Bas
>     >        return C->Kind == BytesDataKind;
>     >      }
>     >
>     >     -static std::string filename(InputSectionBase *S) {
>     >     -  if (!S->File)
>     >     +static std::string filename(InputFile *File) {
>     >     +  if (!File)
>     >          return "";
>     >     -  if (S->File->ArchiveName.empty())
>     >     -    return S->File->getName();
>     >     -  return (S->File->ArchiveName + "(" + S->File->getName() +
> ")").str();
>     >     +  if (File->ArchiveName.empty())
>     >     +    return File->getName();
>     >     +  return (File->ArchiveName + "(" + File->getName() +
> ")").str();
>     >      }
>     >
>     >      bool LinkerScript::shouldKeep(InputSectionBase *S) {
>     >        for (InputSectionDescription *ID : Opt.KeptSections) {
>     >     -    std::string Filename = filename(S);
>     >     +    std::string Filename = filename(S->File);
>     >          if (ID->FilePat.match(Filename))
>     >            for (SectionPattern &P : ID->SectionPatterns)
>     >              if (P.SectionPat.match(S->Name))
>     >     @@ -284,7 +284,7 @@ LinkerScript::computeInputSections(const
>     >            if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA)
>     >              continue;
>     >
>     >     -      std::string Filename = filename(Sec);
>     >     +      std::string Filename = filename(Sec->File);
>     >            if (!Cmd->FilePat.match(Filename) ||
>     >                Pat.ExcludedFilePat.match(Filename) ||
>     >                !Pat.SectionPat.match(Sec->Name))
>     >     @@ -328,8 +328,8 @@ LinkerScript::computeInputSections(const
>     >      void LinkerScript::discard(ArrayRef<InputSectionBase *> V) {
>     >        for (InputSectionBase *S : V) {
>     >          S->Live = false;
>     >     -    if (S == InX::ShStrTab || S == InX::Common || S ==
> InX::Dynamic ||
>     >     -        S == InX::DynSymTab || S == InX::DynStrTab)
>     >     +    if (S == InX::ShStrTab || S == InX::Dynamic || S ==
> InX::DynSymTab ||
>     >     +        S == InX::DynStrTab)
>     >            error("discarding " + S->Name + " section is not
> allowed");
>     >          discard(S->DependentSections);
>     >        }
>     >     @@ -868,7 +868,7 @@ ExprValue LinkerScript::getSymbolValue(c
>     >          if (auto *D = dyn_cast<DefinedRegular>(B))
>     >            return {D->Section, D->Value, Loc};
>     >          if (auto *C = dyn_cast<DefinedCommon>(B))
>     >     -      return {InX::Common, C->Offset, Loc};
>     >     +      return {C->Section, C->Offset, Loc};
>     >        }
>     >        error(Loc + ": symbol not found: " + S);
>     >        return 0;
>     >
>     >     Modified: lld/trunk/ELF/MapFile.cpp
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_ELF_MapFile.cpp-3Frev-
> 3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=B87yHQNSR1ktCxKmP5fqTXzkkaYLMPAVfCo512EUe3U&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/ELF/MapFile.cpp (original)
>     >     +++ lld/trunk/ELF/MapFile.cpp Fri Sep  8 09:22:43 2017
>     >     @@ -57,7 +57,7 @@ template <class ELFT> static std::vector
>     >                  DR->Section->Live)
>     >                V.push_back(DR);
>     >            } else if (auto *DC = dyn_cast<DefinedCommon>(B)) {
>     >     -        if (InX::Common)
>     >     +        if (DC->Section)
>     >                V.push_back(DC);
>     >            }
>     >          }
>     >     @@ -71,8 +71,8 @@ static SymbolMapTy getSectionSyms(ArrayR
>     >        for (Defined *S : Syms) {
>     >          if (auto *DR = dyn_cast<DefinedRegular>(S))
>     >            Ret[DR->Section].push_back(S);
>     >     -    else
>     >     -      Ret[InX::Common].push_back(S);
>     >     +    else if (auto *DC = dyn_cast<DefinedCommon>(S))
>     >     +      Ret[DC->Section].push_back(S);
>     >        }
>     >
>     >        // Sort symbols by address. We want to print out symbols in
> the
>     >
>     >     Modified: lld/trunk/ELF/Symbols.cpp
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_ELF_Symbols.cpp-3Frev-
> 3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=XJ8Ntw-_OTE941EcbDm-3QfMbWAOcu1SOcgas_WsuSs&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/ELF/Symbols.cpp (original)
>     >     +++ lld/trunk/ELF/Symbols.cpp Fri Sep  8 09:22:43 2017
>     >     @@ -99,11 +99,13 @@ static uint64_t getSymVA(const SymbolBod
>     >          }
>     >          return VA;
>     >        }
>     >     -  case SymbolBody::DefinedCommonKind:
>     >     +  case SymbolBody::DefinedCommonKind: {
>     >          if (!Config->DefineCommon)
>     >            return 0;
>     >     -    return InX::Common->getParent()->Addr +
> InX::Common->OutSecOff +
>     >     -           cast<DefinedCommon>(Body).Offset;
>     >     +    auto DC = cast<DefinedCommon>(Body);
>     >     +    return DC.Section->getParent()->Addr +
> DC.Section->OutSecOff +
>     >     +           DC.Offset;
>     >     +  }
>     >        case SymbolBody::SharedKind: {
>     >          auto &SS = cast<SharedSymbol>(Body);
>     >          if (SS.CopyRelSec)
>     >     @@ -202,9 +204,9 @@ OutputSection *SymbolBody::getOutputSect
>     >          return nullptr;
>     >        }
>     >
>     >     -  if (isa<DefinedCommon>(this)) {
>     >     +  if (auto *S = dyn_cast<DefinedCommon>(this)) {
>     >          if (Config->DefineCommon)
>     >     -      return InX::Common->getParent();
>     >     +      return S->Section->getParent();
>     >          return nullptr;
>     >        }
>     >
>     >
>     >     Modified: lld/trunk/ELF/Symbols.h
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_ELF_Symbols.h-3Frev-
> 3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=ymRvyEWwgVa7bH65RA-PV_nwJPNRP_rdJ9CqTwXyozs&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/ELF/Symbols.h (original)
>     >     +++ lld/trunk/ELF/Symbols.h Fri Sep  8 09:22:43 2017
>     >     @@ -27,6 +27,7 @@ namespace elf {
>     >
>     >      class ArchiveFile;
>     >      class BitcodeFile;
>     >     +class BssSection;
>     >      class InputFile;
>     >      class LazyObjFile;
>     >      template <class ELFT> class ObjFile;
>     >     @@ -173,6 +174,7 @@ public:
>     >        // Computed by the writer.
>     >        uint64_t Offset;
>     >        uint64_t Size;
>     >     +  BssSection *Section = nullptr;
>     >      };
>     >
>     >      // Regular defined symbols read from object file symbol tables.
>     >
>     >     Modified: lld/trunk/ELF/SyntheticSections.cpp
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_ELF_SyntheticSections.
> cpp-3Frev-3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=hXG_5Y3y65iZ4sqHptPXnwR-j7hIeqRhMDdIVlgHkx4&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/ELF/SyntheticSections.cpp (original)
>     >     +++ lld/trunk/ELF/SyntheticSections.cpp Fri Sep  8 09:22:43 2017
>     >     @@ -54,35 +54,22 @@ uint64_t SyntheticSection::getVA() const
>     >        return 0;
>     >      }
>     >
>     >     -template <class ELFT> static std::vector<DefinedCommon *>
> getCommonSymbols() {
>     >     -  std::vector<DefinedCommon *> V;
>     >     -  for (Symbol *S : Symtab->getSymbols())
>     >     -    if (auto *B = dyn_cast<DefinedCommon>(S->body()))
>     >     -      V.push_back(B);
>     >     -  return V;
>     >     -}
>     >     -
>     >     -// Find all common symbols and allocate space for them.
>     >     -template <class ELFT> InputSection *elf::createCommonSection() {
>     >     +std::vector<InputSection *> elf::createCommonSections() {
>     >        if (!Config->DefineCommon)
>     >     -    return nullptr;
>     >     +    return {};
>     >
>     >     -  // Sort the common symbols by alignment as an heuristic to
> pack them better.
>     >     -  std::vector<DefinedCommon *> Syms = getCommonSymbols<ELFT>();
>     >     -  if (Syms.empty())
>     >     -    return nullptr;
>     >     -
>     >     -  std::stable_sort(Syms.begin(), Syms.end(),
>     >     -                   [](const DefinedCommon *A, const
> DefinedCommon *B) {
>     >     -                     return A->Alignment > B->Alignment;
>     >     -                   });
>     >     +  std::vector<InputSection *> Ret;
>     >     +  for (Symbol *S : Symtab->getSymbols()) {
>     >     +    auto *Sym = dyn_cast<DefinedCommon>(S->body());
>     >     +    if (!Sym || !Sym->Live)
>     >     +      continue;
>     >
>     >     -  // Allocate space for common symbols.
>     >     -  BssSection *Sec = make<BssSection>("COMMON");
>     >     -  for (DefinedCommon *Sym : Syms)
>     >     -    if (Sym->Live)
>     >     -      Sym->Offset = Sec->reserveSpace(Sym->Size,
> Sym->Alignment);
>     >     -  return Sec;
>     >     +    Sym->Section = make<BssSection>("COMMON");
>     >     +    Sym->Offset = Sym->Section->reserveSpace(Sym->Size,
> Sym->Alignment);
>     >     +    Sym->Section->File = Sym->getFile();
>     >     +    Ret.push_back(Sym->Section);
>     >     +  }
>     >     +  return Ret;
>     >      }
>     >
>     >      // Returns an LLD version string.
>     >     @@ -2321,7 +2308,6 @@ InputSection *InX::ARMAttributes;
>     >      BssSection *InX::Bss;
>     >      BssSection *InX::BssRelRo;
>     >      BuildIdSection *InX::BuildId;
>     >     -InputSection *InX::Common;
>     >      SyntheticSection *InX::Dynamic;
>     >      StringTableSection *InX::DynStrTab;
>     >      SymbolTableBaseSection *InX::DynSymTab;
>     >     @@ -2349,11 +2335,6 @@ template void PltSection::addEntry<ELF32
>     >      template void PltSection::addEntry<ELF64LE>(SymbolBody &Sym);
>     >      template void PltSection::addEntry<ELF64BE>(SymbolBody &Sym);
>     >
>     >     -template InputSection *elf::createCommonSection<ELF32LE>();
>     >     -template InputSection *elf::createCommonSection<ELF32BE>();
>     >     -template InputSection *elf::createCommonSection<ELF64LE>();
>     >     -template InputSection *elf::createCommonSection<ELF64BE>();
>     >     -
>     >      template MergeInputSection *elf::createCommentSection<
> ELF32LE>();
>     >      template MergeInputSection *elf::createCommentSection<
> ELF32BE>();
>     >      template MergeInputSection *elf::createCommentSection<
> ELF64LE>();
>     >
>     >     Modified: lld/trunk/ELF/SyntheticSections.h
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_ELF_SyntheticSections.h-
> 3Frev-3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=lygUGc_3nqWGjJ7d0VlcIx7YSp6SrVkX4khOu7ceK8M&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/ELF/SyntheticSections.h (original)
>     >     +++ lld/trunk/ELF/SyntheticSections.h Fri Sep  8 09:22:43 2017
>     >     @@ -740,7 +740,7 @@ private:
>     >        size_t Size = 0;
>     >      };
>     >
>     >     -template <class ELFT> InputSection *createCommonSection();
>     >     +std::vector<InputSection *> createCommonSections();
>     >      InputSection *createInterpSection();
>     >      template <class ELFT> MergeInputSection *createCommentSection();
>     >      void decompressAndMergeSections();
>     >     @@ -754,7 +754,6 @@ struct InX {
>     >        static BssSection *Bss;
>     >        static BssSection *BssRelRo;
>     >        static BuildIdSection *BuildId;
>     >     -  static InputSection *Common;
>     >        static SyntheticSection *Dynamic;
>     >        static StringTableSection *DynStrTab;
>     >        static SymbolTableBaseSection *DynSymTab;
>     >
>     >     Modified: lld/trunk/ELF/Writer.cpp
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_ELF_Writer.cpp-3Frev-
> 3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=Fo2NoJb9mo4IFU2cCnS7j5mYcFOr2N9yV4wo1Rosz-0&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/ELF/Writer.cpp (original)
>     >     +++ lld/trunk/ELF/Writer.cpp Fri Sep  8 09:22:43 2017
>     >     @@ -299,9 +299,9 @@ template <class ELFT> void Writer<ELFT>:
>     >          Add(InX::BuildId);
>     >        }
>     >
>     >     -  InX::Common = createCommonSection<ELFT>();
>     >     -  if (InX::Common)
>     >     -    Add(InX::Common);
>     >     +  auto Commons = createCommonSections();
>     >     +  for (InputSection *S : Commons)
>     >     +    Add(S);
>     >
>     >        InX::Bss = make<BssSection>(".bss");
>     >        Add(InX::Bss);
>     >
>     >     Modified: lld/trunk/test/ELF/common.s
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_test_ELF_common.s-3Frev-
> 3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=mZkHgNpDyXmZKHfqYrDVazT2K-8jzhgGbaDe_E27Jx4&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/test/ELF/common.s (original)
>     >     +++ lld/trunk/test/ELF/common.s Fri Sep  8 09:22:43 2017
>     >     @@ -12,13 +12,13 @@
>     >      // CHECK-NEXT: ]
>     >      // CHECK-NEXT: Address: 0x201000
>     >      // CHECK-NEXT: Offset:
>     >     -// CHECK-NEXT: Size: 22
>     >     +// CHECK-NEXT: Size: 36
>     >      // CHECK-NEXT: Link: 0
>     >      // CHECK-NEXT: Info: 0
>     >      // CHECK-NEXT: AddressAlignment: 16
>     >
>     >      // CHECK:      Name: sym1
>     >     -// CHECK-NEXT: Value: 0x201004
>     >     +// CHECK-NEXT: Value: 0x201000
>     >      // CHECK-NEXT: Size: 8
>     >      // CHECK-NEXT: Binding: Global
>     >      // CHECK-NEXT: Type: Object
>     >     @@ -26,7 +26,7 @@
>     >      // CHECK-NEXT: Section: .bss
>     >
>     >      // CHECK:      Name: sym2
>     >     -// CHECK-NEXT: Value: 0x20100C
>     >     +// CHECK-NEXT: Value: 0x201008
>     >      // CHECK-NEXT: Size: 8
>     >      // CHECK-NEXT: Binding: Global
>     >      // CHECK-NEXT: Type: Object
>     >     @@ -34,7 +34,7 @@
>     >      // CHECK-NEXT: Section: .bss
>     >
>     >      // CHECK:      Name: sym3
>     >     -// CHECK-NEXT: Value: 0x201014
>     >     +// CHECK-NEXT: Value: 0x201010
>     >      // CHECK-NEXT: Size: 2
>     >      // CHECK-NEXT: Binding: Global
>     >      // CHECK-NEXT: Type: Object
>     >     @@ -42,7 +42,7 @@
>     >      // CHECK-NEXT: Section: .bss
>     >
>     >      // CHECK:      Name: sym4
>     >     -// CHECK-NEXT: Value: 0x201000
>     >     +// CHECK-NEXT: Value: 0x201020
>     >      // CHECK-NEXT: Size: 4
>     >      // CHECK-NEXT: Binding: Global
>     >      // CHECK-NEXT: Type: Object
>     >
>     >     Added: lld/trunk/test/ELF/linkerscript/Inputs/common-filespec1.s
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_test_ELF_linkerscript_
> Inputs_common-2Dfilespec1.s-3Frev-3D312796-26view-3Dauto&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=OTi1bORibcoRGd3l3yexjTochdxrHao98pq17krBYGY&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/test/ELF/linkerscript/Inputs/common-filespec1.s
> (added)
>     >     +++ lld/trunk/test/ELF/linkerscript/Inputs/common-filespec1.s
> Fri Sep  8 09:22:43 2017
>     >     @@ -0,0 +1,2 @@
>     >     +.comm common_uniq_1,8,8
>     >     +.comm common_multiple,16,8
>     >
>     >     Added: lld/trunk/test/ELF/linkerscript/Inputs/common-filespec2.s
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_test_ELF_linkerscript_
> Inputs_common-2Dfilespec2.s-3Frev-3D312796-26view-3Dauto&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=L7MG3FqsEmFJk4lHR_DwrFl9wC4iy906C5ukU5K4-iI&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/test/ELF/linkerscript/Inputs/common-filespec2.s
> (added)
>     >     +++ lld/trunk/test/ELF/linkerscript/Inputs/common-filespec2.s
> Fri Sep  8 09:22:43 2017
>     >     @@ -0,0 +1,2 @@
>     >     +.comm common_uniq_2,16,16
>     >     +.comm common_multiple,32,8
>     >
>     >     Added: lld/trunk/test/ELF/linkerscript/common-exclude.s
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_test_ELF_linkerscript_
> common-2Dexclude.s-3Frev-3D312796-26view-3Dauto&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=b82z4zBHvvWyIABOGqEEBFCIHvF-HnzBQKeZMoUMU6E&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/test/ELF/linkerscript/common-exclude.s (added)
>     >     +++ lld/trunk/test/ELF/linkerscript/common-exclude.s Fri Sep  8
> 09:22:43 2017
>     >     @@ -0,0 +1,86 @@
>     >     +# REQUIRES: x86
>     >     +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o
> %tfile0.o
>     >     +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux
> %p/Inputs/common-filespec1.s -o %tfile1.o
>     >     +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux
> %p/Inputs/common-filespec2.s -o %tfile2.o
>     >     +# RUN: echo "SECTIONS { .common.incl : { *(EXCLUDE_FILE
> (*file2.o) COMMON) } .common.excl : { *(COMMON) } }" > %t.script
>     >     +# RUN: ld.lld -o %t1 --script %t.script %tfile0.o %tfile1.o
> %tfile2.o
>     >     +# RUN: llvm-readobj -s -t %t1 | FileCheck %s
>     >     +
>     >     +# Commons from file0 and file1 are not excluded, so they must
> be in .common.incl
>     >     +# Commons from file2 are excluded from the first rule and
> should be caught by
>     >     +# the second in .common.excl
>     >     +# CHECK:       Section {
>     >     +# CHECK:         Index:
>     >     +# CHECK:         Name: .common.incl
>     >     +# CHECK-NEXT:    Type: SHT_NOBITS
>     >     +# CHECK-NEXT:    Flags [
>     >     +# CHECK-NEXT:      SHF_ALLOC
>     >     +# CHECK-NEXT:      SHF_WRITE
>     >     +# CHECK-NEXT:    ]
>     >     +# CHECK-NEXT:    Address: 0x8
>     >     +# CHECK-NEXT:    Offset: 0x
>     >     +# CHECK-NEXT:    Size: 16
>     >     +# CHECK-NEXT:    Link: 0
>     >     +# CHECK-NEXT:    Info: 0
>     >     +# CHECK-NEXT:    AddressAlignment: 8
>     >     +# CHECK-NEXT:    EntrySize: 0
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Section {
>     >     +# CHECK:         Index:
>     >     +# CHECK:         Name: .common.excl
>     >     +# CHECK-NEXT:    Type: SHT_NOBITS
>     >     +# CHECK-NEXT:    Flags [
>     >     +# CHECK-NEXT:      SHF_ALLOC
>     >     +# CHECK-NEXT:      SHF_WRITE
>     >     +# CHECK-NEXT:    ]
>     >     +# CHECK-NEXT:    Address: 0x20
>     >     +# CHECK-NEXT:    Offset: 0x
>     >     +# CHECK-NEXT:    Size: 48
>     >     +# CHECK-NEXT:    Link: 0
>     >     +# CHECK-NEXT:    Info: 0
>     >     +# CHECK-NEXT:    AddressAlignment: 16
>     >     +# CHECK-NEXT:    EntrySize: 0
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Symbol {
>     >     +# CHECK:         Name: common_multiple
>     >     +# CHECK-NEXT:    Value: 0x20
>     >     +# CHECK-NEXT:    Size: 32
>     >     +# CHECK-NEXT:    Binding: Global
>     >     +# CHECK-NEXT:    Type: Object
>     >     +# CHECK-NEXT:    Other: 0
>     >     +# CHECK-NEXT:    Section: .common.excl
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Symbol {
>     >     +# CHECK:         Name: common_uniq_0
>     >     +# CHECK-NEXT:    Value: 0x8
>     >     +# CHECK-NEXT:    Size: 4
>     >     +# CHECK-NEXT:    Binding: Global
>     >     +# CHECK-NEXT:    Type: Object
>     >     +# CHECK-NEXT:    Other: 0
>     >     +# CHECK-NEXT:    Section: .common.incl
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Symbol {
>     >     +# CHECK:         Name: common_uniq_1
>     >     +# CHECK-NEXT:    Value: 0x10
>     >     +# CHECK-NEXT:    Size: 8
>     >     +# CHECK-NEXT:    Binding: Global
>     >     +# CHECK-NEXT:    Type: Object
>     >     +# CHECK-NEXT:    Other: 0
>     >     +# CHECK-NEXT:    Section: .common.incl
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Symbol {
>     >     +# CHECK:         Name: common_uniq_2
>     >     +# CHECK-NEXT:    Value: 0x40
>     >     +# CHECK-NEXT:    Size: 16
>     >     +# CHECK-NEXT:    Binding: Global
>     >     +# CHECK-NEXT:    Type: Object
>     >     +# CHECK-NEXT:    Other: 0
>     >     +# CHECK-NEXT:    Section: .common.excl
>     >     +# CHECK-NEXT:  }
>     >     +
>     >     +.globl _start
>     >     +_start:
>     >     +  jmp _start
>     >     +
>     >     +.comm common_uniq_0,4,4
>     >     +.comm common_multiple,8,8
>     >
>     >     Added: lld/trunk/test/ELF/linkerscript/common-filespec.s
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_test_ELF_linkerscript_
> common-2Dfilespec.s-3Frev-3D312796-26view-3Dauto&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=0nWbX2M4RGRI6BW72U7yMwZSQK9ofetuuUCD8Hs--XM&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/test/ELF/linkerscript/common-filespec.s (added)
>     >     +++ lld/trunk/test/ELF/linkerscript/common-filespec.s Fri Sep
> 8 09:22:43 2017
>     >     @@ -0,0 +1,105 @@
>     >     +# REQUIRES: x86
>     >     +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o
> %tfile0.o
>     >     +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux
> %p/Inputs/common-filespec1.s -o %tfile1.o
>     >     +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux
> %p/Inputs/common-filespec2.s -o %tfile2.o
>     >     +# RUN: echo "SECTIONS { .common_0 : { *file0.o(COMMON) }
> .common_1 : { *file1.o(COMMON) } .common_2 : { *file2.o(COMMON) } }" >
> %t.script
>     >     +# RUN: ld.lld -o %t1 --script %t.script %tfile0.o %tfile1.o
> %tfile2.o
>     >     +# RUN: llvm-readobj -s -t %t1 | FileCheck %s
>     >     +
>     >     +# Make sure all 3 sections are allocated and they have sizes
> and alignments
>     >     +# corresponding to the commons assigned to them
>     >     +# CHECK:       Section {
>     >     +# CHECK:         Index:
>     >     +# CHECK:         Name: .common_0
>     >     +# CHECK-NEXT:    Type: SHT_NOBITS
>     >     +# CHECK-NEXT:    Flags [
>     >     +# CHECK-NEXT:      SHF_ALLOC
>     >     +# CHECK-NEXT:      SHF_WRITE
>     >     +# CHECK-NEXT:    ]
>     >     +# CHECK-NEXT:    Address: 0x4
>     >     +# CHECK-NEXT:    Offset: 0x
>     >     +# CHECK-NEXT:    Size: 4
>     >     +# CHECK-NEXT:    Link: 0
>     >     +# CHECK-NEXT:    Info: 0
>     >     +# CHECK-NEXT:    AddressAlignment: 4
>     >     +# CHECK-NEXT:    EntrySize: 0
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Section {
>     >     +# CHECK:         Index:
>     >     +# CHECK:         Name: .common_1
>     >     +# CHECK-NEXT:    Type: SHT_NOBITS
>     >     +# CHECK-NEXT:    Flags [
>     >     +# CHECK-NEXT:      SHF_ALLOC
>     >     +# CHECK-NEXT:      SHF_WRITE
>     >     +# CHECK-NEXT:    ]
>     >     +# CHECK-NEXT:    Address: 0x8
>     >     +# CHECK-NEXT:    Offset: 0x
>     >     +# CHECK-NEXT:    Size: 8
>     >     +# CHECK-NEXT:    Link: 0
>     >     +# CHECK-NEXT:    Info: 0
>     >     +# CHECK-NEXT:    AddressAlignment: 8
>     >     +# CHECK-NEXT:    EntrySize: 0
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Section {
>     >     +# CHECK:         Index:
>     >     +# CHECK:         Name: .common_2
>     >     +# CHECK-NEXT:    Type: SHT_NOBITS
>     >     +# CHECK-NEXT:    Flags [
>     >     +# CHECK-NEXT:      SHF_ALLOC
>     >     +# CHECK-NEXT:      SHF_WRITE
>     >     +# CHECK-NEXT:    ]
>     >     +# CHECK-NEXT:    Address: 0x10
>     >     +# CHECK-NEXT:    Offset: 0x
>     >     +# CHECK-NEXT:    Size: 48
>     >     +# CHECK-NEXT:    Link: 0
>     >     +# CHECK-NEXT:    Info: 0
>     >     +# CHECK-NEXT:    AddressAlignment: 16
>     >     +# CHECK-NEXT:    EntrySize: 0
>     >     +# CHECK-NEXT:  }
>     >     +
>     >     +# Commons with unique name in each file must be assigned to
> that file's section.
>     >     +# For a common with multiple definitions, the largest one wins
> and it must be
>     >     +# assigned to the section from the file which provided the
> winning def
>     >     +# CHECK:       Symbol {
>     >     +# CHECK:         Name: common_multiple
>     >     +# CHECK-NEXT:    Value: 0x10
>     >     +# CHECK-NEXT:    Size: 32
>     >     +# CHECK-NEXT:    Binding: Global
>     >     +# CHECK-NEXT:    Type: Object
>     >     +# CHECK-NEXT:    Other: 0
>     >     +# CHECK-NEXT:    Section: .common_2
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Symbol {
>     >     +# CHECK:         Name: common_uniq_0
>     >     +# CHECK-NEXT:    Value: 0x4
>     >     +# CHECK-NEXT:    Size: 4
>     >     +# CHECK-NEXT:    Binding: Global
>     >     +# CHECK-NEXT:    Type: Object
>     >     +# CHECK-NEXT:    Other: 0
>     >     +# CHECK-NEXT:    Section: .common_0
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Symbol {
>     >     +# CHECK:         Name: common_uniq_1
>     >     +# CHECK-NEXT:    Value: 0x8
>     >     +# CHECK-NEXT:    Size: 8
>     >     +# CHECK-NEXT:    Binding: Global
>     >     +# CHECK-NEXT:    Type: Object
>     >     +# CHECK-NEXT:    Other: 0
>     >     +# CHECK-NEXT:    Section: .common_1
>     >     +# CHECK-NEXT:  }
>     >     +# CHECK:       Symbol {
>     >     +# CHECK:         Name: common_uniq_2
>     >     +# CHECK-NEXT:    Value: 0x30
>     >     +# CHECK-NEXT:    Size: 16
>     >     +# CHECK-NEXT:    Binding: Global
>     >     +# CHECK-NEXT:    Type: Object
>     >     +# CHECK-NEXT:    Other: 0
>     >     +# CHECK-NEXT:    Section: .common_2
>     >     +# CHECK-NEXT:  }
>     >     +
>     >     +.globl _start
>     >     +_start:
>     >     +  jmp _start
>     >     +
>     >     +.comm common_uniq_0,4,4
>     >     +.comm common_multiple,8,8
>     >
>     >     Modified: lld/trunk/test/ELF/linkerscript/common.s
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_test_ELF_linkerscript_
> common.s-3Frev-3D312796-26r1-3D312795-26r2-3D312796-26view-
> 3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=
> nQIMrFkM1t_gqODnbXQIOkB-BBcc2v2l4j7arjM9y4k&s=
> vceDSQYVgZInI9HO6kBb02n0VfALTZs8ZmXemo39dYM&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/test/ELF/linkerscript/common.s (original)
>     >     +++ lld/trunk/test/ELF/linkerscript/common.s Fri Sep  8
> 09:22:43 2017
>     >     @@ -4,8 +4,6 @@
>     >      # RUN: ld.lld -o %t1 --script %t.script %t
>     >      # RUN: llvm-readobj -s -t %t1 | FileCheck %s
>     >
>     >     -# q2 alignment is greater than q1, so it should have smaller
> offset
>     >     -# because of sorting
>     >      # CHECK:       Section {
>     >      # CHECK:         Index:
>     >      # CHECK:         Name: .common
>     >     @@ -16,7 +14,7 @@
>     >      # CHECK-NEXT:    ]
>     >      # CHECK-NEXT:    Address: 0x200
>     >      # CHECK-NEXT:    Offset: 0x
>     >     -# CHECK-NEXT:    Size: 256
>     >     +# CHECK-NEXT:    Size: 384
>     >      # CHECK-NEXT:    Link: 0
>     >      # CHECK-NEXT:    Info: 0
>     >      # CHECK-NEXT:    AddressAlignment: 256
>     >     @@ -24,7 +22,7 @@
>     >      # CHECK-NEXT:  }
>     >      # CHECK:       Symbol {
>     >      # CHECK:         Name: q1
>     >     -# CHECK-NEXT:    Value: 0x280
>     >     +# CHECK-NEXT:    Value: 0x200
>     >      # CHECK-NEXT:    Size: 128
>     >      # CHECK-NEXT:    Binding: Global
>     >      # CHECK-NEXT:    Type: Object
>     >     @@ -33,7 +31,7 @@
>     >      # CHECK-NEXT:  }
>     >      # CHECK-NEXT:  Symbol {
>     >      # CHECK-NEXT:    Name: q2
>     >     -# CHECK-NEXT:    Value: 0x200
>     >     +# CHECK-NEXT:    Value: 0x300
>     >      # CHECK-NEXT:    Size: 128
>     >      # CHECK-NEXT:    Binding: Global
>     >      # CHECK-NEXT:    Type: Object
>     >
>     >     Modified: lld/trunk/test/ELF/linkerscript/discard-section-err.s
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_test_ELF_linkerscript_
> discard-2Dsection-2Derr.s-3Frev-3D312796-26r1-3D312795-
> 26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=
> o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-BBcc2v2l4j7arjM9y4k&s=
> MXuje1LylNbUM26IDwE5EEYRU5bBZe69uXFDKmzKh4g&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/test/ELF/linkerscript/discard-section-err.s
> (original)
>     >     +++ lld/trunk/test/ELF/linkerscript/discard-section-err.s Fri
> Sep  8 09:22:43 2017
>     >     @@ -22,9 +22,4 @@
>     >      # RUN:   FileCheck -check-prefix=DYNSTR %s
>     >      # DYNSTR: discarding .dynstr section is not allowed
>     >
>     >     -# RUN: echo "SECTIONS { /DISCARD/ : { *(COMMON) } }" > %t.script
>     >     -# RUN: not ld.lld -pie -o %t --script %t.script %t.o 2>&1 | \
>     >     -# RUN:   FileCheck -check-prefix=COMMON %s
>     >     -# COMMON: discarding COMMON section is not allowed
>     >     -
>     >      .comm foo,4,4
>     >
>     >     Modified: lld/trunk/test/ELF/map-file.s
>     >     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.
> org_viewvc_llvm-2Dproject_lld_trunk_test_ELF_map-2Dfile.s-
> 3Frev-3D312796-26r1-3D312795-26r2-3D312796-26view-3Ddiff&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=0Y0YxzC27SE0tTpInsY5fAZExRhv6WOmWe4YPF4EVhY&e=
>     >     ============================================================
> ==================
>     >     --- lld/trunk/test/ELF/map-file.s (original)
>     >     +++ lld/trunk/test/ELF/map-file.s Fri Sep  8 09:22:43 2017
>     >     @@ -47,7 +47,7 @@ labs = 0x1AB5
>     >      // CHECK-NEXT: 0000000000201014 0000000000000001     4
>  {{.*}}{{/|\\}}map-file.s.tmp4.a(map-file.s.tmp4.o):(.text)
>     >      // CHECK-NEXT: 0000000000201014 0000000000000000     0
>        baz
>     >      // CHECK-NEXT: 0000000000202000 0000000000000004    16 .bss
>     >     -// CHECK-NEXT: 0000000000202000 0000000000000004    16
>  <internal>:(COMMON)
>     >     +// CHECK-NEXT: 0000000000202000 0000000000000004    16
>  {{.*}}{{/|\\}}map-file.s.tmp1.o:(COMMON)
>     >      // CHECK-NEXT: 0000000000202000 0000000000000004     0
>        common
>     >      // CHECK-NEXT: 0000000000000000 0000000000000008     1 .comment
>     >      // CHECK-NEXT: 0000000000000000 0000000000000008     1
>  <internal>:(.comment)
>     >
>     >
>     >     _______________________________________________
>     >     llvm-commits mailing list
>     >     llvm-commits at lists.llvm.org
>     >     https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.
> llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=DwIGaQ&c=
> 5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=nQIMrFkM1t_gqODnbXQIOkB-
> BBcc2v2l4j7arjM9y4k&s=WT8EYeg7stKLcN9t6TUCBTYRJqw9w1KPiCJ8SkTI_nU&e=
>     >
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170912/a87cdf77/attachment.html>


More information about the llvm-commits mailing list