[lld] r275162 - [ELF] - Make few members of Writer to be global and export them for reuse

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 12 01:50:43 PDT 2016


Author: grimar
Date: Tue Jul 12 03:50:42 2016
New Revision: 275162

URL: http://llvm.org/viewvc/llvm-project?rev=275162&view=rev
Log:
[ELF] - Make few members of Writer to be global and export them for reuse

Creating sections on linkerscript side requires some methods
that can be reused if are exported from writer.

Patch implements that change.

Differential revision: http://reviews.llvm.org/D20104

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/Writer.cpp
    lld/trunk/ELF/Writer.h

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=275162&r1=275161&r2=275162&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Jul 12 03:50:42 2016
@@ -12,6 +12,7 @@
 #include "EhFrame.h"
 #include "Error.h"
 #include "InputFiles.h"
+#include "LinkerScript.h"
 #include "OutputSections.h"
 #include "Target.h"
 #include "Thunks.h"
@@ -27,6 +28,11 @@ using namespace llvm::support::endian;
 using namespace lld;
 using namespace lld::elf;
 
+template <class ELFT> bool elf::isDiscarded(InputSectionBase<ELFT> *S) {
+  return !S || S == &InputSection<ELFT>::Discarded || !S->Live ||
+         Script<ELFT>::X->isDiscarded(S);
+}
+
 template <class ELFT>
 InputSectionBase<ELFT>::InputSectionBase(elf::ObjectFile<ELFT> *File,
                                          const Elf_Shdr *Header,
@@ -644,6 +650,11 @@ bool MipsOptionsInputSection<ELFT>::clas
   return S->SectionKind == InputSectionBase<ELFT>::MipsOptions;
 }
 
+template bool elf::isDiscarded<ELF32LE>(InputSectionBase<ELF32LE> *);
+template bool elf::isDiscarded<ELF32BE>(InputSectionBase<ELF32BE> *);
+template bool elf::isDiscarded<ELF64LE>(InputSectionBase<ELF64LE> *);
+template bool elf::isDiscarded<ELF64BE>(InputSectionBase<ELF64BE> *);
+
 template class elf::InputSectionBase<ELF32LE>;
 template class elf::InputSectionBase<ELF32BE>;
 template class elf::InputSectionBase<ELF64LE>;

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=275162&r1=275161&r2=275162&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Jul 12 03:50:42 2016
@@ -21,6 +21,8 @@
 namespace lld {
 namespace elf {
 
+template <class ELFT> bool isDiscarded(InputSectionBase<ELFT> *S);
+
 class SymbolBody;
 
 template <class ELFT> class ICF;

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=275162&r1=275161&r2=275162&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Jul 12 03:50:42 2016
@@ -74,8 +74,6 @@ private:
   void writeHeader();
   void writeSections();
   void writeBuildId();
-  bool isDiscarded(InputSectionBase<ELFT> *IS) const;
-  StringRef getOutputSectionName(InputSectionBase<ELFT> *S) const;
   bool needsInterpSection() const {
     return !Symtab.getSharedFiles().empty() && !Config->DynamicLinker.empty();
   }
@@ -103,6 +101,30 @@ private:
 };
 } // anonymous namespace
 
+template <class ELFT>
+StringRef elf::getOutputSectionName(InputSectionBase<ELFT> *S) {
+  StringRef Dest = Script<ELFT>::X->getOutputSection(S);
+  if (!Dest.empty())
+    return Dest;
+
+  StringRef Name = S->getSectionName();
+  for (StringRef V : {".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.",
+                      ".init_array.", ".fini_array.", ".ctors.", ".dtors.",
+                      ".tbss.", ".gcc_except_table.", ".tdata."})
+    if (Name.startswith(V))
+      return V.drop_back();
+  return Name;
+}
+
+template <class ELFT>
+void elf::reportDiscarded(InputSectionBase<ELFT> *IS,
+                          const std::unique_ptr<elf::ObjectFile<ELFT>> &File) {
+  if (!Config->PrintGcSections || !IS || IS->Live)
+    return;
+  errs() << "removing unused section from '" << IS->getSectionName()
+         << "' in file '" << File->getName() << "'\n";
+}
+
 template <class ELFT> void elf::writeResult(SymbolTable<ELFT> *Symtab) {
   typedef typename ELFT::uint uintX_t;
   typedef typename ELFT::Ehdr Elf_Ehdr;
@@ -474,36 +496,6 @@ void Writer<ELFT>::addCommonSymbols(std:
 }
 
 template <class ELFT>
-StringRef Writer<ELFT>::getOutputSectionName(InputSectionBase<ELFT> *S) const {
-  StringRef Dest = Script<ELFT>::X->getOutputSection(S);
-  if (!Dest.empty())
-    return Dest;
-
-  StringRef Name = S->getSectionName();
-  for (StringRef V : {".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.",
-                      ".init_array.", ".fini_array.", ".ctors.", ".dtors.",
-                      ".tbss.", ".gcc_except_table.", ".tdata."})
-    if (Name.startswith(V))
-      return V.drop_back();
-  return Name;
-}
-
-template <class ELFT>
-void reportDiscarded(InputSectionBase<ELFT> *IS,
-                     const std::unique_ptr<elf::ObjectFile<ELFT>> &File) {
-  if (!Config->PrintGcSections || !IS || IS->Live)
-    return;
-  llvm::errs() << "removing unused section from '" << IS->getSectionName()
-               << "' in file '" << File->getName() << "'\n";
-}
-
-template <class ELFT>
-bool Writer<ELFT>::isDiscarded(InputSectionBase<ELFT> *S) const {
-  return !S || S == &InputSection<ELFT>::Discarded || !S->Live ||
-         Script<ELFT>::X->isDiscarded(S);
-}
-
-template <class ELFT>
 static Symbol *addOptionalSynthetic(SymbolTable<ELFT> &Table, StringRef Name,
                                     OutputSectionBase<ELFT> *Sec,
                                     typename ELFT::uint Val) {

Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=275162&r1=275161&r2=275162&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Tue Jul 12 03:50:42 2016
@@ -10,14 +10,28 @@
 #ifndef LLD_ELF_WRITER_H
 #define LLD_ELF_WRITER_H
 
+#include <memory>
+
+namespace llvm {
+  class StringRef;
+}
+
 namespace lld {
 namespace elf {
-
+template <class ELFT> class InputSectionBase;
+template <class ELFT> class ObjectFile;
 template <class ELFT> class SymbolTable;
 
 template <class ELFT> void writeResult(SymbolTable<ELFT> *Symtab);
 
 template <class ELFT> void markLive();
+
+template <class ELFT>
+llvm::StringRef getOutputSectionName(InputSectionBase<ELFT> *S);
+
+template <class ELFT>
+void reportDiscarded(InputSectionBase<ELFT> *IS,
+                     const std::unique_ptr<elf::ObjectFile<ELFT>> &File);
 }
 }
 




More information about the llvm-commits mailing list