[lld] r316251 - Don't call buildSectionOrder multiple times.

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 20 17:22:33 PDT 2017


On the same machine gold takes about 0.7 seconds to link the kernel :-)

Cheers,
Rafael

Shoaib Meenai <smeenai at fb.com> writes:

> Rui had a talk on LLD at the developer meeting, and the talk included some
> link time numbers. The Linux kernel was the only instance of gold being faster
> than LLD, and a lot of people (including myself) were wondering why that was
> the case. This is awesome :)
>
> On 10/20/17, 5:05 PM, "llvm-commits on behalf of Rafael Espindola via llvm-commits" <llvm-commits-bounces at lists.llvm.org on behalf of llvm-commits at lists.llvm.org> wrote:
>
>     Author: rafael
>     Date: Fri Oct 20 17:05:01 2017
>     New Revision: 316251
>     
>     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D316251-26view-3Drev&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=4IyeZA5wFDIztRZwT5Ikft6eluO180gbHODF81Mf3Ug&s=nNq0DR5WWlYGE3cjull_12CMiIvQooETqug4_X5eGLk&e=
>     Log:
>     Don't call buildSectionOrder multiple times.
>     
>     This takes linking the linux kernel from 1.52s to 0.58s.
>     
>     Modified:
>         lld/trunk/ELF/InputSection.cpp
>         lld/trunk/ELF/LinkerScript.cpp
>         lld/trunk/ELF/LinkerScript.h
>     
>     Modified: lld/trunk/ELF/InputSection.cpp
>     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputSection.cpp-3Frev-3D316251-26r1-3D316250-26r2-3D316251-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=4IyeZA5wFDIztRZwT5Ikft6eluO180gbHODF81Mf3Ug&s=Behy9uothqGelaSOG4LvVOUM2TN8W9eggw9YF8Vj97o&e=
>     ==============================================================================
>     --- lld/trunk/ELF/InputSection.cpp (original)
>     +++ lld/trunk/ELF/InputSection.cpp Fri Oct 20 17:05:01 2017
>     @@ -46,6 +46,10 @@ std::string lld::toString(const InputSec
>      }
>      
>      DenseMap<SectionBase *, int> elf::buildSectionOrder() {
>     +  DenseMap<SectionBase *, int> SectionOrder;
>     +  if (Config->SymbolOrderingFile.empty())
>     +    return SectionOrder;
>     +
>        // Build a map from symbols to their priorities. Symbols that didn't
>        // appear in the symbol ordering file have the lowest priority 0.
>        // All explicitly mentioned symbols have negative (higher) priorities.
>     @@ -55,7 +59,6 @@ DenseMap<SectionBase *, int> elf::buildS
>          SymbolOrder.insert({S, Priority++});
>      
>        // Build a map from sections to their priorities.
>     -  DenseMap<SectionBase *, int> SectionOrder;
>        for (InputFile *File : ObjectFiles) {
>          for (SymbolBody *Body : File->getSymbols()) {
>            auto *D = dyn_cast<DefinedRegular>(Body);
>     
>     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-3D316251-26r1-3D316250-26r2-3D316251-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=4IyeZA5wFDIztRZwT5Ikft6eluO180gbHODF81Mf3Ug&s=Je_3iU9P1LF12KLZrW5An0DBWzvNjnYc1jc4UWEUv0g&e=
>     ==============================================================================
>     --- lld/trunk/ELF/LinkerScript.cpp (original)
>     +++ lld/trunk/ELF/LinkerScript.cpp Fri Oct 20 17:05:01 2017
>     @@ -274,9 +274,9 @@ static void sortInputSections(
>      
>      // Compute and remember which sections the InputSectionDescription matches.
>      std::vector<InputSection *>
>     -LinkerScript::computeInputSections(const InputSectionDescription *Cmd) {
>     +LinkerScript::computeInputSections(const InputSectionDescription *Cmd,
>     +                                   const DenseMap<SectionBase *, int> &Order) {
>        std::vector<InputSection *> Ret;
>     -  DenseMap<SectionBase *, int> Order = buildSectionOrder();
>      
>        // Collects all sections that satisfy constraints of Cmd.
>        for (const SectionPattern &Pat : Cmd->SectionPatterns) {
>     @@ -326,13 +326,13 @@ void LinkerScript::discard(ArrayRef<Inpu
>        }
>      }
>      
>     -std::vector<InputSection *>
>     -LinkerScript::createInputSectionList(OutputSection &OutCmd) {
>     +std::vector<InputSection *> LinkerScript::createInputSectionList(
>     +    OutputSection &OutCmd, const DenseMap<SectionBase *, int> &Order) {
>        std::vector<InputSection *> Ret;
>      
>        for (BaseCommand *Base : OutCmd.SectionCommands) {
>          if (auto *Cmd = dyn_cast<InputSectionDescription>(Base)) {
>     -      Cmd->Sections = computeInputSections(Cmd);
>     +      Cmd->Sections = computeInputSections(Cmd, Order);
>            Ret.insert(Ret.end(), Cmd->Sections.begin(), Cmd->Sections.end());
>          }
>        }
>     @@ -359,6 +359,7 @@ void LinkerScript::processSectionCommand
>        Ctx = make_unique<AddressState>();
>        Ctx->OutSec = Aether;
>      
>     +  DenseMap<SectionBase *, int> Order = buildSectionOrder();
>        // Add input sections to output sections.
>        for (size_t I = 0; I < SectionCommands.size(); ++I) {
>          // Handle symbol assignments outside of any output section.
>     @@ -368,7 +369,7 @@ void LinkerScript::processSectionCommand
>          }
>      
>          if (auto *Sec = dyn_cast<OutputSection>(SectionCommands[I])) {
>     -      std::vector<InputSection *> V = createInputSectionList(*Sec);
>     +      std::vector<InputSection *> V = createInputSectionList(*Sec, Order);
>      
>            // The output section name `/DISCARD/' is special.
>            // Any input section assigned to it is discarded.
>     
>     Modified: lld/trunk/ELF/LinkerScript.h
>     URL: https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LinkerScript.h-3Frev-3D316251-26r1-3D316250-26r2-3D316251-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=4IyeZA5wFDIztRZwT5Ikft6eluO180gbHODF81Mf3Ug&s=pbQ0x-JYey0QxqiIAbrRNWhQ6PJLgAuj9Mu8zFqXRco&e=
>     ==============================================================================
>     --- lld/trunk/ELF/LinkerScript.h (original)
>     +++ lld/trunk/ELF/LinkerScript.h Fri Oct 20 17:05:01 2017
>     @@ -205,9 +205,12 @@ class LinkerScript final {
>        void setDot(Expr E, const Twine &Loc, bool InSec);
>      
>        std::vector<InputSection *>
>     -  computeInputSections(const InputSectionDescription *);
>     +  computeInputSections(const InputSectionDescription *,
>     +                       const llvm::DenseMap<SectionBase *, int> &Order);
>      
>     -  std::vector<InputSection *> createInputSectionList(OutputSection &Cmd);
>     +  std::vector<InputSection *>
>     +  createInputSectionList(OutputSection &Cmd,
>     +                         const llvm::DenseMap<SectionBase *, int> &Order);
>      
>        std::vector<size_t> getPhdrIndices(OutputSection *Sec);
>      
>     
>     
>     _______________________________________________
>     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=4IyeZA5wFDIztRZwT5Ikft6eluO180gbHODF81Mf3Ug&s=aiE8jh76imSNJakqpdctbtvdseFdDLNUrnswv8Z4YiQ&e=
>     


More information about the llvm-commits mailing list