[lld] r297714 - [ELF] - Step to combine LinkerScript and LinkerScriptBase

Rafael Avila de Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 15 05:51:17 PDT 2017


Thanks!
George Rimar via llvm-commits <llvm-commits at lists.llvm.org> writes:

> Author: grimar
> Date: Tue Mar 14 04:03:53 2017
> New Revision: 297714
>
> URL: http://llvm.org/viewvc/llvm-project?rev=297714&view=rev
> Log:
> [ELF] - Step to combine LinkerScript and LinkerScriptBase
>
> We can move all not templated functionality to LinkerScriptBase.
> Patch do that for hasPhdrsCommands() and shows how it helps to detemplate
> things in other places.
>
> Probably we should be able to merge these 2 classes into single one after such steps.
> Even if not, it still looks as reasonable cleanup for me.
>
> Differential revision: https://reviews.llvm.org/D30895
>
> Modified:
>     lld/trunk/ELF/LinkerScript.cpp
>     lld/trunk/ELF/LinkerScript.h
>     lld/trunk/ELF/Writer.cpp
>     lld/trunk/ELF/Writer.h
>
> Modified: lld/trunk/ELF/LinkerScript.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=297714&r1=297713&r2=297714&view=diff
> ==============================================================================
> --- lld/trunk/ELF/LinkerScript.cpp (original)
> +++ lld/trunk/ELF/LinkerScript.cpp Tue Mar 14 04:03:53 2017
> @@ -792,7 +792,7 @@ void LinkerScript<ELFT>::assignAddresses
>        Sec->Addr = 0;
>    }
>  
> -  allocateHeaders<ELFT>(Phdrs, *OutputSections, MinVA);
> +  allocateHeaders(Phdrs, *OutputSections, MinVA);
>  }
>  
>  // Creates program headers as instructed by PHDRS linker script command.
> @@ -902,10 +902,6 @@ template <class ELFT> int LinkerScript<E
>    return INT_MAX;
>  }
>  
> -template <class ELFT> bool LinkerScript<ELFT>::hasPhdrsCommands() {
> -  return !Opt.PhdrsCommands.empty();
> -}
> -
>  template <class ELFT>
>  OutputSection *LinkerScript<ELFT>::getOutputSection(const Twine &Loc,
>                                                      StringRef Name) {
>
> Modified: lld/trunk/ELF/LinkerScript.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=297714&r1=297713&r2=297714&view=diff
> ==============================================================================
> --- lld/trunk/ELF/LinkerScript.h (original)
> +++ lld/trunk/ELF/LinkerScript.h Tue Mar 14 04:03:53 2017
> @@ -205,20 +205,6 @@ struct MemoryRegion {
>    uint32_t NegFlags;
>  };
>  
> -class LinkerScriptBase {
> -protected:
> -  ~LinkerScriptBase() = default;
> -  OutputSection *Aether;
> -
> -public:
> -  virtual uint64_t getSymbolValue(const Twine &Loc, StringRef S) = 0;
> -  uint64_t getDot() { return getSymbolValue("", "."); }
> -  virtual bool isDefined(StringRef S) = 0;
> -  virtual bool isAbsolute(StringRef S) = 0;
> -  virtual OutputSection *getSymbolSection(StringRef S) = 0;
> -  virtual OutputSection *getOutputSection(const Twine &Loc, StringRef S) = 0;
> -  virtual uint64_t getOutputSectionSize(StringRef S) = 0;
> -};
>  
>  // ScriptConfiguration holds linker script parse results.
>  struct ScriptConfiguration {
> @@ -240,6 +226,26 @@ struct ScriptConfiguration {
>  
>  extern ScriptConfiguration *ScriptConfig;
>  
> +class LinkerScriptBase {
> +protected:
> +  ~LinkerScriptBase() = default;
> +  OutputSection *Aether;
> +
> +  // "ScriptConfig" is a bit too long, so define a short name for it.
> +  ScriptConfiguration &Opt = *ScriptConfig;
> +
> +public:
> +  bool hasPhdrsCommands() { return !Opt.PhdrsCommands.empty(); }
> +
> +  virtual uint64_t getSymbolValue(const Twine &Loc, StringRef S) = 0;
> +  uint64_t getDot() { return getSymbolValue("", "."); }
> +  virtual bool isDefined(StringRef S) = 0;
> +  virtual bool isAbsolute(StringRef S) = 0;
> +  virtual OutputSection *getSymbolSection(StringRef S) = 0;
> +  virtual OutputSection *getOutputSection(const Twine &Loc, StringRef S) = 0;
> +  virtual uint64_t getOutputSectionSize(StringRef S) = 0;
> +};
> +
>  // This is a runner of the linker script.
>  template <class ELFT> class LinkerScript final : public LinkerScriptBase {
>    typedef typename ELFT::uint uintX_t;
> @@ -264,7 +270,6 @@ public:
>    void assignOffsets(OutputSectionCommand *Cmd);
>    void placeOrphanSections();
>    void assignAddresses(std::vector<PhdrEntry> &Phdrs);
> -  bool hasPhdrsCommands();
>    uint64_t getSymbolValue(const Twine &Loc, StringRef S) override;
>    bool isDefined(StringRef S) override;
>    bool isAbsolute(StringRef S) override;
> @@ -287,9 +292,6 @@ private:
>    std::vector<InputSectionBase *>
>    createInputSectionList(OutputSectionCommand &Cmd);
>  
> -  // "ScriptConfig" is a bit too long, so define a short name for it.
> -  ScriptConfiguration &Opt = *ScriptConfig;
> -
>    std::vector<size_t> getPhdrIndices(StringRef SectionName);
>    size_t getPhdrIndex(const Twine &Loc, StringRef PhdrName);
>  
>
> Modified: lld/trunk/ELF/Writer.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=297714&r1=297713&r2=297714&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Writer.cpp (original)
> +++ lld/trunk/ELF/Writer.cpp Tue Mar 14 04:03:53 2017
> @@ -1439,7 +1439,6 @@ template <class ELFT> void Writer<ELFT>:
>    }
>  }
>  
> -template <class ELFT>
>  bool elf::allocateHeaders(std::vector<PhdrEntry> &Phdrs,
>                            ArrayRef<OutputSection *> OutputSections,
>                            uint64_t Min) {
> @@ -1466,7 +1465,7 @@ bool elf::allocateHeaders(std::vector<Ph
>    Out::ElfHeader->Addr = Min;
>    Out::ProgramHeaders->Addr = Min + Out::ElfHeader->Size;
>  
> -  if (Script<ELFT>::X->hasPhdrsCommands())
> +  if (ScriptBase->hasPhdrsCommands())
>      return true;
>  
>    if (FirstPTLoad->First)
> @@ -1495,7 +1494,7 @@ template <class ELFT> void Writer<ELFT>:
>      for (const auto &P : Config->SectionStartMap)
>        Min = std::min(Min, P.second);
>  
> -  AllocateHeader = allocateHeaders<ELFT>(Phdrs, OutputSections, Min);
> +  AllocateHeader = allocateHeaders(Phdrs, OutputSections, Min);
>  }
>  
>  // Assign VAs (addresses at run-time) to output sections.
> @@ -1877,19 +1876,6 @@ template void elf::writeResult<ELF32BE>(
>  template void elf::writeResult<ELF64LE>();
>  template void elf::writeResult<ELF64BE>();
>  
> -template bool elf::allocateHeaders<ELF32LE>(std::vector<PhdrEntry> &,
> -                                            ArrayRef<OutputSection *>,
> -                                            uint64_t);
> -template bool elf::allocateHeaders<ELF32BE>(std::vector<PhdrEntry> &,
> -                                            ArrayRef<OutputSection *>,
> -                                            uint64_t);
> -template bool elf::allocateHeaders<ELF64LE>(std::vector<PhdrEntry> &,
> -                                            ArrayRef<OutputSection *>,
> -                                            uint64_t);
> -template bool elf::allocateHeaders<ELF64BE>(std::vector<PhdrEntry> &,
> -                                            ArrayRef<OutputSection *>,
> -                                            uint64_t);
> -
>  template bool elf::isRelroSection<ELF32LE>(const OutputSection *);
>  template bool elf::isRelroSection<ELF32BE>(const OutputSection *);
>  template bool elf::isRelroSection<ELF64LE>(const OutputSection *);
>
> Modified: lld/trunk/ELF/Writer.h
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=297714&r1=297713&r2=297714&view=diff
> ==============================================================================
> --- lld/trunk/ELF/Writer.h (original)
> +++ lld/trunk/ELF/Writer.h Tue Mar 14 04:03:53 2017
> @@ -49,7 +49,6 @@ struct PhdrEntry {
>  
>  llvm::StringRef getOutputSectionName(llvm::StringRef Name);
>  
> -template <class ELFT>
>  bool allocateHeaders(std::vector<PhdrEntry> &, llvm::ArrayRef<OutputSection *>,
>                       uint64_t Min);
>  
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list